aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.include4
-rw-r--r--tests/docker/Makefile.include2
-rwxr-xr-xtests/docker/common.rc14
-rwxr-xr-xtests/docker/docker.py14
-rw-r--r--tests/docker/dockerfiles/centos6.docker6
-rw-r--r--tests/docker/dockerfiles/fedora.docker16
-rw-r--r--tests/docker/dockerfiles/ubuntu.docker4
-rwxr-xr-xtests/docker/run26
-rwxr-xr-xtests/docker/test-quick2
-rw-r--r--tests/ptimer-test-stubs.c107
-rw-r--r--tests/ptimer-test.c568
-rw-r--r--tests/ptimer-test.h22
-rw-r--r--tests/test-crypto-block.c2
-rw-r--r--tests/test-uuid.c177
15 files changed, 940 insertions, 25 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index b4a9cfc8c4..24ac6cfa77 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -70,6 +70,7 @@ test-string-output-visitor
test-thread-pool
test-throttle
test-timed-average
+test-uuid
test-visitor-serialization
test-vmstate
test-write-threshold
diff --git a/tests/Makefile.include b/tests/Makefile.include
index aad96fddde..d8101b3543 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -115,6 +115,7 @@ check-unit-y += tests/test-logging$(EXESUF)
check-unit-$(CONFIG_REPLICATION) += tests/test-replication$(EXESUF)
check-unit-y += tests/test-bufferiszero$(EXESUF)
gcov-files-check-bufferiszero-y = util/bufferiszero.c
+check-unit-y += tests/test-uuid$(EXESUF)
check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
@@ -297,6 +298,7 @@ check-qtest-xtensaeb-y = $(check-qtest-xtensa-y)
check-qtest-s390x-y = tests/boot-serial-test$(EXESUF)
check-qtest-generic-y += tests/qom-test$(EXESUF)
+check-qtest-generic-y += tests/ptimer-test$(EXESUF)
qapi-schema += alternate-any.json
qapi-schema += alternate-array.json
@@ -663,6 +665,8 @@ tests/test-filter-mirror$(EXESUF): tests/test-filter-mirror.o $(qtest-obj-y)
tests/test-filter-redirector$(EXESUF): tests/test-filter-redirector.o $(qtest-obj-y)
tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contrib/ivshmem-server/ivshmem-server.o $(libqos-pc-obj-y)
tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o
+tests/ptimer-test$(EXESUF): tests/ptimer-test.o tests/ptimer-test-stubs.o hw/core/ptimer.o
+tests/test-uuid$(EXESUF): tests/test-uuid.o $(test-util-obj-y)
tests/migration/stress$(EXESUF): tests/migration/stress.o
$(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ," LINK $(TARGET_DIR)$@")
diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
index 19d4cc7077..2fcc3c6418 100644
--- a/tests/docker/Makefile.include
+++ b/tests/docker/Makefile.include
@@ -117,7 +117,7 @@ docker-run-%: docker-qemu-src
$(if $(DEBUG),-i,--net=none) \
-e TARGET_LIST=$(TARGET_LIST) \
-e EXTRA_CONFIGURE_OPTS=$(EXTRA_CONFIGURE_OPTS) \
- -e V=$V -e J=$J -e DEBUG=$(DEBUG)\
+ -e V=$V -e J=$J -e DEBUG=$(DEBUG) -e SHOW_ENV=$(SHOW_ENV)\
-e CCACHE_DIR=/var/tmp/ccache \
-v $$(readlink -e $(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \
-v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \
diff --git a/tests/docker/common.rc b/tests/docker/common.rc
index 0c6d8d5ece..510a3ad3f4 100755
--- a/tests/docker/common.rc
+++ b/tests/docker/common.rc
@@ -23,11 +23,13 @@ requires()
build_qemu()
{
- $QEMU_SRC/configure \
- --enable-werror \
- ${TARGET_LIST:+"--target-list=${TARGET_LIST}"} \
- --prefix="$PWD/install" \
- $EXTRA_CONFIGURE_OPTS \
- "$@"
+ config_opts="--enable-werror \
+ ${TARGET_LIST:+--target-list=${TARGET_LIST}} \
+ --prefix=$PWD/install \
+ $EXTRA_CONFIGURE_OPTS \
+ $@"
+ echo "Configure options:"
+ echo $config_opts
+ $QEMU_SRC/configure $config_opts
make $MAKEFLAGS
}
diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index b85c165130..37d83199e7 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -21,6 +21,7 @@ import uuid
import argparse
import tempfile
import re
+import signal
from tarfile import TarFile, TarInfo
from StringIO import StringIO
from shutil import copy, rmtree
@@ -37,9 +38,12 @@ def _guess_docker_command():
""" Guess a working docker command or raise exception if not found"""
commands = [["docker"], ["sudo", "-n", "docker"]]
for cmd in commands:
- if subprocess.call(cmd + ["images"],
- stdout=DEVNULL, stderr=DEVNULL) == 0:
- return cmd
+ try:
+ if subprocess.call(cmd + ["images"],
+ stdout=DEVNULL, stderr=DEVNULL) == 0:
+ return cmd
+ except OSError:
+ pass
commands_txt = "\n".join([" " + " ".join(x) for x in commands])
raise Exception("Cannot find working docker command. Tried:\n%s" % \
commands_txt)
@@ -98,6 +102,8 @@ class Docker(object):
self._command = _guess_docker_command()
self._instances = []
atexit.register(self._kill_instances)
+ signal.signal(signal.SIGTERM, self._kill_instances)
+ signal.signal(signal.SIGHUP, self._kill_instances)
def _do(self, cmd, quiet=True, infile=None, **kwargs):
if quiet:
@@ -130,7 +136,7 @@ class Docker(object):
self._do_kill_instances(False, False)
return 0
- def _kill_instances(self):
+ def _kill_instances(self, *args, **kwargs):
return self._do_kill_instances(True)
def _output(self, cmd, **kwargs):
diff --git a/tests/docker/dockerfiles/centos6.docker b/tests/docker/dockerfiles/centos6.docker
index 8f4fe46379..34e0d3b91e 100644
--- a/tests/docker/dockerfiles/centos6.docker
+++ b/tests/docker/dockerfiles/centos6.docker
@@ -1,6 +1,8 @@
FROM centos:6
-RUN yum install -y \
+RUN yum install -y epel-release
+ENV PACKAGES libfdt-devel ccache \
tar git make gcc g++ \
zlib-devel glib2-devel SDL-devel pixman-devel \
epel-release
-RUN yum install -y libfdt-devel ccache
+RUN yum install -y $PACKAGES
+RUN rpm -q $PACKAGES | sort > /packages.txt
diff --git a/tests/docker/dockerfiles/fedora.docker b/tests/docker/dockerfiles/fedora.docker
index 1d26a8e98a..478163b8d8 100644
--- a/tests/docker/dockerfiles/fedora.docker
+++ b/tests/docker/dockerfiles/fedora.docker
@@ -1,7 +1,17 @@
-FROM fedora:23
-RUN dnf install -y \
+FROM fedora:latest
+ENV PACKAGES \
ccache git tar PyYAML sparse flex bison \
glib2-devel pixman-devel zlib-devel SDL-devel libfdt-devel \
gcc gcc-c++ clang make perl which bc findutils \
- mingw{32,64}-{pixman,glib2,gmp,SDL,pkg-config,gtk2,gtk3,gnutls,nettle,libtasn1,libjpeg-turbo,libpng,curl,libssh2,bzip2}
+ mingw32-pixman mingw32-glib2 mingw32-gmp mingw32-SDL mingw32-pkg-config \
+ mingw32-gtk2 mingw32-gtk3 mingw32-gnutls mingw32-nettle mingw32-libtasn1 \
+ mingw32-libjpeg-turbo mingw32-libpng mingw32-curl mingw32-libssh2 \
+ mingw32-bzip2 \
+ mingw64-pixman mingw64-glib2 mingw64-gmp mingw64-SDL mingw64-pkg-config \
+ mingw64-gtk2 mingw64-gtk3 mingw64-gnutls mingw64-nettle mingw64-libtasn1 \
+ mingw64-libjpeg-turbo mingw64-libpng mingw64-curl mingw64-libssh2 \
+ mingw64-bzip2
+
+RUN dnf install -y $PACKAGES
+RUN rpm -q $PACKAGES | sort > /packages.txt
ENV FEATURES mingw clang pyyaml
diff --git a/tests/docker/dockerfiles/ubuntu.docker b/tests/docker/dockerfiles/ubuntu.docker
index a8b88c318c..a360a050a2 100644
--- a/tests/docker/dockerfiles/ubuntu.docker
+++ b/tests/docker/dockerfiles/ubuntu.docker
@@ -2,10 +2,12 @@ FROM ubuntu:14.04
RUN echo "deb http://archive.ubuntu.com/ubuntu/ trusty universe multiverse" >> \
/etc/apt/sources.list
RUN apt-get update
-RUN apt-get -y install flex bison \
+ENV PACKAGES flex bison \
libusb-1.0-0-dev libiscsi-dev librados-dev libncurses5-dev \
libseccomp-dev libgnutls-dev libssh2-1-dev libspice-server-dev \
libspice-protocol-dev libnss3-dev libfdt-dev \
libgtk-3-dev libvte-2.90-dev libsdl1.2-dev libpng12-dev libpixman-1-dev \
git make ccache python-yaml gcc clang sparse
+RUN apt-get -y install $PACKAGES
+RUN dpkg -l $PACKAGES | sort > /packages.txt
ENV FEATURES clang pyyaml
diff --git a/tests/docker/run b/tests/docker/run
index d85d49afc1..c1e4513bce 100755
--- a/tests/docker/run
+++ b/tests/docker/run
@@ -40,20 +40,34 @@ for p in dtc pixman; do
fi
done
+if test -n "$SHOW_ENV"; then
+ if test -f /packages.txt; then
+ echo "Packages installed:"
+ cat /packages.txt
+ echo
+ fi
+ echo "Environment variables:"
+ env
+ echo
+fi
+
export QEMU_SRC="$TEST_DIR/src"
cd "$QEMU_SRC/tests/docker"
CMD="$QEMU_SRC/tests/docker/$@"
-if test -n "$DEBUG"; then
- echo "* Prepared to run command:"
- echo " $CMD"
- echo "* Hit Ctrl-D to continue, or type 'exit 1' to abort"
- echo
- $SHELL
+if test -z "$DEBUG"; then
+ exec $CMD
fi
+# DEBUG workflow
+echo "* Prepared to run command:"
+echo " $CMD"
+echo "* Hit Ctrl-D to continue, or type 'exit 1' to abort"
+echo
+$SHELL
+
if "$CMD"; then
exit 0
elif test -n "$DEBUG"; then
diff --git a/tests/docker/test-quick b/tests/docker/test-quick
index 07cdc59a10..7885dfafdb 100755
--- a/tests/docker/test-quick
+++ b/tests/docker/test-quick
@@ -13,7 +13,7 @@
. common.rc
-DEF_TARGET_LIST="$(echo {x86_64,aarch64}-softmmu)"
+DEF_TARGET_LIST="x86_64-softmmu,aarch64-softmmu"
TARGET_LIST=${TARGET_LIST:-$DEF_TARGET_LIST} \
build_qemu
make check $MAKEFLAGS
diff --git a/tests/ptimer-test-stubs.c b/tests/ptimer-test-stubs.c
new file mode 100644
index 0000000000..92a22fbb09
--- /dev/null
+++ b/tests/ptimer-test-stubs.c
@@ -0,0 +1,107 @@
+/*
+ * Stubs for the ptimer-test
+ *
+ * Author: Dmitry Osipenko <digetx@gmail.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/main-loop.h"
+#include "sysemu/replay.h"
+
+#include "ptimer-test.h"
+
+struct QEMUBH {
+ QEMUBHFunc *cb;
+ void *opaque;
+};
+
+QEMUTimerListGroup main_loop_tlg;
+
+int64_t ptimer_test_time_ns;
+
+void timer_init_tl(QEMUTimer *ts,
+ QEMUTimerList *timer_list, int scale,
+ QEMUTimerCB *cb, void *opaque)
+{
+ ts->timer_list = timer_list;
+ ts->cb = cb;
+ ts->opaque = opaque;
+ ts->scale = scale;
+ ts->expire_time = -1;
+}
+
+void timer_mod(QEMUTimer *ts, int64_t expire_time)
+{
+ QEMUTimerList *timer_list = ts->timer_list;
+ QEMUTimer *t = &timer_list->active_timers;
+
+ while (t->next != NULL) {
+ if (t->next == ts) {
+ break;
+ }
+
+ t = t->next;
+ }
+
+ ts->expire_time = MAX(expire_time * ts->scale, 0);
+ ts->next = NULL;
+ t->next = ts;
+}
+
+void timer_del(QEMUTimer *ts)
+{
+ QEMUTimerList *timer_list = ts->timer_list;
+ QEMUTimer *t = &timer_list->active_timers;
+
+ while (t->next != NULL) {
+ if (t->next == ts) {
+ t->next = ts->next;
+ return;
+ }
+
+ t = t->next;
+ }
+}
+
+int64_t qemu_clock_get_ns(QEMUClockType type)
+{
+ return ptimer_test_time_ns;
+}
+
+int64_t qemu_clock_deadline_ns_all(QEMUClockType type)
+{
+ QEMUTimerList *timer_list = main_loop_tlg.tl[type];
+ QEMUTimer *t = timer_list->active_timers.next;
+ int64_t deadline = -1;
+
+ while (t != NULL) {
+ if (deadline == -1) {
+ deadline = t->expire_time;
+ } else {
+ deadline = MIN(deadline, t->expire_time);
+ }
+
+ t = t->next;
+ }
+
+ return deadline;
+}
+
+QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
+{
+ QEMUBH *bh = g_new(QEMUBH, 1);
+
+ bh->cb = cb;
+ bh->opaque = opaque;
+
+ return bh;
+}
+
+void replay_bh_schedule_event(QEMUBH *bh)
+{
+ bh->cb(bh->opaque);
+}
diff --git a/tests/ptimer-test.c b/tests/ptimer-test.c
new file mode 100644
index 0000000000..f207eeb0eb
--- /dev/null
+++ b/tests/ptimer-test.c
@@ -0,0 +1,568 @@
+/*
+ * QTest testcase for the ptimer
+ *
+ * Author: Dmitry Osipenko <digetx@gmail.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include <glib/gprintf.h>
+
+#include "qemu/osdep.h"
+#include "qemu/main-loop.h"
+#include "hw/ptimer.h"
+
+#include "libqtest.h"
+#include "ptimer-test.h"
+
+static bool triggered;
+
+static void ptimer_trigger(void *opaque)
+{
+ triggered = true;
+}
+
+static void ptimer_test_expire_qemu_timers(int64_t expire_time,
+ QEMUClockType type)
+{
+ QEMUTimerList *timer_list = main_loop_tlg.tl[type];
+ QEMUTimer *t = timer_list->active_timers.next;
+
+ while (t != NULL) {
+ if (t->expire_time == expire_time) {
+ timer_del(t);
+
+ if (t->cb != NULL) {
+ t->cb(t->opaque);
+ }
+ }
+
+ t = t->next;
+ }
+}
+
+static void ptimer_test_set_qemu_time_ns(int64_t ns)
+{
+ ptimer_test_time_ns = ns;
+}
+
+static void qemu_clock_step(uint64_t ns)
+{
+ int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
+ int64_t advanced_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + ns;
+
+ while (deadline != -1 && deadline <= advanced_time) {
+ ptimer_test_set_qemu_time_ns(deadline);
+ ptimer_test_expire_qemu_timers(deadline, QEMU_CLOCK_VIRTUAL);
+ deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
+ }
+
+ ptimer_test_set_qemu_time_ns(advanced_time);
+}
+
+static void check_set_count(gconstpointer arg)
+{
+ const uint8_t *policy = arg;
+ QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
+ ptimer_state *ptimer = ptimer_init(bh, *policy);
+
+ triggered = false;
+
+ ptimer_set_count(ptimer, 1000);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 1000);
+ g_assert_false(triggered);
+}
+
+static void check_set_limit(gconstpointer arg)
+{
+ const uint8_t *policy = arg;
+ QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
+ ptimer_state *ptimer = ptimer_init(bh, *policy);
+
+ triggered = false;
+
+ ptimer_set_limit(ptimer, 1000, 0);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 1000);
+ g_assert_false(triggered);
+
+ ptimer_set_limit(ptimer, 2000, 1);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 2000);
+ g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 2000);
+ g_assert_false(triggered);
+}
+
+static void check_oneshot(gconstpointer arg)
+{
+ const uint8_t *policy = arg;
+ QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
+ ptimer_state *ptimer = ptimer_init(bh, *policy);
+
+ triggered = false;
+
+ ptimer_set_period(ptimer, 2000000);
+ ptimer_set_count(ptimer, 10);
+ ptimer_run(ptimer, 1);
+
+ qemu_clock_step(2000000 * 2 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7);
+ g_assert_false(triggered);
+
+ ptimer_stop(ptimer);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7);
+ g_assert_false(triggered);
+
+ qemu_clock_step(2000000 * 11);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7);
+ g_assert_false(triggered);
+
+ ptimer_run(ptimer, 1);
+
+ qemu_clock_step(2000000 * 7 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_true(triggered);
+
+ triggered = false;
+
+ qemu_clock_step(2000000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_false(triggered);
+
+ qemu_clock_step(4000000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_false(triggered);
+
+ ptimer_set_count(ptimer, 10);
+
+ qemu_clock_step(20000000 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
+ g_assert_false(triggered);
+
+ ptimer_set_limit(ptimer, 9, 1);
+
+ qemu_clock_step(20000000 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
+ g_assert_false(triggered);
+
+ ptimer_run(ptimer, 1);
+
+ qemu_clock_step(2000000 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7);
+ g_assert_false(triggered);
+
+ ptimer_set_count(ptimer, 20);
+
+ qemu_clock_step(2000000 * 19 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_false(triggered);
+
+ qemu_clock_step(2000000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_true(triggered);
+
+ ptimer_stop(ptimer);
+
+ triggered = false;
+
+ qemu_clock_step(2000000 * 12 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_false(triggered);
+}
+
+static void check_periodic(gconstpointer arg)
+{
+ const uint8_t *policy = arg;
+ QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
+ ptimer_state *ptimer = ptimer_init(bh, *policy);
+
+ triggered = false;
+
+ ptimer_set_period(ptimer, 2000000);
+ ptimer_set_limit(ptimer, 10, 1);
+ ptimer_run(ptimer, 0);
+
+ qemu_clock_step(2000000 * 10 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
+ g_assert_true(triggered);
+
+ triggered = false;
+
+ qemu_clock_step(2000000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8);
+ g_assert_false(triggered);
+
+ ptimer_set_count(ptimer, 20);
+
+ qemu_clock_step(2000000 * 11 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8);
+ g_assert_false(triggered);
+
+ qemu_clock_step(2000000 * 10);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8);
+ g_assert_true(triggered);
+
+ ptimer_stop(ptimer);
+ triggered = false;
+
+ qemu_clock_step(2000000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8);
+ g_assert_false(triggered);
+
+ ptimer_set_count(ptimer, 3);
+ ptimer_run(ptimer, 0);
+
+ qemu_clock_step(2000000 * 3 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
+ g_assert_true(triggered);
+
+ triggered = false;
+
+ qemu_clock_step(2000000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8);
+ g_assert_false(triggered);
+
+ ptimer_set_count(ptimer, 0);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
+ g_assert_true(triggered);
+
+ triggered = false;
+
+ qemu_clock_step(2000000 * 12 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7);
+ g_assert_true(triggered);
+
+ ptimer_stop(ptimer);
+
+ triggered = false;
+
+ qemu_clock_step(2000000 * 12 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7);
+ g_assert_false(triggered);
+
+ ptimer_run(ptimer, 0);
+ ptimer_set_period(ptimer, 0);
+
+ qemu_clock_step(2000000 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7);
+ g_assert_false(triggered);
+}
+
+static void check_on_the_fly_mode_change(gconstpointer arg)
+{
+ const uint8_t *policy = arg;
+ QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
+ ptimer_state *ptimer = ptimer_init(bh, *policy);
+
+ triggered = false;
+
+ ptimer_set_period(ptimer, 2000000);
+ ptimer_set_limit(ptimer, 10, 1);
+ ptimer_run(ptimer, 1);
+
+ qemu_clock_step(2000000 * 9 + 100000);
+
+ ptimer_run(ptimer, 0);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_false(triggered);
+
+ qemu_clock_step(2000000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
+ g_assert_true(triggered);
+
+ triggered = false;
+
+ qemu_clock_step(2000000 * 9);
+
+ ptimer_run(ptimer, 1);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_false(triggered);
+
+ qemu_clock_step(2000000 * 3);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_true(triggered);
+}
+
+static void check_on_the_fly_period_change(gconstpointer arg)
+{
+ const uint8_t *policy = arg;
+ QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
+ ptimer_state *ptimer = ptimer_init(bh, *policy);
+
+ triggered = false;
+
+ ptimer_set_period(ptimer, 2000000);
+ ptimer_set_limit(ptimer, 8, 1);
+ ptimer_run(ptimer, 1);
+
+ qemu_clock_step(2000000 * 4 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3);
+ g_assert_false(triggered);
+
+ ptimer_set_period(ptimer, 4000000);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3);
+
+ qemu_clock_step(4000000 * 2 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_false(triggered);
+
+ qemu_clock_step(4000000 * 2);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_true(triggered);
+}
+
+static void check_on_the_fly_freq_change(gconstpointer arg)
+{
+ const uint8_t *policy = arg;
+ QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
+ ptimer_state *ptimer = ptimer_init(bh, *policy);
+
+ triggered = false;
+
+ ptimer_set_freq(ptimer, 500);
+ ptimer_set_limit(ptimer, 8, 1);
+ ptimer_run(ptimer, 1);
+
+ qemu_clock_step(2000000 * 4 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3);
+ g_assert_false(triggered);
+
+ ptimer_set_freq(ptimer, 250);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3);
+
+ qemu_clock_step(2000000 * 4 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_false(triggered);
+
+ qemu_clock_step(2000000 * 4);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_true(triggered);
+}
+
+static void check_run_with_period_0(gconstpointer arg)
+{
+ const uint8_t *policy = arg;
+ QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
+ ptimer_state *ptimer = ptimer_init(bh, *policy);
+
+ triggered = false;
+
+ ptimer_set_count(ptimer, 99);
+ ptimer_run(ptimer, 1);
+
+ qemu_clock_step(10 * NANOSECONDS_PER_SECOND);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 99);
+ g_assert_false(triggered);
+}
+
+static void check_run_with_delta_0(gconstpointer arg)
+{
+ const uint8_t *policy = arg;
+ QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
+ ptimer_state *ptimer = ptimer_init(bh, *policy);
+
+ triggered = false;
+
+ ptimer_set_period(ptimer, 2000000);
+ ptimer_set_limit(ptimer, 99, 0);
+ ptimer_run(ptimer, 1);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 99);
+ g_assert_true(triggered);
+
+ triggered = false;
+
+ qemu_clock_step(2000000 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 97);
+ g_assert_false(triggered);
+
+ qemu_clock_step(2000000 * 97);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_false(triggered);
+
+ qemu_clock_step(2000000 * 2);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_true(triggered);
+
+ triggered = false;
+
+ ptimer_set_count(ptimer, 0);
+ ptimer_run(ptimer, 0);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 99);
+ g_assert_true(triggered);
+
+ triggered = false;
+
+ qemu_clock_step(2000000 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 97);
+ g_assert_false(triggered);
+
+ qemu_clock_step(2000000 * 98);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 98);
+ g_assert_true(triggered);
+
+ ptimer_stop(ptimer);
+}
+
+static void check_periodic_with_load_0(gconstpointer arg)
+{
+ const uint8_t *policy = arg;
+ QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
+ ptimer_state *ptimer = ptimer_init(bh, *policy);
+
+ triggered = false;
+
+ ptimer_set_period(ptimer, 2000000);
+ ptimer_run(ptimer, 0);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_true(triggered);
+
+ triggered = false;
+
+ qemu_clock_step(2000000 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_false(triggered);
+
+ ptimer_stop(ptimer);
+}
+
+static void check_oneshot_with_load_0(gconstpointer arg)
+{
+ const uint8_t *policy = arg;
+ QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
+ ptimer_state *ptimer = ptimer_init(bh, *policy);
+
+ triggered = false;
+
+ ptimer_set_period(ptimer, 2000000);
+ ptimer_run(ptimer, 1);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_true(triggered);
+
+ triggered = false;
+
+ qemu_clock_step(2000000 + 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_false(triggered);
+
+ triggered = false;
+
+ qemu_clock_step(2000000 + 100000);
+
+ g_assert_false(triggered);
+}
+
+static void add_ptimer_tests(uint8_t policy)
+{
+ uint8_t *ppolicy = g_malloc(1);
+ char *policy_name = g_malloc(64);
+
+ *ppolicy = policy;
+
+ if (policy == PTIMER_POLICY_DEFAULT) {
+ g_sprintf(policy_name, "default");
+ }
+
+ qtest_add_data_func(
+ g_strdup_printf("/ptimer/set_count policy=%s", policy_name),
+ ppolicy, check_set_count);
+
+ qtest_add_data_func(
+ g_strdup_printf("/ptimer/set_limit policy=%s", policy_name),
+ ppolicy, check_set_limit);
+
+ qtest_add_data_func(
+ g_strdup_printf("/ptimer/oneshot policy=%s", policy_name),
+ ppolicy, check_oneshot);
+
+ qtest_add_data_func(
+ g_strdup_printf("/ptimer/periodic policy=%s", policy_name),
+ ppolicy, check_periodic);
+
+ qtest_add_data_func(
+ g_strdup_printf("/ptimer/on_the_fly_mode_change policy=%s", policy_name),
+ ppolicy, check_on_the_fly_mode_change);
+
+ qtest_add_data_func(
+ g_strdup_printf("/ptimer/on_the_fly_period_change policy=%s", policy_name),
+ ppolicy, check_on_the_fly_period_change);
+
+ qtest_add_data_func(
+ g_strdup_printf("/ptimer/on_the_fly_freq_change policy=%s", policy_name),
+ ppolicy, check_on_the_fly_freq_change);
+
+ qtest_add_data_func(
+ g_strdup_printf("/ptimer/run_with_period_0 policy=%s", policy_name),
+ ppolicy, check_run_with_period_0);
+
+ qtest_add_data_func(
+ g_strdup_printf("/ptimer/run_with_delta_0 policy=%s", policy_name),
+ ppolicy, check_run_with_delta_0);
+
+ qtest_add_data_func(
+ g_strdup_printf("/ptimer/periodic_with_load_0 policy=%s", policy_name),
+ ppolicy, check_periodic_with_load_0);
+
+ qtest_add_data_func(
+ g_strdup_printf("/ptimer/oneshot_with_load_0 policy=%s", policy_name),
+ ppolicy, check_oneshot_with_load_0);
+}
+
+int main(int argc, char **argv)
+{
+ int i;
+
+ g_test_init(&argc, &argv, NULL);
+
+ for (i = 0; i < QEMU_CLOCK_MAX; i++) {
+ main_loop_tlg.tl[i] = g_new0(QEMUTimerList, 1);
+ }
+
+ add_ptimer_tests(PTIMER_POLICY_DEFAULT);
+
+ qtest_allowed = true;
+
+ return g_test_run();
+}
diff --git a/tests/ptimer-test.h b/tests/ptimer-test.h
new file mode 100644
index 0000000000..98d9b8f347
--- /dev/null
+++ b/tests/ptimer-test.h
@@ -0,0 +1,22 @@
+/*
+ * QTest testcase for the ptimer
+ *
+ * Author: Dmitry Osipenko <digetx@gmail.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef PTIMER_TEST_H
+#define PTIMER_TEST_H
+
+extern bool qtest_allowed;
+
+extern int64_t ptimer_test_time_ns;
+
+struct QEMUTimerList {
+ QEMUTimer active_timers;
+};
+
+#endif
diff --git a/tests/test-crypto-block.c b/tests/test-crypto-block.c
index a38110d3ff..1957a86743 100644
--- a/tests/test-crypto-block.c
+++ b/tests/test-crypto-block.c
@@ -28,7 +28,7 @@
#include <sys/resource.h>
#endif
-#if defined(CONFIG_UUID) && (defined(_WIN32) || defined RUSAGE_THREAD)
+#if (defined(_WIN32) || defined RUSAGE_THREAD)
#define TEST_LUKS
#else
#undef TEST_LUKS
diff --git a/tests/test-uuid.c b/tests/test-uuid.c
new file mode 100644
index 0000000000..77dcdc4b55
--- /dev/null
+++ b/tests/test-uuid.c
@@ -0,0 +1,177 @@
+/*
+ * QEMU UUID Library
+ *
+ * Copyright (c) 2016 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/uuid.h"
+
+struct {
+ const char *uuidstr;
+ QemuUUID uuid;
+ bool uuidstr_is_valid;
+ bool check_unparse;
+} uuid_test_data[] = {
+ { /* Normal */
+ "586ece27-7f09-41e0-9e74-e901317e9d42",
+ { { {
+ 0x58, 0x6e, 0xce, 0x27, 0x7f, 0x09, 0x41, 0xe0,
+ 0x9e, 0x74, 0xe9, 0x01, 0x31, 0x7e, 0x9d, 0x42,
+ } } },
+ true, true,
+ }, { /* NULL */
+ "00000000-0000-0000-0000-000000000000",
+ { },
+ true, true,
+ }, { /* Upper case */
+ "0CC6C752-3961-4028-A286-C05CC616D396",
+ { { {
+ 0x0c, 0xc6, 0xc7, 0x52, 0x39, 0x61, 0x40, 0x28,
+ 0xa2, 0x86, 0xc0, 0x5c, 0xc6, 0x16, 0xd3, 0x96,
+ } } },
+ true, false,
+ }, { /* Mixed case */
+ "0CC6C752-3961-4028-a286-c05cc616D396",
+ { { {
+ 0x0c, 0xc6, 0xc7, 0x52, 0x39, 0x61, 0x40, 0x28,
+ 0xa2, 0x86, 0xc0, 0x5c, 0xc6, 0x16, 0xd3, 0x96,
+ } } },
+ true, false,
+ }, { /* Empty */
+ ""
+ }, { /* Too short */
+ "abc",
+ }, { /* Non-hex */
+ "abcdefgh-0000-0000-0000-000000000000",
+ }, { /* No '-' */
+ "0cc6c75239614028a286c05cc616d396",
+ }, { /* '-' in wrong position */
+ "0cc6c-7523961-4028-a286-c05cc616d396",
+ }, { /* Double '-' */
+ "0cc6c752--3961-4028-a286-c05cc616d396",
+ }, { /* Too long */
+ "0000000000000000000000000000000000000000000000",
+ }, { /* Invalid char in the beginning */
+ ")cc6c752-3961-4028-a286-c05cc616d396",
+ }, { /* Invalid char in the beginning, in extra */
+ ")0cc6c752-3961-4028-a286-c05cc616d396",
+ }, { /* Invalid char in the middle */
+ "0cc6c752-39*1-4028-a286-c05cc616d396",
+ }, { /* Invalid char in the middle, in extra */
+ "0cc6c752-39*61-4028-a286-c05cc616d396",
+ }, { /* Invalid char in the end */
+ "0cc6c752-3961-4028-a286-c05cc616d39&",
+ }, { /* Invalid char in the end, in extra */
+ "0cc6c752-3961-4028-a286-c05cc616d396&",
+ }, { /* Short end and trailing space */
+ "0cc6c752-3961-4028-a286-c05cc616d39 ",
+ }, { /* Leading space and short end */
+ " 0cc6c752-3961-4028-a286-c05cc616d39",
+ },
+};
+
+static inline bool uuid_is_valid(QemuUUID *uuid)
+{
+ return qemu_uuid_is_null(uuid) ||
+ ((uuid->data[6] & 0xf0) == 0x40 && (uuid->data[8] & 0xc0) == 0x80);
+}
+
+static void test_uuid_generate(void)
+{
+ QemuUUID uuid;
+ int i;
+
+ for (i = 0; i < 100; ++i) {
+ qemu_uuid_generate(&uuid);
+ g_assert(uuid_is_valid(&uuid));
+ }
+}
+
+static void test_uuid_is_null(void)
+{
+ QemuUUID uuid_null = { };
+ QemuUUID uuid_not_null = { { {
+ 0x58, 0x6e, 0xce, 0x27, 0x7f, 0x09, 0x41, 0xe0,
+ 0x9e, 0x74, 0xe9, 0x01, 0x31, 0x7e, 0x9d, 0x42
+ } } };
+ QemuUUID uuid_not_null_2 = { { { 1 } } };
+
+ g_assert(qemu_uuid_is_null(&uuid_null));
+ g_assert_false(qemu_uuid_is_null(&uuid_not_null));
+ g_assert_false(qemu_uuid_is_null(&uuid_not_null_2));
+}
+
+static void test_uuid_parse(void)
+{
+ int i, r;
+
+ for (i = 0; i < ARRAY_SIZE(uuid_test_data); i++) {
+ QemuUUID uuid;
+ bool is_valid = uuid_test_data[i].uuidstr_is_valid;
+
+ r = qemu_uuid_parse(uuid_test_data[i].uuidstr, &uuid);
+ g_assert_cmpint(!r, ==, is_valid);
+ if (is_valid) {
+ g_assert_cmpint(is_valid, ==, uuid_is_valid(&uuid));
+ g_assert_cmpmem(&uuid_test_data[i].uuid, sizeof(uuid),
+ &uuid, sizeof(uuid));
+ }
+ }
+}
+
+static void test_uuid_unparse(void)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(uuid_test_data); i++) {
+ char out[37];
+
+ if (!uuid_test_data[i].check_unparse) {
+ continue;
+ }
+ qemu_uuid_unparse(&uuid_test_data[i].uuid, out);
+ g_assert_cmpstr(uuid_test_data[i].uuidstr, ==, out);
+ }
+}
+
+static void test_uuid_unparse_strdup(void)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(uuid_test_data); i++) {
+ char *out;
+
+ if (!uuid_test_data[i].check_unparse) {
+ continue;
+ }
+ out = qemu_uuid_unparse_strdup(&uuid_test_data[i].uuid);
+ g_assert_cmpstr(uuid_test_data[i].uuidstr, ==, out);
+ }
+}
+
+int main(int argc, char **argv)
+{
+ g_test_init(&argc, &argv, NULL);
+ g_test_add_func("/uuid/generate", test_uuid_generate);
+ g_test_add_func("/uuid/is_null", test_uuid_is_null);
+ g_test_add_func("/uuid/parse", test_uuid_parse);
+ g_test_add_func("/uuid/unparse", test_uuid_unparse);
+ g_test_add_func("/uuid/unparse_strdup", test_uuid_unparse_strdup);
+
+ return g_test_run();
+}