]>
Commit | Line | Data |
---|---|---|
fcbf4a3c TH |
1 | /* |
2 | * Test OpenBIOS-based machines. | |
3 | * | |
4 | * Copyright (c) 2016 Red Hat Inc. | |
5 | * | |
6 | * Author: | |
7 | * Thomas Huth <thuth@redhat.com> | |
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 | * | |
53687348 DG |
12 | * This test is used to check that some Open Firmware based machines (i.e. |
13 | * OpenBIOS or SLOF) can be started successfully in TCG mode. To do this, we | |
14 | * first put some Forth code into the "boot-command" Open Firmware environment | |
15 | * variable. This Forth code writes a well-known magic value to a known location | |
16 | * in memory. Then we start the guest so that the firmware can boot and finally | |
17 | * run the Forth code. | |
fcbf4a3c TH |
18 | * The testing code here then can finally check whether the value has been |
19 | * successfully written into the guest memory. | |
20 | */ | |
21 | ||
22 | #include "qemu/osdep.h" | |
23 | #include "libqtest.h" | |
24 | ||
25 | #define MAGIC 0xcafec0de | |
26 | #define ADDRESS 0x4000 | |
27 | ||
28 | static void check_guest_memory(void) | |
29 | { | |
30 | uint32_t signature; | |
31 | int i; | |
32 | ||
33 | /* Poll until code has run and modified memory. Wait at most 30 seconds */ | |
eaf8d91c | 34 | for (i = 0; i < 10000; ++i) { |
fcbf4a3c TH |
35 | signature = readl(ADDRESS); |
36 | if (signature == MAGIC) { | |
37 | break; | |
38 | } | |
39 | g_usleep(10000); | |
40 | } | |
41 | ||
42 | g_assert_cmphex(signature, ==, MAGIC); | |
43 | } | |
44 | ||
45 | static void test_machine(const void *machine) | |
46 | { | |
47 | char *args; | |
48 | ||
49 | args = g_strdup_printf("-M %s,accel=tcg -prom-env 'boot-command=%x %x l!'", | |
50 | (const char *)machine, MAGIC, ADDRESS); | |
51 | ||
52 | qtest_start(args); | |
53 | check_guest_memory(); | |
54 | qtest_quit(global_qtest); | |
55 | ||
56 | g_free(args); | |
57 | } | |
58 | ||
59 | static void add_tests(const char *machines[]) | |
60 | { | |
61 | int i; | |
62 | char *name; | |
63 | ||
64 | for (i = 0; machines[i] != NULL; i++) { | |
65 | name = g_strdup_printf("prom-env/%s", machines[i]); | |
66 | qtest_add_data_func(name, machines[i], test_machine); | |
67 | g_free(name); | |
68 | } | |
69 | } | |
70 | ||
71 | int main(int argc, char *argv[]) | |
72 | { | |
73 | const char *sparc_machines[] = { "SPARCbook", "Voyager", "SS-20", NULL }; | |
74 | const char *sparc64_machines[] = { "sun4u", "sun4v", NULL }; | |
53687348 DG |
75 | const char *ppc_machines[] = { "mac99", "g3beige", NULL }; |
76 | const char *ppc64_machines[] = { "mac99", "g3beige", "pseries", NULL }; | |
fcbf4a3c TH |
77 | const char *arch = qtest_get_arch(); |
78 | ||
79 | g_test_init(&argc, &argv, NULL); | |
80 | ||
53687348 DG |
81 | if (!strcmp(arch, "ppc")) { |
82 | add_tests(ppc_machines); | |
83 | } else if (!strcmp(arch, "ppc64")) { | |
84 | add_tests(ppc64_machines); | |
fcbf4a3c TH |
85 | } else if (!strcmp(arch, "sparc")) { |
86 | add_tests(sparc_machines); | |
87 | } else if (!strcmp(arch, "sparc64")) { | |
88 | add_tests(sparc64_machines); | |
89 | } else { | |
90 | g_assert_not_reached(); | |
91 | } | |
92 | ||
93 | return g_test_run(); | |
94 | } |