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-remove testchardev1",
30 "device_add usb-mouse,id=mouse1",
35 "dump-guest-memory /dev/null 0 4096",
37 "host_net_add user id=net0",
38 "hostfwd_add tcp::43210-:43210",
39 "hostfwd_remove tcp::43210-:43210",
40 "host_net_remove 0 net0",
44 "memsave 0 4096 \"/dev/null\"",
45 "migrate_set_cache_size 1",
46 "migrate_set_downtime 1",
47 "migrate_set_speed 1",
48 "netdev_add user,id=net1",
54 "object_add memory-backend-ram,id=mem1,size=256M",
56 "pmemsave 0 4096 \"/dev/null\"",
59 "qom-set /machine initrd test",
60 "screendump /dev/null",
63 "wavcapture /dev/null",
71 /* Run through the list of pre-defined commands */
72 static void test_commands(void)
77 for (i = 0; hmp_cmds[i] != NULL; i++) {
79 fprintf(stderr, "\t%s\n", hmp_cmds[i]);
81 response = hmp(hmp_cmds[i]);
87 /* Run through all info commands and call them blindly (without arguments) */
88 static void test_info_commands(void)
90 char *resp, *info, *info_buf, *endp;
92 info_buf = info = hmp("help info");
95 /* Extract the info command, ignore parameters and description */
96 g_assert(strncmp(info, "info ", 5) == 0);
97 endp = strchr(&info[5], ' ');
98 g_assert(endp != NULL);
100 /* Now run the info command */
102 fprintf(stderr, "\t%s\n", info);
106 /* And move forward to the next line */
107 info = strchr(endp + 1, '\n');
117 static void test_machine(gconstpointer data)
119 const char *machine = data;
122 args = g_strdup_printf("-S -M %s", machine);
125 test_info_commands();
130 g_free((void *)data);
133 static void add_machine_test_case(const char *mname)
137 /* Ignore blacklisted machines that have known problems */
138 if (!strcmp("puv3", mname) || !strcmp("tricore_testboard", mname) ||
139 !strcmp("xenfv", mname) || !strcmp("xenpv", mname)) {
143 path = g_strdup_printf("hmp/%s", mname);
144 qtest_add_data_func(path, g_strdup(mname), test_machine);
148 int main(int argc, char **argv)
150 char *v_env = getenv("V");
152 if (v_env && *v_env >= '2') {
156 g_test_init(&argc, &argv, NULL);
158 qtest_cb_for_every_machine(add_machine_test_case);