2 * Boot order test cases.
4 * Copyright (c) 2013 Red Hat Inc.
7 * Michael S. Tsirkin <mst@redhat.com>,
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
14 * How to add or update the tests:
16 * 1. add empty files for new tables, if any, under tests/data/acpi
17 * 2. list any changed files in tests/bios-tables-test-allowed-diff.h
18 * 3. commit the above *before* making changes that affect the tables
20 * After 1-3 above tests will pass but ignore differences with the expected files.
21 * You will also notice that tests/bios-tables-test-allowed-diff.h lists
22 * a bunch of files. This is your hint that you need to do the below:
25 * this will produce a bunch of warnings about differences
26 * beween actual and expected ACPI tables. If you have IASL installed,
27 * they will also be disassembled so you can look at the disassembled
28 * output. If not - disassemble them yourself in any way you like.
29 * Look at the differences - make sure they make sense and match what the
30 * changes you are merging are supposed to do.
32 * 5. From build directory, run:
33 * $(SRC_PATH)/tests/data/acpi/rebuild-expected-aml.sh
34 * 6. Now commit any changes.
35 * 7. Before doing a pull request, make sure tests/bios-tables-test-allowed-diff.h
36 * is empty - this will ensure following changes to ACPI tables will
40 #include "qemu/osdep.h"
41 #include <glib/gstdio.h>
42 #include "qemu-common.h"
43 #include "hw/firmware/smbios.h"
44 #include "qemu/bitmap.h"
45 #include "acpi-utils.h"
46 #include "boot-sector.h"
48 #define MACHINE_PC "pc"
49 #define MACHINE_Q35 "q35"
51 #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
60 const uint64_t ram_start
;
61 const uint64_t scan_len
;
63 uint8_t rsdp_table
[36 /* ACPI 2.0+ RSDP size */];
65 uint32_t smbios_ep_addr
;
66 struct smbios_21_entry_point smbios_ep_table
;
67 uint8_t *required_struct_types
;
68 int required_struct_types_len
;
72 static char disk
[] = "tests/acpi-test-disk-XXXXXX";
73 static const char *data_dir
= "tests/data/acpi";
75 static const char *iasl
= stringify(CONFIG_IASL
);
77 static const char *iasl
;
80 static bool compare_signature(const AcpiSdtTable
*sdt
, const char *signature
)
82 return !memcmp(sdt
->aml
, signature
, 4);
85 static void cleanup_table_descriptor(AcpiSdtTable
*table
)
88 if (table
->aml_file
&&
89 !table
->tmp_files_retain
&&
90 g_strstr_len(table
->aml_file
, -1, "aml-")) {
91 unlink(table
->aml_file
);
93 g_free(table
->aml_file
);
95 if (table
->asl_file
&&
96 !table
->tmp_files_retain
) {
97 unlink(table
->asl_file
);
99 g_free(table
->asl_file
);
102 static void free_test_data(test_data
*data
)
106 for (i
= 0; i
< data
->tables
->len
; ++i
) {
107 cleanup_table_descriptor(&g_array_index(data
->tables
, AcpiSdtTable
, i
));
110 g_array_free(data
->tables
, true);
113 static void test_acpi_rsdp_table(test_data
*data
)
115 uint8_t *rsdp_table
= data
->rsdp_table
;
117 acpi_fetch_rsdp_table(data
->qts
, data
->rsdp_addr
, rsdp_table
);
119 switch (rsdp_table
[15 /* Revision offset */]) {
120 case 0: /* ACPI 1.0 RSDP */
121 /* With rev 1, checksum is only for the first 20 bytes */
122 g_assert(!acpi_calc_checksum(rsdp_table
, 20));
124 case 2: /* ACPI 2.0+ RSDP */
125 /* With revision 2, we have 2 checksums */
126 g_assert(!acpi_calc_checksum(rsdp_table
, 20));
127 g_assert(!acpi_calc_checksum(rsdp_table
, 36));
130 g_assert_not_reached();
134 static void test_acpi_rxsdt_table(test_data
*data
)
136 const char *sig
= "RSDT";
137 AcpiSdtTable rsdt
= {};
139 int addr_off
= 16 /* RsdtAddress */;
142 if (data
->rsdp_table
[15 /* Revision offset */] != 0) {
143 addr_off
= 24 /* XsdtAddress */;
147 /* read [RX]SDT table */
148 acpi_fetch_table(data
->qts
, &rsdt
.aml
, &rsdt
.aml_len
,
149 &data
->rsdp_table
[addr_off
], entry_size
, sig
, true);
151 /* Load all tables and add to test list directly RSDT referenced tables */
152 ACPI_FOREACH_RSDT_ENTRY(rsdt
.aml
, rsdt
.aml_len
, ent
, entry_size
) {
153 AcpiSdtTable ssdt_table
= {};
155 acpi_fetch_table(data
->qts
, &ssdt_table
.aml
, &ssdt_table
.aml_len
, ent
,
156 entry_size
, NULL
, true);
157 /* Add table to ASL test tables list */
158 g_array_append_val(data
->tables
, ssdt_table
);
160 cleanup_table_descriptor(&rsdt
);
163 static void test_acpi_fadt_table(test_data
*data
)
165 /* FADT table is 1st */
166 AcpiSdtTable table
= g_array_index(data
->tables
, typeof(table
), 0);
167 uint8_t *fadt_aml
= table
.aml
;
168 uint32_t fadt_len
= table
.aml_len
;
170 int dsdt_offset
= 40 /* DSDT */;
171 int dsdt_entry_size
= 4;
173 g_assert(compare_signature(&table
, "FACP"));
175 /* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */
176 memcpy(&val
, fadt_aml
+ 112 /* Flags */, 4);
177 val
= le32_to_cpu(val
);
178 if (!(val
& 1UL << 20 /* HW_REDUCED_ACPI */)) {
179 acpi_fetch_table(data
->qts
, &table
.aml
, &table
.aml_len
,
180 fadt_aml
+ 36 /* FIRMWARE_CTRL */, 4, "FACS", false);
181 g_array_append_val(data
->tables
, table
);
184 memcpy(&val
, fadt_aml
+ dsdt_offset
, 4);
185 val
= le32_to_cpu(val
);
187 dsdt_offset
= 140 /* X_DSDT */;
190 acpi_fetch_table(data
->qts
, &table
.aml
, &table
.aml_len
,
191 fadt_aml
+ dsdt_offset
, dsdt_entry_size
, "DSDT", true);
192 g_array_append_val(data
->tables
, table
);
194 memset(fadt_aml
+ 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */
195 memset(fadt_aml
+ 40, 0, 4); /* sanitize DSDT ptr */
196 if (fadt_aml
[8 /* FADT Major Version */] >= 3) {
197 memset(fadt_aml
+ 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr */
198 memset(fadt_aml
+ 140, 0, 8); /* sanitize X_DSDT ptr */
201 /* update checksum */
202 fadt_aml
[9 /* Checksum */] = 0;
203 fadt_aml
[9 /* Checksum */] -= acpi_calc_checksum(fadt_aml
, fadt_len
);
206 static void dump_aml_files(test_data
*data
, bool rebuild
)
209 GError
*error
= NULL
;
210 gchar
*aml_file
= NULL
;
215 for (i
= 0; i
< data
->tables
->len
; ++i
) {
216 const char *ext
= data
->variant
? data
->variant
: "";
217 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
221 aml_file
= g_strdup_printf("%s/%s/%.4s%s", data_dir
, data
->machine
,
223 fd
= g_open(aml_file
, O_WRONLY
|O_TRUNC
|O_CREAT
,
224 S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IWGRP
|S_IROTH
);
230 fd
= g_file_open_tmp("aml-XXXXXX", &sdt
->aml_file
, &error
);
231 g_assert_no_error(error
);
234 ret
= qemu_write_full(fd
, sdt
->aml
, sdt
->aml_len
);
235 g_assert(ret
== sdt
->aml_len
);
243 static bool load_asl(GArray
*sdts
, AcpiSdtTable
*sdt
)
246 GError
*error
= NULL
;
247 GString
*command_line
= g_string_new(iasl
);
249 gchar
*out
, *out_err
;
253 fd
= g_file_open_tmp("asl-XXXXXX.dsl", &sdt
->asl_file
, &error
);
254 g_assert_no_error(error
);
257 /* build command line */
258 g_string_append_printf(command_line
, " -p %s ", sdt
->asl_file
);
259 if (compare_signature(sdt
, "DSDT") ||
260 compare_signature(sdt
, "SSDT")) {
261 for (i
= 0; i
< sdts
->len
; ++i
) {
262 temp
= &g_array_index(sdts
, AcpiSdtTable
, i
);
263 if (compare_signature(temp
, "DSDT") ||
264 compare_signature(temp
, "SSDT")) {
265 g_string_append_printf(command_line
, "-e %s ", temp
->aml_file
);
269 g_string_append_printf(command_line
, "-d %s", sdt
->aml_file
);
271 /* pass 'out' and 'out_err' in order to be redirected */
272 ret
= g_spawn_command_line_sync(command_line
->str
, &out
, &out_err
, NULL
, &error
);
273 g_assert_no_error(error
);
275 ret
= g_file_get_contents(sdt
->asl_file
, &sdt
->asl
,
276 &sdt
->asl_len
, &error
);
278 g_assert_no_error(error
);
279 ret
= (sdt
->asl_len
> 0);
284 g_string_free(command_line
, true);
289 #define COMMENT_END "*/"
290 #define DEF_BLOCK "DefinitionBlock ("
291 #define BLOCK_NAME_END ","
293 static GString
*normalize_asl(gchar
*asl_code
)
295 GString
*asl
= g_string_new(asl_code
);
296 gchar
*comment
, *block_name
;
298 /* strip comments (different generation days) */
299 comment
= g_strstr_len(asl
->str
, asl
->len
, COMMENT_END
);
301 comment
+= strlen(COMMENT_END
);
302 while (*comment
== '\n') {
305 asl
= g_string_erase(asl
, 0, comment
- asl
->str
);
308 /* strip def block name (it has file path in it) */
309 if (g_str_has_prefix(asl
->str
, DEF_BLOCK
)) {
310 block_name
= g_strstr_len(asl
->str
, asl
->len
, BLOCK_NAME_END
);
311 g_assert(block_name
);
312 asl
= g_string_erase(asl
, 0,
313 block_name
+ sizeof(BLOCK_NAME_END
) - asl
->str
);
319 static GArray
*load_expected_aml(test_data
*data
)
323 GError
*error
= NULL
;
327 GArray
*exp_tables
= g_array_new(false, true, sizeof(AcpiSdtTable
));
331 for (i
= 0; i
< data
->tables
->len
; ++i
) {
332 AcpiSdtTable exp_sdt
;
333 gchar
*aml_file
= NULL
;
334 const char *ext
= data
->variant
? data
->variant
: "";
336 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
338 memset(&exp_sdt
, 0, sizeof(exp_sdt
));
341 aml_file
= g_strdup_printf("%s/%s/%.4s%s", data_dir
, data
->machine
,
344 fprintf(stderr
, "Looking for expected file '%s'\n", aml_file
);
346 if (g_file_test(aml_file
, G_FILE_TEST_EXISTS
)) {
347 exp_sdt
.aml_file
= aml_file
;
348 } else if (*ext
!= '\0') {
349 /* try fallback to generic (extension less) expected file */
354 g_assert(exp_sdt
.aml_file
);
356 fprintf(stderr
, "Using expected file '%s'\n", aml_file
);
358 ret
= g_file_get_contents(aml_file
, (gchar
**)&exp_sdt
.aml
,
360 exp_sdt
.aml_len
= aml_len
;
362 g_assert_no_error(error
);
363 g_assert(exp_sdt
.aml
);
364 if (!exp_sdt
.aml_len
) {
365 fprintf(stderr
, "Warning! zero length expected file '%s'\n",
369 g_array_append_val(exp_tables
, exp_sdt
);
375 static bool test_acpi_find_diff_allowed(AcpiSdtTable
*sdt
)
377 const gchar
*allowed_diff_file
[] = {
378 #include "bios-tables-test-allowed-diff.h"
383 for (f
= allowed_diff_file
; *f
; ++f
) {
384 if (!g_strcmp0(sdt
->aml_file
, *f
)) {
391 /* test the list of tables in @data->tables against reference tables */
392 static void test_acpi_asl(test_data
*data
)
395 AcpiSdtTable
*sdt
, *exp_sdt
;
397 gboolean exp_err
, err
, all_tables_match
= true;
399 memset(&exp_data
, 0, sizeof(exp_data
));
400 exp_data
.tables
= load_expected_aml(data
);
401 dump_aml_files(data
, false);
402 for (i
= 0; i
< data
->tables
->len
; ++i
) {
403 GString
*asl
, *exp_asl
;
405 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
406 exp_sdt
= &g_array_index(exp_data
.tables
, AcpiSdtTable
, i
);
408 if (sdt
->aml_len
== exp_sdt
->aml_len
&&
409 !memcmp(sdt
->aml
, exp_sdt
->aml
, sdt
->aml_len
)) {
410 /* Identical table binaries: no need to disassemble. */
415 "acpi-test: Warning! %.4s binary file mismatch. "
416 "Actual [aml:%s], Expected [aml:%s].\n",
417 exp_sdt
->aml
, sdt
->aml_file
, exp_sdt
->aml_file
);
419 all_tables_match
= all_tables_match
&&
420 test_acpi_find_diff_allowed(exp_sdt
);
423 * don't try to decompile if IASL isn't present, in this case user
424 * will just 'get binary file mismatch' warnings and test failure
430 err
= load_asl(data
->tables
, sdt
);
431 asl
= normalize_asl(sdt
->asl
);
433 exp_err
= load_asl(exp_data
.tables
, exp_sdt
);
434 exp_asl
= normalize_asl(exp_sdt
->asl
);
436 /* TODO: check for warnings */
437 g_assert(!err
|| exp_err
);
439 if (g_strcmp0(asl
->str
, exp_asl
->str
)) {
440 sdt
->tmp_files_retain
= true;
443 "Warning! iasl couldn't parse the expected aml\n");
445 exp_sdt
->tmp_files_retain
= true;
447 "acpi-test: Warning! %.4s mismatch. "
448 "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
449 exp_sdt
->aml
, sdt
->asl_file
, sdt
->aml_file
,
450 exp_sdt
->asl_file
, exp_sdt
->aml_file
);
452 const char *diff_cmd
= getenv("DIFF");
454 int ret G_GNUC_UNUSED
;
455 char *diff
= g_strdup_printf("%s %s %s", diff_cmd
,
456 exp_sdt
->asl_file
, sdt
->asl_file
);
460 fprintf(stderr
, "acpi-test: Warning. not showing "
461 "difference since no diff utility is specified. "
462 "Set 'DIFF' environment variable to a preferred "
463 "diff utility and run 'make V=1 check' again to "
464 "see ASL difference.");
469 g_string_free(asl
, true);
470 g_string_free(exp_asl
, true);
472 if (!iasl
&& !all_tables_match
) {
473 fprintf(stderr
, "to see ASL diff between mismatched files install IASL,"
474 " rebuild QEMU from scratch and re-run tests with V=1"
475 " environment variable set");
477 g_assert(all_tables_match
);
479 free_test_data(&exp_data
);
482 static bool smbios_ep_table_ok(test_data
*data
)
484 struct smbios_21_entry_point
*ep_table
= &data
->smbios_ep_table
;
485 uint32_t addr
= data
->smbios_ep_addr
;
487 qtest_memread(data
->qts
, addr
, ep_table
, sizeof(*ep_table
));
488 if (memcmp(ep_table
->anchor_string
, "_SM_", 4)) {
491 if (memcmp(ep_table
->intermediate_anchor_string
, "_DMI_", 5)) {
494 if (ep_table
->structure_table_length
== 0) {
497 if (ep_table
->number_of_structures
== 0) {
500 if (acpi_calc_checksum((uint8_t *)ep_table
, sizeof *ep_table
) ||
501 acpi_calc_checksum((uint8_t *)ep_table
+ 0x10,
502 sizeof *ep_table
- 0x10)) {
508 static void test_smbios_entry_point(test_data
*data
)
512 /* find smbios entry point structure */
513 for (off
= 0xf0000; off
< 0x100000; off
+= 0x10) {
514 uint8_t sig
[] = "_SM_";
517 for (i
= 0; i
< sizeof sig
- 1; ++i
) {
518 sig
[i
] = qtest_readb(data
->qts
, off
+ i
);
521 if (!memcmp(sig
, "_SM_", sizeof sig
)) {
522 /* signature match, but is this a valid entry point? */
523 data
->smbios_ep_addr
= off
;
524 if (smbios_ep_table_ok(data
)) {
530 g_assert_cmphex(off
, <, 0x100000);
533 static inline bool smbios_single_instance(uint8_t type
)
549 static void test_smbios_structs(test_data
*data
)
551 DECLARE_BITMAP(struct_bitmap
, SMBIOS_MAX_TYPE
+1) = { 0 };
552 struct smbios_21_entry_point
*ep_table
= &data
->smbios_ep_table
;
553 uint32_t addr
= le32_to_cpu(ep_table
->structure_table_address
);
554 int i
, len
, max_len
= 0;
555 uint8_t type
, prv
, crt
;
557 /* walk the smbios tables */
558 for (i
= 0; i
< le16_to_cpu(ep_table
->number_of_structures
); i
++) {
560 /* grab type and formatted area length from struct header */
561 type
= qtest_readb(data
->qts
, addr
);
562 g_assert_cmpuint(type
, <=, SMBIOS_MAX_TYPE
);
563 len
= qtest_readb(data
->qts
, addr
+ 1);
565 /* single-instance structs must not have been encountered before */
566 if (smbios_single_instance(type
)) {
567 g_assert(!test_bit(type
, struct_bitmap
));
569 set_bit(type
, struct_bitmap
);
571 /* seek to end of unformatted string area of this struct ("\0\0") */
575 crt
= qtest_readb(data
->qts
, addr
+ len
);
579 /* keep track of max. struct size */
582 g_assert_cmpuint(max_len
, <=, ep_table
->max_structure_size
);
585 /* start of next structure */
589 /* total table length and max struct size must match entry point values */
590 g_assert_cmpuint(le16_to_cpu(ep_table
->structure_table_length
), ==,
591 addr
- le32_to_cpu(ep_table
->structure_table_address
));
592 g_assert_cmpuint(le16_to_cpu(ep_table
->max_structure_size
), ==, max_len
);
594 /* required struct types must all be present */
595 for (i
= 0; i
< data
->required_struct_types_len
; i
++) {
596 g_assert(test_bit(data
->required_struct_types
[i
], struct_bitmap
));
600 static void test_acpi_one(const char *params
, test_data
*data
)
603 bool use_uefi
= data
->uefi_fl1
&& data
->uefi_fl2
;
607 * TODO: convert '-drive if=pflash' to new syntax (see e33763be7cd3)
608 * when arm/virt boad starts to support it.
610 args
= g_strdup_printf("-machine %s,accel=%s -nodefaults -nographic "
611 "-drive if=pflash,format=raw,file=%s,readonly "
612 "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s",
613 data
->machine
, data
->accel
? data
->accel
: "kvm:tcg",
614 data
->uefi_fl1
, data
->uefi_fl2
, data
->cd
, params
? params
: "");
617 /* Disable kernel irqchip to be able to override apic irq0. */
618 args
= g_strdup_printf("-machine %s,accel=%s,kernel-irqchip=off "
619 "-net none -display none %s "
620 "-drive id=hd0,if=none,file=%s,format=raw "
621 "-device ide-hd,drive=hd0 ",
622 data
->machine
, data
->accel
? data
->accel
: "kvm:tcg",
623 params
? params
: "", disk
);
626 data
->qts
= qtest_init(args
);
629 g_assert(data
->scan_len
);
630 data
->rsdp_addr
= acpi_find_rsdp_address_uefi(data
->qts
,
631 data
->ram_start
, data
->scan_len
);
633 boot_sector_test(data
->qts
);
634 data
->rsdp_addr
= acpi_find_rsdp_address(data
->qts
);
635 g_assert_cmphex(data
->rsdp_addr
, <, 0x100000);
638 data
->tables
= g_array_new(false, true, sizeof(AcpiSdtTable
));
639 test_acpi_rsdp_table(data
);
640 test_acpi_rxsdt_table(data
);
641 test_acpi_fadt_table(data
);
643 if (getenv(ACPI_REBUILD_EXPECTED_AML
)) {
644 dump_aml_files(data
, true);
650 * TODO: make SMBIOS tests work with UEFI firmware,
651 * Bug on uefi-test-tools to provide entry point:
652 * https://bugs.launchpad.net/qemu/+bug/1821884
655 test_smbios_entry_point(data
);
656 test_smbios_structs(data
);
659 qtest_quit(data
->qts
);
663 static uint8_t base_required_struct_types
[] = {
664 0, 1, 3, 4, 16, 17, 19, 32, 127
667 static void test_acpi_piix4_tcg(void)
671 /* Supplying -machine accel argument overrides the default (qtest).
672 * This is to make guest actually run.
674 memset(&data
, 0, sizeof(data
));
675 data
.machine
= MACHINE_PC
;
676 data
.required_struct_types
= base_required_struct_types
;
677 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
678 test_acpi_one(NULL
, &data
);
679 free_test_data(&data
);
682 static void test_acpi_piix4_tcg_bridge(void)
686 memset(&data
, 0, sizeof(data
));
687 data
.machine
= MACHINE_PC
;
688 data
.variant
= ".bridge";
689 data
.required_struct_types
= base_required_struct_types
;
690 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
691 test_acpi_one("-device pci-bridge,chassis_nr=1", &data
);
692 free_test_data(&data
);
695 static void test_acpi_q35_tcg(void)
699 memset(&data
, 0, sizeof(data
));
700 data
.machine
= MACHINE_Q35
;
701 data
.required_struct_types
= base_required_struct_types
;
702 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
703 test_acpi_one(NULL
, &data
);
704 free_test_data(&data
);
707 static void test_acpi_q35_tcg_bridge(void)
711 memset(&data
, 0, sizeof(data
));
712 data
.machine
= MACHINE_Q35
;
713 data
.variant
= ".bridge";
714 data
.required_struct_types
= base_required_struct_types
;
715 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
716 test_acpi_one("-device pci-bridge,chassis_nr=1",
718 free_test_data(&data
);
721 static void test_acpi_q35_tcg_mmio64(void)
724 .machine
= MACHINE_Q35
,
725 .variant
= ".mmio64",
726 .required_struct_types
= base_required_struct_types
,
727 .required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
)
730 test_acpi_one("-m 128M,slots=1,maxmem=2G "
731 "-object memory-backend-ram,id=ram0,size=128M "
732 "-numa node,memdev=ram0 "
733 "-device pci-testdev,membar=2G",
735 free_test_data(&data
);
738 static void test_acpi_piix4_tcg_cphp(void)
742 memset(&data
, 0, sizeof(data
));
743 data
.machine
= MACHINE_PC
;
744 data
.variant
= ".cphp";
745 test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6"
746 " -object memory-backend-ram,id=ram0,size=64M"
747 " -object memory-backend-ram,id=ram1,size=64M"
748 " -numa node,memdev=ram0 -numa node,memdev=ram1"
749 " -numa dist,src=0,dst=1,val=21",
751 free_test_data(&data
);
754 static void test_acpi_q35_tcg_cphp(void)
758 memset(&data
, 0, sizeof(data
));
759 data
.machine
= MACHINE_Q35
;
760 data
.variant
= ".cphp";
761 test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
762 " -object memory-backend-ram,id=ram0,size=64M"
763 " -object memory-backend-ram,id=ram1,size=64M"
764 " -numa node,memdev=ram0 -numa node,memdev=ram1"
765 " -numa dist,src=0,dst=1,val=21",
767 free_test_data(&data
);
770 static uint8_t ipmi_required_struct_types
[] = {
771 0, 1, 3, 4, 16, 17, 19, 32, 38, 127
774 static void test_acpi_q35_tcg_ipmi(void)
778 memset(&data
, 0, sizeof(data
));
779 data
.machine
= MACHINE_Q35
;
780 data
.variant
= ".ipmibt";
781 data
.required_struct_types
= ipmi_required_struct_types
;
782 data
.required_struct_types_len
= ARRAY_SIZE(ipmi_required_struct_types
);
783 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
784 " -device isa-ipmi-bt,bmc=bmc0",
786 free_test_data(&data
);
789 static void test_acpi_piix4_tcg_ipmi(void)
793 /* Supplying -machine accel argument overrides the default (qtest).
794 * This is to make guest actually run.
796 memset(&data
, 0, sizeof(data
));
797 data
.machine
= MACHINE_PC
;
798 data
.variant
= ".ipmikcs";
799 data
.required_struct_types
= ipmi_required_struct_types
;
800 data
.required_struct_types_len
= ARRAY_SIZE(ipmi_required_struct_types
);
801 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
802 " -device isa-ipmi-kcs,irq=0,bmc=bmc0",
804 free_test_data(&data
);
807 static void test_acpi_q35_tcg_memhp(void)
811 memset(&data
, 0, sizeof(data
));
812 data
.machine
= MACHINE_Q35
;
813 data
.variant
= ".memhp";
814 test_acpi_one(" -m 128,slots=3,maxmem=1G"
815 " -object memory-backend-ram,id=ram0,size=64M"
816 " -object memory-backend-ram,id=ram1,size=64M"
817 " -numa node,memdev=ram0 -numa node,memdev=ram1"
818 " -numa dist,src=0,dst=1,val=21",
820 free_test_data(&data
);
823 static void test_acpi_piix4_tcg_memhp(void)
827 memset(&data
, 0, sizeof(data
));
828 data
.machine
= MACHINE_PC
;
829 data
.variant
= ".memhp";
830 test_acpi_one(" -m 128,slots=3,maxmem=1G"
831 " -object memory-backend-ram,id=ram0,size=64M"
832 " -object memory-backend-ram,id=ram1,size=64M"
833 " -numa node,memdev=ram0 -numa node,memdev=ram1"
834 " -numa dist,src=0,dst=1,val=21",
836 free_test_data(&data
);
839 static void test_acpi_q35_tcg_numamem(void)
843 memset(&data
, 0, sizeof(data
));
844 data
.machine
= MACHINE_Q35
;
845 data
.variant
= ".numamem";
846 test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
847 " -numa node -numa node,memdev=ram0", &data
);
848 free_test_data(&data
);
851 static void test_acpi_piix4_tcg_numamem(void)
855 memset(&data
, 0, sizeof(data
));
856 data
.machine
= MACHINE_PC
;
857 data
.variant
= ".numamem";
858 test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
859 " -numa node -numa node,memdev=ram0", &data
);
860 free_test_data(&data
);
863 static void test_acpi_tcg_dimm_pxm(const char *machine
)
867 memset(&data
, 0, sizeof(data
));
868 data
.machine
= machine
;
869 data
.variant
= ".dimmpxm";
870 test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu"
872 " -m 128M,slots=3,maxmem=1G"
873 " -object memory-backend-ram,id=ram0,size=32M"
874 " -object memory-backend-ram,id=ram1,size=32M"
875 " -object memory-backend-ram,id=ram2,size=32M"
876 " -object memory-backend-ram,id=ram3,size=32M"
877 " -numa node,memdev=ram0,nodeid=0"
878 " -numa node,memdev=ram1,nodeid=1"
879 " -numa node,memdev=ram2,nodeid=2"
880 " -numa node,memdev=ram3,nodeid=3"
881 " -numa cpu,node-id=0,socket-id=0"
882 " -numa cpu,node-id=1,socket-id=1"
883 " -numa cpu,node-id=2,socket-id=2"
884 " -numa cpu,node-id=3,socket-id=3"
885 " -object memory-backend-ram,id=ram4,size=128M"
886 " -object memory-backend-ram,id=nvm0,size=128M"
887 " -device pc-dimm,id=dimm0,memdev=ram4,node=1"
888 " -device nvdimm,id=dimm1,memdev=nvm0,node=2",
890 free_test_data(&data
);
893 static void test_acpi_q35_tcg_dimm_pxm(void)
895 test_acpi_tcg_dimm_pxm(MACHINE_Q35
);
898 static void test_acpi_piix4_tcg_dimm_pxm(void)
900 test_acpi_tcg_dimm_pxm(MACHINE_PC
);
903 static void test_acpi_virt_tcg_memhp(void)
908 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
909 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
910 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
911 .ram_start
= 0x40000000ULL
,
912 .scan_len
= 256ULL * 1024 * 1024,
915 data
.variant
= ".memhp";
916 test_acpi_one(" -cpu cortex-a57"
917 " -m 256M,slots=3,maxmem=1G"
918 " -object memory-backend-ram,id=ram0,size=128M"
919 " -object memory-backend-ram,id=ram1,size=128M"
920 " -numa node,memdev=ram0 -numa node,memdev=ram1"
921 " -numa dist,src=0,dst=1,val=21",
924 free_test_data(&data
);
928 static void test_acpi_virt_tcg_numamem(void)
933 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
934 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
935 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
936 .ram_start
= 0x40000000ULL
,
937 .scan_len
= 128ULL * 1024 * 1024,
940 data
.variant
= ".numamem";
941 test_acpi_one(" -cpu cortex-a57"
942 " -object memory-backend-ram,id=ram0,size=128M"
943 " -numa node,memdev=ram0",
946 free_test_data(&data
);
950 static void test_acpi_virt_tcg(void)
955 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
956 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
957 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
958 .ram_start
= 0x40000000ULL
,
959 .scan_len
= 128ULL * 1024 * 1024,
962 test_acpi_one("-cpu cortex-a57", &data
);
963 free_test_data(&data
);
966 int main(int argc
, char *argv
[])
968 const char *arch
= qtest_get_arch();
971 g_test_init(&argc
, &argv
, NULL
);
973 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
974 ret
= boot_sector_init(disk
);
979 qtest_add_func("acpi/piix4", test_acpi_piix4_tcg
);
980 qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge
);
981 qtest_add_func("acpi/q35", test_acpi_q35_tcg
);
982 qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge
);
983 qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64
);
984 qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi
);
985 qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi
);
986 qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp
);
987 qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp
);
988 qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp
);
989 qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp
);
990 qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem
);
991 qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem
);
992 qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm
);
993 qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm
);
994 } else if (strcmp(arch
, "aarch64") == 0) {
995 qtest_add_func("acpi/virt", test_acpi_virt_tcg
);
996 qtest_add_func("acpi/virt/numamem", test_acpi_virt_tcg_numamem
);
997 qtest_add_func("acpi/virt/memhp", test_acpi_virt_tcg_memhp
);
1000 boot_sector_cleanup(disk
);