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 * Contributor or ACPI Maintainer (steps 4-7 need to be redone to resolve conflicts
21 * in binary commit created in step 6):
23 * After 1-3 above tests will pass but ignore differences with the expected files.
24 * You will also notice that tests/bios-tables-test-allowed-diff.h lists
25 * a bunch of files. This is your hint that you need to do the below:
28 * this will produce a bunch of warnings about differences
29 * beween actual and expected ACPI tables. If you have IASL installed,
30 * they will also be disassembled so you can look at the disassembled
31 * output. If not - disassemble them yourself in any way you like.
32 * Look at the differences - make sure they make sense and match what the
33 * changes you are merging are supposed to do.
34 * Save the changes, preferably in form of ASL diff for the commit log in
37 * 5. From build directory, run:
38 * $(SRC_PATH)/tests/data/acpi/rebuild-expected-aml.sh
39 * 6. Now commit any changes to the expected binary, include diff from step 4
41 * 7. Before sending patches to the list (Contributor)
42 * or before doing a pull request (Maintainer), make sure
43 * tests/bios-tables-test-allowed-diff.h is empty - this will ensure
44 * following changes to ACPI tables will be noticed.
46 * The resulting patchset/pull request then looks like this:
47 * - patch 1: list changed files in tests/bios-tables-test-allowed-diff.h.
48 * - patches 2 - n: real changes, may contain multiple patches.
49 * - patch n + 1: update golden master binaries and empty
50 * tests/bios-tables-test-allowed-diff.h
53 #include "qemu/osdep.h"
54 #include <glib/gstdio.h>
55 #include "qemu-common.h"
56 #include "hw/firmware/smbios.h"
57 #include "qemu/bitmap.h"
58 #include "acpi-utils.h"
59 #include "boot-sector.h"
61 #define MACHINE_PC "pc"
62 #define MACHINE_Q35 "q35"
64 #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
73 const uint64_t ram_start
;
74 const uint64_t scan_len
;
76 uint8_t rsdp_table
[36 /* ACPI 2.0+ RSDP size */];
78 uint32_t smbios_ep_addr
;
79 struct smbios_21_entry_point smbios_ep_table
;
80 uint8_t *required_struct_types
;
81 int required_struct_types_len
;
85 static char disk
[] = "tests/acpi-test-disk-XXXXXX";
86 static const char *data_dir
= "tests/data/acpi";
88 static const char *iasl
= stringify(CONFIG_IASL
);
90 static const char *iasl
;
93 static bool compare_signature(const AcpiSdtTable
*sdt
, const char *signature
)
95 return !memcmp(sdt
->aml
, signature
, 4);
98 static void cleanup_table_descriptor(AcpiSdtTable
*table
)
101 if (table
->aml_file
&&
102 !table
->tmp_files_retain
&&
103 g_strstr_len(table
->aml_file
, -1, "aml-")) {
104 unlink(table
->aml_file
);
106 g_free(table
->aml_file
);
108 if (table
->asl_file
&&
109 !table
->tmp_files_retain
) {
110 unlink(table
->asl_file
);
112 g_free(table
->asl_file
);
115 static void free_test_data(test_data
*data
)
119 for (i
= 0; i
< data
->tables
->len
; ++i
) {
120 cleanup_table_descriptor(&g_array_index(data
->tables
, AcpiSdtTable
, i
));
123 g_array_free(data
->tables
, true);
126 static void test_acpi_rsdp_table(test_data
*data
)
128 uint8_t *rsdp_table
= data
->rsdp_table
;
130 acpi_fetch_rsdp_table(data
->qts
, data
->rsdp_addr
, rsdp_table
);
132 switch (rsdp_table
[15 /* Revision offset */]) {
133 case 0: /* ACPI 1.0 RSDP */
134 /* With rev 1, checksum is only for the first 20 bytes */
135 g_assert(!acpi_calc_checksum(rsdp_table
, 20));
137 case 2: /* ACPI 2.0+ RSDP */
138 /* With revision 2, we have 2 checksums */
139 g_assert(!acpi_calc_checksum(rsdp_table
, 20));
140 g_assert(!acpi_calc_checksum(rsdp_table
, 36));
143 g_assert_not_reached();
147 static void test_acpi_rxsdt_table(test_data
*data
)
149 const char *sig
= "RSDT";
150 AcpiSdtTable rsdt
= {};
152 int addr_off
= 16 /* RsdtAddress */;
155 if (data
->rsdp_table
[15 /* Revision offset */] != 0) {
156 addr_off
= 24 /* XsdtAddress */;
160 /* read [RX]SDT table */
161 acpi_fetch_table(data
->qts
, &rsdt
.aml
, &rsdt
.aml_len
,
162 &data
->rsdp_table
[addr_off
], entry_size
, sig
, true);
164 /* Load all tables and add to test list directly RSDT referenced tables */
165 ACPI_FOREACH_RSDT_ENTRY(rsdt
.aml
, rsdt
.aml_len
, ent
, entry_size
) {
166 AcpiSdtTable ssdt_table
= {};
168 acpi_fetch_table(data
->qts
, &ssdt_table
.aml
, &ssdt_table
.aml_len
, ent
,
169 entry_size
, NULL
, true);
170 /* Add table to ASL test tables list */
171 g_array_append_val(data
->tables
, ssdt_table
);
173 cleanup_table_descriptor(&rsdt
);
176 static void test_acpi_fadt_table(test_data
*data
)
178 /* FADT table is 1st */
179 AcpiSdtTable table
= g_array_index(data
->tables
, typeof(table
), 0);
180 uint8_t *fadt_aml
= table
.aml
;
181 uint32_t fadt_len
= table
.aml_len
;
183 int dsdt_offset
= 40 /* DSDT */;
184 int dsdt_entry_size
= 4;
186 g_assert(compare_signature(&table
, "FACP"));
188 /* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */
189 memcpy(&val
, fadt_aml
+ 112 /* Flags */, 4);
190 val
= le32_to_cpu(val
);
191 if (!(val
& 1UL << 20 /* HW_REDUCED_ACPI */)) {
192 acpi_fetch_table(data
->qts
, &table
.aml
, &table
.aml_len
,
193 fadt_aml
+ 36 /* FIRMWARE_CTRL */, 4, "FACS", false);
194 g_array_append_val(data
->tables
, table
);
197 memcpy(&val
, fadt_aml
+ dsdt_offset
, 4);
198 val
= le32_to_cpu(val
);
200 dsdt_offset
= 140 /* X_DSDT */;
203 acpi_fetch_table(data
->qts
, &table
.aml
, &table
.aml_len
,
204 fadt_aml
+ dsdt_offset
, dsdt_entry_size
, "DSDT", true);
205 g_array_append_val(data
->tables
, table
);
207 memset(fadt_aml
+ 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */
208 memset(fadt_aml
+ 40, 0, 4); /* sanitize DSDT ptr */
209 if (fadt_aml
[8 /* FADT Major Version */] >= 3) {
210 memset(fadt_aml
+ 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr */
211 memset(fadt_aml
+ 140, 0, 8); /* sanitize X_DSDT ptr */
214 /* update checksum */
215 fadt_aml
[9 /* Checksum */] = 0;
216 fadt_aml
[9 /* Checksum */] -= acpi_calc_checksum(fadt_aml
, fadt_len
);
219 static void dump_aml_files(test_data
*data
, bool rebuild
)
222 GError
*error
= NULL
;
223 gchar
*aml_file
= NULL
;
228 for (i
= 0; i
< data
->tables
->len
; ++i
) {
229 const char *ext
= data
->variant
? data
->variant
: "";
230 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
234 aml_file
= g_strdup_printf("%s/%s/%.4s%s", data_dir
, data
->machine
,
236 fd
= g_open(aml_file
, O_WRONLY
|O_TRUNC
|O_CREAT
,
237 S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IWGRP
|S_IROTH
);
243 fd
= g_file_open_tmp("aml-XXXXXX", &sdt
->aml_file
, &error
);
244 g_assert_no_error(error
);
247 ret
= qemu_write_full(fd
, sdt
->aml
, sdt
->aml_len
);
248 g_assert(ret
== sdt
->aml_len
);
256 static bool load_asl(GArray
*sdts
, AcpiSdtTable
*sdt
)
259 GError
*error
= NULL
;
260 GString
*command_line
= g_string_new(iasl
);
262 gchar
*out
, *out_err
;
266 fd
= g_file_open_tmp("asl-XXXXXX.dsl", &sdt
->asl_file
, &error
);
267 g_assert_no_error(error
);
270 /* build command line */
271 g_string_append_printf(command_line
, " -p %s ", sdt
->asl_file
);
272 if (compare_signature(sdt
, "DSDT") ||
273 compare_signature(sdt
, "SSDT")) {
274 for (i
= 0; i
< sdts
->len
; ++i
) {
275 temp
= &g_array_index(sdts
, AcpiSdtTable
, i
);
276 if (compare_signature(temp
, "DSDT") ||
277 compare_signature(temp
, "SSDT")) {
278 g_string_append_printf(command_line
, "-e %s ", temp
->aml_file
);
282 g_string_append_printf(command_line
, "-d %s", sdt
->aml_file
);
284 /* pass 'out' and 'out_err' in order to be redirected */
285 ret
= g_spawn_command_line_sync(command_line
->str
, &out
, &out_err
, NULL
, &error
);
286 g_assert_no_error(error
);
288 ret
= g_file_get_contents(sdt
->asl_file
, &sdt
->asl
,
289 &sdt
->asl_len
, &error
);
291 g_assert_no_error(error
);
292 ret
= (sdt
->asl_len
> 0);
297 g_string_free(command_line
, true);
302 #define COMMENT_END "*/"
303 #define DEF_BLOCK "DefinitionBlock ("
304 #define BLOCK_NAME_END ","
306 static GString
*normalize_asl(gchar
*asl_code
)
308 GString
*asl
= g_string_new(asl_code
);
309 gchar
*comment
, *block_name
;
311 /* strip comments (different generation days) */
312 comment
= g_strstr_len(asl
->str
, asl
->len
, COMMENT_END
);
314 comment
+= strlen(COMMENT_END
);
315 while (*comment
== '\n') {
318 asl
= g_string_erase(asl
, 0, comment
- asl
->str
);
321 /* strip def block name (it has file path in it) */
322 if (g_str_has_prefix(asl
->str
, DEF_BLOCK
)) {
323 block_name
= g_strstr_len(asl
->str
, asl
->len
, BLOCK_NAME_END
);
324 g_assert(block_name
);
325 asl
= g_string_erase(asl
, 0,
326 block_name
+ sizeof(BLOCK_NAME_END
) - asl
->str
);
332 static GArray
*load_expected_aml(test_data
*data
)
336 GError
*error
= NULL
;
340 GArray
*exp_tables
= g_array_new(false, true, sizeof(AcpiSdtTable
));
344 for (i
= 0; i
< data
->tables
->len
; ++i
) {
345 AcpiSdtTable exp_sdt
;
346 gchar
*aml_file
= NULL
;
347 const char *ext
= data
->variant
? data
->variant
: "";
349 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
351 memset(&exp_sdt
, 0, sizeof(exp_sdt
));
354 aml_file
= g_strdup_printf("%s/%s/%.4s%s", data_dir
, data
->machine
,
357 fprintf(stderr
, "Looking for expected file '%s'\n", aml_file
);
359 if (g_file_test(aml_file
, G_FILE_TEST_EXISTS
)) {
360 exp_sdt
.aml_file
= aml_file
;
361 } else if (*ext
!= '\0') {
362 /* try fallback to generic (extension less) expected file */
367 g_assert(exp_sdt
.aml_file
);
369 fprintf(stderr
, "Using expected file '%s'\n", aml_file
);
371 ret
= g_file_get_contents(aml_file
, (gchar
**)&exp_sdt
.aml
,
373 exp_sdt
.aml_len
= aml_len
;
375 g_assert_no_error(error
);
376 g_assert(exp_sdt
.aml
);
377 if (!exp_sdt
.aml_len
) {
378 fprintf(stderr
, "Warning! zero length expected file '%s'\n",
382 g_array_append_val(exp_tables
, exp_sdt
);
388 static bool test_acpi_find_diff_allowed(AcpiSdtTable
*sdt
)
390 const gchar
*allowed_diff_file
[] = {
391 #include "bios-tables-test-allowed-diff.h"
396 for (f
= allowed_diff_file
; *f
; ++f
) {
397 if (!g_strcmp0(sdt
->aml_file
, *f
)) {
404 /* test the list of tables in @data->tables against reference tables */
405 static void test_acpi_asl(test_data
*data
)
408 AcpiSdtTable
*sdt
, *exp_sdt
;
410 gboolean exp_err
, err
, all_tables_match
= true;
412 memset(&exp_data
, 0, sizeof(exp_data
));
413 exp_data
.tables
= load_expected_aml(data
);
414 dump_aml_files(data
, false);
415 for (i
= 0; i
< data
->tables
->len
; ++i
) {
416 GString
*asl
, *exp_asl
;
418 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
419 exp_sdt
= &g_array_index(exp_data
.tables
, AcpiSdtTable
, i
);
421 if (sdt
->aml_len
== exp_sdt
->aml_len
&&
422 !memcmp(sdt
->aml
, exp_sdt
->aml
, sdt
->aml_len
)) {
423 /* Identical table binaries: no need to disassemble. */
428 "acpi-test: Warning! %.4s binary file mismatch. "
429 "Actual [aml:%s], Expected [aml:%s].\n",
430 exp_sdt
->aml
, sdt
->aml_file
, exp_sdt
->aml_file
);
432 all_tables_match
= all_tables_match
&&
433 test_acpi_find_diff_allowed(exp_sdt
);
436 * don't try to decompile if IASL isn't present, in this case user
437 * will just 'get binary file mismatch' warnings and test failure
443 err
= load_asl(data
->tables
, sdt
);
444 asl
= normalize_asl(sdt
->asl
);
446 exp_err
= load_asl(exp_data
.tables
, exp_sdt
);
447 exp_asl
= normalize_asl(exp_sdt
->asl
);
449 /* TODO: check for warnings */
450 g_assert(!err
|| exp_err
);
452 if (g_strcmp0(asl
->str
, exp_asl
->str
)) {
453 sdt
->tmp_files_retain
= true;
456 "Warning! iasl couldn't parse the expected aml\n");
458 exp_sdt
->tmp_files_retain
= true;
460 "acpi-test: Warning! %.4s mismatch. "
461 "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
462 exp_sdt
->aml
, sdt
->asl_file
, sdt
->aml_file
,
463 exp_sdt
->asl_file
, exp_sdt
->aml_file
);
465 const char *diff_cmd
= getenv("DIFF");
467 int ret G_GNUC_UNUSED
;
468 char *diff
= g_strdup_printf("%s %s %s", diff_cmd
,
469 exp_sdt
->asl_file
, sdt
->asl_file
);
473 fprintf(stderr
, "acpi-test: Warning. not showing "
474 "difference since no diff utility is specified. "
475 "Set 'DIFF' environment variable to a preferred "
476 "diff utility and run 'make V=1 check' again to "
477 "see ASL difference.");
482 g_string_free(asl
, true);
483 g_string_free(exp_asl
, true);
485 if (!iasl
&& !all_tables_match
) {
486 fprintf(stderr
, "to see ASL diff between mismatched files install IASL,"
487 " rebuild QEMU from scratch and re-run tests with V=1"
488 " environment variable set");
490 g_assert(all_tables_match
);
492 free_test_data(&exp_data
);
495 static bool smbios_ep_table_ok(test_data
*data
)
497 struct smbios_21_entry_point
*ep_table
= &data
->smbios_ep_table
;
498 uint32_t addr
= data
->smbios_ep_addr
;
500 qtest_memread(data
->qts
, addr
, ep_table
, sizeof(*ep_table
));
501 if (memcmp(ep_table
->anchor_string
, "_SM_", 4)) {
504 if (memcmp(ep_table
->intermediate_anchor_string
, "_DMI_", 5)) {
507 if (ep_table
->structure_table_length
== 0) {
510 if (ep_table
->number_of_structures
== 0) {
513 if (acpi_calc_checksum((uint8_t *)ep_table
, sizeof *ep_table
) ||
514 acpi_calc_checksum((uint8_t *)ep_table
+ 0x10,
515 sizeof *ep_table
- 0x10)) {
521 static void test_smbios_entry_point(test_data
*data
)
525 /* find smbios entry point structure */
526 for (off
= 0xf0000; off
< 0x100000; off
+= 0x10) {
527 uint8_t sig
[] = "_SM_";
530 for (i
= 0; i
< sizeof sig
- 1; ++i
) {
531 sig
[i
] = qtest_readb(data
->qts
, off
+ i
);
534 if (!memcmp(sig
, "_SM_", sizeof sig
)) {
535 /* signature match, but is this a valid entry point? */
536 data
->smbios_ep_addr
= off
;
537 if (smbios_ep_table_ok(data
)) {
543 g_assert_cmphex(off
, <, 0x100000);
546 static inline bool smbios_single_instance(uint8_t type
)
562 static void test_smbios_structs(test_data
*data
)
564 DECLARE_BITMAP(struct_bitmap
, SMBIOS_MAX_TYPE
+1) = { 0 };
565 struct smbios_21_entry_point
*ep_table
= &data
->smbios_ep_table
;
566 uint32_t addr
= le32_to_cpu(ep_table
->structure_table_address
);
567 int i
, len
, max_len
= 0;
568 uint8_t type
, prv
, crt
;
570 /* walk the smbios tables */
571 for (i
= 0; i
< le16_to_cpu(ep_table
->number_of_structures
); i
++) {
573 /* grab type and formatted area length from struct header */
574 type
= qtest_readb(data
->qts
, addr
);
575 g_assert_cmpuint(type
, <=, SMBIOS_MAX_TYPE
);
576 len
= qtest_readb(data
->qts
, addr
+ 1);
578 /* single-instance structs must not have been encountered before */
579 if (smbios_single_instance(type
)) {
580 g_assert(!test_bit(type
, struct_bitmap
));
582 set_bit(type
, struct_bitmap
);
584 /* seek to end of unformatted string area of this struct ("\0\0") */
588 crt
= qtest_readb(data
->qts
, addr
+ len
);
592 /* keep track of max. struct size */
595 g_assert_cmpuint(max_len
, <=, ep_table
->max_structure_size
);
598 /* start of next structure */
602 /* total table length and max struct size must match entry point values */
603 g_assert_cmpuint(le16_to_cpu(ep_table
->structure_table_length
), ==,
604 addr
- le32_to_cpu(ep_table
->structure_table_address
));
605 g_assert_cmpuint(le16_to_cpu(ep_table
->max_structure_size
), ==, max_len
);
607 /* required struct types must all be present */
608 for (i
= 0; i
< data
->required_struct_types_len
; i
++) {
609 g_assert(test_bit(data
->required_struct_types
[i
], struct_bitmap
));
613 static void test_acpi_one(const char *params
, test_data
*data
)
616 bool use_uefi
= data
->uefi_fl1
&& data
->uefi_fl2
;
620 * TODO: convert '-drive if=pflash' to new syntax (see e33763be7cd3)
621 * when arm/virt boad starts to support it.
623 args
= g_strdup_printf("-machine %s %s -accel tcg -nodefaults -nographic "
624 "-drive if=pflash,format=raw,file=%s,readonly "
625 "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s",
626 data
->machine
, data
->tcg_only
? "" : "-accel kvm",
627 data
->uefi_fl1
, data
->uefi_fl2
, data
->cd
, params
? params
: "");
630 /* Disable kernel irqchip to be able to override apic irq0. */
631 args
= g_strdup_printf("-machine %s,kernel-irqchip=off %s -accel tcg "
632 "-net none -display none %s "
633 "-drive id=hd0,if=none,file=%s,format=raw "
634 "-device ide-hd,drive=hd0 ",
635 data
->machine
, data
->tcg_only
? "" : "-accel kvm",
636 params
? params
: "", disk
);
639 data
->qts
= qtest_init(args
);
642 g_assert(data
->scan_len
);
643 data
->rsdp_addr
= acpi_find_rsdp_address_uefi(data
->qts
,
644 data
->ram_start
, data
->scan_len
);
646 boot_sector_test(data
->qts
);
647 data
->rsdp_addr
= acpi_find_rsdp_address(data
->qts
);
648 g_assert_cmphex(data
->rsdp_addr
, <, 0x100000);
651 data
->tables
= g_array_new(false, true, sizeof(AcpiSdtTable
));
652 test_acpi_rsdp_table(data
);
653 test_acpi_rxsdt_table(data
);
654 test_acpi_fadt_table(data
);
656 if (getenv(ACPI_REBUILD_EXPECTED_AML
)) {
657 dump_aml_files(data
, true);
663 * TODO: make SMBIOS tests work with UEFI firmware,
664 * Bug on uefi-test-tools to provide entry point:
665 * https://bugs.launchpad.net/qemu/+bug/1821884
668 test_smbios_entry_point(data
);
669 test_smbios_structs(data
);
672 qtest_quit(data
->qts
);
676 static uint8_t base_required_struct_types
[] = {
677 0, 1, 3, 4, 16, 17, 19, 32, 127
680 static void test_acpi_piix4_tcg(void)
684 /* Supplying -machine accel argument overrides the default (qtest).
685 * This is to make guest actually run.
687 memset(&data
, 0, sizeof(data
));
688 data
.machine
= MACHINE_PC
;
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(NULL
, &data
);
692 free_test_data(&data
);
695 static void test_acpi_piix4_tcg_bridge(void)
699 memset(&data
, 0, sizeof(data
));
700 data
.machine
= MACHINE_PC
;
701 data
.variant
= ".bridge";
702 data
.required_struct_types
= base_required_struct_types
;
703 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
704 test_acpi_one("-device pci-bridge,chassis_nr=1", &data
);
705 free_test_data(&data
);
708 static void test_acpi_q35_tcg(void)
712 memset(&data
, 0, sizeof(data
));
713 data
.machine
= MACHINE_Q35
;
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(NULL
, &data
);
717 free_test_data(&data
);
720 static void test_acpi_q35_tcg_bridge(void)
724 memset(&data
, 0, sizeof(data
));
725 data
.machine
= MACHINE_Q35
;
726 data
.variant
= ".bridge";
727 data
.required_struct_types
= base_required_struct_types
;
728 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
729 test_acpi_one("-device pci-bridge,chassis_nr=1",
731 free_test_data(&data
);
734 static void test_acpi_q35_tcg_mmio64(void)
737 .machine
= MACHINE_Q35
,
738 .variant
= ".mmio64",
739 .required_struct_types
= base_required_struct_types
,
740 .required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
)
743 test_acpi_one("-m 128M,slots=1,maxmem=2G "
744 "-object memory-backend-ram,id=ram0,size=128M "
745 "-numa node,memdev=ram0 "
746 "-device pci-testdev,membar=2G",
748 free_test_data(&data
);
751 static void test_acpi_piix4_tcg_cphp(void)
755 memset(&data
, 0, sizeof(data
));
756 data
.machine
= MACHINE_PC
;
757 data
.variant
= ".cphp";
758 test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6"
759 " -object memory-backend-ram,id=ram0,size=64M"
760 " -object memory-backend-ram,id=ram1,size=64M"
761 " -numa node,memdev=ram0 -numa node,memdev=ram1"
762 " -numa dist,src=0,dst=1,val=21",
764 free_test_data(&data
);
767 static void test_acpi_q35_tcg_cphp(void)
771 memset(&data
, 0, sizeof(data
));
772 data
.machine
= MACHINE_Q35
;
773 data
.variant
= ".cphp";
774 test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
775 " -object memory-backend-ram,id=ram0,size=64M"
776 " -object memory-backend-ram,id=ram1,size=64M"
777 " -numa node,memdev=ram0 -numa node,memdev=ram1"
778 " -numa dist,src=0,dst=1,val=21",
780 free_test_data(&data
);
783 static uint8_t ipmi_required_struct_types
[] = {
784 0, 1, 3, 4, 16, 17, 19, 32, 38, 127
787 static void test_acpi_q35_tcg_ipmi(void)
791 memset(&data
, 0, sizeof(data
));
792 data
.machine
= MACHINE_Q35
;
793 data
.variant
= ".ipmibt";
794 data
.required_struct_types
= ipmi_required_struct_types
;
795 data
.required_struct_types_len
= ARRAY_SIZE(ipmi_required_struct_types
);
796 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
797 " -device isa-ipmi-bt,bmc=bmc0",
799 free_test_data(&data
);
802 static void test_acpi_piix4_tcg_ipmi(void)
806 /* Supplying -machine accel argument overrides the default (qtest).
807 * This is to make guest actually run.
809 memset(&data
, 0, sizeof(data
));
810 data
.machine
= MACHINE_PC
;
811 data
.variant
= ".ipmikcs";
812 data
.required_struct_types
= ipmi_required_struct_types
;
813 data
.required_struct_types_len
= ARRAY_SIZE(ipmi_required_struct_types
);
814 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
815 " -device isa-ipmi-kcs,irq=0,bmc=bmc0",
817 free_test_data(&data
);
820 static void test_acpi_q35_tcg_memhp(void)
824 memset(&data
, 0, sizeof(data
));
825 data
.machine
= MACHINE_Q35
;
826 data
.variant
= ".memhp";
827 test_acpi_one(" -m 128,slots=3,maxmem=1G"
828 " -object memory-backend-ram,id=ram0,size=64M"
829 " -object memory-backend-ram,id=ram1,size=64M"
830 " -numa node,memdev=ram0 -numa node,memdev=ram1"
831 " -numa dist,src=0,dst=1,val=21",
833 free_test_data(&data
);
836 static void test_acpi_piix4_tcg_memhp(void)
840 memset(&data
, 0, sizeof(data
));
841 data
.machine
= MACHINE_PC
;
842 data
.variant
= ".memhp";
843 test_acpi_one(" -m 128,slots=3,maxmem=1G"
844 " -object memory-backend-ram,id=ram0,size=64M"
845 " -object memory-backend-ram,id=ram1,size=64M"
846 " -numa node,memdev=ram0 -numa node,memdev=ram1"
847 " -numa dist,src=0,dst=1,val=21",
849 free_test_data(&data
);
852 static void test_acpi_q35_tcg_numamem(void)
856 memset(&data
, 0, sizeof(data
));
857 data
.machine
= MACHINE_Q35
;
858 data
.variant
= ".numamem";
859 test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
860 " -numa node -numa node,memdev=ram0", &data
);
861 free_test_data(&data
);
864 static void test_acpi_piix4_tcg_numamem(void)
868 memset(&data
, 0, sizeof(data
));
869 data
.machine
= MACHINE_PC
;
870 data
.variant
= ".numamem";
871 test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
872 " -numa node -numa node,memdev=ram0", &data
);
873 free_test_data(&data
);
876 static void test_acpi_tcg_dimm_pxm(const char *machine
)
880 memset(&data
, 0, sizeof(data
));
881 data
.machine
= machine
;
882 data
.variant
= ".dimmpxm";
883 test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu"
885 " -m 128M,slots=3,maxmem=1G"
886 " -object memory-backend-ram,id=ram0,size=32M"
887 " -object memory-backend-ram,id=ram1,size=32M"
888 " -object memory-backend-ram,id=ram2,size=32M"
889 " -object memory-backend-ram,id=ram3,size=32M"
890 " -numa node,memdev=ram0,nodeid=0"
891 " -numa node,memdev=ram1,nodeid=1"
892 " -numa node,memdev=ram2,nodeid=2"
893 " -numa node,memdev=ram3,nodeid=3"
894 " -numa cpu,node-id=0,socket-id=0"
895 " -numa cpu,node-id=1,socket-id=1"
896 " -numa cpu,node-id=2,socket-id=2"
897 " -numa cpu,node-id=3,socket-id=3"
898 " -object memory-backend-ram,id=ram4,size=128M"
899 " -object memory-backend-ram,id=nvm0,size=128M"
900 " -device pc-dimm,id=dimm0,memdev=ram4,node=1"
901 " -device nvdimm,id=dimm1,memdev=nvm0,node=2",
903 free_test_data(&data
);
906 static void test_acpi_q35_tcg_dimm_pxm(void)
908 test_acpi_tcg_dimm_pxm(MACHINE_Q35
);
911 static void test_acpi_piix4_tcg_dimm_pxm(void)
913 test_acpi_tcg_dimm_pxm(MACHINE_PC
);
916 static void test_acpi_virt_tcg_memhp(void)
921 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
922 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
923 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
924 .ram_start
= 0x40000000ULL
,
925 .scan_len
= 256ULL * 1024 * 1024,
928 data
.variant
= ".memhp";
929 test_acpi_one(" -cpu cortex-a57"
930 " -m 256M,slots=3,maxmem=1G"
931 " -object memory-backend-ram,id=ram0,size=128M"
932 " -object memory-backend-ram,id=ram1,size=128M"
933 " -numa node,memdev=ram0 -numa node,memdev=ram1"
934 " -numa dist,src=0,dst=1,val=21",
937 free_test_data(&data
);
941 static void test_acpi_virt_tcg_numamem(void)
946 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
947 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
948 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
949 .ram_start
= 0x40000000ULL
,
950 .scan_len
= 128ULL * 1024 * 1024,
953 data
.variant
= ".numamem";
954 test_acpi_one(" -cpu cortex-a57"
955 " -object memory-backend-ram,id=ram0,size=128M"
956 " -numa node,memdev=ram0",
959 free_test_data(&data
);
963 static void test_acpi_tcg_acpi_hmat(const char *machine
)
967 memset(&data
, 0, sizeof(data
));
968 data
.machine
= machine
;
969 data
.variant
= ".acpihmat";
970 test_acpi_one(" -machine hmat=on"
972 " -m 128M,slots=2,maxmem=1G"
973 " -object memory-backend-ram,size=64M,id=m0"
974 " -object memory-backend-ram,size=64M,id=m1"
975 " -numa node,nodeid=0,memdev=m0"
976 " -numa node,nodeid=1,memdev=m1,initiator=0"
977 " -numa cpu,node-id=0,socket-id=0"
978 " -numa cpu,node-id=0,socket-id=1"
979 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
980 "data-type=access-latency,latency=1"
981 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
982 "data-type=access-bandwidth,bandwidth=65534M"
983 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
984 "data-type=access-latency,latency=65534"
985 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
986 "data-type=access-bandwidth,bandwidth=32767M"
987 " -numa hmat-cache,node-id=0,size=10K,level=1,"
988 "associativity=direct,policy=write-back,line=8"
989 " -numa hmat-cache,node-id=1,size=10K,level=1,"
990 "associativity=direct,policy=write-back,line=8",
992 free_test_data(&data
);
995 static void test_acpi_q35_tcg_acpi_hmat(void)
997 test_acpi_tcg_acpi_hmat(MACHINE_Q35
);
1000 static void test_acpi_piix4_tcg_acpi_hmat(void)
1002 test_acpi_tcg_acpi_hmat(MACHINE_PC
);
1005 static void test_acpi_virt_tcg(void)
1010 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
1011 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
1012 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1013 .ram_start
= 0x40000000ULL
,
1014 .scan_len
= 128ULL * 1024 * 1024,
1017 test_acpi_one("-cpu cortex-a57", &data
);
1018 free_test_data(&data
);
1021 int main(int argc
, char *argv
[])
1023 const char *arch
= qtest_get_arch();
1026 g_test_init(&argc
, &argv
, NULL
);
1028 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
1029 ret
= boot_sector_init(disk
);
1034 qtest_add_func("acpi/piix4", test_acpi_piix4_tcg
);
1035 qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge
);
1036 qtest_add_func("acpi/q35", test_acpi_q35_tcg
);
1037 qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge
);
1038 qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64
);
1039 qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi
);
1040 qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi
);
1041 qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp
);
1042 qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp
);
1043 qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp
);
1044 qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp
);
1045 qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem
);
1046 qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem
);
1047 qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm
);
1048 qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm
);
1049 qtest_add_func("acpi/piix4/acpihmat", test_acpi_piix4_tcg_acpi_hmat
);
1050 qtest_add_func("acpi/q35/acpihmat", test_acpi_q35_tcg_acpi_hmat
);
1051 } else if (strcmp(arch
, "aarch64") == 0) {
1052 qtest_add_func("acpi/virt", test_acpi_virt_tcg
);
1053 qtest_add_func("acpi/virt/numamem", test_acpi_virt_tcg_numamem
);
1054 qtest_add_func("acpi/virt/memhp", test_acpi_virt_tcg_memhp
);
1057 boot_sector_cleanup(disk
);