4 * Copyright (c) 2017 Red Hat Inc.
7 * Thomas Huth <thuth@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2
10 * or later. See the COPYING file in the top-level directory.
12 * This test calls some HMP commands for all machines that the current
13 * QEMU binary provides, to check whether they terminate successfully
14 * (i.e. do not crash QEMU).
17 #include "qemu/osdep.h"
22 static const char *hmp_cmds
[] = {
24 "chardev-add null,id=testchardev1",
25 "chardev-send-break testchardev1",
26 "chardev-change testchardev1 ringbuf",
27 "chardev-remove testchardev1",
32 "device_add usb-mouse,id=mouse1",
37 "dump-guest-memory /dev/null 0 4096",
39 "host_net_add user id=net0",
40 "hostfwd_add tcp::43210-:43210",
41 "hostfwd_remove tcp::43210-:43210",
42 "host_net_remove 0 net0",
46 "memsave 0 4096 \"/dev/null\"",
47 "migrate_set_cache_size 1",
48 "migrate_set_downtime 1",
49 "migrate_set_speed 1",
50 "netdev_add user,id=net1",
56 "object_add memory-backend-ram,id=mem1,size=256M",
58 "pmemsave 0 4096 \"/dev/null\"",
61 "qom-set /machine initrd test",
62 "screendump /dev/null",
65 "wavcapture /dev/null",
73 /* Run through the list of pre-defined commands */
74 static void test_commands(void)
79 for (i
= 0; hmp_cmds
[i
] != NULL
; i
++) {
81 fprintf(stderr
, "\t%s\n", hmp_cmds
[i
]);
83 response
= hmp(hmp_cmds
[i
]);
89 /* Run through all info commands and call them blindly (without arguments) */
90 static void test_info_commands(void)
92 char *resp
, *info
, *info_buf
, *endp
;
94 info_buf
= info
= hmp("help info");
97 /* Extract the info command, ignore parameters and description */
98 g_assert(strncmp(info
, "info ", 5) == 0);
99 endp
= strchr(&info
[5], ' ');
100 g_assert(endp
!= NULL
);
102 /* Now run the info command */
104 fprintf(stderr
, "\t%s\n", info
);
108 /* And move forward to the next line */
109 info
= strchr(endp
+ 1, '\n');
119 static void test_machine(gconstpointer data
)
121 const char *machine
= data
;
124 args
= g_strdup_printf("-S -M %s", machine
);
127 test_info_commands();
132 g_free((void *)data
);
135 static void add_machine_test_case(const char *mname
)
139 /* Ignore blacklisted machines that have known problems */
140 if (!strcmp("puv3", mname
) || !strcmp("tricore_testboard", mname
) ||
141 !strcmp("xenfv", mname
) || !strcmp("xenpv", mname
)) {
145 path
= g_strdup_printf("hmp/%s", mname
);
146 qtest_add_data_func(path
, g_strdup(mname
), test_machine
);
150 int main(int argc
, char **argv
)
152 char *v_env
= getenv("V");
154 if (v_env
&& *v_env
>= '2') {
158 g_test_init(&argc
, &argv
, NULL
);
160 qtest_cb_for_every_machine(add_machine_test_case
);