185 Commits
v0.8 ... v0.9.5

Author SHA1 Message Date
Wolfgang Hommel
4c23ee2730 Updated TODO list 2013-10-13 11:19:30 +02:00
Wolfgang Hommel
b659b76c0c Updated installation notes for OS X 2013-10-11 23:37:50 +02:00
Wolfgang Hommel
088eb66b24 Added credits for MacPorts Portfile design and build cleanup 2013-10-11 16:42:38 +02:00
Wolfgang Hommel
0208015a9b set library versions on OSX as suggested by ryandesign at MacPorts 2013-10-11 16:41:01 +02:00
Wolfgang Hommel
a0987efa5c renamed library name from libfaketime.dylib.1 to libfaketime.1.dylib based on Apple design guidelines. Thanks to ryandesign at MacPorts 2013-10-11 16:33:37 +02:00
Wolfgang Hommel
ed9009495b Changes to Makefiles by ryandesign at MacPorts, changeset 112062 2013-10-11 16:29:11 +02:00
Wolfgang Hommel
cee051c2bc avoid unused variables warnings 2013-10-06 13:12:39 +02:00
Wolfgang Hommel
a64b04c441 Added note about how to test without installation 2013-10-05 18:01:38 +02:00
Wolfgang Hommel
ad012825de introducing rudimentary multilib installation path support 2013-10-05 17:53:58 +02:00
Wolfgang Hommel
858eb36e4f Preliminary multi-arch support for faketime wrapper when -DMULTI_ARCH is set 2013-10-05 11:16:12 +02:00
Balint Reczey
7d13d305c9 Add -Wextra and -Werror CFLAGS and also fix compile errors 2013-10-04 22:54:07 +02:00
Balint Reczey
bce065d17d fix missing break;-s 2013-10-04 22:34:12 +02:00
Balint Reczey
8906bfda8f rework endianness handling code to avoid aliasing warnings 2013-10-04 22:26:54 +02:00
Wolfgang Hommel
be2b7c0a0c fix compiler warning with -Wunused-result enabled 2013-10-04 11:48:54 +02:00
Wolfgang Hommel
7c2371e4a8 fix compiler warning with -Wstrict-overflow enabled 2013-10-04 11:45:55 +02:00
Wolfgang Hommel
a7858cb1dd fixed for gcc > 4.6 2013-10-04 10:42:27 +02:00
Wolfgang Hommel
1183cece14 deliberately ignore return values in test program 2013-10-04 10:39:09 +02:00
Wolfgang Hommel
4586eef851 Documentation on building 32-bit libraries on 64-bit platforms 2013-10-04 10:24:23 +02:00
Wolfgang Hommel
d4ffebbf98 Added note about building 32-bit libraries/binaries 2013-10-04 10:22:11 +02:00
Wolfgang Hommel
cb60b68e02 add default PREFIX to main Makefile.OSX 2013-10-03 18:24:27 +02:00
Wolfgang Hommel
782d3585b2 try multiple paths to find libfaketime.dylib.1 on OSX 2013-10-03 18:08:44 +02:00
Wolfgang Hommel
0b1845c36d Update default PREFIX on OSX 2013-10-03 17:58:01 +02:00
Wolfgang Hommel
6dcde9c4d9 Ensure target directory exists 2013-10-03 17:38:39 +02:00
Wolfgang Hommel
bbd2ee58f2 Makefile for OSX man page installation 2013-10-03 17:30:12 +02:00
Wolfgang Hommel
9d669f7528 ensure temporary destroot binpath exists 2013-10-03 17:28:11 +02:00
Wolfgang Hommel
a7297ba25c create bindir during installation if it does not yet exist (fixed) 2013-10-03 17:26:38 +02:00
Wolfgang Hommel
9d85b5a783 create bindir during installation if it does not yet exist 2013-10-03 17:22:39 +02:00
Balint Reczey
7c9a327919 Fix parsing timestamps containing only i... or x... 2013-10-03 15:42:53 +02:00
Wolfgang Hommel
6fafd23f8a fix -lrt call for faketime binary linking 2013-10-03 11:44:51 +02:00
Wolfgang Hommel
3debc093e4 fix -lrt call for library linking 2013-10-03 11:31:57 +02:00
Wolfgang Hommel
f21318289f fix missing linker run 2013-10-03 11:23:41 +02:00
Wolfgang Hommel
47e8fbef18 Merge branch 'develop' 2013-10-02 15:40:02 +02:00
Wolfgang Hommel
f0f8282817 No -DFAKE_TIMERS on OSX 2013-10-02 15:39:43 +02:00
Wolfgang Hommel
338ec2e3df Merge branch 'develop' 2013-10-02 15:36:07 +02:00
Wolfgang Hommel
bb87fb619e improved readability of test script output 2013-10-02 15:32:46 +02:00
Wolfgang Hommel
b9ba8ab444 uniform test output style 2013-10-01 13:15:34 +02:00
Wolfgang Hommel
8c1ba7899d improved output readability for timer tests 2013-10-01 13:12:34 +02:00
Wolfgang Hommel
c59e816539 Ensure that -lrt is passed to compiler/linker for faketime.c 2013-10-01 12:35:08 +02:00
Balint Reczey
50c6ad4dc2 Provide timer related functions compatible with GLIBC 2.2 and >= 2.3.3 [pr32 @8615959] 2013-09-30 16:36:13 +02:00
Wolfgang Hommel
cda19e4cb7 Updated gitignore: Ignore new faketime binary wrapper 2013-09-05 16:27:58 +02:00
Wolfgang Hommel
27468e804d Updated gitignore: Ignore new faketime binary wrapper 2013-09-05 14:37:05 +02:00
Wolfgang Hommel
e8846e6245 Merge branch 'master' into develop 2013-09-05 11:17:34 +02:00
Wolfgang Hommel
ae6af2eea9 fixed missing blank line before last timetest call 2013-09-05 11:16:57 +02:00
Balint Reczey
92d37e79b9 Use clock_gettime() to fake ftime() and time() [rbalint/pr31] 2013-09-05 11:15:51 +02:00
Wolfgang Hommel
65cccbbd45 Merge branch 'master' of https://github.com/wolfcw/libfaketime 2013-09-05 10:28:27 +02:00
Wolfgang Hommel
c2087711eb Unbalanced parenthesis in libfaketime.c (#30, a168290) 2013-09-05 10:27:11 +02:00
Wolfgang Hommel
2f9377790c Applied libfaketime name change and style guide 2013-09-05 10:27:11 +02:00
Wolfgang Hommel
51b1a2eba4 Wrap new and experimental features in #ifdef FAKE_SLEEP FAKE_TIMERS 2013-09-05 10:27:11 +02:00
Wolfgang Hommel
98a0cacf3a Updated manpage for upcoming 0.9.5 2013-09-05 10:27:11 +02:00
Balint Reczey
3d63dd33e5 Fix rouding issues, Add reminder to rewrite faking time(), gettimeofday, etc. [rbalint pr29] 2013-09-05 10:27:11 +02:00
Balint Reczey
545685e5a8 Use nanosleep() in faked sleep() and usleep() to avoid rounding issues [rbalint/pr28] 2013-09-05 10:26:57 +02:00
Wolfgang Hommel
e029bf883d Merge branch 'master' into develop 2013-09-04 17:23:29 +02:00
Wolfgang Hommel
6fb53d08dd Unbalanced parenthesis in libfaketime.c (#30, a168290) 2013-09-04 17:22:52 +02:00
Wolfgang Hommel
7fd7051b22 enable FAKE_TIMERS for development branch 2013-09-04 14:23:23 +02:00
Wolfgang Hommel
e09350e374 Applied libfaketime name change and style guide 2013-09-04 14:21:13 +02:00
Wolfgang Hommel
4c508fc375 Wrap new and experimental features in #ifdef FAKE_SLEEP FAKE_TIMERS 2013-09-04 14:20:43 +02:00
Wolfgang Hommel
a9898e91b0 Updated manpage for upcoming 0.9.5 2013-09-04 13:21:41 +02:00
Wolfgang Hommel
afa133ee7f Fix rouding issues, Add reminder to rewrite faking time(), gettimeofday, etc. [rbalint pr29] 2013-09-04 13:10:26 +02:00
Wolfgang Hommel
259a9a0966 Use nanosleep() in faked sleep() and usleep() to avoid rounding issues [rbalint/pr28] 2013-09-04 13:05:04 +02:00
Wolfgang Hommel
3f4563fd92 README.developers added; editor modelines in libfaketime.c 2013-09-04 12:50:00 +02:00
Wolfgang Hommel
e0248e9f4d merge of rbalint/fake-timers 2013-09-03 17:13:16 +02:00
Wolfgang Hommel
cdab1d089e more cleanup, indentation, C style etc. 2013-09-03 13:42:10 +02:00
Wolfgang Hommel
6e789eda25 indentation and other style issues 2013-09-03 13:23:42 +02:00
Wolfgang Hommel
c4a3671219 Merge branch 'fake-poll' into integration 2013-09-03 11:27:52 +02:00
Wolfgang Hommel
227ebff470 testing Makefile adapted for OSX 2013-09-02 14:38:43 +02:00
Wolfgang Hommel
568fef7228 Makefiles and test suite improved for OS X 2013-09-02 14:32:44 +02:00
Wolfgang Hommel
89f58cd720 Updated documentation and credits 2013-09-02 14:09:32 +02:00
Balint Reczey
d69e6557da Fake poll() and ppoll() 2013-09-01 19:28:53 +02:00
Balint Reczey
5d9429257b Fix typo in README 2013-09-01 18:22:47 +02:00
Wolfgang Hommel
aef788c795 Revert "merged rbalint's pr27"
This reverts commit 5283614bec, reversing
changes made to 4ecef4db08.
2013-09-01 16:04:21 +02:00
Wolfgang Hommel
5283614bec merged rbalint's pr27 2013-09-01 15:59:45 +02:00
Balint Reczey
4ecef4db08 Sleep() and alarm() still could apply faking several times 2013-08-31 20:32:45 +02:00
Balint Reczey
d92829adb1 Fake clock_get_time() on __APPLE__ 2013-08-30 20:28:10 +02:00
Balint Reczey
5bef478921 Fix compilation on __APPLE__ 2013-08-30 18:54:05 +02:00
Balint Reczey
9e36de18fb Default to clang on __APPLE__ to support thread local variables 2013-08-30 18:39:28 +02:00
Wolfgang Hommel
ddfebc8645 Improved OS X support
Conflicts:
	src/libfaketime.c
2013-08-30 18:18:51 +02:00
Balint Reczey
564f6e0942 Prevent applying time faking mote than once 2013-08-30 18:08:30 +02:00
Balint Reczey
e2882ef56c Don't use a = {b,c} assignment 2013-08-29 11:35:33 +02:00
Balint Reczey
3b498bf24f Fix missing clock_gettime() related #defines on __APPLE__ 2013-08-29 11:21:45 +02:00
Balint Reczey
59a9a36056 Assume system being little endian on __APPLE__ 2013-08-29 11:10:47 +02:00
Wolfgang Hommel
cde288fb0e fix so ./faketime is not a library 2013-08-29 10:59:57 +02:00
Wolfgang Hommel
c84c37d137 guard against broken dlsym by Toni G 2013-08-29 10:23:26 +02:00
Wolfgang Hommel
ccd43c21cd fix so ./faketime is not a library 2013-08-29 10:17:26 +02:00
Wolfgang Hommel
eff33e1b5b Revert a2c8ac6..8b67256
This rolls back to commit a2c8ac6687.
2013-08-29 10:15:15 +02:00
Wolfgang Hommel
8b67256736 Revert 30dd22e..bdac73e
This rolls back to commit 30dd22e157.
2013-08-29 10:08:32 +02:00
Wolfgang Hommel
bdac73e3b9 failed attempt to get it working on OS X 2013-08-29 10:05:45 +02:00
Wolfgang Hommel
ceca4b2fd7 Merge pull request #26 from rbalint/fake-sleep
Fake sleep
2013-08-29 00:24:01 -07:00
Balint Reczey
6fa8be96fc Fake sleep() and friends
This speeds up testing ;-)
2013-08-28 18:41:54 +02:00
Balint Reczey
6f83e225b1 Fix calculating faked time when user rate is not set 2013-08-28 14:41:49 +02:00
Balint Reczey
15d621d3aa Use global Faketime start time when started using "faketime" 2013-08-28 14:41:49 +02:00
Balint Reczey
77eb253136 Start system time from the same global clocks in every processes after replaying a file 2013-08-28 14:41:49 +02:00
Balint Reczey
7931cd180c Break loop of clock_gettime()-s when stopping replayin timestamps from file 2013-08-28 14:41:48 +02:00
Balint Reczey
6333941bed Fix faketime_common.h's description 2013-08-28 14:41:48 +02:00
Balint Reczey
9c37b38b65 Fake CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW clocks 2013-08-28 14:41:48 +02:00
Balint Reczey
4c253b3865 Speed up/slow down per process timers 2013-08-28 14:41:48 +02:00
Balint Reczey
8bb28faa91 Save faked timestamps to file, load faked timestamps from file
The files can be set using FAKETIME_SAVE_FILE and FAKETIME_LOAD_FILE
environment variables respectively.
2013-08-28 14:41:48 +02:00
Balint Reczey
7caed1a0c8 Fix typo setting wrong value for startup time on __APPLE__ 2013-08-28 14:38:11 +02:00
Wolfgang Hommel
30dd22e157 Merging Balint's files 2013-08-25 10:42:36 +02:00
Balint Reczey
ebf08018ff Refactor time faking calculations 2013-08-24 23:57:08 +02:00
Balint Reczey
6094fa9d87 Use nanosecond resolution for timestamps internally 2013-08-24 23:52:41 +02:00
Wolfgang Hommel
03fbad9bca Revert a0e3346..2dceb57
This rolls back to commit a0e33461a0.
2013-08-24 21:24:57 +02:00
Balint Reczey
45e9b4609e Refactor environment variable parsing and faking calculation 2013-08-24 15:52:09 +02:00
Balint Reczey
639d9caec8 Refactor limited faking and spawn support 2013-08-23 02:41:21 +02:00
Wolfgang Hommel
2dceb574ac Merge pull request #22 from tonigi/master
Libfaketime patch: process-shared "start at"
2013-08-22 06:53:12 -07:00
Toni G
b84e76ccf8 Merge branch 'master' of github.com:tonigi/libfaketime 2013-08-22 02:09:15 +02:00
Toni G
1ac7472769 Comment 2013-08-22 02:08:46 +02:00
Toni G
b4e3028494 explanation in readme 2013-08-22 02:08:30 +02:00
Toni G
b97121f7d6 explanation in readme 2013-08-22 02:07:16 +02:00
Toni G
982d90cbd2 comment 2013-08-22 01:57:39 +02:00
Toni G
af245d9d6c explanation in readme 2013-08-22 01:49:53 +02:00
Toni G
6db9ee8cf2 refactored ^ + @ 2013-08-22 01:30:44 +02:00
Toni G
fd1d3f161e explicit failure if ^ and not faketime 2013-08-22 01:13:31 +02:00
Toni G
ee8b780a87 Caret debugged, works 2013-08-22 01:03:16 +02:00
Toni G
39fc1bb0a8 attempt at global relative 2013-08-21 23:26:04 +02:00
Toni G
4a4673df6c guard against broken dlsym which returns 0 on __clock_gettime but does not set dlerror() 2013-08-21 21:27:02 +02:00
Toni G
65df40a624 added pthreads in make 2013-08-21 20:30:16 +02:00
Wolfgang Hommel
a0e33461a0 avoid_loop Patch by Gerardo Malazdrewicz <gerardo@malazdrewicz.com.ar> 2013-08-21 10:00:50 +02:00
Wolfgang Hommel
a2c8ac6687 moved outside #ifdef FAKE_STAT 2013-08-21 09:54:10 +02:00
Wolfgang Hommel
6f7acba526 Merge pull request #21 from rbalint/deterministic-time
Deterministic time
2013-08-20 23:36:13 -07:00
Balint Reczey
7287f9fe1d Cut _ftpl_time() 2013-08-20 15:40:51 +02:00
Balint Reczey
b9a46c9536 Look up all faked functions during library init
This makes us able to avoid protecting lookups with mutexes
2013-08-20 15:13:23 +02:00
Balint Reczey
bd5150e8dc Merge shared object init to existing constructor function 2013-08-19 21:13:10 +02:00
Balint Reczey
d5cd7064f5 Use the same global clock for all processes spawned by faketime -f '... iN'
In case the clock is set to advance with each faked time(), etc. call, the
counter uses the same clock counter stored in shared memory and protected
by a semaphore.
2013-08-19 14:08:51 +02:00
Balint Reczey
bfd4b9f5f3 Rewrite faketime shell script in C 2013-08-19 13:26:17 +02:00
Balint Reczey
ae45c5c48e Don't set USEDIRECT implicitly when the date looks suspicious 2013-08-17 22:16:44 +02:00
Wolfgang Hommel
c127aec450 Merge pull request #20 from rbalint/deterministic-time
Advance time with each time(), gettimeofday(), etc. call
2013-08-15 12:16:46 -07:00
Balint Reczey
2451de2244 Advance time with each time(), gettimeofday(), etc. call 2013-08-15 18:50:41 +02:00
Wolfgang Hommel
946f8e2378 GNU/kFreeBSD fix by Petr Salinger, fixes Bug#712709 2013-06-20 20:42:44 +02:00
Wolfgang Hommel
043d457fd2 Merge pull request #19 from dkg/wolf
build system fixes
2013-06-12 00:18:38 -07:00
Daniel Kahn Gillmor
02a0a3b231 separate the testing step from the build step
There are circumstances where you just want to repeat the build
without running the tests.  keeping the "test" target distinct from
the "all" target makes it possible to do that cleanly.
2013-06-11 10:23:05 -04:00
Daniel Kahn Gillmor
c818885733 Fix link order for --as-needed (see http://bugs.debian.org/711958)
In Ubuntu, the attached patch was applied to achieve the following:

  * as-needed.patch: Fix object/library link order for --as-needed.

When building with --as-needed, libraries need to be listed on the
link line after the objects that reference them.  In the autotools
world (and elsewhere), the LDFLAGS variable has been split into
LDFLAGS and LDADD to represent the need to list libs last.  This
patch makes that change to your Makefile, so this builds correctly
with --as-needed in LDFLAGS.
2013-06-11 10:13:25 -04:00
Daniel Kahn Gillmor
337581c040 allow overriding specific arguments without changing the Makefile
for example, now you can do:

 make PREFIX=/usr

without any modification to the Makefile and have it behave as
intended.
2013-06-11 10:10:14 -04:00
Wolfgang Hommel
e55e800a4c Merge pull request #16 from adrelanos/master
Time Privacy script
2013-05-09 23:47:56 -07:00
adrelanos
bb350d4b77 added command line options 2013-05-06 03:39:11 +00:00
adrelanos
eaa8e53318 Create timeprivacy
see https://github.com/adrelanos/timeprivacy
2013-05-03 03:45:45 +00:00
Wolfgang Hommel
10074a0030 Hugues Andreux: better support for different installation locations 2013-02-20 19:52:18 +01:00
Wolfgang Hommel
4c2ff5e559 Merge pull request #11 from dfong/master
bug in reading faketimerc
2012-11-28 10:11:52 -08:00
don fong
cd267e8dd5 whitespace fix
replace tabs with spaces to match surrounding code
2012-11-27 14:01:12 -08:00
don fong
bd1de99d3a bug in reading faketimerc
if the faketimerc file begins with an empty line, then the inner
loop that trims trailing eol chars could possibly step backward
past the beginning of the buffer (line).  if the byte just
preceding line also happened to contain a '\n' or '\r',
it could be clobbered.
2012-11-27 13:38:48 -08:00
Wolfgang Hommel
471e2a5620 Fixed 2012-11-24 19:40:10 +01:00
Wolfgang Hommel
037552cfed fixed a bug reported by goofansu 2012-11-23 21:03:39 +01:00
Wolfgang Hommel
dab8698a03 Merge pull request #8 from domo141/d3ff79a
Implementation of implicit '-f'
2012-09-10 22:24:07 -07:00
Tomi Ollila
d3ff79a0aa src/faketime: implicit '-f' for $offset that is faketime-known relative
When $offset arg looks like the relative value described in README
section "4d) Using offsets for relative dates", set USEDIRECT variable
even when '-f' option is not present. Without the '-f' the $offset would
be useless so this is convenience feature for the user. Using '-f' in
command line to explicitly set USEDIRECT is retained.
2012-09-09 20:36:37 +03:00
Wolfgang Hommel
532f0dc65d Merge pull request #7 from domo141/topic-wsc1
whitespace cleanup
2012-08-30 09:48:22 -07:00
Tomi Ollila
b648b7712d whitespace cleanup
Used (emacs) M-x untabify for whole faketime.c as the prevailing
style in that file used spaces for indentation.

Used M-x delete-trailing-whitespace to all files that had either
trailing whitespace or empty lines at the end of file to remove
those.
2012-08-30 10:46:58 +03:00
Wolfgang Hommel
d8053c280c Reorder linker flags as suggested by Lukas Fleischer 2012-02-05 00:07:54 +01:00
Wolfgang Hommel
b067cdce2b Initialize INSTALL as suggested by Lukas Fleischer 2012-02-05 00:05:46 +01:00
Wolfgang Hommel
dac5d28af2 Updated documentation for the upcoming 0.9 release 2012-01-11 22:37:21 +01:00
Wolfgang Hommel
84f61b75b3 Updated todo list to reflect OSX improvements
The Mac OS X 10.7 Lion issues have been fixed. Updated
the todo list accordingly and outlined the next steps.
2012-01-11 22:35:14 +01:00
Wolfgang Hommel
ec89c44011 Added feature to exec external command after x sec
This feature makes libfaketime execute an arbitrary system
command, such as a shell script, after a program has been
running for X seconds or has made Y time-related function
calls.
It is controlled by three environment variables.
FAKETIME_SPAWN_TARGET is the full path + file name +
command line arguments to the user-specified system
command.
FAKETIME_SPAWN_SECONDS is the number of seconds (after
program start / program's first time function call) after
which FAKETIME_SPAWN_TARGET will be executed.
FAKETIME_SPAWN_NUMCALLS can be used as an alternative
to ..._SECONDS.
2012-01-11 22:23:09 +01:00
Wolfgang Hommel
837e2c7e62 Added new feature to limit libfaketime activity
These changes add a new feature that can be used to limit
libfaketime's activity period, and prepares for the upcoming
0.9 release.
Four new environment variables can optionally be set:
FAKETIME_START_AFTER_SECONDS, FAKETIME_STOP_AFTER_SECONDS,
FAKETIME_START_AFTER_NUMCALLS, and FAKETIME_START_AFTER_NUMCALLS.
libfaketime will only return faked timestamps if the program's
runtime is between FAKETIME_START_AFTER_SECONDS and
FAKETIME_STOP_AFTER_SECONDS seconds. For example, a program
may be started with the real current time, and after 60
seconds, it will start to receive faked timestamps, e.g.,
one year in the future. The other pair of environment
variables limits libfaketime's activity based on the number
of time-related system calls of the started program,
instead of its run-time in seconds.
Using this new feature will break applications that cannot
handle larger sudden changes in timestamps, so use it with
care.
2012-01-08 22:41:54 +01:00
Wolfgang Hommel
e72d8e0419 Fixed build issues as suggested by Paul Wouters
- Updates COPYING file (fixed wrong FSE address)
- Avoid overwriting CFLAGS and LDFLAGS in src/Makefile
2011-11-28 19:40:00 +01:00
Wolfgang Hommel
4acfdddc89 Minor changes
Minor changes to README.OSX
2011-10-19 23:03:53 +02:00
Wolfgang Hommel
0a1c887a8a Fixed issues on Mac OS X 10.7 Lion
- Changed interception of internal syscalls on OSX
  and malloc arena treatment
- Adapted the faketime wrapper shell script to set
  the appropriate environment variables on OSX and
  use gdate instead of date
- Added README.OSX to explain the OSX-specific
  aspects of compiling and using libfaketime
2011-10-19 21:03:41 +02:00
Wolfgang Hommel
18adec4fae Added TODO item about libfaketime on OS X 10.7 (Lion)
libfaketime appears not to work on OS X 10.7 (Lion). It does not fake th
e time and sporadically causes a segfault.
2011-07-30 11:19:16 +02:00
Wolfgang Hommel
f07939d948 Minor adaptions for Mac OS X 2011-07-30 10:58:12 +02:00
Wolfgang Hommel
68ccdb74b5 Described recent changes and next steps 2011-07-30 10:50:19 +02:00
wolfcw
a5896e3dcb Merge pull request #3 from dfong/master
eliminate use of dc
2011-07-26 14:33:53 -07:00
don fong
54bc41ffaf compute pow() with shell only, in case we don't have bc, dc, perl 2011-07-26 12:54:42 -07:00
wolfcw
9099c4ab85 Merge pull request #2 from dfong/master
new framework for functional tests
2011-07-25 22:15:25 -07:00
don fong
ea15324e30 add support for new framework for functional tests 2011-07-25 17:04:09 -07:00
Lukas Fleischer
e4cfb671dd NEWS: Add note on MacOS port
Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-07-15 15:50:03 +02:00
Lukas Fleischer
ab66fd5237 NEWS: Fix trailing whitespace
Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-07-15 15:50:03 +02:00
Lukas Fleischer
86f738b25e Restructure meta files
* Move "COPYING" and "Changelog" from "meta/" to the top-level source
  directory. No need to have a separate directory for two small text
  files. Also, it's common practice to put these there.

* Makefile: Merge "meta/Makefile".

* Rename "Changelog" to "NEWS". The file containing a summary of changes
  between two releases in generally called "NEWS". The name "ChangeLog"
  should only be used for a detailed log of every commit.

Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-07-15 15:49:58 +02:00
wolfcw
f2ba5c7750 Merge pull request #1 from dbrashear/master
I ported libfaketime to MacOS.
2011-07-09 09:47:29 -07:00
Derrick Brashear
74852f1682 add multi-architecture support
extra -arch flags should do it.
2011-07-08 08:19:29 -04:00
Derrick Brashear
3c24c524b3 macos: pass one gettimeofday unmodified
needed to avoid a malloc recursion; dyld calls the libSystem
initializer, which calls malloc as the first caller; that uses
the arc4 randomizer, which calls gettimeofday... the call to fake_time
calls strptime_l, _strptime0, gmtsub, and boom, back at malloc.

pass one gettimeofday call to let the malloc succeed.
2011-07-05 10:46:34 -04:00
Derrick Brashear
eb59447a6d libfaketime macos port
port libfaketime to macos and dyld.
1) _ftpl_time calls gettimeofday since real time() does so. needed
   to avoid double adjustment.
2) reduce call stack: use time tptr and call fake_time instead of
   calling time for faking other time calls.
3) provide MacOS makefile and README notes.
4) make posix realtime calls under ifdef; define for base port but not
MacOS.
2011-07-05 09:05:38 -04:00
Wolfgang Hommel
ed25084970 Modified documentation and changelog based on the recent changes 2011-05-22 00:21:04 +02:00
Wolfgang Hommel
2a384f70ba fixed one more hard-coded path
changed the Makefile echo output so it also uses the prefix
environment variables just like the install calls.
2011-05-22 00:05:24 +02:00
Lukas Fleischer
4991c61b77 Overwrite existing man pages when running make install.
Add "-f" option to gzip(1) invocation to avoid user prompts if
compressed man pages already exist in the target directory.

Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-05-10 22:07:49 +02:00
Lukas Fleischer
b6ca32ed23 Use install(1) instead of mkdir(1) and cp(1) in Makefiles.
Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-05-10 22:07:10 +02:00
Lukas Fleischer
bb9b292a41 Use a separate Makefile for meta files.
* Create separate "install" and "uninstall" targets for meta files.

