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[] = {
24 "chardev-add null,id=testchardev1",
25 "chardev-send-break testchardev2",
26 "chardev-remove testchardev1",
31 "device_add usb-mouse,id=mouse1",
36 "dump-guest-memory /dev/null 0 4096",
38 "host_net_add user id=net0",
39 "hostfwd_add tcp::43210-:43210",
40 "hostfwd_remove tcp::43210-:43210",
41 "host_net_remove 0 net0",
45 "memsave 0 4096 \"/dev/null\"",
46 "migrate_set_cache_size 1",
47 "migrate_set_downtime 1",
48 "migrate_set_speed 1",
49 "netdev_add user,id=net1",
55 "object_add memory-backend-ram,id=mem1,size=256M",
57 "pmemsave 0 4096 \"/dev/null\"",
60 "qom-set /machine initrd test",
61 "screendump /dev/null",
64 "wavcapture /dev/null",
72 /* Run through the list of pre-defined commands */
73 static void test_commands(void)
78 for (i = 0; hmp_cmds[i] != NULL; i++) {
80 fprintf(stderr, "\t%s\n", hmp_cmds[i]);
82 response = hmp(hmp_cmds[i]);
88 /* Run through all info commands and call them blindly (without arguments) */
89 static void test_info_commands(void)
91 char *resp, *info, *info_buf, *endp;
93 info_buf = info = hmp("help info");
96 /* Extract the info command, ignore parameters and description */
97 g_assert(strncmp(info, "info ", 5) == 0);
98 endp = strchr(&info[5], ' ');
99 g_assert(endp != NULL);
101 /* Now run the info command */
103 fprintf(stderr, "\t%s\n", info);
107 /* And move forward to the next line */
108 info = strchr(endp + 1, '\n');
118 static void test_machine(gconstpointer data)
120 const char *machine = data;
123 args = g_strdup_printf("-S -M %s", machine);
126 test_info_commands();
131 g_free((void *)data);
134 static void add_machine_test_case(const char *mname)
138 /* Ignore blacklisted machines that have known problems */
139 if (!strcmp("puv3", mname) || !strcmp("tricore_testboard", mname) ||
140 !strcmp("xenfv", mname) || !strcmp("xenpv", mname)) {
144 path = g_strdup_printf("hmp/%s", mname);
145 qtest_add_data_func(path, g_strdup(mname), test_machine);
149 int main(int argc, char **argv)
151 char *v_env = getenv("V");
153 if (v_env && *v_env >= '2') {
157 g_test_init(&argc, &argv, NULL);
159 qtest_cb_for_every_machine(add_machine_test_case);