[libvirt] [PATCH 2/2] qemuxml2argvtest: Test localtime clock basis

Eric Blake eblake at redhat.com
Wed Feb 5 22:26:23 UTC 2014


On 02/05/2014 07:32 AM, Michal Privoznik wrote:
> When trying to introduce a test for previous patch, I've
> noticed that the command line is constructed using current
> time. This won't work in our test suite (unless you guys
> wants to set a specific time prior to each test run :) ).
> Therefore we need to mock calls to time(2) to return the
> same value every time it's called.

Slick.  But as we only support mocking calls on Linux, you have
converted a test from generic platform to Linux-only.  Then again, qemu
tests only run where we support qemu, which is currently Linux only, so
I'm not sure it will matter.  I guess we'll find out if anyone complains
that it broke 'make check' on their platform.

The only other alternative I can think of is to use regex replacement -
in several tests, we have means of munging actual output to recognize
specific patterns and replacing them with fixed contents.  A timestamp
is an easy fixed pattern, and it might be more portable to avoid mocking
time() and instead just munge all timestamps of actual output into the
expected timestamp.  But munging is not quite as precise as your
approach of a known fixed point in time - especially if we end up
testing multiple expected outputs that have different resulting offsets
in relation to the same starting fixed point in time.  So I can live
with your patch, rather than trying to do regex replacement.

> --- /dev/null
> +++ b/tests/qemuxml2argvdata/qemuxml2argv-clock-localtime-basis-localtime.args
> @@ -0,0 +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 \

A quick grep finds:

tests/qemuxml2argvdata/qemuxml2argv-clock-variable.args:base=2010-2-2T18:22:10
-no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 -net none \

so how was that test working, and why is it unchanged by your mock
setting the time to 2009?

> +++ b/tests/qemuxml2argvtest.c
> @@ -618,6 +618,7 @@ mymain(void)
>      DO_TEST("bios", QEMU_CAPS_DEVICE, QEMU_CAPS_SGA);
>      DO_TEST("clock-utc", NONE);
>      DO_TEST("clock-localtime", NONE);
> +    DO_TEST("clock-localtime-basis-localtime", QEMU_CAPS_RTC);
>      /*
>       * Can't be enabled since the absolute timestamp changes every time
>      DO_TEST("clock-variable", QEMU_CAPS_RTC);

Oh, it _wasn't_ working, but now can be MADE to work.  Please uncomment
this test, and fix the fallout, at which point, you have:

ACK.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140205/99c69a2c/attachment-0001.sig>


More information about the libvir-list mailing list