* Add meta file targets to the shortcut Makefile.

Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-05-10 22:02:14 +02:00
Lukas Fleischer
9763cdebd2 Use a separate Makefile for man pages.
* Create separate "install" and "uninstall" targets for man pages.

* Add man page targets to the shortcut Makefile.

Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-05-10 21:43:24 +02:00
Lukas Fleischer
8c6c487b24 Tell the compiler to be C99 compliant, enable all warnings.
Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-05-10 21:43:23 +02:00
Lukas Fleischer
5fa942b4cf Cast time_t to unsigned integer when using printf().
Suppress compiler warnings when using "-Wformat".

Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-05-10 21:43:23 +02:00
Lukas Fleischer
d2108361c0 timetest.c: Add "sys/time.h" include (required for gettimeofday()).
Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-05-10 21:43:23 +02:00
Lukas Fleischer
403d240444 Add shortcut Makefile.
Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-05-10 21:43:23 +02:00
Lukas Fleischer
9b62bb4f38 Test suite Makefile overhaul.
* Use variables for compiler and linker flags.

* Use variables for source/object files and binaries.

* Use proper targets instead of phony targets to build the timetest
  program.

Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-05-10 21:43:23 +02:00
Lukas Fleischer
52c30f866d Source Makefile overhaul.
* Use variables for compiler and linker flags.

* Use variables for source/object files, library names and sonames.

* Use proper targets instead of phony targets to build the shared
  libraries.

Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-05-10 21:43:21 +02:00
Lukas Fleischer
cf0ccef687 Move test suite to a separate subdirectory.
* Move test suite related stuff from "src/" to "test/".

* Fix "test.sh" to search for libfaketime libraries in the right place.

* Split up Makefile into two separate Makefiles (one for the main
  program and one for the test suite).

