]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuxml2argvtest: Set timezone
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 6 Feb 2014 13:24:02 +0000 (14:24 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 6 Feb 2014 14:15:10 +0000 (15:15 +0100)
With my recent work on the test, both time() and localtime() are used.
While mocking the former one, we get predictable result for UTC. But
since the latter function uses timezone to get local time, the result of
localtime() is not so predictive. Therefore, we must set the TZ variable
at the beginning of the test. To be able to catch some things that work
just by a blind chance, I'm choosing a virtual timezone that (hopefully)
no libvirt developer resides in.

tests/qemuxml2argvdata/qemuxml2argv-clock-localtime-basis-localtime.args
tests/qemuxml2argvtest.c

index 24fe89ca5faf93b0692e6e7d3621189e83b8fbfb..ab9e9797bc2ad5b7f3048929790baa73d18fa4f3 100644 (file)
@@ -1,5 +1,5 @@
 LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
 /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic \
--monitor unix:/tmp/test-monitor,server,nowait -rtc base=2009-02-14T01:31:30 \
+-monitor unix:/tmp/test-monitor,server,nowait -rtc base=2009-02-14T00:01:30 \
 -no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 -net none -serial none \
 -parallel none
index c8b385722489abb731320ad184847eff2033e102..dae08d52f5a1a5cc9d881e778539b663c8f7ba07 100644 (file)
@@ -486,6 +486,16 @@ mymain(void)
     if (!abs_top_srcdir)
         abs_top_srcdir = abs_srcdir "/..";
 
+    /* Set the timezone because we are mocking the time() function.
+     * If we don't do that, then localtime() may return unpredictable
+     * results. In order to detect things that just work by a blind
+     * chance, we need to set an virtual timezone that no libvirt
+     * developer resides in. */
+    if (setenv("TZ", "VIR00:30", 1) < 0) {
+        perror("setenv");
+        return EXIT_FAILURE;
+    }
+
     driver.config = virQEMUDriverConfigNew(false);
     VIR_FREE(driver.config->spiceListen);
     VIR_FREE(driver.config->vncListen);