Reduce curses escdelay from 1s to 25ms
[qemu/ar7.git] / tests / test-hmp.c
blob8c49d2fdf1e83a22b7ce3be7b1ddf89ba23eb882
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 "announce_self",
24 "boot_set ndc",
25 "chardev-add null,id=testchardev1",
26 "chardev-send-break testchardev1",
27 "chardev-change testchardev1 ringbuf",
28 "chardev-remove testchardev1",
29 "commit all",
30 "cpu-add 1",
31 "cpu 0",
32 "device_add ?",
33 "device_add usb-mouse,id=mouse1",
34 "mouse_button 7",
35 "mouse_move 10 10",
36 "mouse_button 0",
37 "device_del mouse1",
38 "dump-guest-memory /dev/null 0 4096",
39 "dump-guest-memory /dev/null",
40 "gdbserver",
41 "hostfwd_add tcp::43210-:43210",
42 "hostfwd_remove tcp::43210-:43210",
43 "i /w 0",
44 "log all",
45 "log none",
46 "memsave 0 4096 \"/dev/null\"",
47 "migrate_set_cache_size 1",
48 "migrate_set_downtime 1",
49 "migrate_set_speed 1",
50 "netdev_add user,id=net1",
51 "set_link net1 off",
52 "set_link net1 on",
53 "netdev_del net1",
54 "nmi",
55 "o /w 0 0x1234",
56 "object_add memory-backend-ram,id=mem1,size=256M",
57 "object_del mem1",
58 "pmemsave 0 4096 \"/dev/null\"",
59 "p $pc + 8",
60 "qom-list /",
61 "qom-set /machine initrd test",
62 "screendump /dev/null",
63 "sendkey x",
64 "singlestep on",
65 "wavcapture /dev/null",
66 "stopcapture 0",
67 "sum 0 512",
68 "x /8i 0x100",
69 "xp /16x 0",
70 NULL
73 /* Run through the list of pre-defined commands */
74 static void test_commands(void)
76 char *response;
77 int i;
79 for (i = 0; hmp_cmds[i] != NULL; i++) {
80 response = hmp("%s", hmp_cmds[i]);
81 if (verbose) {
82 fprintf(stderr,
83 "\texecute HMP command: %s\n"
84 "\tresult : %s\n",
85 hmp_cmds[i], response);
87 g_free(response);
92 /* Run through all info commands and call them blindly (without arguments) */
93 static void test_info_commands(void)
95 char *resp, *info, *info_buf, *endp;
97 info_buf = info = hmp("help info");
99 while (*info) {
100 /* Extract the info command, ignore parameters and description */
101 g_assert(strncmp(info, "info ", 5) == 0);
102 endp = strchr(&info[5], ' ');
103 g_assert(endp != NULL);
104 *endp = '\0';
105 /* Now run the info command */
106 if (verbose) {
107 fprintf(stderr, "\t%s\n", info);
109 resp = hmp("%s", info);
110 g_free(resp);
111 /* And move forward to the next line */
112 info = strchr(endp + 1, '\n');
113 if (!info) {
114 break;
116 info += 1;
119 g_free(info_buf);
122 static void test_machine(gconstpointer data)
124 const char *machine = data;
125 char *args;
127 args = g_strdup_printf("-S -M %s", machine);
128 qtest_start(args);
130 test_info_commands();
131 test_commands();
133 qtest_end();
134 g_free(args);
135 g_free((void *)data);
138 static void add_machine_test_case(const char *mname)
140 char *path;
142 /* Ignore blacklisted machines that have known problems */
143 if (!strcmp("xenfv", mname) || !strcmp("xenpv", mname)) {
144 return;
147 path = g_strdup_printf("hmp/%s", mname);
148 qtest_add_data_func(path, g_strdup(mname), test_machine);
149 g_free(path);
152 int main(int argc, char **argv)
154 char *v_env = getenv("V");
156 if (v_env && *v_env >= '2') {
157 verbose = true;
160 g_test_init(&argc, &argv, NULL);
162 qtest_cb_for_every_machine(add_machine_test_case, g_test_quick());
164 /* as none machine has no memory by default, add a test case with memory */
165 qtest_add_data_func("hmp/none+2MB", g_strdup("none -m 2"), test_machine);
167 return g_test_run();