Test cases should go in another directory for the sake of clean code
separation. This will also facilitate the creation of proper Makefiles.

Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-04-27 18:50:40 +02:00
Lukas Fleischer
9234f5df86 Add ".PHONY" target to the Makefile.
This is required for targets that do not directly refer to files.

Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-04-26 17:29:22 +02:00
Lukas Fleischer
cd0667a7a6 Add an uninstall target to the Makefile.
This is especially advantageous if libfaketime is built from source as
there isn't another convenient way to do a clean uninstall.

Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-04-26 17:25:55 +02:00
Lukas Fleischer
46f6bd5b9b Use "$DESTDIR" and "$PREFIX" in the Makefile.
This is a standard used by almost all open source projects and allows
installing to different locations than the default location (which is
especially useful for packagers, e.g.) Switch to installing to
"/usr/local" by default, also. "/usr" should never be used as default
prefix.

Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-04-26 17:22:12 +02:00
Lukas Fleischer
5bbb393e07 Add ".gitignore".
Signed-off-by: Lukas Fleischer <info@cryptocrack.de>
2011-04-26 17:17:16 +02:00
36 changed files with 4174 additions and 1092 deletions

9
.gitignore vendored Normal file
View File

@@ -0,0 +1,9 @@
*.o
*.so.1
timetest
src/libfaketime.dylib.1
src/libfaketime.1.dylib
src/core
src/faketime

View File

@@ -1,12 +1,12 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
@@ -15,7 +15,7 @@ software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
@@ -55,7 +55,8 @@ patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
@@ -109,6 +110,7 @@ above, provided that you also meet all of these conditions:
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
@@ -166,6 +168,7 @@ access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
@@ -222,6 +225,7 @@ impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
@@ -251,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
@@ -273,8 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
@@ -298,17 +303,16 @@ the "copyright" line and a pointer to where the full notice is found.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
@@ -331,5 +335,5 @@ necessary. Here is a sample; alter the names:
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

31
Makefile Normal file
View File

@@ -0,0 +1,31 @@
INSTALL ?= install
all:
$(MAKE) -C src all
test:
$(MAKE) -C test all
install:
$(MAKE) -C src install
$(MAKE) -C man install
$(INSTALL) -dm0755 "${DESTDIR}${PREFIX}/share/doc/faketime/"
$(INSTALL) -m0644 README "${DESTDIR}${PREFIX}/share/doc/faketime/README"
$(INSTALL) -m0644 NEWS "${DESTDIR}${PREFIX}/share/doc/faketime/NEWS"
uninstall:
$(MAKE) -C src uninstall
$(MAKE) -C man uninstall
rm -f "${DESTDIR}${PREFIX}/share/doc/faketime/README"
rm -f "${DESTDIR}${PREFIX}/share/doc/faketime/NEWS"
rmdir "${DESTDIR}${PREFIX}/share/doc/faketime"
clean:
$(MAKE) -C src clean
$(MAKE) -C test clean
distclean:
$(MAKE) -C src distclean
$(MAKE) -C test distclean
.PHONY: all test install uninstall clean distclean

33
Makefile.OSX Normal file
View File

@@ -0,0 +1,33 @@
INSTALL ?= install
PREFIX ?= /usr/local
all:
$(MAKE) -f Makefile.OSX -C src all
test:
$(MAKE) -f Makefile.OSX -C test all
install:
$(MAKE) -f Makefile.OSX -C src install
$(MAKE) -f Makefile.OSX -C man install
$(INSTALL) -dm0755 "${DESTDIR}${PREFIX}/share/doc/faketime/"
$(INSTALL) -m0644 README "${DESTDIR}${PREFIX}/share/doc/faketime/README"
$(INSTALL) -m0644 NEWS "${DESTDIR}${PREFIX}/share/doc/faketime/NEWS"
uninstall:
$(MAKE) -f Makefile.OSX -C src uninstall
$(MAKE) -f Makefile.OSX -C man uninstall
rm -f "${DESTDIR}${PREFIX}/share/doc/faketime/README"
rm -f "${DESTDIR}${PREFIX}/share/doc/faketime/NEWS"
rmdir "${DESTDIR}${PREFIX}/share/doc/faketime"
clean:
$(MAKE) -f Makefile.OSX -C src clean
$(MAKE) -f Makefile.OSX -C test clean
distclean:
$(MAKE) -f Makefile.OSX -C src distclean
$(MAKE) -f Makefile.OSX -C test distclean
.PHONY: all test install uninstall clean distclean

View File

@@ -1,6 +1,58 @@
Since 0.9:
- ryandesign at MacPorts provided a Portfile for MacPorts and
fixed various build issues on OSX.
- Balint Reczey added support for nanosecond resolution, saving
timestamps to files, speeding up and slowing down per-process
timers, CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW, faketime
support for system calls such as sleep() and alarm().
- Applied a patch by Gerardo Malazdrewicz and Toni G to restore
compatibility with newer versions of glibc.
- Balint Reczey added an option to use the same global clock setting
for all libfaketime-spawned processes.
- Balint Reczey has rewritten the faketime wrapper shell script in C
and refactored libfaketime.
- Balint Reczey added support for advancing the time with each time-
related system call ("deterministic time").
- Added "timeprivacy" wrapper by adrelanos; it ensures that programs
are started with unique timestamps.
- Code and documentation cleanup by Tomi Ollila.
- Reworked Makefiles for more flexible installation, including fixes
by Lukas Fleischner, Daniel Kahm Gillmor, and Hugues Andreux.
- Fixed license issues as pointed out by Paul Wouters.
- Mac OS X support has been improved for OS X 10.7 and 10.8; due to
changes to the underlying libraries on OS X, libfaketime 0.9.5 will
no longer work with OS X < 10.6; use libfaketime 0.9(.1) for older
OS X installations.
- Don Fong has contributed a new framework for functional tests.
Petr Salinger ensured its compatibility with GNU/kFreeBSD.
Since 0.8.2:
- Added support for "limited faking".
You can optionally specify when libfaketime starts to fake the
returned timestamps and when it shall stop doing so. For example,
a program can be started regularly, and after 5 minutes run-time
it will be sent two years into the future. Those limiting
start and stop times can be specified in seconds or as the
number of any time-related function calls within the program.
- Added a feature to spawn an external process after x seconds
or y time-related system calls. This can, for example, be used
to execute an arbitrary shell script x seconds after a program
has been started.
Since 0.8.1:
- Added a MacOS port.
Thanks to Derrick Brashear!
- Added a functional test framework that aids in automatically
determining whether libfaketime works properly on the current
machine. Thanks to Don Fong!
Since 0.8:
- Changed directory layout and Makefile structure.
Thanks to Lukas Fleischer!
Since 0.7:
- Added support for fstatat() and fstatat64() which were introduced in
Linux kernel 2.6.16 and used in recent coreutils.
Linux kernel 2.6.16 and used in recent coreutils.
Thanks to Daniel Kahn Gillmor for the report!
This can be disabled by passing -DNO_ATFILE in the Makefile.
- Added a simple wrapper shell script and a man page for it. Makes it
@@ -9,7 +61,7 @@ Since 0.7:
please adjust this path if necessary. The "install" target in the
Makefile has been adapted accordingly.
- Added support for fractional time offsets, such as FAKETIME="+1,5h".
Please note that either , or . has to be used as a delimiter
Please note that either , or . has to be used as a delimiter
depending on your locale. Thanks to Karl Chen!
- Added support for speeding the clock up or slowing it down. For
example, FAKETIME="+5d x2,0" will set the faked time 5 days into
@@ -18,7 +70,7 @@ Since 0.7:
Again, the delimiter to use for the fraction depends on your locale.
Thanks to Karl Chen!
Since 0.6:
Since 0.6:
Main version 0.7 contributions by David North, TDI:
- Added ability to 'start clock at' a specific time.
- Added pthread synchronization support
@@ -31,22 +83,22 @@ Since 0.6:
- Repaired a bug w.r.t. strptime/mktime wherein 'isdst' was uninitialized
which led to pseudorandom +/- 1 hour results being returned in 'start at'
or absolute time modes
Other enhancements:
Other enhancements:
- Fixed missing interceptions to libc-internal functions and added notes
about a workaround for running Java programs with faked times in the
future (they worked properly, but often locked up at exiting). Thanks to
Jamie Cameron of Google for in-depth analysis and prototype solution!
Since 0.5:
- Performance enhancements by means of caching the data read
- Performance enhancements by means of caching the data read
e.g. from $HOME/.faketimerc for 10 seconds.
- Several file timestamp related system calls such as fstat() will be
intercepted now. See the README file on how to turn this off if you
do not need it. Thanks to Philipp Hachtmann!
- A system-wide /etc/faketimerc file will now be used if no FAKETIME
environment variable has been set and no $HOME/.faketimerc is present.
Thanks to David Burley, Jacob Moorman, and Wayne Davison of
Thanks to David Burley, Jacob Moorman, and Wayne Davison of
SourceForge, Inc.!
- Added trivial Makefile targets clean/distclean/install
- Changed Makefile target test to run new test.sh script
@@ -64,4 +116,3 @@ Since 0.2:
Since 0.1:
- Fixed segfault when calling time(NULL). Thanks to Andres Ojamaa!
- Added additional sanity checks.

337
README
View File

