summaryrefslogtreecommitdiff
path: root/tests/libqtest.c
AgeCommit message (Collapse)AuthorFilesLines
2014-03-13qtest: Fix crash if SIGABRT during qtest_init()Stefan Hajnoczi1-1/+2
If an assertion fails during qtest_init() the SIGABRT handler is invoked. This is the correct behavior since we need to kill the QEMU process to avoid leaking it when the test dies. The global_qtest pointer used by the SIGABRT handler is currently only assigned after qtest_init() returns. This results in a segfault if an assertion failure occurs during qtest_init(). Move global_qtest assignment inside qtest_init(). Not pretty but let's face it - the signal handler depends on global state. Reported-by: Marcel Apfelbaum <marcel.a@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Tested-by: Marcel Apfelbaum <marcel.a@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
2014-03-13Merge remote-tracking branch 'remotes/afaerber/tags/qom-devices-for-peter' ↵Peter Maydell1-2/+11
into staging QOM/QTest infrastructure fixes and device conversions * QTest cleanups and test cases for some virtio devices * QTest for sPAPR PCI host bridge * qom-test now tests reading all properties beneath /machine * QOM API leak fixes * QOM cleanups for SSI devices * QOM conversion of QEMUMachine * QOM realize for buses * sPAPR PCI bus name change # gpg: Signature made Thu 13 Mar 2014 00:22:40 GMT 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-peter: (31 commits) libqtest: Fix possible deadlock in qtest initialization pci: Move VMState registration/unregistration to QOM realize/unrealize qdev: Realize buses on device realization qdev: Prepare realize/unrealize hooks for BusState tests: Add spapr-pci-host-bridge qtest virtio-serial-port: Convert to QOM realize/unrealize virtio-console: QOM cast cleanup for VirtConsole tests: Add virtio-console qtest tests: Add virtio-serial qtest tests: Add virtio-scsi qtest tests: Add virtio-rng qtest tests: Add virtio-balloon qtest tests: Add virtio-blk qtest tests: Clean up IndustryPack TPCI200 gcov paths qom-test: Test QOM properties hw/boards: Convert current_machine to MachineState vl: Use MachineClass instead of global QEMUMachine list hw/core: Introduce QEMU machine as QOM object qdev-monitor-test: Don't test human-readable error message qdev-monitor-test: Simplify using g_assert_cmpstr() ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2014-03-13libqtest: Avoid inline varargs functionsPeter Maydell1-0/+20
Older versions of gcc (eg 4.6) can't handle varargs functions declared inline for anything other than completely trivial uses, and complain: tests/qom-test.c: In function 'qmp': tests/libqtest.h:359:60: sorry, unimplemented: function 'qmp' can never be inlined because it uses variable argument lists Avoid this problem by putting the functions into libqtest.c instead of using inline definitions in libqtest.h. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Andreas Färber <afaerber@suse.de>
2014-03-13libqtest: Fix possible deadlock in qtest initializationMarcel Apfelbaum1-2/+11
'socket_accept' waits for QEMU to init its unix socket. If QEMU encounters an error during command line parsing, it can exit before initializing the communication channel. Using a timeout for sockets fixes the issue. Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
2014-02-19qtest: kill QEMU process on g_assert() failureStefan Hajnoczi1-6/+25
The QEMU process stays running if the test case fails. This patch fixes the leak by installing a SIGABRT signal handler which invokes qtest_end(). Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
2014-02-19qtest: make QEMU our direct child processStefan Hajnoczi1-29/+5
qtest_init() cannot use exec*p() to launch QEMU since the exec*p() functions take an argument array while qtest_init() takes char *extra_args. Therefore we execute /bin/sh -c <command-line> and let the shell parse the argument string. This left /bin/sh as our child process and our child's child was QEMU. We still want QEMU's pid so the -pidfile option was used to let QEMU report its pid. The pidfile needs to be unlinked when the test case exits or fails. In other words, the pidfile creates a new problem for us! Simplify all this using the shell 'exec' command. It allows us to replace the /bin/sh process with QEMU. Then we no longer need to use -pidfile because we already know our fork child's pid. Note: Yes, it seems silly to exec /bin/sh when we could just exec QEMU directly. But remember qtest_init() takes a single char *extra_args command-line fragment instead of a real argv[] array, so we need /bin/sh's argument parsing behavior. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com>
2014-02-19qtest: drop unused child_pid fieldStefan Hajnoczi1-2/+0
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com>
2014-02-03qtest: unlink UNIX domain sockets after connectingStefan Hajnoczi1-11/+12
UNIX domain sockets are leaked when tests call abort(3) (indirectly via glib assert functions). Unlink the files immediately after the connection has been established to avoid leaks. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-02-03qtest: unlink QEMU pid file after startupStefan Hajnoczi1-11/+11
After starting the QEMU process and initializing the QMP connection, we can read the pid file and unlink it. Just stash away the pid instead of the pid filename. This way we can avoid pid file leaks since running tests may abort(3) without cleanup. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2013-11-19qtest: Use -display none by defaultAndreas Färber1-0/+1
This avoids each test needing to add it to suppress windows popping up. [Commit 7ceeedd016facf8d58e14a0d1417fa7225d71072 ("blockdev-test: add test case for drive_add duplicate IDs") and commit 43cd209803d6cffb1e1a028c9ff2fd0ff4fce954 ("qdev-monitor-test: add device_add leak test cases") added qtest tests without specifying -display none. As a result, "make check" now tries to use graphics (GTK or SDL). Since graphics are not used by the test and inappropriate for headless "make check" runs, add the missing -display none. This fixes "make check" in the QEMU buildbot. -- Stefan] Signed-off-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2013-11-07libqtest: add qmp(fmt, ...) -> QDict* functionStefan Hajnoczi1-14/+52
Add a qtest qmp() function that returns the response object. This allows test cases to verify the result or to check for error responses. It also allows waiting for QMP events. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Andreas Färber <afaerber@suse.de>
2013-11-07libqtest: rename qmp() to qmp_discard_response()Stefan Hajnoczi1-5/+5
Existing qmp() callers do not expect a response object. In order to implement real QMP test cases it will be necessary to inspect the response object. Rename qmp() to qmp_discard_response(). Later patches will introduce a qmp() function that returns the response object and tests that use it. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Andreas Färber <afaerber@suse.de>
2013-07-18libqtest: Plug fd and memory leaks in qtest_quit()Markus Armbruster1-0/+4
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Andreas Färber <afaerber@suse.de> Message-id: 1371711329-9144-2-git-send-email-armbru@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-04-30libqtest: only call fclose() on open filesJesse Larrew1-1/+1
libqtest.c can segfault when calling fclose() if the pidfile wasn't opened successfully. This patch fixes the issue. Signed-off-by: Jesse Larrew <jlarrew@linux.vnet.ibm.com> Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Message-id: 1367250772-17928-1-git-send-email-jlarrew@linux.vnet.ibm.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-04-17qtest: don't use system command to avoid double forkAnthony Liguori1-7/+4
Currently we waitpid on the child process we spawn off that does nothing more than system() another process. While this does not appear to be incorrect, it's wasteful and confusing so get rid of it. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Message-id: 1366123521-4330-2-git-send-email-aliguori@us.ibm.com
2013-02-18qtest: Add MMIO supportAndreas Färber1-0/+62
Introduce [qtest_]{read,write}[bwlq]() libqtest functions and corresponding QTest protocol commands to replace local versions in libi2c-omap.c. Also convert m48t59-test's cmos_{read,write}_mmio() to {read,write}b(). Signed-off-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Andreas Färber <afaerber@suse.de> Message-id: 1361051043-27944-4-git-send-email-afaerber@suse.de Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-02-18libqtest: Introduce qtest_qmpv() and convert remaining macroAndreas Färber1-4/+10
In order to convert qmp() macro to an inline function, expose a qtest_qmpv() function, reused by qtest_qmp(). We can't apply GCC_FMT_ATTR() since fdc-test is using zero-length format strings, which would result in warnings treated as errors. Signed-off-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Andreas Färber <afaerber@suse.de> Message-id: 1361051043-27944-3-git-send-email-afaerber@suse.de Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-02-01libqtest: Wait for the right child PID after killing QEMUEduardo Habkost1-2/+5
When running "make check" with gcov enabled, we get the following message: hw/tmp105.gcda:cannot open data file, assuming not executed The problem happens because: * tmp105-test exits before QEMU exits, because waitpid() at qtest_quit() fails; * waitpid() fails because there's another process already waiting for the QEMU process; * The process that is already waiting for QEMU is the child created by qtest_init() to run system(); * qtest_quit() is incorrectly waiting for the QEMU PID directly instead of the child created by qtest_init(). This fixes the problem by sending SIGTERM to QEMU, but waiting for the child process created by qtest_init() (that exits immediately after QEMU exits). Reported-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-12-19misc: move include files to include/qemu/Paolo Bonzini1-2/+2
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-05qtest: implement QTEST_STOPPaolo Bonzini1-13/+25
It is quite difficult to debug qtest test cases without extra wrapper scripts for QEMU or similar. This patch adds a simple environment variable-based trigger that sends a STOP signal to the QEMU instance under test, before attempting to connect to its QMP session. This will block execution of the testcase and give time to attach a debugger to the stopped QEMU process. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-07-09qtest: Tidy up temporary files properlyMarkus Armbruster1-13/+16
Each test litters /tmp with several files: a pid file and two sockets. Tidy up. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-06-27qtest: fix infinite loop when QEMU aborts abruptlyAnthony Liguori1-0/+5
From Markus: Makes "make check" hang: QTEST_QEMU_BINARY=x86_64-softmmu/qemu-system-x86_64 gtester -k --verbose -m=quick tests/crash-test tests/rtc-test TEST: tests/crash-test... (pid=972) qemu-system-x86_64: Device needs media, but drive is empty [Nothing happens, wait a while, then hit ^C] make: *** [check-qtest-x86_64] Interrupt This was due to the fact that we weren't checked for errors when reading from the QMP socket. This patch adds appropriate error checking. Reported-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-06-22libqtest: Fix socket_accept() to pass address_lenAndreas Färber1-0/+1
accept() expects address_len to point to the length of the sockaddr on input. Initialize it accordingly. Resolves an assertion due to EFAULT on illumos. Signed-off-by: Andreas Färber <andreas.faerber@web.de> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-05-10qtest: Add function to send QMP commandsKevin Wolf1-27/+96
Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
2012-04-26qtest: Fix more format errors with qtest_sendfStefan Weil1-3/+4
After adding GCC_FMT_ATTR to qtest_sendf, more format errors are reported by the compiler. These are fixed here. Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-04-23qtest: fix memread and memwrite on 32 bit hostsBlue Swirl1-2/+2
Use PRIx64 to print 64 bit values to avoid truncation on 32 bit hosts. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2012-03-30qtest: add C version of test infrastructureAnthony Liguori1-0/+387
This also includes a qtest wrapper script to make it easier to launch qtest tests directly. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>