diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2014-03-31 22:11:29 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2014-03-31 22:11:30 +0100 |
commit | 95224e87a71d3190f46bf543ec9bc59ae36050eb (patch) | |
tree | ce74fe55855beb42d02fcdd6cd088315ec1e250f /tests | |
parent | 63678e17cf399ff81b93417fe7bee8d6ef6b6b1b (diff) | |
parent | 7373fc76930fc0994bab1bc2defd1d3a2b2adaa3 (diff) |
Merge remote-tracking branch 'remotes/afaerber/tags/qom-devices-for-2.0' into staging
QOM/QTest infrastructure fixes
* Revised QTest SIGABRT fix
* Test cleanups for non-POSIX hosts
* QTest test cases for NVMe, virtio-9p, pvpanic, i82801b11
* QTest API addition for reading events
* TMP105 fix and regression test
# gpg: Signature made Mon 31 Mar 2014 22:08:10 BST using RSA key ID 3E7E013F
# gpg: Good signature from "Andreas Färber <afaerber@suse.de>"
# gpg: aka "Andreas Färber <afaerber@suse.com>"
* remotes/afaerber/tags/qom-devices-for-2.0:
tmp105-test: Test QOM property and precision
tmp105-test: Add a second sensor and test that one
tmp105-test: Wrap simple building blocks for testing
tmp105: Read temperature in milli-celsius
tests: Add i82801b11 qtest
pvpanic-test: Assert pause event
qtest: Factor out qtest_qmp_receive()
tests: Add pvpanic qtest
tests: Add virtio-9p qtest
tests: Add nvme qtest
nvme: Permit zero-length block devices
tests: Correctly skip qtest on non-POSIX hosts
tests: Skip POSIX-only tests on Windows
tests: Remove unsupported tests for MinGW
qtest: Keep list of qtest instances for SIGABRT handler
Revert "qtest: Fix crash if SIGABRT during qtest_init()"
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile | 23 | ||||
-rw-r--r-- | tests/i82801b11-test.c | 33 | ||||
-rw-r--r-- | tests/libqtest.c | 65 | ||||
-rw-r--r-- | tests/libqtest.h | 22 | ||||
-rw-r--r-- | tests/nvme-test.c | 34 | ||||
-rw-r--r-- | tests/pvpanic-test.c | 47 | ||||
-rw-r--r-- | tests/test-aio.c | 16 | ||||
-rw-r--r-- | tests/tmp105-test.c | 136 | ||||
-rw-r--r-- | tests/virtio-9p-test.c | 46 |
9 files changed, 379 insertions, 43 deletions
diff --git a/tests/Makefile b/tests/Makefile index 2d021fb16d..6086f68698 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -35,7 +35,7 @@ check-unit-y += tests/test-visitor-serialization$(EXESUF) check-unit-y += tests/test-iov$(EXESUF) gcov-files-test-iov-y = util/iov.c check-unit-y += tests/test-aio$(EXESUF) -check-unit-y += tests/test-rfifolock$(EXESUF) +check-unit-$(CONFIG_POSIX) += tests/test-rfifolock$(EXESUF) check-unit-y += tests/test-throttle$(EXESUF) gcov-files-test-aio-$(CONFIG_WIN32) = aio-win32.c gcov-files-test-aio-$(CONFIG_POSIX) = aio-posix.c @@ -59,7 +59,7 @@ check-unit-y += tests/test-bitops$(EXESUF) check-unit-y += tests/test-qdev-global-props$(EXESUF) check-unit-y += tests/check-qom-interface$(EXESUF) gcov-files-check-qom-interface-y = qom/object.c -check-unit-y += tests/test-vmstate$(EXESUF) +check-unit-$(CONFIG_POSIX) += tests/test-vmstate$(EXESUF) check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh @@ -84,6 +84,11 @@ check-qtest-virtio-y += tests/virtio-rng-test$(EXESUF) gcov-files-virtio-y += hw/virtio/virtio-rng.c check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF) gcov-files-virtio-y += i386-softmmu/hw/scsi/virtio-scsi.c +ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy) +check-qtest-virtio-y += tests/virtio-9p-test$(EXESUF) +gcov-files-virtio-y += hw/9pfs/virtio-9p.c +gcov-files-virtio-y += i386-softmmu/hw/9pfs/virtio-9p-device.c +endif check-qtest-virtio-y += tests/virtio-serial-test$(EXESUF) gcov-files-virtio-y += i386-softmmu/hw/char/virtio-serial-bus.c check-qtest-virtio-y += $(check-qtest-virtioserial-y) @@ -100,6 +105,8 @@ check-qtest-pci-y += tests/eepro100-test$(EXESUF) gcov-files-pci-y += hw/net/eepro100.c check-qtest-pci-y += tests/ne2000-test$(EXESUF) gcov-files-pci-y += hw/net/ne2000.c +check-qtest-pci-y += tests/nvme-test$(EXESUF) +gcov-files-pci-y += hw/block/nvme.c check-qtest-pci-y += $(check-qtest-virtio-y) gcov-files-pci-y += $(gcov-files-virtio-y) hw/virtio/virtio-pci.c check-qtest-pci-y += tests/tpci200-test$(EXESUF) @@ -126,6 +133,10 @@ check-qtest-i386-y += tests/vmxnet3-test$(EXESUF) gcov-files-i386-y += hw/net/vmxnet3.c gcov-files-i386-y += hw/net/vmxnet_rx_pkt.c gcov-files-i386-y += hw/net/vmxnet_tx_pkt.c +check-qtest-i386-y += tests/pvpanic-test$(EXESUF) +gcov-files-i386-y += i386-softmmu/hw/misc/pvpanic.c +check-qtest-i386-y += tests/i82801b11-test$(EXESUF) +gcov-files-i386-y += hw/pci-bridge/i82801b11.c check-qtest-x86_64-y = $(check-qtest-i386-y) gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c gcov-files-x86_64-y = $(subst i386-softmmu/,x86_64-softmmu/,$(gcov-files-i386-y)) @@ -265,6 +276,7 @@ tests/virtio-blk-test$(EXESUF): tests/virtio-blk-test.o tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o tests/virtio-rng-test$(EXESUF): tests/virtio-rng-test.o tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o +tests/virtio-9p-test$(EXESUF): tests/virtio-9p-test.o tests/virtio-serial-test$(EXESUF): tests/virtio-serial-test.o tests/virtio-console-test$(EXESUF): tests/virtio-console-test.o tests/tpci200-test$(EXESUF): tests/tpci200-test.o @@ -272,13 +284,18 @@ tests/ipoctal232-test$(EXESUF): tests/ipoctal232-test.o tests/qom-test$(EXESUF): tests/qom-test.o tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y) tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y) +tests/nvme-test$(EXESUF): tests/nvme-test.o +tests/pvpanic-test$(EXESUF): tests/pvpanic-test.o +tests/i82801b11-test$(EXESUF): tests/i82801b11-test.o tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o # QTest rules TARGETS=$(patsubst %-softmmu,%, $(filter %-softmmu,$(TARGET_DIRS))) +ifeq ($(CONFIG_POSIX),y) QTEST_TARGETS=$(foreach TARGET,$(TARGETS), $(if $(check-qtest-$(TARGET)-y), $(TARGET),)) -check-qtest-$(CONFIG_POSIX)=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)-y)) +check-qtest-y=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)-y)) +endif qtest-obj-y = tests/libqtest.o libqemuutil.a libqemustub.a $(check-qtest-y): $(qtest-obj-y) diff --git a/tests/i82801b11-test.c b/tests/i82801b11-test.c new file mode 100644 index 0000000000..78d9ce0e6b --- /dev/null +++ b/tests/i82801b11-test.c @@ -0,0 +1,33 @@ +/* + * QTest testcase for i82801b11 + * + * Copyright (c) 2014 SUSE LINUX Products GmbH + * + * 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.h> +#include <string.h> +#include "libqtest.h" +#include "qemu/osdep.h" + +/* Tests only initialization so far. TODO: Replace with functional tests */ +static void nop(void) +{ +} + +int main(int argc, char **argv) +{ + int ret; + + g_test_init(&argc, &argv, NULL); + qtest_add_func("/i82801b11/nop", nop); + + qtest_start("-machine q35 -device i82801b11-bridge,bus=pcie.0,addr=1e.0"); + ret = g_test_run(); + + qtest_end(); + + return ret; +} diff --git a/tests/libqtest.c b/tests/libqtest.c index b03b57a3db..8155695848 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -48,6 +48,9 @@ struct QTestState struct sigaction sigact_old; /* restored on exit */ }; +static GList *qtest_instances; +static struct sigaction sigact_old; + #define g_assert_no_errno(ret) do { \ g_assert_cmpint(ret, !=, -1); \ } while (0) @@ -104,7 +107,28 @@ static void kill_qemu(QTestState *s) static void sigabrt_handler(int signo) { - kill_qemu(global_qtest); + GList *elem; + for (elem = qtest_instances; elem; elem = elem->next) { + kill_qemu(elem->data); + } +} + +static void setup_sigabrt_handler(void) +{ + struct sigaction sigact; + + /* Catch SIGABRT to clean up on g_assert() failure */ + sigact = (struct sigaction){ + .sa_handler = sigabrt_handler, + .sa_flags = SA_RESETHAND, + }; + sigemptyset(&sigact.sa_mask); + sigaction(SIGABRT, &sigact, &sigact_old); +} + +static void cleanup_sigabrt_handler(void) +{ + sigaction(SIGABRT, &sigact_old, NULL); } QTestState *qtest_init(const char *extra_args) @@ -115,12 +139,11 @@ QTestState *qtest_init(const char *extra_args) gchar *qmp_socket_path; gchar *command; const char *qemu_binary; - struct sigaction sigact; qemu_binary = getenv("QTEST_QEMU_BINARY"); g_assert(qemu_binary != NULL); - global_qtest = s = g_malloc(sizeof(*s)); + s = g_malloc(sizeof(*s)); socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid()); qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid()); @@ -128,13 +151,12 @@ QTestState *qtest_init(const char *extra_args) sock = init_socket(socket_path); qmpsock = init_socket(qmp_socket_path); - /* Catch SIGABRT to clean up on g_assert() failure */ - sigact = (struct sigaction){ - .sa_handler = sigabrt_handler, - .sa_flags = SA_RESETHAND, - }; - sigemptyset(&sigact.sa_mask); - sigaction(SIGABRT, &sigact, &s->sigact_old); + /* Only install SIGABRT handler once */ + if (!qtest_instances) { + setup_sigabrt_handler(); + } + + qtest_instances = g_list_prepend(qtest_instances, s); s->qemu_pid = fork(); if (s->qemu_pid == 0) { @@ -180,8 +202,12 @@ QTestState *qtest_init(const char *extra_args) void qtest_quit(QTestState *s) { - sigaction(SIGABRT, &s->sigact_old, NULL); - global_qtest = NULL; + /* Uninstall SIGABRT handler on last instance */ + if (qtest_instances && !qtest_instances->next) { + cleanup_sigabrt_handler(); + } + + qtest_instances = g_list_remove(qtest_instances, s); kill_qemu(s); close(s->fd); @@ -319,14 +345,10 @@ static void qmp_response(JSONMessageParser *parser, QList *tokens) qmp->response = (QDict *)obj; } -QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap) +QDict *qtest_qmp_receive(QTestState *s) { QMPResponseParser qmp; - /* Send QMP request */ - socket_sendf(s->qmp_fd, fmt, ap); - - /* Receive reply */ qmp.response = NULL; json_message_parser_init(&qmp.parser, qmp_response); while (!qmp.response) { @@ -350,6 +372,15 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap) return qmp.response; } +QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap) +{ + /* Send QMP request */ + socket_sendf(s->qmp_fd, fmt, ap); + + /* Receive reply */ + return qtest_qmp_receive(s); +} + QDict *qtest_qmp(QTestState *s, const char *fmt, ...) { va_list ap; diff --git a/tests/libqtest.h b/tests/libqtest.h index 27a58fdb1c..8f323c7030 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -83,6 +83,14 @@ void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list ap); QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap); /** + * qtest_receive: + * @s: #QTestState instance to operate on. + * + * Reads a QMP message from QEMU and returns the response. + */ +QDict *qtest_qmp_receive(QTestState *s); + +/** * qtest_get_irq: * @s: #QTestState instance to operate on. * @num: Interrupt to observe. @@ -335,7 +343,8 @@ void qtest_add_func(const char *str, void (*fn)); */ static inline QTestState *qtest_start(const char *args) { - return qtest_init(args); + global_qtest = qtest_init(args); + return global_qtest; } /** @@ -346,6 +355,7 @@ static inline QTestState *qtest_start(const char *args) static inline void qtest_end(void) { qtest_quit(global_qtest); + global_qtest = NULL; } /** @@ -365,6 +375,16 @@ QDict *qmp(const char *fmt, ...); void qmp_discard_response(const char *fmt, ...); /** + * qmp_receive: + * + * Reads a QMP message from QEMU and returns the response. + */ +static inline QDict *qmp_receive(void) +{ + return qtest_qmp_receive(global_qtest); +} + +/** * get_irq: * @num: Interrupt to observe. * diff --git a/tests/nvme-test.c b/tests/nvme-test.c new file mode 100644 index 0000000000..85768e837b --- /dev/null +++ b/tests/nvme-test.c @@ -0,0 +1,34 @@ +/* + * QTest testcase for NVMe + * + * Copyright (c) 2014 SUSE LINUX Products GmbH + * + * 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.h> +#include <string.h> +#include "libqtest.h" +#include "qemu/osdep.h" + +/* Tests only initialization so far. TODO: Replace with functional tests */ +static void nop(void) +{ +} + +int main(int argc, char **argv) +{ + int ret; + + g_test_init(&argc, &argv, NULL); + qtest_add_func("/nvme/nop", nop); + + qtest_start("-drive id=drv0,if=none,file=/dev/null " + "-device nvme,drive=drv0,serial=foo"); + ret = g_test_run(); + + qtest_end(); + + return ret; +} diff --git a/tests/pvpanic-test.c b/tests/pvpanic-test.c new file mode 100644 index 0000000000..a7ad6b3064 --- /dev/null +++ b/tests/pvpanic-test.c @@ -0,0 +1,47 @@ +/* + * QTest testcase for PV Panic + * + * Copyright (c) 2014 SUSE LINUX Products GmbH + * + * 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.h> +#include <string.h> +#include "libqtest.h" +#include "qemu/osdep.h" + +static void test_panic(void) +{ + uint8_t val; + QDict *response, *data; + + val = inb(0x505); + g_assert_cmpuint(val, ==, 1); + + outb(0x505, 0x1); + + response = qmp_receive(); + g_assert(qdict_haskey(response, "event")); + g_assert_cmpstr(qdict_get_str(response, "event"), ==, "GUEST_PANICKED"); + g_assert(qdict_haskey(response, "data")); + data = qdict_get_qdict(response, "data"); + g_assert(qdict_haskey(data, "action")); + g_assert_cmpstr(qdict_get_str(data, "action"), ==, "pause"); +} + +int main(int argc, char **argv) +{ + int ret; + + g_test_init(&argc, &argv, NULL); + qtest_add_func("/pvpanic/panic", test_panic); + + qtest_start("-device pvpanic"); + ret = g_test_run(); + + qtest_end(); + + return ret; +} diff --git a/tests/test-aio.c b/tests/test-aio.c index 56f4288ca8..e5f8b55d30 100644 --- a/tests/test-aio.c +++ b/tests/test-aio.c @@ -65,6 +65,8 @@ static void bh_test_cb(void *opaque) } } +#if !defined(_WIN32) + static void timer_test_cb(void *opaque) { TimerTestData *data = opaque; @@ -78,6 +80,8 @@ static void dummy_io_handler_read(void *opaque) { } +#endif /* !_WIN32 */ + static void bh_delete_cb(void *opaque) { BHTestData *data = opaque; @@ -423,6 +427,8 @@ static void test_wait_event_notifier_noflush(void) event_notifier_cleanup(&data.e); } +#if !defined(_WIN32) + static void test_timer_schedule(void) { TimerTestData data = { .n = 0, .ctx = ctx, .ns = SCALE_MS * 750LL, @@ -484,6 +490,8 @@ static void test_timer_schedule(void) timer_del(&data.timer); } +#endif /* !_WIN32 */ + /* Now the same tests, using the context as a GSource. They are * very similar to the ones above, with g_main_context_iteration * replacing aio_poll. However: @@ -766,6 +774,8 @@ static void test_source_wait_event_notifier_noflush(void) event_notifier_cleanup(&data.e); } +#if !defined(_WIN32) + static void test_source_timer_schedule(void) { TimerTestData data = { .n = 0, .ctx = ctx, .ns = SCALE_MS * 750LL, @@ -815,6 +825,8 @@ static void test_source_timer_schedule(void) timer_del(&data.timer); } +#endif /* !_WIN32 */ + /* End of tests. */ @@ -845,7 +857,9 @@ int main(int argc, char **argv) g_test_add_func("/aio/event/wait", test_wait_event_notifier); g_test_add_func("/aio/event/wait/no-flush-cb", test_wait_event_notifier_noflush); g_test_add_func("/aio/event/flush", test_flush_event_notifier); +#if !defined(_WIN32) g_test_add_func("/aio/timer/schedule", test_timer_schedule); +#endif g_test_add_func("/aio-gsource/notify", test_source_notify); g_test_add_func("/aio-gsource/flush", test_source_flush); @@ -860,6 +874,8 @@ int main(int argc, char **argv) g_test_add_func("/aio-gsource/event/wait", test_source_wait_event_notifier); g_test_add_func("/aio-gsource/event/wait/no-flush-cb", test_source_wait_event_notifier_noflush); g_test_add_func("/aio-gsource/event/flush", test_source_flush_event_notifier); +#if !defined(_WIN32) g_test_add_func("/aio-gsource/timer/schedule", test_source_timer_schedule); +#endif return g_test_run(); } diff --git a/tests/tmp105-test.c b/tests/tmp105-test.c index 0834219e35..15ddaf38d4 100644 --- a/tests/tmp105-test.c +++ b/tests/tmp105-test.c @@ -15,44 +15,135 @@ #define OMAP2_I2C_1_BASE 0x48070000 -#define N8X0_ADDR 0x48 +#define TMP105_TEST_ID "tmp105-test" +#define TMP105_TEST_ADDR 0x49 static I2CAdapter *i2c; -static uint8_t addr; -static void send_and_receive(void) +static uint16_t tmp105_get8(I2CAdapter *i2c, uint8_t addr, uint8_t reg) { - uint8_t cmd[3]; - uint8_t resp[2]; + uint8_t resp[1]; + i2c_send(i2c, addr, ®, 1); + i2c_recv(i2c, addr, resp, 1); + return resp[0]; +} - cmd[0] = TMP105_REG_TEMPERATURE; - i2c_send(i2c, addr, cmd, 1); +static uint16_t tmp105_get16(I2CAdapter *i2c, uint8_t addr, uint8_t reg) +{ + uint8_t resp[2]; + i2c_send(i2c, addr, ®, 1); i2c_recv(i2c, addr, resp, 2); - g_assert_cmpuint(((uint16_t)resp[0] << 8) | resp[1], ==, 0); + return (resp[0] << 8) | resp[1]; +} + +static void tmp105_set8(I2CAdapter *i2c, uint8_t addr, uint8_t reg, + uint8_t value) +{ + uint8_t cmd[2]; + uint8_t resp[1]; - cmd[0] = TMP105_REG_CONFIG; - cmd[1] = 0x0; /* matches the reset value */ + cmd[0] = reg; + cmd[1] = value; i2c_send(i2c, addr, cmd, 2); i2c_recv(i2c, addr, resp, 1); g_assert_cmphex(resp[0], ==, cmd[1]); +} - cmd[0] = TMP105_REG_T_LOW; - cmd[1] = 0x12; - cmd[2] = 0x34; - i2c_send(i2c, addr, cmd, 3); - i2c_recv(i2c, addr, resp, 2); - g_assert_cmphex(resp[0], ==, cmd[1]); - g_assert_cmphex(resp[1], ==, cmd[2]); +static void tmp105_set16(I2CAdapter *i2c, uint8_t addr, uint8_t reg, + uint16_t value) +{ + uint8_t cmd[3]; + uint8_t resp[2]; - cmd[0] = TMP105_REG_T_HIGH; - cmd[1] = 0x42; - cmd[2] = 0x31; + cmd[0] = reg; + cmd[1] = value >> 8; + cmd[2] = value & 255; i2c_send(i2c, addr, cmd, 3); i2c_recv(i2c, addr, resp, 2); g_assert_cmphex(resp[0], ==, cmd[1]); g_assert_cmphex(resp[1], ==, cmd[2]); } +static int qmp_tmp105_get_temperature(const char *id) +{ + QDict *response; + int ret; + + response = qmp("{ 'execute': 'qom-get', 'arguments': { 'path': '%s', " + "'property': 'temperature' } }", id); + g_assert(qdict_haskey(response, "return")); + ret = qdict_get_int(response, "return"); + QDECREF(response); + return ret; +} + +static void qmp_tmp105_set_temperature(const char *id, int value) +{ + QDict *response; + + response = qmp("{ 'execute': 'qom-set', 'arguments': { 'path': '%s', " + "'property': 'temperature', 'value': %d } }", id, value); + g_assert(qdict_haskey(response, "return")); + QDECREF(response); +} + +#define TMP105_PRECISION (1000/16) +static void send_and_receive(void) +{ + uint16_t value; + + value = qmp_tmp105_get_temperature(TMP105_TEST_ID); + g_assert_cmpuint(value, ==, 0); + + value = tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + g_assert_cmphex(value, ==, 0); + + qmp_tmp105_set_temperature(TMP105_TEST_ID, 20000); + value = qmp_tmp105_get_temperature(TMP105_TEST_ID); + g_assert_cmpuint(value, ==, 20000); + + value = tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + g_assert_cmphex(value, ==, 0x1400); + + qmp_tmp105_set_temperature(TMP105_TEST_ID, 20938); /* 20 + 15/16 */ + value = qmp_tmp105_get_temperature(TMP105_TEST_ID); + g_assert_cmpuint(value, >=, 20938 - TMP105_PRECISION/2); + g_assert_cmpuint(value, <, 20938 + TMP105_PRECISION/2); + + /* Set config */ + tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x60); + value = tmp105_get8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG); + g_assert_cmphex(value, ==, 0x60); + + value = tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + g_assert_cmphex(value, ==, 0x14f0); + + /* Set precision to 9, 10, 11 bits. */ + tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x00); + value = tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + g_assert_cmphex(value, ==, 0x1480); + + tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x20); + value = tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + g_assert_cmphex(value, ==, 0x14c0); + + tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x40); + value = tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + g_assert_cmphex(value, ==, 0x14e0); + + /* stored precision remains the same */ + value = qmp_tmp105_get_temperature(TMP105_TEST_ID); + g_assert_cmpuint(value, >=, 20938 - TMP105_PRECISION/2); + g_assert_cmpuint(value, <, 20938 + TMP105_PRECISION/2); + + tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x60); + value = tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + g_assert_cmphex(value, ==, 0x14f0); + + tmp105_set16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_LOW, 0x1234); + tmp105_set16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_HIGH, 0x4231); +} + int main(int argc, char **argv) { QTestState *s = NULL; @@ -60,9 +151,10 @@ int main(int argc, char **argv) g_test_init(&argc, &argv, NULL); - s = qtest_start("-machine n800"); + s = qtest_start("-machine n800 " + "-device tmp105,bus=i2c-bus.0,id=" TMP105_TEST_ID + ",address=0x49"); i2c = omap_i2c_create(OMAP2_I2C_1_BASE); - addr = N8X0_ADDR; qtest_add_func("/tmp105/tx-rx", send_and_receive); diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c new file mode 100644 index 0000000000..1fae47797e --- /dev/null +++ b/tests/virtio-9p-test.c @@ -0,0 +1,46 @@ +/* + * QTest testcase for VirtIO 9P + * + * Copyright (c) 2014 SUSE LINUX Products GmbH + * + * 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 <stdlib.h> +#include <string.h> +#include <glib.h> +#include "libqtest.h" +#include "qemu-common.h" +#include "qemu/osdep.h" + +/* Tests only initialization so far. TODO: Replace with functional tests */ +static void pci_nop(void) +{ +} + +static char test_share[] = "/tmp/qtest.XXXXXX"; + +int main(int argc, char **argv) +{ + char *args; + int ret; + + g_test_init(&argc, &argv, NULL); + qtest_add_func("/virtio/9p/pci/nop", pci_nop); + + g_assert(mkdtemp(test_share)); + + args = g_strdup_printf("-fsdev local,id=fsdev0,security_model=none,path=%s " + "-device virtio-9p-pci,fsdev=fsdev0,mount_tag=qtest", + test_share); + qtest_start(args); + g_free(args); + + ret = g_test_run(); + + qtest_end(); + rmdir(test_share); + + return ret; +} |