@@ -1,6 +1,7 @@
===================================================
FakeTime Preload Library, version 0.8 (August 2008)
===================================================
=======================================================
libfaketime, version 0.9.5 (October 2013)
(previously also know as FakeTime Preload Library)
=======================================================
Content of this file:
@@ -17,6 +18,9 @@ Content of this file:
e) Advanced features and caveats
f) Faking the date and time system-wide
g) Using the "faketime" wrapper script
h) "Limiting" libfaketime
i) Spawning an external process
j) Saving timestamps to file, loading them from file
5. License
6. Contact
@@ -25,35 +29,35 @@ Content of this file:
1. Introduction
---------------
FTPL intercepts various system calls which programs use to retrieve the
current date and time. It can then report faked dates and times (as
specified by you, the user) to these programs. This means you can modify
the system time a program sees without having to change the time system-
wide.
libfaketime intercepts various system calls which programs use to
retrieve the current date and time. It can then report faked dates and times
(as specified by you, the user) to these programs. This means you can modify
the system time a program sees without having to change the time system-wide.
FTPL allows you to specify both absolute dates (e.g., 01/01/2004) and
libfaketime allows you to specify both absolute dates (e.g., 01/01/2004) and
relative dates (e.g., 10 days ago).
FTPL might be used for various purposes, for example
libfaketime might be used for various purposes, for example
- running legacy software with y2k bugs
- testing software for year-2038 compliance
- debugging time-related issues, such as expired SSL certificates
- running software which ceases to run outside a certain timeframe
- using different system-wide date and time settings, e.g. on OpenVZ-
based virtual machines running on the same host
- using different system-wide date and time settings, e.g., on OpenVZ-
based virtual machines running on the same host.
2. Compatibility issues
-----------------------
* FTPL has been designed on and for Linux 2.x, but is supposed and has been
reported to work on other *NIXes as well.
* libfaketime has been designed on and for Linux, but is supposed and has been
reported to work on other *NIXes as well, including Mac OS X.
* FTPL uses the library preload mechanism and thus cannot work with statically
linked binaries or binaries that have the setuid-flag set (e.g., suidroot
programs like "ping" or "passwd").
* libfaketime uses the library preload mechanism and thus cannot work with
statically linked binaries or binaries that have the setuid-flag set (e.g.,
suidroot programs like "ping" or "passwd"). Please see you system linker's
manpage for further details (man ld).
* As of version 0.7, support has been added for use in a pthreads environment. A
separate library is built (libfaketimeMT.so.1) which contains the pthread
@@ -72,22 +76,37 @@ FTPL might be used for various purposes, for example
required for Java with faked times in the future. Thanks to Jamie Cameron for
reporting this issue and finding a workaround!
* libfaketime will eventually be bypassed by applications that dynamically load
system libraries, such as librt, explicitly themselves instead of relying on
the linker to do so at application start time. libfaketime will not work with
those applications unless you can modify them.
* Applications can explicitly be designed to prevent libfaketime from working,
e.g., by checking whether certain environment variables are set or whether
libfaketime-specific files are present.
3. Installation
---------------
Running "make" should compile both library versions and a test program, which
it then also executes.
it then also executes.
If the test works fine, you should copy the FTPL libraries (libfaketime.so.1,
and libfaketimeMT.so.1) to the place you want them in. Running "make install"
will attempt to place them in /usr/lib/faketime and will install the wrapper
shell script "faketime" in /usr/bin, both of which most likely will require
root privileges; however, from a technical point of view, there is no
necessity for a system-wide installation, so you can use FTPL also on machines
where you do not have root privileges.
If the test works fine, you should copy the libfaketime libraries
(libfaketime.so.1, and libfaketimeMT.so.1) to the place you want them in.
Running "make install" will attempt to place them in /usr/local/lib/faketime
and will install the wrapper shell script "faketime" in /usr/local/bin, both of
which most likely will require root privileges; however, from a technical point
of view, there is no necessity for a system-wide installation, so you can use
libfaketime also on machines where you do not have root privileges. You may want
to adjust the PREFIX variable in the Makefiles accordingly.
Since version 0.6, system calls to file timestamps are also intercepted now,
By default, the Makefile compiles/links libfaketime for your default system
architecture. If you need to build, e.g., 32-bit files on a 64-bit platform,
please see the notes about CFLAGS and LDFLAGS in src/Makefile.
Since version 0.6, system calls to file timestamps are also intercepted,
thanks to a contribution by Philipp Hachtmann. This is especially useful in
combination with relative time offsets as explained in section 4d) below, if a
program writes and reads files whose timestamps also shall be faked. If you do
@@ -95,6 +114,15 @@ not need this feature or if it confuses the application you want to use FTPL
with, define the environment variable NO_FAKE_STAT, and the intercepted stat
calls will be passed through unaltered.
On OS X, it is necessary to compile differently, due to the different
behavior dyld has. Use the Makefile.MacOS provided to compile
libfaketime.1.dylib. Additionally, instead of using LD_PRELOAD,
the variable DYLD_INSERT_LIBRARIES should be set to the path to
libfaketime.1.dylib, and the variable DYLD_FORCE_FLAT_NAMESPACE should be
set (to anything). Mac OS X users should read README.OSX for additional
details.
4. Usage
--------
@@ -102,14 +130,14 @@ calls will be passed through unaltered.
4a) Usage basics
----------------
Using FTPL on a program of your choice consists of two steps:
Using libfaketime on a program of your choice consists of two steps:
1. Making sure FTPL gets loaded.
1. Making sure libfaketime gets loaded by the system's linker.
2. Specify the faked time.
As an example, we want the "date" command to report our faked time. To do so,
we could use the following command line:
we could use the following command line on Linux:
user@host> date
Tue Nov 23 12:01:05 CEST 2007
@@ -118,9 +146,10 @@ user@host> LD_PRELOAD=/usr/local/lib/libfaketime.so.1 FAKETIME="-15d" date
Mon Nov 8 12:01:12 CEST 2007
The basic way of running any command/program with FTPL enabled is to make sure
the environment variable LD_PRELOAD contains the full path and filename of the
FTPL library. This can either be done by setting it once beforehand:
The basic way of running any command/program with libfaketime enabled is to
make sure the environment variable LD_PRELOAD contains the full path and
filename of the libfaketime library. This can either be done by setting it once
beforehand:
export LD_PRELOAD=/path/to/libfaketime.so.1
(now run any command you want)
@@ -130,31 +159,31 @@ Or it can be done by specifying it on the command line itself:
LD_PRELOAD=/path/to/libfaketime.so.1 your_command_here
(These examples are for the bash shell; how environment variables are set may
(These examples are for the bash shell; how environment variables are set may
vary on your system.)
However, also the faked time should be specified; otherwise, FTPL will be
loaded, but just report the real system time. There are three ways to specify
the faked time:
However, also the faked time should be specified; otherwise, libfaketime
will be loaded, but just report the real system time. There are three
ways to specify the faked time:
a) By setting the environment variable FAKETIME.
b) By using the file .faketimerc in your home directory.
c) By using the file /etc/faketimerc for a system-wide default.
If you want to use b) or c), $HOME/.faketimerc or /etc/faketimerc consist of
only one line of text with exactly the same content as the FAKETIME environment
If you want to use b) or c), $HOME/.faketimerc or /etc/faketimerc consist of
only one line of text with exactly the same content as the FAKETIME environment
variable, which is described below. Note that /etc/faketimerc will only be used
if there is no $HOME/.faketimerc, and the FAKETIME environment variable always
has priority over the files.
4b) Using absolute dates
------------------------
The format which _must_ be used for _absolute_ dates is "YYYY-MM-DD hh:mm:ss".
The format which _must_ be used for _absolute_ dates is "YYYY-MM-DD hh:mm:ss".
For example, the 24th of December, 2002, 8:30 PM would have to be specified as
FAKETIME="2002-12-24 20:30:00".
FAKETIME="2002-12-24 20:30:00".
4c) Using 'start at' dates
@@ -162,9 +191,9 @@ FAKETIME="2002-12-24 20:30:00".
(Thanks to a major contribution by David North, TDI in version 0.7)
The format which _must_ be used for _start_at_ dates is "@YYYY-MM-DD hh:mm:ss".
The format which _must_ be used for _start_at_ dates is "@YYYY-MM-DD hh:mm:ss".
For example, the 24th of December, 2002, 8:30 PM would have to be specified as
FAKETIME="@2002-12-24 20:30:00".
FAKETIME="@2002-12-24 20:30:00".
The absolute dates described in 4b simulate a STOPPED system clock at the
specified absolute time. The 'start at' format allows a 'relative' clock
@@ -179,14 +208,14 @@ Relative date offsets can be positive or negative, thus what you put into
FAKETIME _must_ either start with a + or a -, followed by a number, and
optionally followed by a multiplier:
- by default, the offset you specify is in seconds. Example:
- by default, the offset you specify is in seconds. Example:
export FAKETIME="-120" will set the faked time 2 minutes (120 seconds) behind
the real time.
- the multipliers "m", "h", "d" and "y" can be used to specify the offset in
- the multipliers "m", "h", "d" and "y" can be used to specify the offset in
minutes, hours, days and years (365 days each), respectively. Examples:
export FAKETIME="-10m" sets the faked time 10 minutes behind the real time.
export FAKETIME="+14d" sets the faked time to 14 days in the future.
@@ -202,7 +231,7 @@ Moreno Baricevic has contributed support for the FAKETIME_FMT environment
variable, which allows to optionally set the strptime() format:
Some simple examples:
LD_PRELOAD=./libfaketime.so.1 FAKETIME_FMT=%s FAKETIME="`date +%s -d'1 year ago'`" date
LD_PRELOAD=./libfaketime.so.1 FAKETIME_FMT=%s FAKETIME="`date +%s -d'1 year ago'`" date
LD_PRELOAD=./libfaketime.so.1 FAKETIME_FMT=%s FAKETIME="`stat -c %Y somefile`" date
LD_PRELOAD=./libfaketime.so.1 FAKETIME_FMT=%c FAKETIME="`date`" date
@@ -223,11 +252,13 @@ depends on your locale settings, so actually you might need to use
FAKETIME="+1.5h"
You should figure out the proper delimiter, e.g. by using FTPL on a command
like /bin/date where you immediately can verify whether it worked as expected.
You should figure out the proper delimiter, e.g. by using libfaketime on
a command like /bin/date where you immediately can verify whether it worked as
expected.
Also contributed by Karl Chen in v0.8 is the option to speed up or slow down
the wall clock time for the program which is executed using FTPL. For example,
Also contributed by Karl Chen in v0.8 is the option to speed up or slow
down the wall clock time for the program which is executed using libfaketime.
For example,
FAKETIME="+1y x2"
@@ -237,39 +268,50 @@ twice as fast. Similarly,
FAKETIME="+1y x0,5"
will make the clock run only half as fast. As stated above, the fraction
delimiter depends on your locale.
delimiter depends on your locale.
FAKETIME="+1y i2,0"
will make the clock step two seconds per each time(), etc. call, running
completely independently of the system clock. It helps running programs
with some determinism. In this single case all spawned processes will use
the same global clock without restaring it at the start of each process.
For testing, your should run a command like
LD_PRELOAD=./libfaketime.so.1 FAKETIME="+1,5y x10,0" \
/bin/bash -c 'while true; do echo $SECONDS ; sleep 1 ; done'
For each second that the endless loop sleeps, the executed bash shell will
think that 10 seconds have passed ($SECONDS is a bash-internal variable
For each second that the endless loop sleeps, the executed bash shell will
think that 10 seconds have passed ($SECONDS is a bash-internal variable
measuring the time since the shell was started).
(Please note that replacing "echo $SECONDS" e.g. with a call to "/bin/date"
will not give the expected result, since /bin/date will always be started
as a new process for which also FTPL will be re-initialized. It will show
the correct offset (1.5 years in the future), but no speed-ups or
the correct offset (1.5 years in the future), but no speed-ups or
slow-downs.)
For applications that should use a different date & time each time they are
run, consider using the included timeprivacy wrapper shellscript (contributed
by adrelanos at riseup dot net).
Caveats:
--------
Whenever possible, you should use relative offsets or 'start at' dates, and not
use absolute dates.
Whenever possible, you should use relative offsets or 'start at' dates,
and not use absolute dates.
Why? Because the absolute date/time you set is fixed, i.e. if a program
retrieves the current time, and retrieves the current time again 5 minutes
later, it will still get the same result twice. This is likely to break
programs which measure the time passing by (e.g. a mail program which checks
Why? Because the absolute date/time you set is fixed, i.e., if a program
retrieves the current time, and retrieves the current time again 5
minutes later, it will still get the same result twice. This is likely to break
programs which measure the time passing by (e.g., a mail program which checks
for new mail every X minutes).
Using relative offsets or 'start at' dates solves this problem. FTPL then will
always report the faked time based on the real current time and the offset
you've specified.
Using relative offsets or 'start at' dates solves this problem.
libfaketime then will always report the faked time based on the real
current time and the offset you've specified.
Please also note that your specification of the fake time is cached for 10
seconds in order to enhance the library's performance. Thus, if you change the
@@ -282,22 +324,31 @@ command line option -DNO_CACHING to this library's Makefile.
4f) Faking the date and time system-wide
----------------------------------------
David Burley of SourceForge, Inc. reported an interesting use case of applying
FTPL system-wide: Currently, all virtual machines running inside an OpenVZ host
have the same system date and time. In order to use multiple sandboxes with
different system dates, the FTPL library can be put into /etc/ld.so.preload;
it will then be applied to all commands and programs automatically. This is
of course best used with a system-wide /etc/faketimerc file. Kudos to
SourceForge, Inc. for providing the patch!
David Burley of SourceForge, Inc. reported an interesting use case of applying
libfaketime system-wide: Currently, all virtual machines running inside
an OpenVZ host have the same system date and time. In order to use multiple
sandboxes with different system dates, the libfaketime library can be put into
/etc/ld.so.preload; it will then be applied to all commands and programs
automatically. This is of course best used with a system-wide /etc/faketimerc
file. Kudos to SourceForge, Inc. for providing the patch!
Caveat: If you run a virtual machine, its real-time clock might be reset to the
real world date & time when you reboot. Depending on your FAKETIME setting,
this may lead to side effects, such as forced file system checks on each reboot.
System-wide faked time may also lead to unexpected side effects with software
auto-update tools, if the offset between real world time and faked system time
is too large. If in doubt, set your system's date to the faked time and try out
whether everything still works as expected before applying libfaketime
system-wide.
4g) Using the "faketime" wrapper script
---------------------------------------
4g) Using the "faketime" wrapper
--------------------------------
As of version 0.8, FTPL provides a shell script named "faketime" which is
As of version 0.8, libfaketime provides a command named "faketime", which is
placed into /usr/bin by "make install". It spares the hassle of setting
the LD_PRELOAD and FAKETIME environment variables manually, but only exposes
a subset of FTPL's functionality. On the other hand, it uses the date
a subset of libfaketime's functionality. On the other hand, it uses the date
interpretation function by /bin/date in order to provide higher flexibility
regarding the specification of the faked date and time. For example, you
can use
@@ -310,20 +361,142 @@ faketime '2008-12-24 08:15:42' /bin/date
Thanks to Daniel Kahn Gillmor for providing these suggestions!
Balint Reczey has rewritten the wrapper in 0.9.5 from a simple shell script
to an efficient wrapper application.
4h) "Limiting" libfaketime
--------------------------
Starting with version 0.9, libfaketime can be configured to not be continuously
active, but only during a certain time interval.
For example, you might want to start a program with the real current time, but
after 5 minutes of usage, you might want it to see a faked time, e.g., a year
in the future.
Dynamic changes to the faked time are alternatively possible by
- changing the FAKETIME environment variable at run-time; this is the preferred
way if you use libfaketime for debugging and testing as a programmer, as it
gives you the most direct control of libfaketime without any performance
penalities.
- not using the FAKETIME environment variable, but specifying the fake time in a
file (such as ~/.faketimerc). You can change the content of this file at
run-time. This works best with caching disabled (see Makefile), but comes at a
performance cost because this file has to be read and evaluated each time.
The feature described here works based on two pairs of environment variables,
FAKETIME_START_AFTER_SECONDS and FAKETIME_STOP_AFTER_SECONDS, and
FAKETIME_START_AFTER_NUMCALLS and FAKETIME_STOP_AFTER_NUMCALLS
The default value for each of these environment variables is -1, which means
"ignore this value".
If you want libfaketime to be only active during the run-time minutes 2 to 5
of your application, you would set
FAKETIME_START_AFTER_SECONDS=60
FAKETIME_STOP_AFTER_SECONDS=300
This means that your application will work with the real time from start (second
0) up to second 60. It will then see a faked time from run-time seconds 60 to
300 (minutes 2, 3, 4, and 5). After run-time second 600, it will again see the
real (not-faked) time.
This approach is not as flexible as changing the FAKETIME environment variable
during runtime, but may be easier to use, works on a per-program (and not a
per-user or system-wide) scope, and has only a minor performance overhead.
Using the other pair of environment variables, you can limit the activity time
of libfaketime not based on wall-clock seconds, but on the number of
time-related function calls the started program performs. This alternative is
probably only suitable for programmers who either know the code of the program
in order to determine useful start/stop values or want to perform fuzzing
tests.
Both pairs of environment variables can be combined to further restrict
libfaketime activity, although this is only useful in very few scenarios.
Limiting libfaketime activity in this way is not recommended in general. Many
programs will break when they are subject to sudden changes in time, especially
if they are started using the current (real) time and are then sent back into
the past after, e.g., 5 minutes. For example, they may appear to be frozen or
stuck because they are waiting until a certain point in time that, however, is
never reached due to the delayed libfaketime activity. Avoid using this
functionality unless you are sure you really need it and know what you are
doing.
4i) Spawning an external process
--------------------------------
From version 0.9 on, libfaketime can execute a shell command once after an
arbitrary number of seconds or number of time-related system calls of the
program started. This has two limitations one needs to be aware of:
* Spawning the external process happens during a time-related system call
of the original program. If you want the external process to be started
5 seconds after program start, but this program does not make any time-
related system calls before run-time second 8, the start of your external
process will be delayed until run-time second 8.
* The original program is blocked until the external process is finished,
because the intercepting time-related system call will not return earlier. If
you need to start a long-running external process, make sure it forks into the
background.
Spawning the external process is controlled using three environment variables:
FAKETIME_SPAWN_TARGET, FAKETIME_SPAWN_SECONDS, FAKETIME_SPAWN_NUMCALLS.
Example (using bash on Linux):
(... usual libfaketime setup here, setting LD_PRELOAD and FAKETIME ...)
export FAKETIME_SPAWN_TARGET="/bin/echo 'Hello world'"
export FAKETIME_SPAWN_SECONDS=5
/opt/local/bin/myprogram
This will run the "echo" command with the given parameter during the first
time-related system function call that "myprogram" performs after running for 5
seconds.
4j) Saving timestamps to file, loading them from file
-----------------------------------------------------
Faketime can save faked timestamps to a file specified by FAKETIME_SAVE_FILE
environment variable. It can also use the file specified by FAKETIME_LOAD_FILE
to replay timestamps from it. After consuming the whole file, libfaketime
returns to using the rule set in FAKETIME variable, but the timestamp processes
will start counting from will be the last timestamp in the file.
The file stores each timestamp in a stream of saved_timestamp structs
without any metadata or padding:
/* Storage format for timestamps written to file. Big endian. */
struct saved_timestamp {
int64_t sec;
uint64_t nsec;
};
Faketime needs to be run using the faketime wrapper to use these files. This
functionality has been added by Balint Reczey in v0.9.5.
5. License
----------
FTPL has been released under the GNU Public License, GPL. Please see the
libfaketime has been released under the GNU Public License, GPL. Please see the
included COPYING file.
6. Contact
-----------
Bug reports, feature suggestions, success reports and patches are highly
appreciated.
Bug reports, feature suggestions, success reports, and patches/pull
requests are highly appreciated:
Please send an email to: wolf /at/ code-wizards.com
https://github.com/wolfcw/libfaketime

126
README.OSX Normal file
View File

