Merge tag 'v3.1.0-rc0'
[qemu/ar7.git] / tests / prom-env-test.c
blobe38ec9d51e9a9750d38322b4bab2d8cf03900065
1 /*
2 * Test Open-Firmware-based machines.
4 * Copyright (c) 2016, 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 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.
18 * The testing code here then can finally check whether the value has been
19 * successfully written into the guest memory.
22 #include "qemu/osdep.h"
23 #include "libqtest.h"
25 #define MAGIC 0xcafec0de
26 #define ADDRESS 0x4000
28 static void check_guest_memory(void)
30 const int max_seconds = 120;
31 uint32_t signature;
32 int i;
34 /* Poll until code has run and modified memory. Wait at most max_seconds. */
35 for (i = 0; i < max_seconds; ++i) {
36 signature = readl(ADDRESS);
37 if (signature == MAGIC) {
38 break;
40 g_usleep(1000000);
43 g_assert(i < max_seconds);
44 g_assert_cmphex(signature, ==, MAGIC);
47 static void test_machine(const void *machine)
49 const char *extra_args;
51 /* The pseries firmware boots much faster without the default devices */
52 extra_args = strcmp(machine, "pseries") == 0 ? "-nodefaults" : "";
54 global_qtest = qtest_initf("-M %s,accel=tcg %s "
55 "-prom-env 'use-nvramrc?=true' "
56 "-prom-env 'nvramrc=%x %x l!' ",
57 (const char *)machine, extra_args,
58 MAGIC, ADDRESS);
59 check_guest_memory();
60 qtest_quit(global_qtest);
63 static void add_tests(const char *machines[])
65 int i;
66 char *name;
68 for (i = 0; machines[i] != NULL; i++) {
69 name = g_strdup_printf("prom-env/%s", machines[i]);
70 qtest_add_data_func(name, machines[i], test_machine);
71 g_free(name);
75 int main(int argc, char *argv[])
77 const char *sparc_machines[] = { "SPARCbook", "Voyager", "SS-20", NULL };
78 const char *sparc64_machines[] = { "sun4u", NULL };
79 const char *ppc_machines[] = { "mac99", "g3beige", NULL };
80 const char *arch = qtest_get_arch();
82 g_test_init(&argc, &argv, NULL);
84 if (!strcmp(arch, "ppc")) {
85 add_tests(ppc_machines);
86 } else if (!strcmp(arch, "ppc64")) {
87 add_tests(ppc_machines);
88 if (g_test_slow()) {
89 qtest_add_data_func("prom-env/pseries", "pseries", test_machine);
91 } else if (!strcmp(arch, "sparc")) {
92 add_tests(sparc_machines);
93 } else if (!strcmp(arch, "sparc64")) {
94 add_tests(sparc64_machines);
95 } else {
96 g_assert_not_reached();
99 return g_test_run();