]> git.proxmox.com Git - mirror_qemu.git/blame - tests/qtest/prom-env-test.c
Merge tag 'pull-ppc-20211217' of https://github.com/legoater/qemu into staging
[mirror_qemu.git] / tests / qtest / prom-env-test.c
CommitLineData
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 <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"
a2ce7dbd 23#include "libqos/libqtest.h"
63d57c8f 24#include "libqos/libqos-spapr.h"
fcbf4a3c
TH
25
26#define MAGIC 0xcafec0de
27#define ADDRESS 0x4000
28
dc4c1587 29static void check_guest_memory(QTestState *qts)
fcbf4a3c
TH
30{
31 uint32_t signature;
32 int i;
33
b95b5a0a
TH
34 /* Poll until code has run and modified memory. Wait at most 600 seconds */
35 for (i = 0; i < 60000; ++i) {
dc4c1587 36 signature = qtest_readl(qts, ADDRESS);
fcbf4a3c
TH
37 if (signature == MAGIC) {
38 break;
39 }
40 g_usleep(10000);
41 }
42
43 g_assert_cmphex(signature, ==, MAGIC);
44}
45
46static void test_machine(const void *machine)
47{
ba3b40de 48 const char *extra_args = "";
dc4c1587 49 QTestState *qts;
fcbf4a3c 50
ba3b40de
DG
51 /*
52 * The pseries firmware boots much faster without the default
53 * devices, it also needs Spectre/Meltdown workarounds disabled to
54 * avoid warnings with TCG
55 */
56 if (strcmp(machine, "pseries") == 0) {
57 extra_args = "-nodefaults"
63d57c8f 58 " -machine " PSERIES_DEFAULT_CAPABILITIES;
ba3b40de 59 }
61eedf7a 60
6f6e1698 61 qts = qtest_initf("-M %s -accel tcg %s -prom-env 'use-nvramrc?=true' "
dc4c1587
TH
62 "-prom-env 'nvramrc=%x %x l!' ", (const char *)machine,
63 extra_args, MAGIC, ADDRESS);
64 check_guest_memory(qts);
65 qtest_quit(qts);
fcbf4a3c
TH
66}
67
68static void add_tests(const char *machines[])
69{
70 int i;
71 char *name;
72
73 for (i = 0; machines[i] != NULL; i++) {
719051ca
TH
74 if (qtest_has_machine(machines[i])) {
75 name = g_strdup_printf("prom-env/%s", machines[i]);
76 qtest_add_data_func(name, machines[i], test_machine);
77 g_free(name);
78 }
fcbf4a3c
TH
79 }
80}
81
82int main(int argc, char *argv[])
83{
84 const char *sparc_machines[] = { "SPARCbook", "Voyager", "SS-20", NULL };
6b591ad6 85 const char *sparc64_machines[] = { "sun4u", NULL };
53687348 86 const char *ppc_machines[] = { "mac99", "g3beige", NULL };
fcbf4a3c
TH
87 const char *arch = qtest_get_arch();
88
89 g_test_init(&argc, &argv, NULL);
90
53687348
DG
91 if (!strcmp(arch, "ppc")) {
92 add_tests(ppc_machines);
93 } else if (!strcmp(arch, "ppc64")) {
b95b5a0a
TH
94 add_tests(ppc_machines);
95 if (g_test_slow()) {
96 qtest_add_data_func("prom-env/pseries", "pseries", test_machine);
97 }
fcbf4a3c
TH
98 } else if (!strcmp(arch, "sparc")) {
99 add_tests(sparc_machines);
100 } else if (!strcmp(arch, "sparc64")) {
101 add_tests(sparc64_machines);
102 } else {
103 g_assert_not_reached();
104 }
105
106 return g_test_run();
107}