<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Diplomats can code too! (Posts about gettimeofday)</title><link>https://wintermade.it/blog/</link><description></description><atom:link href="https://wintermade.it/blog/categories/gettimeofday.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Sat, 05 Oct 2019 08:14:28 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Suzuha: a shim for gettimeofday</title><link>https://wintermade.it/blog/posts/suzuha-a-shim-for-gettimeofday.html</link><dc:creator>Alessandro Balzano</dc:creator><description>&lt;div&gt;&lt;p&gt;In my daily work, I have to develop a logging system for realtime applications.
Nothing too complex though, but it's &lt;em&gt;nice to have&lt;/em&gt; when your system crashes and you don't know why.&lt;/p&gt;
&lt;p&gt;I need to do a bit of integration testing, and I want to &lt;a class="reference external" href="https://wintermade.it/blog/posts/embeddable-scripting-languages-are-for-integration-testing-too.html"&gt;automatize&lt;/a&gt; it.
Obviously, requirements talk about possible timing issues and some time-based business logic,
so I have to test it, and using &lt;tt class="docutils literal"&gt;sleep&lt;/tt&gt; is not an option.&lt;/p&gt;
&lt;p&gt;How hard can it be to mock &lt;tt class="docutils literal"&gt;gettimeofday&lt;/tt&gt; ?
In C++, it requires a bit of work, but it's not impossible.
At least, a bit more work than installing &lt;a class="reference external" href="https://github.com/spulec/freezegun"&gt;freezegun&lt;/a&gt; or &lt;a class="reference external" href="https://github.com/harvesthq/time-warp"&gt;time warp&lt;/a&gt; for projects in
scripting languages such as Python or Ruby :D&lt;/p&gt;
&lt;p&gt;After a fast search on github, I found two interesting projects: &lt;a class="reference external" href="https://github.com/brettdh/mocktime"&gt;mocktime&lt;/a&gt;
and &lt;a class="reference external" href="https://github.com/dtzWill/gtod-shim"&gt;gtod-shim&lt;/a&gt;. The main problem of the former is I don't want to change my actual code to
call something different than &lt;tt class="docutils literal"&gt;gettimeofday&lt;/tt&gt;.
The latter was promising: a dynamic library you have to load at startup
that changes the runtime behaviour of time functions, making it suitable to test
time-related bugs in various applications.&lt;/p&gt;
&lt;p&gt;After some modifications (mainly make users able to change the time shift using
&lt;tt class="docutils literal"&gt;settimeofday&lt;/tt&gt; and automated testing), &lt;a class="reference external" href="https://github.com/alfateam123/suzuha"&gt;suzuha&lt;/a&gt; is now released in beta.
You can read more in the README, and check the unit tests.&lt;/p&gt;&lt;/div&gt;</description><category>c++</category><category>gettimeofday</category><guid>https://wintermade.it/blog/posts/suzuha-a-shim-for-gettimeofday.html</guid><pubDate>Sat, 26 Sep 2015 21:44:05 GMT</pubDate></item></channel></rss>