]>
Commit | Line | Data |
---|---|---|
78f86a2b TH |
1 | /* |
2 | * Test HMP commands. | |
3 | * | |
4 | * Copyright (c) 2017 Red Hat Inc. | |
5 | * | |
6 | * Author: | |
7 | * Thomas Huth <[email protected]> | |
8 | * | |
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. | |
11 | * | |
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). | |
15 | */ | |
16 | ||
17 | #include "qemu/osdep.h" | |
18 | #include "libqtest.h" | |
19 | ||
20 | static int verbose; | |
21 | ||
22 | static const char *hmp_cmds[] = { | |
23 | "boot_set ndc", | |
24 | "chardev-add null,id=testchardev1", | |
bd1d5ad9 | 25 | "chardev-send-break testchardev2", |
78f86a2b TH |
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 | |
70 | }; | |
71 | ||
72 | /* Run through the list of pre-defined commands */ | |
73 | static void test_commands(void) | |
74 | { | |
75 | char *response; | |
76 | int i; | |
77 | ||
78 | for (i = 0; hmp_cmds[i] != NULL; i++) { | |
79 | if (verbose) { | |
80 | fprintf(stderr, "\t%s\n", hmp_cmds[i]); | |
81 | } | |
82 | response = hmp(hmp_cmds[i]); | |
83 | g_free(response); | |
84 | } | |
85 | ||
86 | } | |
87 | ||
88 | /* Run through all info commands and call them blindly (without arguments) */ | |
89 | static void test_info_commands(void) | |
90 | { | |
91 | char *resp, *info, *info_buf, *endp; | |
92 | ||
93 | info_buf = info = hmp("help info"); | |
94 | ||
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); | |
104 | } | |
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; | |
111 | } | |
112 | info += 1; | |
113 | } | |
114 | ||
115 | g_free(info_buf); | |
116 | } | |
117 | ||
118 | static void test_machine(gconstpointer data) | |
119 | { | |
120 | const char *machine = data; | |
121 | char *args; | |
122 | ||
123 | args = g_strdup_printf("-S -M %s", machine); | |
124 | qtest_start(args); | |
125 | ||
126 | test_info_commands(); | |
127 | test_commands(); | |
128 | ||
129 | qtest_end(); | |
130 | g_free(args); | |
131 | g_free((void *)data); | |
132 | } | |
133 | ||
134 | static void add_machine_test_case(const char *mname) | |
135 | { | |
136 | char *path; | |
137 | ||
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; | |
142 | } | |
143 | ||
144 | path = g_strdup_printf("hmp/%s", mname); | |
145 | qtest_add_data_func(path, g_strdup(mname), test_machine); | |
146 | g_free(path); | |
147 | } | |
148 | ||
149 | int main(int argc, char **argv) | |
150 | { | |
151 | char *v_env = getenv("V"); | |
152 | ||
153 | if (v_env && *v_env >= '2') { | |
154 | verbose = true; | |
155 | } | |
156 | ||
157 | g_test_init(&argc, &argv, NULL); | |
158 | ||
159 | qtest_cb_for_every_machine(add_machine_test_case); | |
160 | ||
161 | return g_test_run(); | |
162 | } |