Unix Programming - How to spoof system time for a process?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2006 > How to spoof system time for a process?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How to spoof system time for a process?
stush@rocketmail.com

2006-07-26, 1:26 pm

I'm trying to build an automated regression testing tool for a large,
dynamic system.

What I would like to do is, when a particular process (assume I don't
have the source code) queries the OS for the system time (for example,
calls time()), I want to intercept that call and supply my own time
value.

The general idea is the first time the system time is queried, I would
return some predetermined starting value, and then each subsequent time
after that, I will return the last value returned + 1.

The reason behind this is, right now, if I apply the huge test script
to two copies of the system (one with changes needing regression
tested), I cannot compare the two systems at the end of the script
because the output is too dependant on the system time. (I would get
thousands of false hits because of the time for a hundred different
reseaons)

Any help appreciated on how to do this. Thanks.

Lew Pitcher

2006-07-26, 1:26 pm


stush@rocketmail.com wrote:
> I'm trying to build an automated regression testing tool for a large,
> dynamic system.
>
> What I would like to do is, when a particular process (assume I don't
> have the source code) queries the OS for the system time (for example,
> calls time()), I want to intercept that call and supply my own time
> value.
>
> The general idea is the first time the system time is queried, I would
> return some predetermined starting value, and then each subsequent time
> after that, I will return the last value returned + 1.

[snip]
> Any help appreciated on how to do this. Thanks.


I guess it depends on which platform you want to do this. Some
platforms offer methods to permit the "pre-loading" of SO files, which
/can/ override the functions offerend in the demand-loaded SO files. It
is thus possible to write an SO that provides a custom time() function
(written to your regression test specs) which would override the time()
function supplied by the standard library.

In Linux, for instance, you can look at the LD_PRELOAD environment
variable, which would contain a path to your replacement SO file. In
other posix-like (unixish) environments the mechanism may be the same,
or at least similar.

HTH
--
Lew Pitcher

Keith Thompson

2006-07-26, 7:28 pm

stush@rocketmail.com writes:
> I'm trying to build an automated regression testing tool for a large,
> dynamic system.
>
> What I would like to do is, when a particular process (assume I don't
> have the source code) queries the OS for the system time (for example,
> calls time()), I want to intercept that call and supply my own time
> value.
>
> The general idea is the first time the system time is queried, I would
> return some predetermined starting value, and then each subsequent time
> after that, I will return the last value returned + 1.
>
> The reason behind this is, right now, if I apply the huge test script
> to two copies of the system (one with changes needing regression
> tested), I cannot compare the two systems at the end of the script
> because the output is too dependant on the system time. (I would get
> thousands of false hits because of the time for a hundred different
> reseaons)
>
> Any help appreciated on how to do this. Thanks.


I think there are (system-specific) ways to do this. Note that if
your application cares about the system time, having time() return
artificial values could affect the behavior of the application and
invalidate your testing.

If you're comparing text output logs, you might be able to recognize
any timestamps in the logs and convert them to some fixed string
before comparing. It sounds like you're doing something more
elaborate that than, though, so this kind of approach may or may not
be practical.

Of course, the simplest way to affect the value returned by time() is
to set the system clock.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mr. Uh Clem

2006-07-26, 7:28 pm

Keith Thompson wrote:
> stush@rocketmail.com writes:
>
> I think there are (system-specific) ways to do this. Note that if
> your application cares about the system time, having time() return
> artificial values could affect the behavior of the application and
> invalidate your testing.
>
> If you're comparing text output logs, you might be able to recognize
> any timestamps in the logs and convert them to some fixed string
> before comparing. It sounds like you're doing something more
> elaborate that than, though, so this kind of approach may or may not
> be practical.
>
> Of course, the simplest way to affect the value returned by time() is
> to set the system clock.


Which might not be unreasonable if you had test system(s) running under
virtualization (VMware or Xen?)


--
Clem
"If you push something hard enough, it will fall over."
- Fudd's first law of opposition
koretek

2006-07-27, 1:27 pm


stush@rocketmail.com wrote:
> I'm trying to build an automated regression testing tool for a large,
> dynamic system.
>
> What I would like to do is, when a particular process (assume I don't
> have the source code) queries the OS for the system time (for example,
> calls time()), I want to intercept that call and supply my own time
> value.


Easy solution is write some type of sub-routine/function to get system
time & then manipulate any way you want. That way you just have to call
your own functions instead of messing in the OS and you retain control
of return values and add easy manipulation of values.

Martin Jost

2006-07-27, 1:27 pm


<stush@rocketmail.com> schrieb im Newsbeitrag =
news:1153927797.526237.196960@s13g2000cwa.googlegroups.com...
> What I would like to do is, when a particular process (assume I don't
> have the source code) queries the OS for the system time (for example,
> calls time()), I want to intercept that call and supply my own time
> value.


Some time ago I read about a tool for GNU/Linux systems which allow to =
"capture" the system-calls of a program.
Later on, you can run the program under control of the tool, which gives =
the recorded return values for the system calls the program now does.

Unfortunately I can't find the reference to the program right now...
(Or even remamber the name - which would finding it much easier)

But maybe this rings a bell for someone ?

Martin

Martin Jost

2006-07-28, 7:27 am


"Martin Jost" <Martin.Jost@siemens.com> schrieb im Newsbeitrag =
news:eaaenp$r2s$1@daniel-new.mch.sbs.de...

<stush@rocketmail.com> schrieb im Newsbeitrag =
news:1153927797.526237.196960@s13g2000cwa.googlegroups.com...
> What I would like to do is, when a particular process (assume I don't
> have the source code) queries the OS for the system time (for example,
> calls time()), I want to intercept that call and supply my own time
> value.


Some time ago I read about a tool for GNU/Linux systems which allow to =
"capture" the system-calls of a program.
Later on, you can run the program under control of the tool, which gives =
the recorded return values for the system calls the program now does.

Unfortunately I can't find the reference to the program right now...

Ok, sleeping one night over it can help sometimes...
Here it is:
http://home.gna.org/jockey/

HTH

Martin

Logan Shaw

2006-07-29, 1:23 am

stush@rocketmail.com wrote:
> I'm trying to build an automated regression testing tool for a large,
> dynamic system.
>
> What I would like to do is, when a particular process (assume I don't
> have the source code) queries the OS for the system time (for example,
> calls time()), I want to intercept that call and supply my own time
> value.
>
> The general idea is the first time the system time is queried, I would
> return some predetermined starting value, and then each subsequent time
> after that, I will return the last value returned + 1.
>
> The reason behind this is, right now, if I apply the huge test script
> to two copies of the system (one with changes needing regression
> tested), I cannot compare the two systems at the end of the script
> because the output is too dependant on the system time. (I would get
> thousands of false hits because of the time for a hundred different
> reseaons)


Is there any way you can massage the output, whatever it may be,
so that the times are removed? For example, if it were generating
a log file, you could run a PERL script or something on that log
file before you compare the outputs.

- Logan
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com