Commit Graph

79 Commits

Author SHA1 Message Date
Daniel Kahn Gillmor
a92d6ffe7c add snippet testing clock_gettime(CLOCK_REALTIME) 2021-03-02 10:23:11 -05:00
Daniel Kahn Gillmor
253774c8d8 added new simple snippet "time.c" 2021-03-01 21:47:18 -05:00
Daniel Kahn Gillmor
986e6e1cdc Clarify test/Makefile and snippet testing documentation
Hopefully this makes it easier for future development work to augment
the snippet-based testing.
2021-03-01 21:40:57 -05:00
Daniel Kahn Gillmor
0bfb72b627 tests: normalize "where" variable to include framework prefix and snippet name 2021-03-01 21:08:00 -05:00
Daniel Kahn Gillmor
5a1bd98979 parallelize library_contructors test 2021-03-01 21:05:22 -05:00
Daniel Kahn Gillmor
7e62881c8f Name "snippets" explicitly
Earlier, this code was conceived of to test a "function" specifically,
but some future snippet could test multiple function calls, or a
subset of a function call (e.g. snippets/syscall_clock_gettime.c
already only tests one particular syscall diversion number).

Normalizing on the name "snippet" should make it easier to understand
the code going forward.
2021-03-01 15:06:22 -05:00
Daniel Kahn Gillmor
940502b3de Added snippet for syscall(__NR_clock_gettime)
Closes: #176
2021-02-25 23:33:30 -05:00
Daniel Kahn Gillmor
26b4b395e9 Include a check for getentropy interception
This snippet applies to both the library constructors and variable
data test frameworks.
2021-02-25 23:17:25 -05:00
Daniel Kahn Gillmor
0b0cc29d2e test/randomtest.sh: avoid touching the filesystem 2021-02-25 23:17:25 -05:00
Daniel Kahn Gillmor
a5885f1479 Drop more duplicative tests
Now that we have the snippet-driven test_variable_data suite, most of
the other longer hand-written tests are duplicative.
2021-02-25 23:17:25 -05:00
Daniel Kahn Gillmor
0872c6c0c0 Add test_variable_data framework that reuses the snippets
Most of these snippets are likely to have some env var that causes the
data to hold constant, while the data will otherwise be likely to vary
over time.

This framework offers a way to test those snippets, by dropping the
variable and an example value in the test/snippets/FOO.variable
one-line file.

Note that the test/snippets/syscall.c snippet is *not* expected to
vary over time (or to differ when any given variable is set), so we
simply don't add any test/snippets/syscall.variable file to avoid it
being tested in this way.
2021-02-25 23:17:25 -05:00
Daniel Kahn Gillmor
f47223ff12 Include snippet for syscall() interception in library constructors 2021-02-25 23:17:25 -05:00
Daniel Kahn Gillmor
7b1d0958b5 Drop duplicate library constructor preload tests
These tests are already taken care of with the snippet-driven library
constructor tests.
2021-02-25 23:17:25 -05:00
Daniel Kahn Gillmor
17522c5ba1 Overhaul testing library constructors
We want to make it easier to test a bunch of different functions that
might be invoked in constructors of other libraries.

It seems conceivable that with these snippets, we could design other
tests that also work across a wide range of intercepted functions.
2021-02-25 23:17:25 -05:00
Daniel Kahn Gillmor
01f6bc76c9 clean up after syscall_test properly 2021-02-25 18:12:04 -05:00
Daniel Kahn Gillmor
f329eee8c5 Send test output to stdout, not stderr
debian autopkgtest instances (and maybe other test systems) will
report a failure if messages are sent to stderr.