@@ -0,0 +1,126 @@
README file for libfaketime on Mac OS X
=======================================
Support for Mac OS X is still considered preliminary, although many
command line and GUI applications will run stable.
Developments and tests are done on OSX 10.8+ currently, although the
current version will also work with OSX 10.7.
Version 0.9.5 no longer works with OSX <= 10.6 due to changes in the
underlying system libraries. If you need libfaketime on OSX <= 10.6,
please use libfaketime version 0.9.
Installing and using libfaketime on OS X is slightly different than
on Linux. Please make sure to read the README file for general
setup and usage, and refer to this file only about OS X specifics.
1) Installing libfaketime on OS X
---------------------------------
If you use MacPorts, libfaketime can be installed on the command line
as follows:
sudo port install libfaketime
Otherwise, you have to compile and install libfaketime manually; this
will require a working installation of Xcode and its command line tools
on your machine.
Use the OSX-specific Makefile that is provided:
make -f Makefile.OSX
The resulting library will be named libfaketime.1.dylib ; to check
whether it works properly, run the test suite and verify whether its
output is correct:
cd test
make -f Makefile.OSX
2) Using libfaketime from the command line on OS X
--------------------------------------------------
You will need to set three environment variables. In a Terminal.app
or iTerm2 session, the following commands can be used:
export DYLD_FORCE_FLAT_NAMESPACE=1
export DYLD_INSERT_LIBRARIES=/path/to/libfaketime.1.dylib
export FAKETIME="your favorite faketime-spec here"
Please refer to the general README file concerning the format
of the FAKETIME environment variable value and other environment
variables that are related to it.
The "faketime" wrapper application has been adapted to OS X;
it offers the same limited libfaketime functionality as on Linux
in a simple-to-use manner without the need to manually set
those environment variables. Run "faketime" without parameters
for help and use "man faketime" for details.
3) Integrating libfaketime with applications
--------------------------------------------
Given the limited number of system calls libfaketime intercepts,
it may not work too well with specific GUI applications on OS X.
This can result in crashes after a seemingly random time, or an
application will not or at least not always see the faked time,
and so on.
A safe way to try out whether a specific application works fine
with libfaketime is to start it from the command line. Perform
the steps outlined above and run the application by issuing the
following command:
/Applications/ApplicationName.app/Contents/MacOS/ApplicationName
(Make sure to replace "ApplicationName" twice in that command with
the name of your actual application.)
If it works fine, you can configure the application to permanently
run with libfaketime by editing its Info.plist file. Add the
LSEnvironment key unless it is already there and add a dictionary
with the three keys like this:
<key>LSEnvironment</key>
<dict>
<key>DYLD_FORCE_FLAT_NAMESPACE</key>
<string>1</string>
<key>DYLD_INSERT_LIBRARIES</key>
<string>/path/to/libfaketime.1.dylib</string>
<key>FAKETIME</key>
<string>value of FAKETIME here</string>
</dict>
(If the application is installed in /Applications instead of in
$HOME/Applications, you eventually will need root privileges. If
the application's Info.plist is not in XML, but in binary format,
use appropriate editing or conversion tools.)
Afterwards, you will probably need to run
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/ApplicationName.app
to make sure the change to Info.plist does not go unnoticed.
Please note that modifications to Info.plist will be lost when the
application is updated, so this process needs to be repeated after
such updates, including own new builds when using Xcode.
Please feel free to report non-working applications on the Github
libfaketime issues website. This may help us to identify further
time-related system calls that need to be intercepted on OS X.
https://github.com/wolfcw/libfaketime/issues
4) Notes for developers of OS X applications
--------------------------------------------
The environment variable FAKETIME can be changed at application run-time
and always takes precedence over other user-controlled settings. It can
be re-set to 0 (zero) to work around potential incompatibilities.

106
README.developers Normal file
View File

@@ -0,0 +1,106 @@
This file contains information for libfaketime developers and contributors.
GENERAL
=======
Starting with libfaketime v0.9.5, development and issue handling is
completely done via Github:
https://github.com/wolfcw/libfaketime
- Official releases are tagged.
- Code contributions and bugfixes are merged into the "development" branch,
which is considered unstable and may contain code that is not yet fully
tested.
- The "master" branch is updated with tested code only; it is ensured that
it compiles and works cleanly at least on current Linux and OS X systems.
Code contributions are highly welcome, preferrably via pull requests on Github.
CODE STYLE
==========
Please try to stick to the following code formatting style guidelines:
- No tabs, only spaces for indentation.
- Avoid trailing whitespace.
- Indentation is 2 spaces for each level.
- Opening and closing curly brackets have to be on lines of their own.
- Use under_score_names for function and variable names; avoid using camelCase.
- // and /*...*/ style comments may and shall be used.
Example:
/* This function will do nothing */
void do_nothing(int how_often)
{
int counter;
for (counter = 0; counter < how_often; counter++)
{
counter = counter; // our do-nothing algorithm
}
}
- Use -DDEBUG and #ifdef DEBUG for development and testing. Avoid printing
to stdout or stderr outside "#ifdef DEBUG"; if it is necessary to inform
the user a run-time, prefix your output with "faketime" or make otherwise
sure that the user knows where the message is coming from.
- If you add new functions to libfaketime.c, try placing them somewhere
where they fit will: Usually, functions are grouped by functionality
(e.g., all functions related to faking file timestamps). If that's not
possible, group them by contributor, or document your placement strategy
in the commit message.
DEVELOPMENT, BUILDING, AND TESTING
==================================
- Don't break existing behaviour. Backward compatibility matters (unless
the modification fixes bugs :-)).
- Add tests for new features. Extend test/timetest.c appropriately and
try to use the functional testing framework wherever possible.
- Compiler and linker warnings are treated as errors and not acceptable.
- If you cannot test the code on both Linux and OS X yourself, please
let us know and consider wrapping your code in #ifdef / #ifndef __APPLE__
statements.
DOCUMENTATION
=============
For anything more than small bugfixes, please update the user documentation
and credits appropriately:
- The NEWS file should mention the change and your credits.
- The README and README.OSX files should be updated whenever functionality
is added or modified.
- The manpage man/faketime.1 should be updated when the wrapper application
is modified.
For credits, please either mention your real name, your Github username, or
your email address.
In your own interest, please be verbose on user documentation and comments
in the source code. Users will not know about new features unless they are
documented. Other authors and maintainers will need to understand your code
easily.
RELEASES
========
Official new releases are created whenever a significant amount of changes
(bugfixes or new functionality) has piled up; on average, there is one new
official release per year. Users who need to stick to the bleeding edge
are supposed to use the current state of the "master" branch at any time.
libfaketime maintainers for several Linux distributions are informed about
release candidates and new releases by email. Contact wolfcw on Github if
you are interested in receiving notifications, or use Github functionality
to get informed about updates.

11
TODO Normal file
View File

@@ -0,0 +1,11 @@
Open issues / next steps for libfaketime development
- add more functional tests that check more than the basic functionality
- use the testing framework to also implement unit tests
- make the new "limiting" and "spawning" features more flexible to use
and available through the wrapper shell script
- fake timer_create and friends
- handle CLOCK_REALTIME_COARSE and CLOCK_MONOTONIC_COARSE
- work around thread local storage issue, e.g., by using pthreads
- add autoconf/automake support to get rid of separate Makefile.OSX

14
man/Makefile Normal file
View File

@@ -0,0 +1,14 @@
INSTALL ?= install
PREFIX ?= /usr/local
all:
install:
$(INSTALL) -Dm0644 faketime.1 "${DESTDIR}${PREFIX}/share/man/man1/faketime.1"
gzip -f "${DESTDIR}${PREFIX}/share/man/man1/faketime.1"
uninstall:
rm -f "${DESTDIR}${PREFIX}/share/man/man1/faketime.1.gz"
.PHONY: all install uninstall

15
man/Makefile.OSX Normal file
View File

@@ -0,0 +1,15 @@
INSTALL ?= install
PREFIX ?= /usr/local
all:
install:
$(INSTALL) -dm0644 "${DESTDIR}${PREFIX}/share/man/man1"
$(INSTALL) -m0644 faketime.1 "${DESTDIR}${PREFIX}/share/man/man1/faketime.1"
gzip -f "${DESTDIR}${PREFIX}/share/man/man1/faketime.1"
uninstall:
rm -f "${DESTDIR}${PREFIX}/share/man/man1/faketime.1.gz"
.PHONY: all install uninstall

View File

