]>
Commit | Line | Data |
---|---|---|
fcbf4a3c | 1 | /* |
b95b5a0a | 2 | * Test Open-Firmware-based machines. |
fcbf4a3c | 3 | * |
b95b5a0a | 4 | * Copyright (c) 2016, 2017 Red Hat Inc. |
fcbf4a3c TH |
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 | * | |
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 | ||
b95b5a0a TH |
33 | /* Poll until code has run and modified memory. Wait at most 600 seconds */ |
34 | for (i = 0; i < 60000; ++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 | { | |
61eedf7a | 47 | const char *extra_args; |
fcbf4a3c | 48 | |
61eedf7a TH |
49 | /* The pseries firmware boots much faster without the default devices */ |
50 | extra_args = strcmp(machine, "pseries") == 0 ? "-nodefaults" : ""; | |
51 | ||
78b27bad EB |
52 | global_qtest = qtest_startf("-M %s,accel=tcg %s " |
53 | "-prom-env 'use-nvramrc?=true' " | |
54 | "-prom-env 'nvramrc=%x %x l!' ", | |
55 | (const char *)machine, extra_args, | |
56 | MAGIC, ADDRESS); | |
fcbf4a3c TH |
57 | check_guest_memory(); |
58 | qtest_quit(global_qtest); | |
fcbf4a3c TH |
59 | } |
60 | ||
61 | static void add_tests(const char *machines[]) | |
62 | { | |
63 | int i; | |
64 | char *name; | |
65 | ||
66 | for (i = 0; machines[i] != NULL; i++) { | |
67 | name = g_strdup_printf("prom-env/%s", machines[i]); | |
68 | qtest_add_data_func(name, machines[i], test_machine); | |
69 | g_free(name); | |
70 | } | |
71 | } | |
72 | ||
73 | int main(int argc, char *argv[]) | |
74 | { | |
75 | const char *sparc_machines[] = { "SPARCbook", "Voyager", "SS-20", NULL }; | |
6b591ad6 | 76 | const char *sparc64_machines[] = { "sun4u", NULL }; |
53687348 | 77 | const char *ppc_machines[] = { "mac99", "g3beige", NULL }; |
fcbf4a3c TH |
78 | const char *arch = qtest_get_arch(); |
79 | ||
80 | g_test_init(&argc, &argv, NULL); | |
81 | ||
53687348 DG |
82 | if (!strcmp(arch, "ppc")) { |
83 | add_tests(ppc_machines); | |
84 | } else if (!strcmp(arch, "ppc64")) { | |
b95b5a0a TH |
85 | add_tests(ppc_machines); |
86 | if (g_test_slow()) { | |
87 | qtest_add_data_func("prom-env/pseries", "pseries", test_machine); | |
88 | } | |
fcbf4a3c TH |
89 | } else if (!strcmp(arch, "sparc")) { |
90 | add_tests(sparc_machines); | |
91 | } else if (!strcmp(arch, "sparc64")) { | |
92 | add_tests(sparc64_machines); | |
93 | } else { | |
94 | g_assert_not_reached(); | |
95 | } | |
96 | ||
97 | return g_test_run(); | |
98 | } |