]>
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", | |
25 | "chardev-remove testchardev1", | |
26 | "commit all", | |
27 | "cpu-add 1", | |
28 | "cpu 0", | |
29 | "device_add ?", | |
30 | "device_add usb-mouse,id=mouse1", | |
31 | "mouse_button 7", | |
32 | "mouse_move 10 10", | |
33 | "mouse_button 0", | |
34 | "device_del mouse1", | |
35 | "dump-guest-memory /dev/null 0 4096", | |
36 | "gdbserver", | |
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", | |
41 | "i /w 0", | |
42 | "log all", | |
43 | "log none", | |
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", | |
49 | "set_link net1 off", | |
50 | "set_link net1 on", | |
51 | "netdev_del net1", | |
52 | "nmi", | |
53 | "o /w 0 0x1234", | |
54 | "object_add memory-backend-ram,id=mem1,size=256M", | |
55 | "object_del mem1", | |
56 | "pmemsave 0 4096 \"/dev/null\"", | |
57 | "p $pc + 8", | |
58 | "qom-list /", | |
59 | "qom-set /machine initrd test", | |
60 | "screendump /dev/null", | |
61 | "sendkey x", | |
62 | "singlestep on", | |
63 | "wavcapture /dev/null", | |
64 | "stopcapture 0", | |
65 | "sum 0 512", | |
66 | "x /8i 0x100", | |
67 | "xp /16x 0", | |
68 | NULL | |
69 | }; | |
70 | ||
71 | /* Run through the list of pre-defined commands */ | |
72 | static void test_commands(void) | |
73 | { | |
74 | char *response; | |
75 | int i; | |
76 | ||
77 | for (i = 0; hmp_cmds[i] != NULL; i++) { | |
78 | if (verbose) { | |
79 | fprintf(stderr, "\t%s\n", hmp_cmds[i]); | |
80 | } | |
81 | response = hmp(hmp_cmds[i]); | |
82 | g_free(response); | |
83 | } | |
84 | ||
85 | } | |
86 | ||
87 | /* Run through all info commands and call them blindly (without arguments) */ | |
88 | static void test_info_commands(void) | |
89 | { | |
90 | char *resp, *info, *info_buf, *endp; | |
91 | ||
92 | info_buf = info = hmp("help info"); | |
93 | ||
94 | while (*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); | |
99 | *endp = '\0'; | |
100 | /* Now run the info command */ | |
101 | if (verbose) { | |
102 | fprintf(stderr, "\t%s\n", info); | |
103 | } | |
104 | resp = hmp(info); | |
105 | g_free(resp); | |
106 | /* And move forward to the next line */ | |
107 | info = strchr(endp + 1, '\n'); | |
108 | if (!info) { | |
109 | break; | |
110 | } | |
111 | info += 1; | |
112 | } | |
113 | ||
114 | g_free(info_buf); | |
115 | } | |
116 | ||
117 | static void test_machine(gconstpointer data) | |
118 | { | |
119 | const char *machine = data; | |
120 | char *args; | |
121 | ||
122 | args = g_strdup_printf("-S -M %s", machine); | |
123 | qtest_start(args); | |
124 | ||
125 | test_info_commands(); | |
126 | test_commands(); | |
127 | ||
128 | qtest_end(); | |
129 | g_free(args); | |
130 | g_free((void *)data); | |
131 | } | |
132 | ||
133 | static void add_machine_test_case(const char *mname) | |
134 | { | |
135 | char *path; | |
136 | ||
137 | /* Ignore blacklisted machines that have known problems */ | |
138 | if (!strcmp("puv3", mname) || !strcmp("tricore_testboard", mname) || | |
139 | !strcmp("xenfv", mname) || !strcmp("xenpv", mname)) { | |
140 | return; | |
141 | } | |
142 | ||
143 | path = g_strdup_printf("hmp/%s", mname); | |
144 | qtest_add_data_func(path, g_strdup(mname), test_machine); | |
145 | g_free(path); | |
146 | } | |
147 | ||
148 | int main(int argc, char **argv) | |
149 | { | |
150 | char *v_env = getenv("V"); | |
151 | ||
152 | if (v_env && *v_env >= '2') { | |
153 | verbose = true; | |
154 | } | |
155 | ||
156 | g_test_init(&argc, &argv, NULL); | |
157 | ||
158 | qtest_cb_for_every_machine(add_machine_test_case); | |
159 | ||
160 | return g_test_run(); | |
161 | } |