@@ -1,4 +1,4 @@
.TH FAKETIME "1" "August 2008" "faketime 0.8" W.Hommel
.TH FAKETIME "1" "October 2013" "faketime 0.9.5" wolfcw
.SH NAME
faketime \- manipulate the system time for a given command
.SH SYNOPSIS
@@ -8,10 +8,10 @@ faketime \- manipulate the system time for a given command
.\" \fIfaketime\fR will trick the given program into seeing the specified timestamp as its starting date and time.
.PP
The given command will be tricked into believing that the current system time is the one specified in the timestamp. The wall clock will continue to run
from this date and time unless specified otherwise (see advanced options). Actually, faketime is a simple wrapper for libfaketime, which uses the LD_PRELOAD
from this date and time unless specified otherwise (see advanced options). Actually, faketime is a simple wrapper for libfaketime, which uses the LD_PRELOAD
mechanism to load a small library which intercepts system calls to functions such as
\fItime(2)\fR and \fIfstat(2)\fR. This wrapper exposes only a subset of libfaketime's functionality; please refer to the README file that came with faketime
for more details and advanced options.
for more details and advanced options, or have a look at http://github.com/wolfcw/libfaketime
.SH OPTIONS
.TP
\fB\-\-help\fR
@@ -32,38 +32,41 @@ faketime 'last Friday 5 pm' /bin/date
faketime '2008-12-24 08:15:42' /bin/date
faketime -f '+2,5y x10,0' /bin/bash -c 'date; while true; do echo $SECONDS ; sleep 1 ; done'
faketime -f '+2,5y x0,50' /bin/bash -c 'date; while true; do echo $SECONDS ; sleep 1 ; done'
faketime -f '+2,5y i2,0' /bin/bash -c 'while true; do date ; sleep 1 ; done'
In this single case all spawned processes will use the same global clock without restaring it at the start of each process.
(Please note that it depends on your locale settings whether . or , has to be used for fractional offsets)
.fi
.SH ADVANCED TIMESTAMP FORMAT
The simple timestamp format used by default applies the \fB/bin/date -d\fR command to parse user-friendly specifications such as 'last friday'. When using
the faketime option \fB\-f\fR, the timestamp specified on the command line is directly passed to libfaketime, which enables a couple of additional features
such as speeding the clock up or slowing it down for the target program. It is strongly recommended that you have a look at the README file that came with
faketime for the details. Summary:
such as speeding the clock up or slowing it down for the target program. It is strongly recommended that you have a look at the libfaketime documentation. Summary:
.TP
Freeze clock at absolute timestamp: \fB"YYYY-MM-DD hh:mm:ss"\fR
If you want to specify an absolute point in time, exactly this format must be used. Please note that freezing the clock is usually not what you want and may break the application. Only use if you know what you're doing!
.TP
Relative time offset: \fB"[+/-]123[m/h/d/y]\fR, e.g. "+60m", "+2y"
This is the most often used format and specifies the faked time relatively to the current real time. The first character of the format string \fBmust\fR be a + or a -. The numeric value by default represents seconds, but the modifiers m, h, d, and y can be used to specify minutes, hours, days, or years, respectively. For example, "-2y" means "two years ago". Fractional time offsets can be used, e.g. "+2,5y", which means "two and a half years in the future". Please note that the fraction delimiter depends on your locale settings, so if "+2,5y" does not work, you might want to try "+2.5y".
This is the most often used format and specifies the faked time relatively to the current real time. The first character of the format string \fBmust\fR be a + or a -. The numeric value by default represents seconds, but the modifiers m, h, d, and y can be used to specify minutes, hours, days, or years, respectively. For example, "-2y" means "two years ago". Fractional time offsets can be used, e.g. "+2,5y", which means "two and a half years in the future". Please note that the fraction delimiter depends on your locale settings, so if "+2,5y" does not work, you might want to try "+2.5y".
.TP
Start-at timestamps: \fB"@YYYY-MM-DD hh:mm:ss"\fR
The wall clock will start counting at the given timestamp for the program. This can be used for specifying absolute timestamps without freezing the clock.
The wall clock will start counting at the given timestamp for the program. This can be used for specifying absolute timestamps without freezing the clock.
.SH ADVANCED USAGE
When using relative time offsets or start-at timestamps (see ADVANCED TIMESTAMP FORMAT above and option \fB\-f\fR), the clock speed can be adjusted, i.e. time may run faster or slower for the executed program. For example, \fB"+5y x10"\fR will set the faked time 5 years into the future and make the time pass 10 times as fast (one real second equals 10 seconds measured by the program). Similarly, the flow of time can be slowed, e.g. using \fB"-7d x0,2"\fR, which will set the faked time 7 days in the past and set the clock speed to 20 percent, i.e. it takes five real world seconds for one second measured by the program. Again, depending on your locale, either "x2.0" or "x2,0" may be required regarding the delimiter.
When using relative time offsets or start-at timestamps (see ADVANCED TIMESTAMP FORMAT above and option \fB\-f\fR), the clock speed can be adjusted, i.e. time may run faster or slower for the executed program. For example, \fB"+5y x10"\fR will set the faked time 5 years into the future and make the time pass 10 times as fast (one real second equals 10 seconds measured by the program). Similarly, the flow of time can be slowed, e.g. using \fB"-7d x0,2"\fR, which will set the faked time 7 days in the past and set the clock speed to 20 percent, i.e. it takes five real world seconds for one second measured by the program. Again, depending on your locale, either "x2.0" or "x2,0" may be required regarding the delimiter. You can also make faketime to advance the reported time by a preset interval upon each time() call independently from the system's time using \fB"-7d i2,0"\fR, where
\fB"i"\fR is followed by the increase interval in seconds.
.PP
Faking times for multiple programs or even system-wide can be simplified by using ~/.faketimerc files and /etc/faketimerc. Please refer to the README that came with faketime for warnings and details.
.SH AUTHOR
Maintained by Wolfgang Hommel <wolf@code-wizards.com>. Please see the README and Changelog files for contributers.
Please see the README and NEWS files for contributers.
.SH BUGS
Due to limitations of the LD_PRELOAD mechanism, faketime will not work with suidroot and statically linked programs.
Due to limitations of the LD_PRELOAD mechanism, faketime will not work with suidroot and statically linked programs.
While timestamps and time offsets will work for child processes, speeding the clock up or slowing it down might not
work for child processes spawned by the executed program as expected; a new instance of libfaketime is used for each
child process, which means that the libfaketime start time, which is used in speed adjustments, will also be
re-initialized.
child process, which means that the libfaketime start time, which is used in speed adjustments, will also be
re-initialized. Some programs may dynamically load system libraries, such as librt, at run-time and therefore bypass libfaketime. You may report programs that do not work with libfaketime, but only if they are available as open source.
.SH "REPORTING BUGS"
Please send an e-mail to Wolfgang Hommel <wolf@code-wizards.com>
Please use https://github.com/wolfcw/libfaketime/issues
.SH COPYRIGHT
Copyright \(co 2003-2008 by Wolfgang Hommel.
Copyright \(co 2003-2013 by the libfaketime authors.
.PP
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. You may redistribute copies of faketime under the

View File

@@ -4,11 +4,11 @@
# * Compilation Defines:
#
# FAKE_STAT
# - Enables time faking also for files' timestamps.
# - Enables time faking also for files' timestamps.
#
# NO_ATFILE
# - Disables support for the fstatat() group of functions
#
#
# PTHREAD
# - Define this to enable multithreading support.
#
@@ -19,17 +19,28 @@
# try it unsynchronized.
#
# FAKE_INTERNAL_CALLS
# - Also intercept libc internal __functions, e.g. not just time(),
# - Also intercept libc internal __functions, e.g. not just time(),
# but also __time(). Enhances compatibility with applications
# that make use of low-level system calls, such as Java Virtual
# Machines.
# Machines.
#
# FAKE_SLEEP
# - Also intercept sleep(), nanosleep(), usleep(), alarm(), [p]poll()
#
# FAKE_TIMERS
# - Also intercept timer_settime() and timer_gettime()
#
# NO_CACHING
# - Disables the caching of the fake time offset. Only disable caching
# if you change the fake time offset during program runtime very
# if you change the fake time offset during program runtime very
# frequently. Disabling the cache may negatively influence the
# performance.
# performance.
#
# MULTI_ARCH
# - If MULTI_ARCH is set, the faketime wrapper program will put a literal
# $LIB into the LD_PRELOAD environment variable it creates, which makes
# ld automatically choose the correct library version to use for the
# target binary. Use for Linux platforms with Multi-Arch support only!
#
# * Compilation addition: second libMT target added for building the pthread-
# enabled library as a separate library
@@ -39,44 +50,64 @@
# which is used to activate the start-at times when specified. This also initializes
# the dynamic disabling of the FAKE_STAT calls.
#
# By default, libfaketime will be compiled for your system's default architecture.
# To build 32-bit libraries and binaries, add -m32 to CFLAGS and LDFLAGS.
#
# Change PREFIX to where you want libfaketime (libraries and wrapper binary) installed.
# LIBDIRNAME is relative to PREFIX. The default is to install into $PREFIX/lib/faketime,
# but you can set LIBDIRNAME to, e.g., /lib64 if you want to install it elsewhere.
# LIBDIRNAME has been introduced to support MultiLib systems. Please do not change the
# default value on MultiArch systems.
#
# For testing in the current directory without installation, try make PREFIX= LIBDIRNAME='.'
CC = gcc
CC ?= gcc
INSTALL ?= install
all: lib libMT testprog test
PREFIX ?= /usr/local
LIBDIRNAME ?= /lib/faketime
libs: lib libMT
CFLAGS += -std=gnu99 -Wall -Wextra -Werror -DFAKE_STAT -DFAKE_SLEEP -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -DPREFIX='"'$(PREFIX)'"' -DLIBDIRNAME='"'$(LIBDIRNAME)'"'
LIB_LDFLAGS += -shared
LDFLAGS += -Wl,--version-script=libfaketime.map -lrt
LDADD += -ldl -lm -lpthread -lrt
lib: faketime.c
${CC} -DFAKE_STAT -DFAKE_INTERNAL_CALLS -shared -fPIC -Wl,-soname,libfaketime.so.1 -o libfaketime.so.1 faketime.c -ldl -lm -lpthread
SRC = libfaketime.c
LIBS_OBJ = libfaketime.o libfaketimeMT.o
BINS = faketime
libMT: faketime.c
${CC} -DFAKE_STAT -DFAKE_INTERNAL_CALLS -DPTHREAD -DPTHREAD_SINGLETHREADED_TIME -shared -fPIC -Wl,-soname,libfaketimeMT.so.1 -o libfaketimeMT.so.1 faketime.c -ldl -lm -lpthread
SONAME = 1
LIBS = libfaketime.so.${SONAME} libfaketimeMT.so.${SONAME}
testprog: timetest.c
${CC} -DFAKE_STAT -o timetest timetest.c -lrt
all: ${LIBS} ${BINS}
test: lib testprog
@echo
@./test.sh
faketimeMT.o: EXTRA_FLAGS := -DPTHREAD -DPTHREAD_SINGLETHREADED_TIME
notest: lib libMT testprog
@echo
${LIBS_OBJ}: libfaketime.c
${CC} -o $@ -c ${CFLAGS} ${EXTRA_FLAGS} $<
clean:
@rm -f libfaketime.so.1 libfaketimeMT.so.1 timetest
%.so.${SONAME}: %.o libfaketime.map
${CC} -o $@ -Wl,-soname,$@ ${LDFLAGS} ${LIB_LDFLAGS} $< ${LDADD}
${BINS}: faketime.c
${CC} -o $@ ${CFLAGS} ${EXTRA_FLAGS} $< ${LDFLAGS} ${LDADD}
clean:
@rm -f ${LIBS_OBJ} ${LIBS} ${BINS}
distclean: clean
@echo
@echo
install: libs
@echo
@echo "Copying the libraries to /usr/lib/faketime and the wrapper script to /usr/bin ..."
-mkdir -p /usr/lib/faketime
cp libfaketime.so.1 libfaketimeMT.so.1 /usr/lib/faketime
cp faketime /usr/bin
cp faketime.1 /usr/share/man/man1/faketime.1
gzip /usr/share/man/man1/faketime.1
-mkdir -p /usr/share/doc/faketime
cp README /usr/share/doc/faketime/README
cp Changelog /usr/share/doc/faketime/Changelog
install: ${LIBS} ${BINS}
@echo
@echo "Copying the faketime libraries to ${DESTDIR}${PREFIX}${LIBDIRNAME} and the faketime wrapper script to ${DESTDIR}${PREFIX}/bin ..."
$(INSTALL) -dm0755 "${DESTDIR}${PREFIX}${LIBDIRNAME}/"
$(INSTALL) -m0644 ${LIBS} "${DESTDIR}${PREFIX}${LIBDIRNAME}/"
$(INSTALL) -Dm0755 faketime "${DESTDIR}${PREFIX}/bin/faketime"
uninstall:
for f in ${LIBS}; do rm -f "${DESTDIR}${PREFIX}${LIBDIRNAME}/$$f"; done
rmdir "${DESTDIR}${PREFIX}${LIBDIRNAME}"
rm -f "${DESTDIR}${PREFIX}/bin/faketime"
.PHONY: all clean distclean install uninstall

81
src/Makefile.OSX Normal file
View File

@@ -0,0 +1,81 @@
#
# Notes:
#
# * Compilation Defines:
#
# FAKE_STAT
# - Enables time faking also for files' timestamps.
#
# NO_ATFILE
# - Disables support for the fstatat() group of functions
#
# PTHREAD
# - Define this to enable multithreading support.
#
# PTHREAD_SINGLETHREADED_TIME
# - Define this if you want to single-thread time() ... there ARE
# possibile caching side-effects in a multithreaded environment
# without this, but the performance impact may require you to
# try it unsynchronized.
#
# FAKE_SLEEP
# - Also intercept sleep(), nanosleep(), usleep(), alarm(), [p]poll()
#
# NO_CACHING
# - Disables the caching of the fake time offset. Only disable caching
# if you change the fake time offset during program runtime very
# frequently. Disabling the cache may negatively influence the
# performance.
#
# * Compilation addition: second libMT target added for building the pthread-
# enabled library as a separate library
#
# * Compilation switch change: previous versions compiled using '-nostartfiles'
# This is no longer the case since there is a 'startup' constructor for the library
# which is used to activate the start-at times when specified. This also initializes
# the dynamic disabling of the FAKE_STAT calls.
#
# By default, libfaketime will be compiled for your system's default architecture.
# To build for a different architecture, add -arch flags to CFLAGS and LDFLAGS.
#
# default to clang to support thread local variables
CC ?= clang
INSTALL ?= install
PREFIX ?= /usr/local
CFLAGS += -DFAKE_SLEEP -DPREFIX='"'${PREFIX}'"'
LIB_LDFLAGS += -dynamiclib -current_version 0.9.5 -compatibility_version 0.7
SONAME = 1
LIBS = libfaketime.${SONAME}.dylib
BINS = faketime
all: ${LIBS} ${BINS}
libfaketime.${SONAME}.dylib: libfaketime.c
${CC} -o $@ ${CFLAGS} ${LDFLAGS} ${LIB_LDFLAGS} -install_name ${PREFIX}/lib/faketime/$@ $<
faketime: faketime.c
${CC} -o $@ ${CFLAGS} ${LDFLAGS} $<
clean:
@rm -f ${OBJ} ${LIBS} ${BINS}
distclean: clean
@echo
install: ${LIBS} ${BINS}
@echo
@echo "Copying the faketime libraries to ${DESTDIR}${PREFIX}/lib/faketime and the faketime wrapper script to ${DESTDIR}${PREFIX}/bin ..."
$(INSTALL) -dm0755 "${DESTDIR}${PREFIX}/lib/faketime/"
$(INSTALL) -m0644 ${LIBS} "${DESTDIR}${PREFIX}/lib/faketime/"
$(INSTALL) -dm0755 "${DESTDIR}${PREFIX}/bin"
$(INSTALL) -m0755 faketime "${DESTDIR}${PREFIX}/bin/faketime"
uninstall:
for f in ${LIBS}; do rm -f "${DESTDIR}${PREFIX}/lib/faketime/$$f"; done
rmdir "${DESTDIR}${PREFIX}/lib/faketime"
rm -f "${DESTDIR}${PREFIX}/bin/faketime"
.PHONY: all clean distclean install uninstall

View File

@@ -1,102 +0,0 @@
#!/bin/sh
# Simple wrapper shell script for FTPL (faketime preload library)
# Thanks to Daniel Kahn Gillmor for improvement suggestions.
# It allows you to modify the date and time a program sees when using
# system library calls such as time() and fstat().
# This wrapper exposes only a small subset of the FTPL functionality.
# Please see FTPL's README file for more details
# Acknowledgment: Parts of the functionality of this wrapper have been
# inspired by Matthias Urlichs' datefudge 1.14.
# Configuration: Path where the libfaketime libraries can be found.
FTPL_PATH=/usr/lib/faketime
offset="$1"
USEMT=0
USEDIRECT=0
if [ "$offset" = "-v" -o "$offset" = "--version" ] ; then
echo ""
echo "$0: Version 0.8"
echo "For usage information please use '$0 --help'."
echo ""
exit 0
fi
if [ "$offset" = "-m" ] ; then USEMT=1; shift; offset="$1"; fi
if [ "$offset" = "-f" ] ; then USEDIRECT=1; shift; offset="$1"; fi
if [ "$offset" = "-m" ] ; then USEMT=1; shift; offset="$1"; fi
if [ -z "$offset" -o "$offset" = "-h" -o "$offset" = "-?" -o "$offset" = "--help" ] ; then
echo ""
echo "Usage: $0 [switches] timestamp program arguments"
echo ""
echo "This will run the specified 'program' with the given 'arguments'."
echo "The program will be tricked into seeing the given 'timestamp' as its starting date and time."
echo "The clock will continue to run from this timestamp. Please see the manpage (man faketime)"
echo "for advanced options, such as stopping the wall clock and make it run faster or slower."
echo ""
echo "The optional switches are:"
echo " -m : Use the multi-threaded version of libfaketime"
echo " -f : Use the advanced timestamp specification format (see manpage)"
echo ""
echo "Examples:"
echo "$0 'last friday 5 pm' /bin/date"
echo "$0 '2008-12-24 08:15:42' /bin/date"
echo "$0 -f '+2,5y x10,0' /bin/bash -c 'date; while true; do echo \$SECONDS ; sleep 1 ; done'"
echo "$0 -f '+2,5y x0,50' /bin/bash -c 'date; while true; do echo \$SECONDS ; sleep 1 ; done'"
echo "(Please note that it depends on your locale settings whether . or , has to be used for fractions)"
echo ""
if [ -z "$offset" ] ; then
exit 1;
fi
exit 0
fi
shift
# Setting LD_PRELOAD ...
if [ "$USEMT" -eq 0 ] ; then
export LD_PRELOAD="${LD_PRELOAD}${LD_PRELOAD:+:}$FTPL_PATH/libfaketime.so.1"
fi
if [ "$USEMT" -eq 1 ] ; then
export LD_PRELOAD="${LD_PRELOAD}${LD_PRELOAD:+:}$FTPL_PATH/libfaketimeMT.so.1"
fi
###
# Setting FAKETIME ...
if [ "$USEDIRECT" -eq 0 ] ; then
seconds=$(date -d "$offset" '+%s')
if [ $? -ne 0 ] ; then
echo "Error: Timestamp to fake not recognized, please re-try with a different timestamp."
exit 1
fi
offset=$(expr $seconds - $(date '+%s'))
if [ $? -ne 0 ] ; then
echo "Error: Cannot calculate the faketime offset in seconds, please re-try with a different timestamp."
exit 1
fi
FAKETIMEPREFIX=""
if [ "$offset" -ge 0 ] ; then
FAKETIMEPREFIX="+"
fi
export FAKETIME="$FAKETIMEPREFIX$offset"
fi
if [ "$USEDIRECT" -eq 1 ] ; then
export FAKETIME="$offset"
fi
###
# Executing the user-specified command ...
exec "$@"

File diff suppressed because it is too large Load Diff

50
src/faketime_common.h Normal file
View File

@@ -0,0 +1,50 @@
/*
* Faketime's common definitions
*
* Copyright 2013 Balint Reczey <balint@balintreczey.hu>
*
* This file is part of the libfaketime.
*
* libfaketime is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License v2 as published by the Free
* Software Foundation.
*
* libfaketime is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License v2 along
* with libfaketime; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef FAKETIME_COMMON_H
#define FAKETIME_COMMON_H
#include <stdint.h>
struct system_time_s
{
/* System time according to CLOCK_REALTIME */
struct timespec real;
/* System time according to CLOCK_MONOTONIC */
struct timespec mon;
/* System time according to CLOCK_MONOTONIC_RAW */
struct timespec mon_raw;
};
/* Data shared among faketime-spawned processes */
struct ft_shared_s
{
/*
* When advancing time linearly with each time(), etc. call, the calls are
* counted here */
uint64_t ticks;
/* Index of timstamp to be loaded from file */
uint64_t file_idx;
/* System time Faketime started at */
struct system_time_s start_time;
};
#endif

1901
src/libfaketime.c Normal file

File diff suppressed because it is too large Load Diff

10
src/libfaketime.map Normal file
View File

@@ -0,0 +1,10 @@
GLIBC_2.2 {
global:
timer_gettime; timer_settime;
local: timer_settime_*; timer_gettime_*;
};
GLIBC_2.3.3 {
# Changed timer_t.
timer_gettime; timer_settime;
} GLIBC_2.2;

View File

@@ -1,40 +0,0 @@
#!/bin/sh
if [ -f /etc/faketimerc ] ; then
echo "Running the test program with your system-wide default in /etc/faketimerc"
echo "\$ LD_PRELOAD=./libfaketime.so.1 ./timetest"
LD_PRELOAD=./libfaketime.so.1 ./timetest
echo
else
echo "Running the test program with no faked time specified"
echo "\$ LD_PRELOAD=./libfaketime.so.1 ./timetest"
LD_PRELOAD=./libfaketime.so.1 ./timetest
echo
fi
echo "Running the test program with absolute date 2003-01-01 10:00:05 specified"
echo "\$ LD_PRELOAD=./libfaketime.so.1 FAKETIME=\"2003-01-01 10:00:05\" ./timetest"
LD_PRELOAD=./libfaketime.so.1 FAKETIME="2003-01-01 10:00:05" ./timetest
echo
echo "Running the test program with START date @2005-03-29 14:14:14 specified"
echo "\$ LD_PRELOAD=./libfaketime.so.1 FAKETIME=\"@2005-03-29 14:14:14\" ./timetest"
LD_PRELOAD=./libfaketime.so.1 FAKETIME="@2005-03-29 14:14:14" ./timetest
echo
echo "Running the test program with 10 days negative offset specified"
echo "LD_PRELOAD=./libfaketime.so.1 FAKETIME=\"-10d\" ./timetest"
LD_PRELOAD=./libfaketime.so.1 FAKETIME="-10d" ./timetest
echo
echo "Running the test program with 10 days negative offset specified, and FAKE_STAT disabled"
echo "\$ LD_PRELOAD=./libfaketime.so.1 FAKETIME=\"-10d\" NO_FAKE_STAT=1 ./timetest"
LD_PRELOAD=./libfaketime.so.1 FAKETIME="-10d" NO_FAKE_STAT=1 ./timetest
echo
echo "Running the 'date' command with 15 days negative offset specified"
echo "\$ LD_PRELOAD=./libfaketime.so.1 FAKETIME=\"-15d\" date"
LD_PRELOAD=./libfaketime.so.1 FAKETIME="-15d" date
echo
exit 0

99
src/time_ops.h Normal file
View File

@@ -0,0 +1,99 @@
/*
* Time operation macros based on sys/time.h
* Copyright 2013 Balint Reczey <balint@balintreczey.hu>
*
* This file is part of libfaketime.
*
* libfaketime is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License v2 as published by the Free
* Software Foundation.
*
* libfaketime is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License v2 along
* with libfaketime; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef TIME_OPS_H
#define TIME_OPS_H
#include <time.h>
#define SEC_TO_uSEC 1000000
#define SEC_TO_nSEC 1000000000
/* Convenience macros for operations on timevals.
NOTE: `timercmp' does not work for >= or <=. */
#define timerisset2(tvp, prefix) ((tvp)->tv_sec || (tvp)->tv_##prefix##sec)
#define timerclear2(tvp, prefix) ((tvp)->tv_sec = (tvp)->tv_##prefix##sec = 0)
#define timercmp2(a, b, CMP, prefix) \
(((a)->tv_sec == (b)->tv_sec) ? \
((a)->tv_##prefix##sec CMP (b)->tv_##prefix##sec) : \
((a)->tv_sec CMP (b)->tv_sec))
#define timeradd2(a, b, result, prefix) \
do { \
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
(result)->tv_##prefix##sec = (a)->tv_##prefix##sec + \
(b)->tv_##prefix##sec; \
if ((result)->tv_##prefix##sec >= SEC_TO_##prefix##SEC) \
{ \
++(result)->tv_sec; \
(result)->tv_##prefix##sec -= SEC_TO_##prefix##SEC; \
} \
} while (0)
#define timersub2(a, b, result, prefix) \
do { \
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
(result)->tv_##prefix##sec = (a)->tv_##prefix##sec - \
(b)->tv_##prefix##sec; \
if ((result)->tv_##prefix##sec < 0) { \
--(result)->tv_sec; \
(result)->tv_##prefix##sec += SEC_TO_##prefix##SEC; \
} \
} while (0)
#define timermul2(tvp, c, result, prefix) \
do { \
long long tmp_time; \
tmp_time = (c) * ((tvp)->tv_sec * SEC_TO_##prefix##SEC + \
(tvp)->tv_##prefix##sec); \
(result)->tv_##prefix##sec = tmp_time % SEC_TO_##prefix##SEC; \
(result)->tv_sec = (tmp_time - (result)->tv_##prefix##sec) / \
SEC_TO_##prefix##SEC; \
if ((result)->tv_##prefix##sec < 0) { \
(result)->tv_##prefix##sec += SEC_TO_##prefix##SEC; \
(result)->tv_sec -= 1; \
} \
} while (0)
/* ops for microsecs */
#ifndef timerisset
#define timerisset(tvp) timerisset2(tvp,u)
#endif
#ifndef timerclear
#define timerclear(tvp) timerclear2(tvp, u)
#endif
#ifndef timercmp
#define timercmp(a, b, CMP) timercmp2(a, b, CMP, u)
#endif
#ifndef timeradd
#define timeradd(a, b, result) timeradd2(a, b, result, u)
#endif
#ifndef timersub
#define timersub(a, b, result) timersub2(a, b, result, u)
#endif
#ifndef timersub
#define timermul(a, c, result) timermul2(a, c, result, u)
#endif
/* ops for nanosecs */
#define timespecisset(tvp) timerisset2(tvp,n)
#define timespecclear(tvp) timerclear2(tvp, n)
#define timespeccmp(a, b, CMP) timercmp2(a, b, CMP, n)
#define timespecadd(a, b, result) timeradd2(a, b, result, n)
#define timespecsub(a, b, result) timersub2(a, b, result, n)
#define timespecmul(a, c, result) timermul2(a, c, result, n)
#endif

270
src/timeprivacy Normal file
View File

@@ -0,0 +1,270 @@
#!/bin/bash
## Copyright (c) 2013, adrelanos at riseup dot net
## All rights reserved.
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions are met:
##
## 1. Redistributions of source code must retain the above copyright notice, this
## list of conditions and the following disclaimer.
## 2. Redistributions in binary form must reproduce the above copyright notice,
## this list of conditions and the following disclaimer in the documentation
## and/or other materials provided with the distribution.
##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
## WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
## (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
## SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#set -x
SCRIPTNAME="$(basename $0)"
usage() {
echo "$SCRIPTNAME
Usage: $SCRIPTNAME [-h help] [-d day] [-m month] [-y year] [-i increment in seconds (0-60)] [-r random increment in seconds (0-60)] [-f history folder]
Example: $SCRIPTNAME -d 30 -m 12 -y 2013 -i 10 -f /tmp/$SCRIPTNAMEtest
sudo $SCRIPTNAME -d 30 -m 12 -y 2013 -r -f /tmp/$SCRIPTNAMEtest"
}
_randomincrement="none"
_increment="none"
while [ -n "$1" ]; do
case "$1" in
-h)
usage
exit 0
;;
-d)
_day="$2"
shift
;;
-m)
_month="$2"
shift
;;
-y)
_year="$2"
shift
;;
-i)
_increment="$2"
shift
;;
-r)
_randomincrement="$2"
shift
;;
-f)
TIMEDIR="$2"
shift
;;
*)
command="$(which $1)"
## From now on the complete to-be wrapped command + its args
## are stored in $@, which will expand like we want it for
## handling quoted arguments with whitespaces in it, etc.
break
esac
shift
done
if [ -z "$_day" ]; then
_day="$(date +"%d")"
fi
if [ -z "$_month" ]; then
_month="$(date +"%m")"
fi
if [ -z "$_year" ]; then
_year="$(date +"%Y")"
fi
if [ "$_randomincrement" = "none" ] && [ "$_increment" = "none" ]; then
_increment="1"
fi
if [ "$_randomincrement" = "none" ]; then
if [ -z "$_increment" ]; then
_increment="1"
fi
elif [ "$_increment" = "none" ]; then
if [ "$_randomincrement" = "" ]; then
echo "randomincrement must be a positive number."
exit 1
else
## random number between 1 and $_randomincrement
random_number="$(( 0+($(od -An -N2 -i /dev/random) )%($_randomincrement-0+1) ))"
_increment="$random_number"
fi
else
echo "You can not combine -r and -i."
exit 1
fi
if [ -z "$TIMEDIR" ]; then
TIMEDIR=~/.timeprivacy
fi
nodigits="$(echo $_increment | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
echo "increment is not a digit."
exit 1
fi
nodigits="$(echo $_year | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
echo "_day is not a digit."
exit 1
fi
nodigits="$(echo $_year | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
echo "year is not a digit."
exit 1
fi
nodigits="$(echo $_month | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
echo "month is not a digit."
exit 1
fi
nodigits="$(echo $_day | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
echo "day is not a digit."
exit 1
fi
nodigits="$(echo $_increment | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
echo "increment is not a digit."
exit 1
fi
SECONDS_FILE="$TIMEDIR/seconds_file"
MINUTES_FILE="$TIMEDIR/minutes_file"
HOURS_FILE="$TIMEDIR/hours_file"
#DAYS_FILE="$TIMEDIR/days_file"
#MONTHS_FILE="$TIMEDIR/months_file"
#YEARS_FILE="$TIMEDIR/years_file"
#true "TIMEDIR: $TIMEDIR"
#true "year: $_year"
#true "month: $_month"
#true "day: $_day"
#true "_randomincrement: $_randomincrement"
#true "_increment: $_increment"
read_date_file() {
if [ ! -d "$TIMEDIR" ]; then
mkdir -p "$TIMEDIR"
fi
if [ ! -f "$SECONDS_FILE" ]; then
echo "0" > "$SECONDS_FILE"
fi
if [ ! -f "$MINUTES_FILE" ]; then
echo "0" > "$MINUTES_FILE"
fi
if [ ! -f "$HOURS_FILE" ]; then
echo "0" > "$HOURS_FILE"
fi
#if [ ! -f "$DAYS_FILE" ]; then
#echo "1" > "$DAYS_FILE"
#fi
#if [ ! -f "$MONTHS_FILE" ]; then
#echo "1" > "$MONTHS_FILE"
#fi
#if [ ! -f "$YEARS_FILE" ]; then
#echo "2013" > "$YEARS_FILE"
#fi
SECONDS="$(cat "$SECONDS_FILE")"
MINUTES="$(cat "$MINUTES_FILE")"
HOURS="$(cat "$HOURS_FILE")"
if [ -z "$SECONDS" ]; then
SECONDS="0"
fi
if [ -z "$MINUTES" ]; then
MINUTES="0"
fi
if [ -z "$HOURS" ]; then
HOURS="0"
fi
local nodigits="$(echo $SECONDS | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
SECONDS="0"
fi
local nodigits="$(echo $MINUTES | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
MINUTES="0"
fi
local nodigits="$(echo $HOURS | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
HOURS="0"
fi
SECONDS="$(expr "$SECONDS" + "$_increment")" || true
if [ "$SECONDS" -ge "60" ]; then
SECONDS="0"
MINUTES="$(expr "$MINUTES" + "1")" || true
if [ "$MINUTES" -ge "60" ]; then
MINUTES="0"
HOURS="$(expr "$HOURS" + "1")" || true
if [ "$HOURS" -ge "24" ]; then
HOURS="0"
fi
echo "$HOURS" > "$HOURS_FILE"
fi
echo "$MINUTES" > "$MINUTES_FILE"
fi
echo "$SECONDS" > "$SECONDS_FILE"
#echo "$HOURS $MINUTES $SECONDS"
}
need_new_date() {
## Testing
#while [ 1 ]; do
# read_date_file
#done
read_date_file
## Testing
#echo "faketime '$_year-$_month-$_day $HOURS:$MINUTES:$SECONDS' /bin/date"
#faketime "$_year-$_month-$_day $HOURS:$MINUTES:$SECONDS" /bin/date
echo "$_year-$_month-$_day $HOURS:$MINUTES:$SECONDS"
}
need_new_date

