mirror of
https://github.com/wolfcw/libfaketime.git
synced 2026-05-17 00:26:16 +03:00
Revert "merged rbalint's pr27"
This reverts commit5283614bec, reversing changes made to4ecef4db08.
This commit is contained in:
23
README
23
README
@@ -19,6 +19,7 @@ Content of this file:
|
||||
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
|
||||
|
||||
@@ -424,11 +425,31 @@ 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 faketime 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 the files.
|
||||
|
||||
5. License
|
||||
----------
|
||||
|
||||
FTPL has been released under the GNU Public License, GPL. Please see the
|
||||
FTPL has been released under the GNU Public License, GPL. Please see xthe
|
||||
included COPYING file.
|
||||
|
||||
|
||||
|
||||
2
TODO
2
TODO
@@ -4,3 +4,5 @@ Open issues / next steps for libfaketime development
|
||||
- use the new 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
|
||||
|
||||
10
src/Makefile
10
src/Makefile
@@ -30,14 +30,6 @@
|
||||
# frequently. Disabling the cache may negatively influence the
|
||||
# performance.
|
||||
#
|
||||
# LIMITEDFAKING
|
||||
# - Support environment variables that limit time faking to certain
|
||||
# time intervals or number of function calls.
|
||||
#
|
||||
# SPAWNSUPPORT
|
||||
# - Enable support for spawning an external process at a given
|
||||
# timestamp.
|
||||
#
|
||||
# * Compilation addition: second libMT target added for building the pthread-
|
||||
# enabled library as a separate library
|
||||
#
|
||||
@@ -52,7 +44,7 @@ INSTALL ?= install
|
||||
|
||||
PREFIX ?= /usr/local
|
||||
|
||||
CFLAGS += -std=gnu99 -Wall -DFAKE_STAT -DFAKE_INTERNAL_CALLS -fPIC -DPOSIX_REALTIME -DLIMITEDFAKING -DSPAWNSUPPORT -DPREFIX='"'$(PREFIX)'"'
|
||||
CFLAGS += -std=gnu99 -Wall -DFAKE_STAT -DFAKE_INTERNAL_CALLS -fPIC -DPREFIX='"'$(PREFIX)'"'
|
||||
LIB_LDFLAGS += -shared
|
||||
LDFLAGS += -lrt
|
||||
LDADD += -ldl -lm -lpthread
|
||||
|
||||
@@ -30,15 +30,6 @@
|
||||
# frequently. Disabling the cache may negatively influence the
|
||||
# performance.
|
||||
#
|
||||
# LIMITEDFAKING
|
||||
# - Support environment variables that limit time faking to certain
|
||||
# time intervals or number of function calls.
|
||||
#
|
||||
# SPAWNSUPPORT
|
||||
# - Enable support for spawning an external process at a given
|
||||
# timestamp.
|
||||
#
|
||||
#
|
||||
# * Compilation addition: second libMT target added for building the pthread-
|
||||
# enabled library as a separate library
|
||||
#
|
||||
@@ -60,7 +51,7 @@ PREFIX ?= /usr/local
|
||||
# 10.5
|
||||
#CFLAGS = -dynamiclib -DFAKE_INTERNAL_CALLS -arch i386 -arch ppc
|
||||
# 10.6
|
||||
CFLAGS = -dynamiclib -DFAKE_INTERNAL_CALLS -arch i386 -arch x86_64 -DLIMITEDFAKING -DSPAWNSUPPORT -DPREFIX='"'$(PREFIX)'"'
|
||||
CFLAGS = -dynamiclib -DFAKE_INTERNAL_CALLS -arch i386 -arch x86_64 -DPREFIX='"'$(PREFIX)'"'
|
||||
LIB_SRC = libfaketime.c
|
||||
|
||||
SONAME = 1
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#include <sys/mman.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#include "faketime_common.h"
|
||||
|
||||
const char version[] = "0.8";
|
||||
|
||||
#ifdef __APPLE__
|
||||
@@ -161,7 +163,7 @@ int main (int argc, char **argv)
|
||||
/* create semaphores and shared memory */
|
||||
int shm_fd;
|
||||
sem_t *sem;
|
||||
uint64_t *ticks;
|
||||
struct ft_shared_s *ft_shared;
|
||||
char shared_objs[PATH_BUFSIZE];
|
||||
|
||||
snprintf(sem_name, PATH_BUFSIZE -1 ,"/faketime_sem_%d", getpid());
|
||||
@@ -189,7 +191,7 @@ int main (int argc, char **argv)
|
||||
}
|
||||
|
||||
/* map shm */
|
||||
if (MAP_FAILED == (ticks = mmap(NULL, sizeof(uint64_t), PROT_READ|PROT_WRITE,
|
||||
if (MAP_FAILED == (ft_shared = mmap(NULL, sizeof(struct ft_shared_s), PROT_READ|PROT_WRITE,
|
||||
MAP_SHARED, shm_fd, 0))) {
|
||||
perror("mmap");
|
||||
cleanup_shobjs();
|
||||
@@ -203,8 +205,16 @@ int main (int argc, char **argv)
|
||||
}
|
||||
|
||||
/* init elapsed time ticks to zero */
|
||||
*ticks = 0;
|
||||
if (-1 == munmap(ticks, (sizeof(uint64_t)))) {
|
||||
ft_shared->ticks = 0;
|
||||
ft_shared->file_idx = 0;
|
||||
ft_shared->start_time.real.tv_sec = 0;
|
||||
ft_shared->start_time.real.tv_nsec = -1;
|
||||
ft_shared->start_time.mon.tv_sec = 0;
|
||||
ft_shared->start_time.mon.tv_nsec = -1;
|
||||
ft_shared->start_time.mon_raw.tv_sec = 0;
|
||||
ft_shared->start_time.mon_raw.tv_nsec = -1;
|
||||
|
||||
if (-1 == munmap(ft_shared, (sizeof(struct ft_shared_s)))) {
|
||||
perror("munmap");
|
||||
cleanup_shobjs();
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
49
src/faketime_common.h
Normal file
49
src/faketime_common.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Faketime's common definitions
|
||||
*
|
||||
* Copyright 2013 Balint Reczey <balint@balintreczey.hu>
|
||||
*
|
||||
* 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 v2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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 v2
|
||||
* 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
|
||||
*/
|
||||
|
||||
#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
|
||||
1180
src/libfaketime.c
1180
src/libfaketime.c
File diff suppressed because it is too large
Load Diff
99
src/time_ops.h
Normal file
99
src/time_ops.h
Normal 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 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 v2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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 v2
|
||||
* 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
|
||||
*/
|
||||
|
||||
#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
|
||||
@@ -30,6 +30,10 @@ 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 "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 "Running the 'date' command with 15 days negative offset specified"
|
||||
|
||||
Reference in New Issue
Block a user