qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] Add chardev-send-break monitor command


From: Stefan Fritsch
Subject: Re: [Qemu-devel] [PATCH] Add chardev-send-break monitor command
Date: Tue, 6 Jun 2017 21:47:47 +0200 (CEST)
User-agent: Alpine 2.11 (DEB 23 2013-08-11)

On Tue, 6 Jun 2017, Markus Armbruster wrote:
> >> Is there an obvious test that we can enhance to add coverage of the new
> >> QMP command?
> >
> > You could have a new test covering hw/char/serial.c, but I wouldn't let
> > that hold the patch.
> 
> Holding patches is pretty much the only leverage I have to get tests for
> new stuff :)
> 
> Asking for tests that cover all of serial.c wouldn't be fair.  But I am
> asking for basic test coverage of new QMP commands.

One can easily extend tests/test-hmp.c, but AFAICS that only checks that 
qemu does not crash when the command is executed.

But I have managed to extend tests/test-char.c to call 
qmp_chardev_send_break() in the char_file_test() (see below). Is that what 
you had in mind? It seems it is not possible to use 
qtest_qmp_discard_response() from a unit test, so I don't know how to send 
actual json from inside test-char.c

Cheers,
Stefan


diff --git a/tests/test-char.c b/tests/test-char.c
index dfe856cb85..ad20b55f77 100644
--- a/tests/test-char.c
+++ b/tests/test-char.c
@@ -53,7 +53,9 @@ static void fe_event(void *opaque, int event)
     FeHandler *h = opaque;
 
     h->last_event = event;
-    quit = true;
+    if (event != CHR_EVENT_BREAK) {
+        quit = true;
+    }
 }
 
 #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
@@ -491,7 +493,7 @@ static void char_file_test(void)
 
         file.in = fifo;
         file.has_in = true;
-        chr = qemu_chardev_new(NULL, TYPE_CHARDEV_FILE, &backend,
+        chr = qemu_chardev_new("label-file", TYPE_CHARDEV_FILE, &backend,
                                &error_abort);
 
         qemu_chr_fe_init(&be, chr, &error_abort);
@@ -501,6 +503,10 @@ static void char_file_test(void)
                                  fe_event,
                                  &fe, NULL, true);
 
+        g_assert_cmpint(fe.last_event, !=, CHR_EVENT_BREAK);
+        qmp_chardev_send_break("label-file", NULL);
+        g_assert_cmpint(fe.last_event, ==, CHR_EVENT_BREAK);
+
         main_loop();
 
         close(fd);
diff --git a/tests/test-hmp.c b/tests/test-hmp.c
index 99e35ec15a..6dfa0c36e2 100644
--- a/tests/test-hmp.c
+++ b/tests/test-hmp.c
@@ -22,6 +22,7 @@ static int verbose;
 static const char *hmp_cmds[] = {
     "boot_set ndc",
     "chardev-add null,id=testchardev1",
+    "chardev-send-break testchardev1",
     "chardev-remove testchardev1",
     "commit all",
     "cpu-add 1",



reply via email to

[Prev in Thread] Current Thread [Next in Thread]