View File

@@ -1,66 +0,0 @@
/*
* Copyright (C) 2003,2007 Wolfgang Hommel
*
* This file is part of the FakeTime Preload Library.
*
* The FakeTime Preload Library is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* The FakeTime Preload Library is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the FakeTime Preload Library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/timeb.h>
#ifdef FAKE_STAT
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
int main (int argc, char **argv) {
time_t now;
struct timeb tb;
struct timeval tv;
struct timespec ts;
#ifdef FAKE_STAT
struct stat buf;
#endif
time(&now);
printf("time() : Current date and time: %s", ctime(&now));
printf("time(NULL) : Seconds since Epoch : %u\n", time(NULL));
ftime(&tb);
printf("ftime() : Current date and time: %s", ctime(&tb.time));
printf("(Intentionally sleeping 2 seconds...)\n");
fflush(stdout);
sleep(2);
gettimeofday(&tv, NULL);
printf("gettimeofday() : Current date and time: %s", ctime(&tv.tv_sec));
clock_gettime(CLOCK_REALTIME, &ts);
printf("clock_gettime(): Current date and time: %s", ctime(&ts.tv_sec));
#ifdef FAKE_STAT
lstat(argv[0], &buf);
printf("stat(): mod. time of file '%s': %s", argv[0], ctime(&buf.st_mtime));
#endif
return 0;
}

31
test/Makefile Normal file
View File

@@ -0,0 +1,31 @@
CC = gcc
CFLAGS = -std=gnu99 -Wall -DFAKE_STAT -Werror -Wextra
LDFLAGS = -lrt
SRC = timetest.c
OBJ = ${SRC:.c=.o}
all: timetest test
.c.o:
${CC} -c ${CFLAGS} $<
timetest: ${OBJ}
${CC} -o $@ ${OBJ} ${LDFLAGS}
test: timetest functest
@echo
@./test.sh
# run functional tests
functest:
./testframe.sh functests
clean:
@rm -f ${OBJ} timetest
distclean: clean
@echo
.PHONY: all test clean distclean

31
test/Makefile.OSX Normal file
View File

@@ -0,0 +1,31 @@
CC = gcc
CFLAGS = -std=gnu99 -Wall -DFAKE_STAT
LDFLAGS =
SRC = timetest.c
OBJ = ${SRC:.c=.o}
all: timetest test
.c.o:
${CC} -c ${CFLAGS} $<
timetest: ${OBJ}
${CC} -o $@ ${OBJ} ${LDFLAGS}
test: timetest functest
@echo
@./test_OSX.sh
# run functional tests
functest:
./testframe.sh functests
clean:
@rm -f ${OBJ} timetest
distclean: clean
@echo
.PHONY: all test clean distclean

39
test/README-testframe.txt Normal file
View File

@@ -0,0 +1,39 @@
# here's how the testframe script works.
#
# Usage for testing:
# usage: testframe.sh DIR
# testframe.sh runs each testsuite script found within DIR.
# (in the context of libfaketime, the DIR is functest.)
# exits with status 0 if all tests succeed.
#
# Interface:
# by convention, each testsuite script (within DIR) must be
# a bash script named test_*.sh. the script must define a
# function named "run". run takes no arguments. run is
# expected to call the framework-provided function
# run_testcase once for each test function. run_testcase
# uses the global vars NFAIL and NSUCC to keep track of how
# many testcases failed/succeeded.
#
# the test function is expected to call something like
# asserteq or assertneq (again, framework-provided).
#
# fine print: for each testsuite, the framework creates a
# subshell and dots in the script. also dotted in are
# testframe.inc and DIR/common.inc (if it exists). the
# testsuite script can make use of any functions defined
# in these inc files. the environment variable
# TESTSUITE_NAME is set to the filename of the testsuite
# script, for possible use in warning or info messages.
#
# see functests/test_true.sh for a simple example of
# a test suite script.
#
# Simple steps to add a new testsuite:
# 1. decide its name - eg, XXX.
# 2. choose a DIR of similar testsuites to put it in, or create a new one.
# 3. create DIR/test_XXX.sh.
# 4. write a run function and testcase functions in DIR/test_XXX.sh.
# 5. within the run function, call run_testcase for each testcase function.
# 6. within each testcase funtion, call assertneq or asserteq, or do
# the equivalent.

53
test/functests/common.inc Normal file
View File

@@ -0,0 +1,53 @@
# libfaketime-specific common support routines for tests
# say which *_fakecmd wrapper to use
platform()
{
# may want to expand the pattern for linuxlike
typeset out=$(uname)
case "$out" in
*Darwin*) echo "mac" ;;
*Linux*) echo "linuxlike" ;;
GNU|GNU/kFreeBSD) echo "linuxlike" ;;
*) echo 1>&2 unsupported platform, uname=\"$out\" ;;
esac
}
# run faked command on a mac
# UNTESTED
mac_fakecmd()
{
typeset timestring="$1"; shift
typeset fakelib=../src/libfaketime.1.dylib
export DYLD_INSERT_LIBRARIES=$fakelib
export DYLD_FORCE_FLAT_NAMESPACE=1
FAKETIME="$timestring" \
"$@"
}
# run faked command on linuxlike OS
linuxlike_fakecmd()
{
typeset timestring="$1"; shift
typeset fakelib=../src/libfaketime.so.1
export LD_PRELOAD=$fakelib
FAKETIME="$timestring" \
"$@"
}
# run a command with libfaketime using the given timestring
fakecmd()
{
${PLATFORM}_fakecmd "$@"
}
# generate a sequence of numbers from a to b
range()
{
typeset a=$1 b=$2
typeset i=$a
while ((i <= b)); do
echo $i
((i = i+1))
done
}

View File

@@ -0,0 +1,6 @@
# a testsuite that will force failure - for testing purposes
run()
{
run_testcase false
}

View File

@@ -0,0 +1,13 @@
# check that the date doesn't happen to be 0.
run()
{
run_testcase nulltest
}
nulltest()
{
typeset tdate=${I2DATES[0]}
assertneq 0 "$(date +%s)" "($tdate)"
}

View File

@@ -0,0 +1,7 @@
# test suite that always succeds - for testing framework
run()
{
run_testcase true
return 0
}

67
test/functests/test_walkone.sh Executable file
View File

@@ -0,0 +1,67 @@
# walking-1 test.
# sourced in from testframe.sh.
#
# this script defines a suite of functional tests
# that verifies the correct operation of libfaketime
# with the date command.
run()
{
init
for i in $(range 0 30); do
run_testcase test_with_i $i
done
}
# ----- support routines
init()
{
typeset testsuite="$1"
PLATFORM=$(platform)
if [ -z "$PLATFORM" ]; then
echo "$testsuite: unknown platform! quitting"
return 1
fi
echo "# PLATFORM=$PLATFORM"
return 0
}
# run date cmd under faketime, print time in secs
fakedate()
{
#
# let the time format be raw seconds since Epoch
# for both input to libfaketime, and output of the date cmd.
#
typeset fmt='%s'
export FAKETIME_FMT=$fmt
fakecmd "$1" date +$fmt
}
#
# compute x**n.
# use only the shell, in case we need to run on machines
# without bc, dc, perl, etc.
#
pow()
{
typeset x="$1" n="$2"
typeset r=1
typeset i=0
while ((i < n)); do
((r = r*x))
((i++))
done
echo $r
}
# run a fakedate test with a given time t
test_with_i()
{
typeset i="$1"
typeset t=$(pow 2 $i)
asserteq $(fakedate $t) $t "(secs since Epoch)"
}

66
test/test.sh Executable file
View File

@@ -0,0 +1,66 @@
#!/bin/sh
if [ -f /etc/faketimerc ] ; then
echo "Running the test program with your system-wide default in /etc/faketimerc"
echo "\$ LD_PRELOAD=../src/libfaketime.so.1 ./timetest"
LD_PRELOAD=../src/libfaketime.so.1 ./timetest
echo
else
echo "Running the test program with no faked time specified"
echo "\$ LD_PRELOAD=../src/libfaketime.so.1 ./timetest"
LD_PRELOAD=../src/libfaketime.so.1 ./timetest
echo
fi
echo "============================================================================="
echo
echo "Running the test program with absolute date 2003-01-01 10:00:05 specified"
echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"2003-01-01 10:00:05\" ./timetest"
LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="2003-01-01 10:00:05" ./timetest
echo
echo "============================================================================="
echo
echo "Running the test program with START date @2005-03-29 14:14:14 specified"
echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"@2005-03-29 14:14:14\" ./timetest"
LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="@2005-03-29 14:14:14" ./timetest
echo
echo "============================================================================="
echo
echo "Running the test program with 10 days negative offset specified"
echo "LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"-10d\" ./timetest"
LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="-10d" ./timetest
echo
echo "============================================================================="
echo
echo "Running the test program with 10 days negative offset specified, and FAKE_STAT disabled"
echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"-10d\" NO_FAKE_STAT=1 ./timetest"
LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="-10d" NO_FAKE_STAT=1 ./timetest
echo
echo "============================================================================="
echo
echo "Running the test program with 10 days postive offset specified, and sped up 2 times"
echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"+10d x2\" ./timetest"
LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="+10d x2" NO_FAKE_STAT=1 ./timetest
echo
echo "============================================================================="
echo
echo "Running the 'date' command with 15 days negative offset specified"
echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"-15d\" date"
LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="-15d" date
echo
echo "============================================================================="
echo "Testing finished."
exit 0

46
test/test_OSX.sh Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/sh
export DYLD_FORCE_FLAT_NAMESPACE=1
export DYLD_INSERT_LIBRARIES=../src/libfaketime.1.dylib
if [ -f /etc/faketimerc ] ; then
echo "Running the test program with your system-wide default in /etc/faketimerc"
./timetest
echo
else
echo "Running the test program with no faked time specified"
./timetest
echo
fi
echo "Running the test program with absolute date 2003-01-01 10:00:05 specified"
echo "FAKETIME=\"2003-01-01 10:00:05\" ./timetest"
FAKETIME="2003-01-01 10:00:05" ./timetest
echo
echo "Running the test program with START date @2005-03-29 14:14:14 specified"
echo "FAKETIME=\"@2005-03-29 14:14:14\" ./timetest"
FAKETIME="@2005-03-29 14:14:14" ./timetest
echo
echo "Running the test program with 10 days negative offset specified"
echo "FAKETIME=\"-10d\" ./timetest"
FAKETIME="-10d" ./timetest
echo
echo "Running the test program with 10 days negative offset specified, and FAKE_STAT disabled"
echo "FAKETIME=\"-10d\" NO_FAKE_STAT=1 ./timetest"
FAKETIME="-10d" NO_FAKE_STAT=1 ./timetest
echo
echo "Running the test program with 10 days postive offset specified, and sped up 2 times"
echo "FAKETIME=\"+10d x2\" ./timetest"
FAKETIME="+10d x2" NO_FAKE_STAT=1 ./timetest
echo
echo "Running the 'date' command with 15 days negative offset specified"
echo "FAKETIME=\"-15d\" date"
FAKETIME="-15d" date
echo
exit 0

55
test/testframe.inc Normal file
View File

@@ -0,0 +1,55 @@
# framework common functions for use in test suites and test cases
#
# run a test and keep stats on success/failure.
# arguments: a command, possibly a shell function.
# return value: 0 on success, 1 on failure.
# side effects: increments global var NSUCC on success, NFAIL on failure.
#
run_testcase()
{
if "$@"; then
((NSUCC++))
return 0
else
((NFAIL++))
return 1
fi
}
#
# verbosely check that the test output matches the expected value.
# arguments: the test output, the expected value, and a description.
# return value: 0 on if test output equals expected value; 1 otherwise.
# side effects: prints a descriptive message.
#
asserteq()
{
typeset out="$1" expected="$2" desc="$3"
echo -n "out=$out $desc"
if [ "$out" = "$expected" ]; then
echo " - ok"
return 0
else
echo " expected=$expected - bad"
return 1
fi
}
#
# verbosely check that the test output doesn't match the reference value.
# return value: 1 on if test output equals expected value; 0 if not equal.
# side effects: prints descriptive message.
#
assertneq()
{
typeset out="$1" ref="$2" desc="$3"
echo -n "out=$out $desc"
if [ "$out" = "$ref" ]; then
echo " ref=$ref - bad"
return 1
else
echo " ref=$ref - ok"
return 0
fi
}

99
test/testframe.sh Executable file
View File

@@ -0,0 +1,99 @@
#! /bin/bash
# testframe.sh DIR
# bare-bones testing framework.
# run the test suites in the given DIR;
# exit with nonzero status if any of them failed.
# see README.testframe.txt for details.
#
# echo labelled error/warning message to stderr
report()
{
echo $PROG: $* 1>&2
}
# echo OK or BAD depending on argument (0 or not)
status_word()
{
if [ "$1" -eq 0 ]; then
echo OK
else
echo BAD
fi
}
# run the given testsuite, return nonzero if any testcase failed.
run_testsuite()
{
typeset testsuite="$1"
NFAIL=0
NSUCC=0
# add testsuite dir to PATH for convenience
typeset dir=$(dirname $testsuite)
PATH=$dir:$PATH
. testframe.inc
if [ -f $dir/common.inc ]; then
. $dir/common.inc
fi
. $testsuite
export TESTSUITE_NAME=$testsuite
echo ""
echo "# Begin $testsuite"
run
typeset runstat=$?
echo "# $testsuite summary: $NSUCC succeeded, $NFAIL failed"
if [ $runstat -ne 0 ]; then
((NFAIL++))
report "error: $testsuite run exit_status=$runstat!"
fi
echo "# End $testsuite -" $(status_word $NFAIL)
[ $NFAIL -eq 0 ]
}
#
# list all testsuite scripts in the given directories.
# a testsuite file must be a bash script whose name is of the form test_*.sh .
#
list_testsuites()
{
for dir in "$@"; do
ls $dir/test_*.sh 2>/dev/null
done
}
main()
{
TS_NFAIL=0
TS_NSUCC=0
echo "# Begin Test Suites in $*"
typeset testsuites=$(list_testsuites "$@")
if [ -z "$testsuites" ]; then
report "error: no testsuites found"
exit 1
fi
for testsuite in $testsuites; do
if run_testsuite $testsuite; then
((TS_NSUCC++))
else
((TS_NFAIL++))
fi
done
echo ""
echo "# Test Suites summary: $TS_NSUCC succeeded, $TS_NFAIL failed"
echo "# End Test Suites -" $(status_word $TS_NFAIL)
[ $TS_NFAIL -eq 0 ]
}
# ----- start of mainline code
PROG=${0##*/}
main "${@:-.}"

