block: split BlockAcctStats creation and setup
[qemu.git] / tests / prom-env-test.c
blobeac207b30ea5f590ae1d5d36c6c53979194531ba
1 /*
2 * Test OpenBIOS-based machines.
4 * Copyright (c) 2016 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 uint32_t signature;
31 int i;
33 /* Poll until code has run and modified memory. Wait at most 120 seconds */
34 for (i = 0; i < 12000; ++i) {
35 signature = readl(ADDRESS);
36 if (signature == MAGIC) {
37 break;
39 g_usleep(10000);
42 g_assert_cmphex(signature, ==, MAGIC);
45 static void test_machine(const void *machine)
47 char *args;
48 const char *extra_args;
50 /* The pseries firmware boots much faster without the default devices */
51 extra_args = strcmp(machine, "pseries") == 0 ? "-nodefaults" : "";
53 args = g_strdup_printf("-M %s,accel=tcg %s -prom-env 'use-nvramrc?=true' "
54 "-prom-env 'nvramrc=%x %x l!' ",
55 (const char *)machine, extra_args, MAGIC, ADDRESS);
57 qtest_start(args);
58 check_guest_memory();
59 qtest_quit(global_qtest);
61 g_free(args);
64 static void add_tests(const char *machines[])
66 int i;
67 char *name;
69 for (i = 0; machines[i] != NULL; i++) {
70 name = g_strdup_printf("prom-env/%s", machines[i]);
71 qtest_add_data_func(name, machines[i], test_machine);
72 g_free(name);
76 int main(int argc, char *argv[])
78 const char *sparc_machines[] = { "SPARCbook", "Voyager", "SS-20", NULL };
79 const char *sparc64_machines[] = { "sun4u", NULL };
80 const char *ppc_machines[] = { "mac99", "g3beige", NULL };
81 const char *ppc64_machines[] = { "mac99", "g3beige", "pseries", NULL };
82 const char *arch = qtest_get_arch();
84 g_test_init(&argc, &argv, NULL);
86 if (!strcmp(arch, "ppc")) {
87 add_tests(ppc_machines);
88 } else if (!strcmp(arch, "ppc64")) {
89 add_tests(ppc64_machines);
90 } else if (!strcmp(arch, "sparc")) {
91 add_tests(sparc_machines);
92 } else if (!strcmp(arch, "sparc64")) {
93 add_tests(sparc64_machines);
94 } else {
95 g_assert_not_reached();
98 return g_test_run();