DrWhy has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks,

I'm testing licensing restrictions on a Window application (using a Perl test scripts) and I want to test the behavior when the license expires. The format of the license file (FlexLM) does not allow you to set an expiration time, only an expiration date. The expiration happens at midnight. I want to be able to run the test at any time -- not just midnight. Is there anyway in Perl to mock the system clock so that the application when launched by Perl will see the time I want it to see, rather than the real clock?

Note: This is not a job for Test::MockTime because that only mocks time inside the Perl interpreter itself, not external processes it launches.

--DrWhy

"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

Replies are listed 'Best First'.
Re: Mock system clock on Windows?
by ikegami (Patriarch) on Apr 25, 2007 at 03:10 UTC
    Use "DOS" command time to change the clock, then net time /set to resynchronize the clock?
      This looks like it will work well enough for my purposes, although it really isn't mocking the clock. Actually net time /set doesn't work for our system -- I think because our network doesn't use domain controllers -- or something. What does work for us is
      w32tm /resync
      Thanks!

      --DrWhy

      "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

Re: Mock system clock on Windows?
by Fletch (Bishop) on Apr 25, 2007 at 03:27 UTC

    On *NIXen you can play games (sometimes) with the shared library linker (ld.so or the like) and shim in your own version of library routines. Perhaps there's some analogue for Win32?

    Another solution might be to use some virtualization package (e.g. VMWare) and set the clock in that to whatever you desire. (although that might be overkill :)