190
test/timetest.c Normal file
View File

@@ -0,0 +1,190 @@
/*
* Copyright (C) 2003,2007 Wolfgang Hommel
*
* This file is part of the FakeTime Preload Library.
*
* The FakeTime Preload Library is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* The FakeTime Preload Library is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the FakeTime Preload Library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <sys/timeb.h>
#ifdef FAKE_STAT
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#ifndef __APPLE__
#include <signal.h>
#define VERBOSE 0
static void
handler(int sig, siginfo_t *si, void *uc)
{
/* Note: calling printf() from a signal handler is not
strictly correct, since printf() is not async-signal-safe;
see signal(7) */
if ((si == NULL) || (si != uc))
{
printf("Caught signal %d\n", sig);
}
signal(sig, SIG_IGN);
}
#endif
int main (int argc, char **argv) {
time_t now;
struct timeb tb;
struct timeval tv;
#ifndef __APPLE__
struct timespec ts;
timer_t timerid1 = 0, timerid2;
struct sigevent sev;
struct itimerspec its;
sigset_t mask;
struct sigaction sa;
#endif
#ifdef FAKE_STAT
struct stat buf;
#endif
#ifndef __APPLE__
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = handler;
sigemptyset(&sa.sa_mask);
if (sigaction(SIGRTMIN, &sa, NULL) == -1) {
perror("sigaction");
exit(EXIT_FAILURE);
}
/* Block timer signal temporarily */
printf("Blocking signal %d\n", SIGRTMIN);
sigemptyset(&mask);
sigaddset(&mask, SIGRTMIN);
if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) {
perror("sigaction");
exit(EXIT_FAILURE);
}
/* Create the timer */
sev.sigev_notify = SIGEV_SIGNAL;
sev.sigev_signo = SIGRTMIN;
sev.sigev_value.sival_ptr = &timerid1;
if (timer_create(CLOCK_REALTIME, &sev, &timerid1) == -1) {
perror("timer_create");
exit(EXIT_FAILURE);
}
/* Start timer1 */
/* start timer ticking after one second */
its.it_value.tv_sec = 1;
its.it_value.tv_nsec = 0;
/* fire in every 0.3 seconds */
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = 300000000;
if (timer_settime(timerid1, 0, &its, NULL) == -1) {
perror("timer_settime");
exit(EXIT_FAILURE);
}
sev.sigev_value.sival_ptr = &timerid2;
if (timer_create(CLOCK_REALTIME, &sev, &timerid2) == -1) {
perror("timer_create");
exit(EXIT_FAILURE);
}
/* Start timer2 */
clock_gettime(CLOCK_REALTIME, &its.it_value);
/* start timer ticking after one second */
its.it_value.tv_sec += 3;
/* fire once */
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = 0;
if (timer_settime(timerid2, TIMER_ABSTIME, &its, NULL) == -1) {
perror("timer_settime");
exit(EXIT_FAILURE);
}
#endif
time(&now);
printf("time() : Current date and time: %s", ctime(&now));
printf("time(NULL) : Seconds since Epoch : %u\n", (unsigned int)time(NULL));
ftime(&tb);
printf("ftime() : Current date and time: %s", ctime(&tb.time));
printf("(Intentionally sleeping 2 seconds...)\n");
fflush(stdout);
if (argc < 3)
{
sleep(1);
usleep(1000000);
}
gettimeofday(&tv, NULL);
printf("gettimeofday() : Current date and time: %s", ctime(&tv.tv_sec));
#ifndef __APPLE__
if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1) {
perror("sigprocmask");
exit(EXIT_FAILURE);
}
clock_gettime(CLOCK_REALTIME, &ts);
printf("clock_gettime(): Current date and time: %s", ctime(&ts.tv_sec));
int timer_getoverrun_timerid1 = timer_getoverrun(timerid1);
if (timer_getoverrun_timerid1 != 3) {
printf("timer_getoverrun(timerid1) FAILED, must be 3 but got: %d\n", timer_getoverrun_timerid1);
}
timer_gettime(timerid1, &its);
if (VERBOSE == 1) {
printf("timer_gettime(timerid1, &its); its = {{%ld, %ld}, {%ld, %ld}}}\n",
its.it_interval.tv_sec, its.it_interval.tv_nsec,
its.it_value.tv_sec, its.it_value.tv_nsec);
}
int timer_getoverrun_timerid2 = timer_getoverrun(timerid2);
if (timer_getoverrun_timerid2 != 0) {
printf("timer_getoverrun(timerid2) FAILED, must be 0 but got: %d\n", timer_getoverrun_timerid2);
}
timer_gettime(timerid2, &its);
if (VERBOSE == 1) {
printf("timer_gettime(timerid2, &its); its = {{%ld, %ld}, {%ld, %ld}}}\n",
its.it_interval.tv_sec, its.it_interval.tv_nsec,
its.it_value.tv_sec, its.it_value.tv_nsec);
}
#endif
#ifdef FAKE_STAT
lstat(argv[0], &buf);
printf("stat(): mod. time of file '%s': %s", argv[0], ctime(&buf.st_mtime));
#endif
return 0;
}