libfaketime for Windows
Short answer: libfaketime does not run on Windows, and cannot -
it is built on LD_PRELOAD, which Windows does not have. Chrono Mock is
the same idea built the way Windows allows.
Why it cannot simply be ported
libfaketime works by having the
dynamic loader place a small library in front of the C library, so that a program's
calls to time() reach the replacement first. That hook is
LD_PRELOAD on Linux and DYLD_INSERT_LIBRARIES on macOS.
Its own README lists exactly those two platforms.
Windows has no equivalent, and its clock does not live behind one function anyway. Applications read the time through the Win32 API, through the native API below it, and through whatever their runtime wraps around either - so the Windows version of this idea is a library injected into the target process, redirecting a set of exported functions rather than one symbol.
The flags, mapped across
| libfaketime | Chrono Mock |
|---|---|
FAKETIME="2020-12-24 20:30:00" |
--at 2020-12-24T20:30:00 |
FAKETIME="+14d" |
--at +14d |
FAKETIME="-10m" |
--at -10m |
FAKETIME="+0 x2" |
--mode x2 |
FAKETIME_DONT_FAKE_MONOTONIC=1 |
the default here - see below |
LD_PRELOAD=libfaketime.so.1 |
nothing to set - the tool injects |
So the two sides of the same test look like this:
# Linux FAKETIME="2020-12-24 20:30:00" LD_PRELOAD=/usr/local/lib/libfaketime.so.1 ./test # Windows chrono run "C:\apps\test.exe" --at 2020-12-24T20:30:00
Where the two genuinely differ
Monotonic clocks are inverted. libfaketime fakes them by default and
gives you FAKETIME_DONT_FAKE_MONOTONIC to stop it. Here the
high-resolution counter stays real by default, because scaling it destabilised
rendering in testing, and --scale-qpc opts in. That switch is what makes
Python 3.13+ monotonic, .NET Stopwatch and Java
nanoTime follow the session clock.
Windows has more places to intercept. Beyond the wall clock there is the time zone, the elapsed-time axis, four families of timer, the sleep and wait functions, and process creation - 41 channels in total.
This one reports its own coverage. Every session ends with a verdict, the channels the application actually read with a count for each, and the channels that were missed. That is the part with no equivalent on either platform.
libfaketime is older and broader on its own ground. It has years of use behind it, covers a wide range of C library entry points, and on Linux it is the right tool. Nothing here replaces it there.
If you actually want libfaketime itself
Two honest routes, both of which move the program under test onto Linux:
- WSL - build and run libfaketime inside the Linux subsystem. Fine when the thing being tested is a Linux program you happen to develop on Windows.
- A container - same idea, more reproducible.
Neither helps with a Windows application, which is the case this tool exists for.