s390x/css: use SubchDev.orb
[qemu/ar7.git] / tests / test-hmp.c
blob6dfa0c36e2986e93ecc436ef6dc5ffd64804ff74
1 /*
2 * Test HMP commands.
4 * Copyright (c) 2017 Red Hat Inc.
6 * Author:
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"
18 #include "libqtest.h"
20 static int verbose;
22 static const char *hmp_cmds[] = {
23 "boot_set ndc",
24 "chardev-add null,id=testchardev1",
25 "chardev-send-break testchardev2",
26 "chardev-remove testchardev1",
27 "commit all",
28 "cpu-add 1",
29 "cpu 0",
30 "device_add ?",
31 "device_add usb-mouse,id=mouse1",
32 "mouse_button 7",
33 "mouse_move 10 10",
34 "mouse_button 0",
35 "device_del mouse1",
36 "dump-guest-memory /dev/null 0 4096",
37 "gdbserver",
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",
42 "i /w 0",
43 "log all",
44 "log none",
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",
50 "set_link net1 off",
51 "set_link net1 on",
52 "netdev_del net1",
53 "nmi",
54 "o /w 0 0x1234",
55 "object_add memory-backend-ram,id=mem1,size=256M",
56 "object_del mem1",
57 "pmemsave 0 4096 \"/dev/null\"",
58 "p $pc + 8",
59 "qom-list /",
60 "qom-set /machine initrd test",
61 "screendump /dev/null",
62 "sendkey x",
63 "singlestep on",
64 "wavcapture /dev/null",
65 "stopcapture 0",
66 "sum 0 512",
67 "x /8i 0x100",
68 "xp /16x 0",
69 NULL
72 /* Run through the list of pre-defined commands */
73 static void test_commands(void)
75 char *response;
76 int i;
78 for (i = 0; hmp_cmds[i] != NULL; i++) {
79 if (verbose) {
80 fprintf(stderr, "\t%s\n", hmp_cmds[i]);
82 response = hmp(hmp_cmds[i]);
83 g_free(response);
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");
95 while (*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);
100 *endp = '\0';
101 /* Now run the info command */
102 if (verbose) {
103 fprintf(stderr, "\t%s\n", info);
105 resp = hmp(info);
106 g_free(resp);
107 /* And move forward to the next line */
108 info = strchr(endp + 1, '\n');
109 if (!info) {
110 break;
112 info += 1;
115 g_free(info_buf);
118 static void test_machine(gconstpointer data)
120 const char *machine = data;
121 char *args;
123 args = g_strdup_printf("-S -M %s", machine);
124 qtest_start(args);
126 test_info_commands();
127 test_commands();
129 qtest_end();
130 g_free(args);
131 g_free((void *)data);
134 static void add_machine_test_case(const char *mname)
136 char *path;
138 /* Ignore blacklisted machines that have known problems */
139 if (!strcmp("puv3", mname) || !strcmp("tricore_testboard", mname) ||
140 !strcmp("xenfv", mname) || !strcmp("xenpv", mname)) {
141 return;
144 path = g_strdup_printf("hmp/%s", mname);
145 qtest_add_data_func(path, g_strdup(mname), test_machine);
146 g_free(path);
149 int main(int argc, char **argv)
151 char *v_env = getenv("V");
153 if (v_env && *v_env >= '2') {
154 verbose = true;
157 g_test_init(&argc, &argv, NULL);
159 qtest_cb_for_every_machine(add_machine_test_case);
161 return g_test_run();