1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include "qemu/osdep.h"
23#include "libqos/libqtest.h"
24#include "libqos/libqos-spapr.h"
25
26#define MAGIC 0xcafec0de
27#define ADDRESS 0x4000
28
29static void check_guest_memory(QTestState *qts)
30{
31 uint32_t signature;
32 int i;
33
34
35 for (i = 0; i < 60000; ++i) {
36 signature = qtest_readl(qts, ADDRESS);
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{
48 const char *extra_args = "";
49 QTestState *qts;
50
51
52
53
54
55
56 if (strcmp(machine, "pseries") == 0) {
57 extra_args = "-nodefaults"
58 " -machine " PSERIES_DEFAULT_CAPABILITIES;
59 }
60
61 qts = qtest_initf("-M %s -accel tcg %s -prom-env 'use-nvramrc?=true' "
62 "-prom-env 'nvramrc=%x %x l!' ", (const char *)machine,
63 extra_args, MAGIC, ADDRESS);
64 check_guest_memory(qts);
65 qtest_quit(qts);
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++) {
74 name = g_strdup_printf("prom-env/%s", machines[i]);
75 qtest_add_data_func(name, machines[i], test_machine);
76 g_free(name);
77 }
78}
79
80int main(int argc, char *argv[])
81{
82 const char *sparc_machines[] = { "SPARCbook", "Voyager", "SS-20", NULL };
83 const char *sparc64_machines[] = { "sun4u", NULL };
84 const char *ppc_machines[] = { "mac99", "g3beige", NULL };
85 const char *arch = qtest_get_arch();
86
87 g_test_init(&argc, &argv, NULL);
88
89 if (!strcmp(arch, "ppc")) {
90 add_tests(ppc_machines);
91 } else if (!strcmp(arch, "ppc64")) {
92 add_tests(ppc_machines);
93 if (g_test_slow()) {
94 qtest_add_data_func("prom-env/pseries", "pseries", test_machine);
95 }
96 } else if (!strcmp(arch, "sparc")) {
97 add_tests(sparc_machines);
98 } else if (!strcmp(arch, "sparc64")) {
99 add_tests(sparc64_machines);
100 } else {
101 g_assert_not_reached();
102 }
103
104 return g_test_run();
105}
106