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