Since these messages are diagnostic messages for the test suite, and
not indicators of actual failure, they should go to stdout, not
stderr.
2021-02-25 18:11:52 -05:00
Wolfgang Hommel
9337bccfcb Merge pull request #304 from dkg/cover-getentropy
better testing for interception of randomness from the kernel, including getentropy()
2021-02-25 06:27:35 +01:00
Daniel Kahn Gillmor
3db9d20828 Test getentropy
We want to ensure that tools that call getentropy() are also
controlled appropriately.
2021-02-24 16:03:57 -05:00
Daniel Kahn Gillmor
20e74b1b02 clean up randomtest.sh, make more flexible 2021-02-24 15:58:54 -05:00
Daniel Kahn Gillmor
00d6edf90c Test repeated invocations of getrandom()
A single program that invokes getrandom() repeatedly should end up
with the same stream of bytes, regardless of how it chunks up the
reading from the entropy source.

This test already passses.  I'm including it because it seems
like a useful confirmation.
2021-02-24 15:24:45 -05:00
Daniel Kahn Gillmor
811283e683 Intercept syscall
This is an attempt at an implementation to address #301.

Some things worth noting:

 - I am not particularly confident in my reverse of the variadic C
   ABI. While the code appears to work for me on x86_64, I could
   imagine some variations between platforms that I'm not
   understanding.

 - This works to intercept the invocation of syscall as seen in
   test/syscalltest.sh, as long as it was compiled with -DFAKE_RANDOM

 - defining -DINTERCEPT_SYSCALL on non-Linux platforms should result
   in a compile-time error.

 - This does *not* work to intercept the syscall sent by `openssl
   rand`, for some reason I don't yet understand.  Perhaps openssl has
   some platform-specific syscall mechanism that doesn't route them
   through libc's syscall() shim?
