]> git.proxmox.com Git - mirror_qemu.git/blame - tests/prom-env-test.c
qcow2: Inform block layer about discard boundaries
[mirror_qemu.git] / tests / prom-env-test.c
CommitLineData
fcbf4a3c
TH
1/*
2 * Test OpenBIOS-based machines.
3 *
4 * Copyright (c) 2016 Red Hat Inc.
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 *
12 * This test is used to check that some OpenBIOS machines can be started
13 * successfully in TCG mode. To do this, we first put some Forth code into
14 * the "boot-command" Open Firmware environment variable. This Forth code
15 * writes a well-known magic value to a known location in memory. Then we
16 * start the guest so that OpenBIOS can boot and finally run the Forth code.
17 * The testing code here then can finally check whether the value has been
18 * successfully written into the guest memory.
19 */
20
21#include "qemu/osdep.h"
22#include "libqtest.h"
23
24#define MAGIC 0xcafec0de
25#define ADDRESS 0x4000
26
27static void check_guest_memory(void)
28{
29 uint32_t signature;
30 int i;
31
32 /* Poll until code has run and modified memory. Wait at most 30 seconds */
eaf8d91c 33 for (i = 0; i < 10000; ++i) {
fcbf4a3c
TH
34 signature = readl(ADDRESS);
35 if (signature == MAGIC) {
36 break;
37 }
38 g_usleep(10000);
39 }
40
41 g_assert_cmphex(signature, ==, MAGIC);
42}
43
44static void test_machine(const void *machine)
45{
46 char *args;
47
48 args = g_strdup_printf("-M %s,accel=tcg -prom-env 'boot-command=%x %x l!'",
49 (const char *)machine, MAGIC, ADDRESS);
50
51 qtest_start(args);
52 check_guest_memory();
53 qtest_quit(global_qtest);
54
55 g_free(args);
56}
57
58static void add_tests(const char *machines[])
59{
60 int i;
61 char *name;
62
63 for (i = 0; machines[i] != NULL; i++) {
64 name = g_strdup_printf("prom-env/%s", machines[i]);
65 qtest_add_data_func(name, machines[i], test_machine);
66 g_free(name);
67 }
68}
69
70int main(int argc, char *argv[])
71{
72 const char *sparc_machines[] = { "SPARCbook", "Voyager", "SS-20", NULL };
73 const char *sparc64_machines[] = { "sun4u", "sun4v", NULL };
74 const char *mac_machines[] = { "mac99", "g3beige", NULL };
75 const char *arch = qtest_get_arch();
76
77 g_test_init(&argc, &argv, NULL);
78
79 if (!strcmp(arch, "ppc") || !strcmp(arch, "ppc64")) {
80 add_tests(mac_machines);
81 } else if (!strcmp(arch, "sparc")) {
82 add_tests(sparc_machines);
83 } else if (!strcmp(arch, "sparc64")) {
84 add_tests(sparc64_machines);
85 } else {
86 g_assert_not_reached();
87 }
88
89 return g_test_run();
90}