4 * Copyright (c) 2017 Red Hat Inc.
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[] = {
25 "chardev-add null,id=testchardev1",
26 "chardev-send-break testchardev1",
27 "chardev-change testchardev1 ringbuf",
28 "chardev-remove testchardev1",
33 "device_add usb-mouse,id=mouse1",
34 "drive_add ignored format=help",
39 "dump-guest-memory /dev/null 0 4096",
40 "dump-guest-memory /dev/null",
42 "hostfwd_add tcp::43210-:43210",
43 "hostfwd_remove tcp::43210-:43210",
47 "memsave 0 4096 \"/dev/null\"",
48 "migrate_set_cache_size 1",
49 "migrate_set_downtime 1",
50 "migrate_set_speed 1",
51 "netdev_add user,id=net1",
57 "object_add memory-backend-ram,id=mem1,size=256M",
59 "pmemsave 0 4096 \"/dev/null\"",
62 "qom-set /machine initrd test",
63 "screendump /dev/null",
66 "wavcapture /dev/null",
74 /* Run through the list of pre-defined commands */
75 static void test_commands(void)
80 for (i = 0; hmp_cmds[i] != NULL; i++) {
81 response = hmp("%s", hmp_cmds[i]);
84 "\texecute HMP command: %s\n"
86 hmp_cmds[i], response);
93 /* Run through all info commands and call them blindly (without arguments) */
94 static void test_info_commands(void)
96 char *resp, *info, *info_buf, *endp;
98 info_buf = info = hmp("help info");
101 /* Extract the info command, ignore parameters and description */
102 g_assert(strncmp(info, "info ", 5) == 0);
103 endp = strchr(&info[5], ' ');
104 g_assert(endp != NULL);
106 /* Now run the info command */
108 fprintf(stderr, "\t%s\n", info);
110 resp = hmp("%s", info);
112 /* And move forward to the next line */
113 info = strchr(endp + 1, '\n');
123 static void test_machine(gconstpointer data)
125 const char *machine = data;
128 args = g_strdup_printf("-S -M %s", machine);
131 test_info_commands();
136 g_free((void *)data);
139 static void add_machine_test_case(const char *mname)
143 /* Ignore blacklisted machines that have known problems */
144 if (!strcmp("xenfv", mname) || !strcmp("xenpv", mname)) {
148 path = g_strdup_printf("hmp/%s", mname);
149 qtest_add_data_func(path, g_strdup(mname), test_machine);
153 int main(int argc, char **argv)
155 char *v_env = getenv("V");
157 if (v_env && *v_env >= '2') {
161 g_test_init(&argc, &argv, NULL);
163 qtest_cb_for_every_machine(add_machine_test_case, g_test_quick());
165 /* as none machine has no memory by default, add a test case with memory */
166 qtest_add_data_func("hmp/none+2MB", g_strdup("none -m 2"), test_machine);