2021-02-24 14:45:38 -05:00
Daniel Kahn Gillmor
2ca0b719e3 test getpid() against library with constructor that calls it
This is an attempt to ensure that an external library invocation of
getpid doesn't trigger a crash (e.g. #295) or an infinite loop
(e.g. #297).
2021-02-24 11:15:31 -05:00
Daniel Kahn Gillmor
f6ddc32695 Genericize build rules for testing external libraries with constructor
This paves the way for testing other interceptions like getpid() with
shared objects that do devious things in their consturctors.
2021-02-24 11:15:01 -05:00
Daniel Kahn Gillmor
8de66f799f randomtest.sh requires librandom.so to be present
In some configurations, GNU make might treat librandom.so as an
ephemeral/intermediate build artifact and destroy it before
randomtest.sh is run.  This ensures the shared object is present when
needed.
2021-02-24 11:14:37 -05:00
Daniel Kahn Gillmor
004222585e Enable intercepting getpid()
I went with the runtime environment variable being FAKETIME_FAKEPID
since it seems less likely to collide with anything else.

Closes: #297
2021-02-23 22:19:08 -05:00
Daniel Kahn Gillmor
8f2c856d8e test getrandom() in library initialization without FAKERANDOM_SEED
Running "make randomtest" should demonstrates the segfault described
in https://github.com/wolfcw/libfaketime/issues/295
2021-02-23 11:14:37 -05:00
Daniel Kahn Gillmor
54994ceb0d Improve tests for FAKE_RANDOM
Previously, we had failed to test code with getrandom() against
LD_PRELOAD when FAKERANDOM_SEED was unset.

We also want to try calling getrandom twice in a single process to
make sure that works OK.
2021-02-22 22:49:05 -05:00
Wolfgang Hommel
772d9523a7 Do not fail due to timer overrun counter mismatch on GNU/Hurd for now (#287) 2021-02-12 16:59:42 +01:00
Wolfgang Hommel
3ba66842aa Make randomtest.sh use FAKETIME_TESTLIB like the rest of the test cases 2021-02-04 21:40:55 +01:00
Wolfgang Hommel
4359458c7c Merge pull request #289 from dkg/getrandom_test-cleanup
Ease build of getrandom_test
2021-02-04 21:39:02 +01:00
Wolfgang Hommel
8853afb509 Added optional FAKETIME_TESTLIB environment variable for make test (#288) 2021-02-04 21:30:01 +01:00
Daniel Kahn Gillmor
206ae9ea80 Ease build of getrandom_test
In trying to test the experimental getrandom features, I found a few
minor problems.  These changes should make it easier to test.

After building, the developer can now just do:

    make -C test randomtest

This will do a basic verfication that the feature works as expected.

I haven't tried to integrate this with the overall "make test".  To do
that right, it should condition the test on the definition of
FAKE_RANDOM.
2021-02-03 13:12:32 -05:00
Wolfgang Hommel
ca2f3fefa1 Preliminary support to intercept getrandom() #275 2020-11-15 21:57:10 +01:00
Robin Linden
f19d68ea32 Fix make test build failure on gcc 9.3
On Ubuntu 20.04 using gcc 9.3, make test fails due to a deprecated
function (ftime) warning in combination with -Werror in timetest.c.
Since the warning is from a test testing that the deprecated function
can be replaced using LD_PRELOAD, I think it's reasonable to just
silence the warning in that case.
2020-05-28 23:26:25 +02:00
Wolfgang Hommel
3123ad7fe2 Revert "Automake branch" 2019-11-30 09:36:46 +01:00
Michael D. Stemle, Jr
f92d919fb0 Merged master in and cleaned up.
We no longer need the OSX-specific test. Tests are passing, too.
2019-11-27 14:32:15 -05:00
Wolfgang Hommel
a238cfa2b6 Added FAKETIME_COMPILE_CFLAGS to Makefiles 2019-08-23 11:38:35 +02:00
Wolfgang Hommel
ba32d1b01c Added FORCE_MONOTONIC_FIX CFLAG to avoid hangs on timedwait (#202 #142) 2019-08-23 10:29:53 +02:00
Wolfgang Hommel
5ddb237842 Adjusted tests on macOS based on compilation defaults 2019-08-21 18:42:05 +02:00
Wolfgang Hommel
d923612c2b Improved cross-platform compatibility defaults 2019-08-19 19:16:07 +02:00
Mathis Beer
5c4fdb5173 Rename DONT_FAKE_MONOTONIC to FAKETIME_DONT_FAKE_MONOTONIC for consistency.
The old variable still works.
2019-02-05 07:45:31 +01:00
Michael D. Stemle, Jr
39a85e380c Fixed a _bunch_ of autotools bugs. 2018-10-07 22:38:55 -04:00
Michael D. Stemle, Jr
825043515f Applying fixes for GNU/Linux, and the MT variant of the library. 2018-10-03 22:17:28 -04:00
Michael D. Stemle, Jr
24fd806e6b Added GNU autotools support. 2018-10-02 22:02:30 -04:00
Michael D. Stemle, Jr
39c6872f6d Removing old makefiles. 2018-10-01 20:08:27 -04:00
Daniel Kahn Gillmor
b3a2667e9f fix spelling :) 2018-01-16 14:21:36 -05:00
Matthias Liertzer
fb91c4fcde Implement a fix for pthread_cond_timedwait with faketime
pthread_cond_timedwait takes an absolute time as an argument, which
the function directly passes on to the kernel via the futex
syscall. In an application this absolute time argument is calculated
via the fake times provided by libfaketime. Since the kernel has no
knowledge of the fake time, pthread_cond_timedwait must be redefined
such that it converts the fake time back to real time before passing
it on.
2018-01-02 02:22:59 +01:00
Matthias Liertzer
d117ad79a2 Fix spelling of positive 2018-01-02 01:42:41 +01:00
Adam Borowski
cc4c1c3a29 Fix build failure on x32 (printf warnings).
On x32, time_t is 64-bit to avoid Y2038 problems.  This doesn't play well
using printf("%ld"), and -Werror turns this into a build failure.
2015-03-09 08:39:06 +01:00
Julien Gilli
95b70c7acc Make libfaketime build, run and pass tests on SmartOS.
Since SmartOS is close to SunOS, it's possible that these changes make
libfaketime build and run on other SunOS-like platforms.

These changes were tested on MacOS X and Ubuntu 12.04, and no regression
appeared during testing.
2014-08-06 11:29:02 -07:00