Suzuha: a shim for gettimeofday

In my daily work, I have to develop a logging system for realtime applications. Nothing too complex though, but it's nice to have when your system crashes and you don't know why.

I need to do a bit of integration testing, and I want to automatize it. Obviously, requirements talk about possible timing issues and some time-based business logic, so I have to test it, and using sleep is not an option.

How hard can it be to mock gettimeofday ? In C++, it requires a bit of work, but it's not impossible. At least, a bit more work than installing freezegun or time warp for projects in scripting languages such as Python or Ruby :D

After a fast search on github, I found two interesting projects: mocktime and gtod-shim. The main problem of the former is I don't want to change my actual code to call something different than gettimeofday. 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.

After some modifications (mainly make users able to change the time shift using settimeofday and automated testing), suzuha is now released in beta. You can read more in the README, and check the unit tests.