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 or commit changes that affect ACPI tables:
16 * 1. add empty files for new tables, if any, under tests/data/acpi
17 * 2. list any changed files in tests/qtest/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/qtest/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 * Expected binary updates needs to be a separate patch from the code that
42 * introduces changes to ACPI tables. It lets the maintainer drop
43 * and regenerate binary updates in case of merge conflicts. Further, a code
44 * change is easily reviewable but a binary blob is not (without doing a
46 * 7. Before sending patches to the list (Contributor)
47 * or before doing a pull request (Maintainer), make sure
48 * tests/qtest/bios-tables-test-allowed-diff.h is empty - this will ensure
49 * following changes to ACPI tables will be noticed.
51 * The resulting patchset/pull request then looks like this:
52 * - patch 1: list changed files in tests/qtest/bios-tables-test-allowed-diff.h.
53 * - patches 2 - n: real changes, may contain multiple patches.
54 * - patch n + 1: update golden master binaries and empty
55 * tests/qtest/bios-tables-test-allowed-diff.h
58 #include "qemu/osdep.h"
59 #include <glib/gstdio.h>
60 #include "hw/firmware/smbios.h"
61 #include "qemu/bitmap.h"
62 #include "acpi-utils.h"
63 #include "boot-sector.h"
65 #include "hw/acpi/tpm.h"
66 #include "qemu/cutils.h"
68 #define MACHINE_PC "pc"
69 #define MACHINE_Q35 "q35"
71 #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
74 #define OEM_TABLE_ID "OEM"
75 #define OEM_TEST_ARGS "-machine x-oem-id=" OEM_ID ",x-oem-table-id=" \
81 const char *machine_param
;
87 const uint64_t ram_start
;
88 const uint64_t scan_len
;
90 uint8_t rsdp_table
[36 /* ACPI 2.0+ RSDP size */];
92 uint64_t smbios_ep_addr
[SMBIOS_ENTRY_POINT_TYPE__MAX
];
93 SmbiosEntryPoint smbios_ep_table
;
94 uint16_t smbios_cpu_max_speed
;
95 uint16_t smbios_cpu_curr_speed
;
96 uint8_t smbios_core_count
;
97 uint16_t smbios_core_count2
;
98 uint8_t *required_struct_types
;
99 int required_struct_types_len
;
103 static char disk
[] = "tests/acpi-test-disk-XXXXXX";
104 static const char *data_dir
= "tests/data/acpi";
106 static const char *iasl
= CONFIG_IASL
;
108 static const char *iasl
;
111 static int verbosity_level
;
113 static bool compare_signature(const AcpiSdtTable
*sdt
, const char *signature
)
115 return !memcmp(sdt
->aml
, signature
, 4);
118 static void cleanup_table_descriptor(AcpiSdtTable
*table
)
121 if (table
->aml_file
&&
122 !table
->tmp_files_retain
&&
123 g_strstr_len(table
->aml_file
, -1, "aml-")) {
124 unlink(table
->aml_file
);
126 g_free(table
->aml_file
);
128 if (table
->asl_file
&&
129 !table
->tmp_files_retain
) {
130 unlink(table
->asl_file
);
132 g_free(table
->asl_file
);
135 static void free_test_data(test_data
*data
)
142 for (i
= 0; i
< data
->tables
->len
; ++i
) {
143 cleanup_table_descriptor(&g_array_index(data
->tables
, AcpiSdtTable
, i
));
146 g_array_free(data
->tables
, true);
149 static void test_acpi_rsdp_table(test_data
*data
)
151 uint8_t *rsdp_table
= data
->rsdp_table
;
153 acpi_fetch_rsdp_table(data
->qts
, data
->rsdp_addr
, rsdp_table
);
155 switch (rsdp_table
[15 /* Revision offset */]) {
156 case 0: /* ACPI 1.0 RSDP */
157 /* With rev 1, checksum is only for the first 20 bytes */
158 g_assert(!acpi_calc_checksum(rsdp_table
, 20));
160 case 2: /* ACPI 2.0+ RSDP */
161 /* With revision 2, we have 2 checksums */
162 g_assert(!acpi_calc_checksum(rsdp_table
, 20));
163 g_assert(!acpi_calc_checksum(rsdp_table
, 36));
166 g_assert_not_reached();
170 static void test_acpi_rxsdt_table(test_data
*data
)
172 const char *sig
= "RSDT";
173 AcpiSdtTable rsdt
= {};
175 int addr_off
= 16 /* RsdtAddress */;
178 if (data
->rsdp_table
[15 /* Revision offset */] != 0) {
179 addr_off
= 24 /* XsdtAddress */;
183 /* read [RX]SDT table */
184 acpi_fetch_table(data
->qts
, &rsdt
.aml
, &rsdt
.aml_len
,
185 &data
->rsdp_table
[addr_off
], entry_size
, sig
, true);
187 /* Load all tables and add to test list directly RSDT referenced tables */
188 ACPI_FOREACH_RSDT_ENTRY(rsdt
.aml
, rsdt
.aml_len
, ent
, entry_size
) {
189 AcpiSdtTable ssdt_table
= {};
191 acpi_fetch_table(data
->qts
, &ssdt_table
.aml
, &ssdt_table
.aml_len
, ent
,
192 entry_size
, NULL
, true);
193 /* Add table to ASL test tables list */
194 g_array_append_val(data
->tables
, ssdt_table
);
196 cleanup_table_descriptor(&rsdt
);
199 static void test_acpi_fadt_table(test_data
*data
)
201 /* FADT table is 1st */
202 AcpiSdtTable table
= g_array_index(data
->tables
, typeof(table
), 0);
203 uint8_t *fadt_aml
= table
.aml
;
204 uint32_t fadt_len
= table
.aml_len
;
206 int dsdt_offset
= 40 /* DSDT */;
207 int dsdt_entry_size
= 4;
209 g_assert(compare_signature(&table
, "FACP"));
211 /* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */
212 memcpy(&val
, fadt_aml
+ 112 /* Flags */, 4);
213 val
= le32_to_cpu(val
);
214 if (!(val
& 1UL << 20 /* HW_REDUCED_ACPI */)) {
215 acpi_fetch_table(data
->qts
, &table
.aml
, &table
.aml_len
,
216 fadt_aml
+ 36 /* FIRMWARE_CTRL */, 4, "FACS", false);
217 g_array_append_val(data
->tables
, table
);
220 memcpy(&val
, fadt_aml
+ dsdt_offset
, 4);
221 val
= le32_to_cpu(val
);
223 dsdt_offset
= 140 /* X_DSDT */;
226 acpi_fetch_table(data
->qts
, &table
.aml
, &table
.aml_len
,
227 fadt_aml
+ dsdt_offset
, dsdt_entry_size
, "DSDT", true);
228 g_array_append_val(data
->tables
, table
);
230 memset(fadt_aml
+ 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */
231 memset(fadt_aml
+ 40, 0, 4); /* sanitize DSDT ptr */
232 if (fadt_aml
[8 /* FADT Major Version */] >= 3) {
233 memset(fadt_aml
+ 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr */
234 memset(fadt_aml
+ 140, 0, 8); /* sanitize X_DSDT ptr */
237 /* update checksum */
238 fadt_aml
[9 /* Checksum */] = 0;
239 fadt_aml
[9 /* Checksum */] -= acpi_calc_checksum(fadt_aml
, fadt_len
);
242 static void dump_aml_files(test_data
*data
, bool rebuild
)
245 GError
*error
= NULL
;
246 gchar
*aml_file
= NULL
;
251 for (i
= 0; i
< data
->tables
->len
; ++i
) {
252 const char *ext
= data
->variant
? data
->variant
: "";
253 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
257 aml_file
= g_strdup_printf("%s/%s/%.4s%s", data_dir
, data
->machine
,
259 fd
= g_open(aml_file
, O_WRONLY
|O_TRUNC
|O_CREAT
,
260 S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IWGRP
|S_IROTH
);
266 fd
= g_file_open_tmp("aml-XXXXXX", &sdt
->aml_file
, &error
);
267 g_assert_no_error(error
);
270 ret
= qemu_write_full(fd
, sdt
->aml
, sdt
->aml_len
);
271 g_assert(ret
== sdt
->aml_len
);
279 static bool create_tmp_asl(AcpiSdtTable
*sdt
)
281 GError
*error
= NULL
;
284 fd
= g_file_open_tmp("asl-XXXXXX.dsl", &sdt
->asl_file
, &error
);
285 g_assert_no_error(error
);
291 static bool load_asl(GArray
*sdts
, AcpiSdtTable
*sdt
)
294 GError
*error
= NULL
;
295 GString
*command_line
= g_string_new(iasl
);
296 gchar
*out
, *out_err
;
302 /* build command line */
303 g_string_append_printf(command_line
, " -p %s ", sdt
->asl_file
);
304 if (compare_signature(sdt
, "DSDT") ||
305 compare_signature(sdt
, "SSDT")) {
306 for (i
= 0; i
< sdts
->len
; ++i
) {
307 temp
= &g_array_index(sdts
, AcpiSdtTable
, i
);
308 if (compare_signature(temp
, "DSDT") ||
309 compare_signature(temp
, "SSDT")) {
310 g_string_append_printf(command_line
, "-e %s ", temp
->aml_file
);
314 g_string_append_printf(command_line
, "-d %s", sdt
->aml_file
);
316 /* pass 'out' and 'out_err' in order to be redirected */
317 ret
= g_spawn_command_line_sync(command_line
->str
, &out
, &out_err
, NULL
, &error
);
318 g_assert_no_error(error
);
320 ret
= g_file_get_contents(sdt
->asl_file
, &sdt
->asl
,
321 &sdt
->asl_len
, &error
);
323 g_assert_no_error(error
);
324 ret
= (sdt
->asl_len
> 0);
329 g_string_free(command_line
, true);
334 #define COMMENT_END "*/"
335 #define DEF_BLOCK "DefinitionBlock ("
336 #define BLOCK_NAME_END ","
338 static GString
*normalize_asl(gchar
*asl_code
)
340 GString
*asl
= g_string_new(asl_code
);
341 gchar
*comment
, *block_name
;
343 /* strip comments (different generation days) */
344 comment
= g_strstr_len(asl
->str
, asl
->len
, COMMENT_END
);
346 comment
+= strlen(COMMENT_END
);
347 while (*comment
== '\n') {
350 asl
= g_string_erase(asl
, 0, comment
- asl
->str
);
353 /* strip def block name (it has file path in it) */
354 if (g_str_has_prefix(asl
->str
, DEF_BLOCK
)) {
355 block_name
= g_strstr_len(asl
->str
, asl
->len
, BLOCK_NAME_END
);
356 g_assert(block_name
);
357 asl
= g_string_erase(asl
, 0,
358 block_name
+ sizeof(BLOCK_NAME_END
) - asl
->str
);
364 static GArray
*load_expected_aml(test_data
*data
)
368 GError
*error
= NULL
;
372 GArray
*exp_tables
= g_array_new(false, true, sizeof(AcpiSdtTable
));
373 if (verbosity_level
>= 2) {
376 for (i
= 0; i
< data
->tables
->len
; ++i
) {
377 AcpiSdtTable exp_sdt
;
378 gchar
*aml_file
= NULL
;
379 const char *ext
= data
->variant
? data
->variant
: "";
381 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
383 memset(&exp_sdt
, 0, sizeof(exp_sdt
));
386 aml_file
= g_strdup_printf("%s/%s/%.4s%s", data_dir
, data
->machine
,
388 if (verbosity_level
>= 2) {
389 fprintf(stderr
, "Looking for expected file '%s'\n", aml_file
);
391 if (g_file_test(aml_file
, G_FILE_TEST_EXISTS
)) {
392 exp_sdt
.aml_file
= aml_file
;
393 } else if (*ext
!= '\0') {
394 /* try fallback to generic (extension less) expected file */
399 g_assert(exp_sdt
.aml_file
);
400 if (verbosity_level
>= 2) {
401 fprintf(stderr
, "Using expected file '%s'\n", aml_file
);
403 ret
= g_file_get_contents(aml_file
, (gchar
**)&exp_sdt
.aml
,
405 exp_sdt
.aml_len
= aml_len
;
407 g_assert_no_error(error
);
408 g_assert(exp_sdt
.aml
);
409 if (!exp_sdt
.aml_len
) {
410 fprintf(stderr
, "Warning! zero length expected file '%s'\n",
414 g_array_append_val(exp_tables
, exp_sdt
);
420 static bool test_acpi_find_diff_allowed(AcpiSdtTable
*sdt
)
422 const gchar
*allowed_diff_file
[] = {
423 #include "bios-tables-test-allowed-diff.h"
428 for (f
= allowed_diff_file
; *f
; ++f
) {
429 if (!g_strcmp0(sdt
->aml_file
, *f
)) {
436 /* test the list of tables in @data->tables against reference tables */
437 static void test_acpi_asl(test_data
*data
)
440 AcpiSdtTable
*sdt
, *exp_sdt
;
442 gboolean exp_err
, err
, all_tables_match
= true;
444 memset(&exp_data
, 0, sizeof(exp_data
));
445 exp_data
.tables
= load_expected_aml(data
);
446 dump_aml_files(data
, false);
447 for (i
= 0; i
< data
->tables
->len
; ++i
) {
448 GString
*asl
, *exp_asl
;
450 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
451 exp_sdt
= &g_array_index(exp_data
.tables
, AcpiSdtTable
, i
);
453 if (sdt
->aml_len
== exp_sdt
->aml_len
&&
454 !memcmp(sdt
->aml
, exp_sdt
->aml
, sdt
->aml_len
)) {
455 /* Identical table binaries: no need to disassemble. */
460 "acpi-test: Warning! %.4s binary file mismatch. "
461 "Actual [aml:%s], Expected [aml:%s].\n"
462 "See source file tests/qtest/bios-tables-test.c "
463 "for instructions on how to update expected files.\n",
464 exp_sdt
->aml
, sdt
->aml_file
, exp_sdt
->aml_file
);
466 all_tables_match
= all_tables_match
&&
467 test_acpi_find_diff_allowed(exp_sdt
);
470 * don't try to decompile if IASL isn't present, in this case user
471 * will just 'get binary file mismatch' warnings and test failure
477 err
= load_asl(data
->tables
, sdt
);
478 asl
= normalize_asl(sdt
->asl
);
481 * If expected file is empty - it's likely that it was a stub just
482 * created for step 1 above: we do want to decompile the actual one.
484 if (exp_sdt
->aml_len
) {
485 exp_err
= load_asl(exp_data
.tables
, exp_sdt
);
486 exp_asl
= normalize_asl(exp_sdt
->asl
);
488 exp_err
= create_tmp_asl(exp_sdt
);
489 exp_asl
= g_string_new("");
492 /* TODO: check for warnings */
493 g_assert(!err
|| exp_err
|| !exp_sdt
->aml_len
);
495 if (g_strcmp0(asl
->str
, exp_asl
->str
)) {
496 sdt
->tmp_files_retain
= true;
499 "Warning! iasl couldn't parse the expected aml\n");
501 exp_sdt
->tmp_files_retain
= true;
503 "acpi-test: Warning! %.4s mismatch. "
504 "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
505 exp_sdt
->aml
, sdt
->asl_file
, sdt
->aml_file
,
506 exp_sdt
->asl_file
, exp_sdt
->aml_file
);
508 if (verbosity_level
>= 1) {
509 const char *diff_env
= getenv("DIFF");
510 const char *diff_cmd
= diff_env
? diff_env
: "diff -U 16";
511 char *diff
= g_strdup_printf("%s %s %s", diff_cmd
,
512 exp_sdt
->asl_file
, sdt
->asl_file
);
513 int out
= dup(STDOUT_FILENO
);
514 int ret G_GNUC_UNUSED
;
518 dupret
= dup2(STDERR_FILENO
, STDOUT_FILENO
);
519 g_assert(dupret
>= 0);
521 dupret
= dup2(out
, STDOUT_FILENO
);
522 g_assert(dupret
>= 0);
528 g_string_free(asl
, true);
529 g_string_free(exp_asl
, true);
531 if (!iasl
&& !all_tables_match
) {
532 fprintf(stderr
, "to see ASL diff between mismatched files install IASL,"
533 " rebuild QEMU from scratch and re-run tests with V=1"
534 " environment variable set");
536 g_assert(all_tables_match
);
538 free_test_data(&exp_data
);
541 static bool smbios_ep2_table_ok(test_data
*data
, uint32_t addr
)
543 struct smbios_21_entry_point
*ep_table
= &data
->smbios_ep_table
.ep21
;
545 qtest_memread(data
->qts
, addr
, ep_table
, sizeof(*ep_table
));
546 if (memcmp(ep_table
->anchor_string
, "_SM_", 4)) {
549 if (memcmp(ep_table
->intermediate_anchor_string
, "_DMI_", 5)) {
552 if (ep_table
->structure_table_length
== 0) {
555 if (ep_table
->number_of_structures
== 0) {
558 if (acpi_calc_checksum((uint8_t *)ep_table
, sizeof *ep_table
) ||
559 acpi_calc_checksum((uint8_t *)ep_table
+ 0x10,
560 sizeof *ep_table
- 0x10)) {
566 static bool smbios_ep3_table_ok(test_data
*data
, uint64_t addr
)
568 struct smbios_30_entry_point
*ep_table
= &data
->smbios_ep_table
.ep30
;
570 qtest_memread(data
->qts
, addr
, ep_table
, sizeof(*ep_table
));
571 if (memcmp(ep_table
->anchor_string
, "_SM3_", 5)) {
575 if (acpi_calc_checksum((uint8_t *)ep_table
, sizeof *ep_table
)) {
582 static SmbiosEntryPointType
test_smbios_entry_point(test_data
*data
)
586 /* find smbios entry point structure */
587 for (off
= 0xf0000; off
< 0x100000; off
+= 0x10) {
588 uint8_t sig
[] = "_SM_", sig3
[] = "_SM3_";
591 for (i
= 0; i
< sizeof sig
- 1; ++i
) {
592 sig
[i
] = qtest_readb(data
->qts
, off
+ i
);
595 if (!memcmp(sig
, "_SM_", sizeof sig
)) {
596 /* signature match, but is this a valid entry point? */
597 if (smbios_ep2_table_ok(data
, off
)) {
598 data
->smbios_ep_addr
[SMBIOS_ENTRY_POINT_TYPE_32
] = off
;
602 for (i
= 0; i
< sizeof sig3
- 1; ++i
) {
603 sig3
[i
] = qtest_readb(data
->qts
, off
+ i
);
606 if (!memcmp(sig3
, "_SM3_", sizeof sig3
)) {
607 if (smbios_ep3_table_ok(data
, off
)) {
608 data
->smbios_ep_addr
[SMBIOS_ENTRY_POINT_TYPE_64
] = off
;
609 /* found 64-bit entry point, no need to look for 32-bit one */
615 /* found at least one entry point */
616 g_assert_true(data
->smbios_ep_addr
[SMBIOS_ENTRY_POINT_TYPE_32
] ||
617 data
->smbios_ep_addr
[SMBIOS_ENTRY_POINT_TYPE_64
]);
619 return data
->smbios_ep_addr
[SMBIOS_ENTRY_POINT_TYPE_64
] ?
620 SMBIOS_ENTRY_POINT_TYPE_64
: SMBIOS_ENTRY_POINT_TYPE_32
;
623 static inline bool smbios_single_instance(uint8_t type
)
639 static void smbios_cpu_test(test_data
*data
, uint32_t addr
,
640 SmbiosEntryPointType ep_type
)
642 uint8_t core_count
, expected_core_count
= data
->smbios_core_count
;
643 uint16_t speed
, expected_speed
[2];
644 uint16_t core_count2
, expected_core_count2
= data
->smbios_core_count2
;
648 /* Check CPU speed for backward compatibility */
649 offset
[0] = offsetof(struct smbios_type_4
, max_speed
);
650 offset
[1] = offsetof(struct smbios_type_4
, current_speed
);
651 expected_speed
[0] = data
->smbios_cpu_max_speed
? : 2000;
652 expected_speed
[1] = data
->smbios_cpu_curr_speed
? : 2000;
654 for (i
= 0; i
< 2; i
++) {
655 speed
= qtest_readw(data
->qts
, addr
+ offset
[i
]);
656 g_assert_cmpuint(speed
, ==, expected_speed
[i
]);
659 core_count
= qtest_readb(data
->qts
,
660 addr
+ offsetof(struct smbios_type_4
, core_count
));
662 if (expected_core_count
) {
663 g_assert_cmpuint(core_count
, ==, expected_core_count
);
666 if (ep_type
== SMBIOS_ENTRY_POINT_TYPE_64
) {
667 core_count2
= qtest_readw(data
->qts
,
668 addr
+ offsetof(struct smbios_type_4
, core_count2
));
670 /* Core Count has reached its limit, checking Core Count 2 */
671 if (expected_core_count
== 0xFF && expected_core_count2
) {
672 g_assert_cmpuint(core_count2
, ==, expected_core_count2
);
677 static void test_smbios_structs(test_data
*data
, SmbiosEntryPointType ep_type
)
679 DECLARE_BITMAP(struct_bitmap
, SMBIOS_MAX_TYPE
+1) = { 0 };
681 SmbiosEntryPoint
*ep_table
= &data
->smbios_ep_table
;
682 int i
= 0, len
, max_len
= 0;
683 uint8_t type
, prv
, crt
;
686 if (ep_type
== SMBIOS_ENTRY_POINT_TYPE_32
) {
687 addr
= le32_to_cpu(ep_table
->ep21
.structure_table_address
);
689 addr
= le64_to_cpu(ep_table
->ep30
.structure_table_address
);
692 /* walk the smbios tables */
695 /* grab type and formatted area length from struct header */
696 type
= qtest_readb(data
->qts
, addr
);
697 g_assert_cmpuint(type
, <=, SMBIOS_MAX_TYPE
);
698 len
= qtest_readb(data
->qts
, addr
+ 1);
700 /* single-instance structs must not have been encountered before */
701 if (smbios_single_instance(type
)) {
702 g_assert(!test_bit(type
, struct_bitmap
));
704 set_bit(type
, struct_bitmap
);
707 smbios_cpu_test(data
, addr
, ep_type
);
710 /* seek to end of unformatted string area of this struct ("\0\0") */
714 crt
= qtest_readb(data
->qts
, addr
+ len
);
718 /* keep track of max. struct size */
719 if (ep_type
== SMBIOS_ENTRY_POINT_TYPE_32
&& max_len
< len
) {
721 g_assert_cmpuint(max_len
, <=, ep_table
->ep21
.max_structure_size
);
724 /* start of next structure */
728 * Until all structures have been scanned (ep21)
729 * or an EOF structure is found (ep30)
731 } while (ep_type
== SMBIOS_ENTRY_POINT_TYPE_32
?
732 ++i
< le16_to_cpu(ep_table
->ep21
.number_of_structures
) :
735 if (ep_type
== SMBIOS_ENTRY_POINT_TYPE_32
) {
737 * Total table length and max struct size
738 * must match entry point values
740 g_assert_cmpuint(le16_to_cpu(ep_table
->ep21
.structure_table_length
), ==,
741 addr
- le32_to_cpu(ep_table
->ep21
.structure_table_address
));
743 g_assert_cmpuint(le16_to_cpu(ep_table
->ep21
.max_structure_size
), ==,
747 /* required struct types must all be present */
748 for (i
= 0; i
< data
->required_struct_types_len
; i
++) {
749 g_assert(test_bit(data
->required_struct_types
[i
], struct_bitmap
));
753 static void test_acpi_load_tables(test_data
*data
)
755 if (data
->uefi_fl1
&& data
->uefi_fl2
) { /* use UEFI */
756 g_assert(data
->scan_len
);
757 data
->rsdp_addr
= acpi_find_rsdp_address_uefi(data
->qts
,
758 data
->ram_start
, data
->scan_len
);
760 boot_sector_test(data
->qts
);
761 data
->rsdp_addr
= acpi_find_rsdp_address(data
->qts
);
762 g_assert_cmphex(data
->rsdp_addr
, <, 0x100000);
765 data
->tables
= g_array_new(false, true, sizeof(AcpiSdtTable
));
766 test_acpi_rsdp_table(data
);
767 test_acpi_rxsdt_table(data
);
768 test_acpi_fadt_table(data
);
771 static char *test_acpi_create_args(test_data
*data
, const char *params
)
775 if (data
->uefi_fl1
&& data
->uefi_fl2
) { /* use UEFI */
777 * TODO: convert '-drive if=pflash' to new syntax (see e33763be7cd3)
778 * when arm/virt boad starts to support it.
781 args
= g_strdup_printf("-machine %s%s %s -accel tcg "
782 "-nodefaults -nographic "
783 "-drive if=pflash,format=raw,file=%s,readonly=on "
784 "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s",
785 data
->machine
, data
->machine_param
?: "",
786 data
->tcg_only
? "" : "-accel kvm",
787 data
->uefi_fl1
, data
->uefi_fl2
, data
->cd
, params
? params
: "");
789 args
= g_strdup_printf("-machine %s%s %s -accel tcg "
790 "-nodefaults -nographic "
791 "-drive if=pflash,format=raw,file=%s,readonly=on "
792 "-drive if=pflash,format=raw,file=%s,snapshot=on %s",
793 data
->machine
, data
->machine_param
?: "",
794 data
->tcg_only
? "" : "-accel kvm",
795 data
->uefi_fl1
, data
->uefi_fl2
, params
? params
: "");
798 args
= g_strdup_printf("-machine %s%s %s -accel tcg "
800 "-drive id=hd0,if=none,file=%s,format=raw "
801 "-device %s,drive=hd0 ",
802 data
->machine
, data
->machine_param
?: "",
803 data
->tcg_only
? "" : "-accel kvm",
804 params
? params
: "", disk
,
805 data
->blkdev
?: "ide-hd");
810 static void test_vm_prepare(const char *params
, test_data
*data
)
812 char *args
= test_acpi_create_args(data
, params
);
813 data
->qts
= qtest_init(args
);
817 static void process_acpi_tables_noexit(test_data
*data
)
819 test_acpi_load_tables(data
);
821 if (getenv(ACPI_REBUILD_EXPECTED_AML
)) {
822 dump_aml_files(data
, true);
828 * TODO: make SMBIOS tests work with UEFI firmware,
829 * Bug on uefi-test-tools to provide entry point:
830 * https://bugs.launchpad.net/qemu/+bug/1821884
832 if (!(data
->uefi_fl1
&& data
->uefi_fl2
)) {
833 SmbiosEntryPointType ep_type
= test_smbios_entry_point(data
);
834 test_smbios_structs(data
, ep_type
);
838 static void process_acpi_tables(test_data
*data
)
840 process_acpi_tables_noexit(data
);
841 qtest_quit(data
->qts
);
844 static void test_acpi_one(const char *params
, test_data
*data
)
846 test_vm_prepare(params
, data
);
847 process_acpi_tables(data
);
850 static uint8_t base_required_struct_types
[] = {
851 0, 1, 3, 4, 16, 17, 19, 32, 127
854 static void test_acpi_piix4_tcg(void)
858 /* Supplying -machine accel argument overrides the default (qtest).
859 * This is to make guest actually run.
861 memset(&data
, 0, sizeof(data
));
862 data
.machine
= MACHINE_PC
;
863 data
.required_struct_types
= base_required_struct_types
;
864 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
865 test_acpi_one(NULL
, &data
);
866 free_test_data(&data
);
869 static void test_acpi_piix4_tcg_bridge(void)
873 memset(&data
, 0, sizeof(data
));
874 data
.machine
= MACHINE_PC
;
875 data
.variant
= ".bridge";
876 data
.required_struct_types
= base_required_struct_types
;
877 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
879 " -device pci-bridge,chassis_nr=1"
880 " -device pci-bridge,bus=pci.1,addr=1.0,chassis_nr=2"
881 " -device pci-testdev,bus=pci.0,addr=5.0"
882 " -device pci-testdev,bus=pci.1", &data
);
884 /* hotplugged bridges section */
885 qtest_qmp_device_add(data
.qts
, "pci-bridge", "hpbr",
886 "{'bus': 'pci.1', 'addr': '2.0', 'chassis_nr': 3 }");
887 qtest_qmp_device_add(data
.qts
, "pci-bridge", "hpbr_multifunc",
888 "{'bus': 'pci.1', 'addr': '0xf.1', 'chassis_nr': 4 }");
889 qtest_qmp_device_add(data
.qts
, "pci-bridge", "hpbrhost",
890 "{'bus': 'pci.0', 'addr': '4.0', 'chassis_nr': 5 }");
891 qtest_qmp_device_add(data
.qts
, "pci-testdev", "d1", "{'bus': 'pci.0' }");
892 qtest_qmp_device_add(data
.qts
, "pci-testdev", "d2", "{'bus': 'pci.1' }");
893 qtest_qmp_device_add(data
.qts
, "pci-testdev", "d3", "{'bus': 'hpbr', "
895 qtest_qmp_send(data
.qts
, "{'execute':'cont' }");
896 qtest_qmp_eventwait(data
.qts
, "RESUME");
898 process_acpi_tables_noexit(&data
);
899 free_test_data(&data
);
901 /* check that reboot/reset doesn't change any ACPI tables */
902 qtest_qmp_send(data
.qts
, "{'execute':'system_reset' }");
903 process_acpi_tables(&data
);
904 free_test_data(&data
);
907 static void test_acpi_piix4_no_root_hotplug(void)
911 memset(&data
, 0, sizeof(data
));
912 data
.machine
= MACHINE_PC
;
913 data
.variant
= ".roothp";
914 data
.required_struct_types
= base_required_struct_types
;
915 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
916 test_acpi_one("-global PIIX4_PM.acpi-root-pci-hotplug=off "
917 "-device pci-bridge,chassis_nr=1 "
918 "-device pci-bridge,bus=pci.1,addr=1.0,chassis_nr=2 "
919 "-device pci-testdev,bus=pci.0 "
920 "-device pci-testdev,bus=pci.1", &data
);
921 free_test_data(&data
);
924 static void test_acpi_piix4_no_bridge_hotplug(void)
928 memset(&data
, 0, sizeof(data
));
929 data
.machine
= MACHINE_PC
;
930 data
.variant
= ".hpbridge";
931 data
.required_struct_types
= base_required_struct_types
;
932 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
933 test_acpi_one("-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off "
934 "-device pci-bridge,chassis_nr=1 "
935 "-device pci-bridge,bus=pci.1,addr=1.0,chassis_nr=2 "
936 "-device pci-testdev,bus=pci.0 "
937 "-device pci-testdev,bus=pci.1,addr=2.0", &data
);
938 free_test_data(&data
);
941 static void test_acpi_piix4_no_acpi_pci_hotplug(void)
945 memset(&data
, 0, sizeof(data
));
946 data
.machine
= MACHINE_PC
;
947 data
.variant
= ".hpbrroot";
948 data
.required_struct_types
= base_required_struct_types
;
949 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
950 test_acpi_one("-global PIIX4_PM.acpi-root-pci-hotplug=off "
951 "-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off "
952 "-device pci-bridge,chassis_nr=1 "
953 "-device pci-testdev,bus=pci.0 "
954 "-device pci-testdev,bus=pci.1", &data
);
955 free_test_data(&data
);
958 static void test_acpi_q35_tcg(void)
962 memset(&data
, 0, sizeof(data
));
963 data
.machine
= MACHINE_Q35
;
964 data
.required_struct_types
= base_required_struct_types
;
965 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
966 test_acpi_one(NULL
, &data
);
967 free_test_data(&data
);
969 data
.smbios_cpu_max_speed
= 3000;
970 data
.smbios_cpu_curr_speed
= 2600;
971 test_acpi_one("-smbios type=4,max-speed=3000,current-speed=2600", &data
);
972 free_test_data(&data
);
975 static void test_acpi_q35_tcg_core_count2(void)
978 .machine
= MACHINE_Q35
,
979 .variant
= ".core-count2",
980 .required_struct_types
= base_required_struct_types
,
981 .required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
),
982 .smbios_core_count
= 0xFF,
983 .smbios_core_count2
= 275,
986 test_acpi_one("-machine smbios-entry-point-type=64 -smp 275", &data
);
987 free_test_data(&data
);
990 static void test_acpi_q35_tcg_bridge(void)
994 memset(&data
, 0, sizeof(data
));
995 data
.machine
= MACHINE_Q35
;
996 data
.variant
= ".bridge";
997 data
.required_struct_types
= base_required_struct_types
;
998 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
999 test_acpi_one("-device pci-bridge,chassis_nr=1,id=br1"
1000 " -device pci-testdev,bus=pcie.0"
1001 " -device pci-testdev,bus=br1", &data
);
1002 free_test_data(&data
);
1005 static void test_acpi_q35_multif_bridge(void)
1008 .machine
= MACHINE_Q35
,
1009 .variant
= ".multi-bridge",
1011 test_vm_prepare("-S"
1012 " -device virtio-balloon,id=balloon0,addr=0x4.0x2"
1013 " -device pcie-root-port,id=rp0,multifunction=on,"
1014 "port=0x0,chassis=1,addr=0x2"
1015 " -device pcie-root-port,id=rp1,port=0x1,chassis=2,addr=0x3.0x1"
1016 " -device pcie-root-port,id=rp2,port=0x0,chassis=3,bus=rp1,addr=0.0"
1017 " -device pci-bridge,bus=rp2,chassis_nr=4,id=br1"
1018 " -device pcie-root-port,id=rphptgt1,port=0x0,chassis=5,addr=2.1"
1019 " -device pcie-root-port,id=rphptgt2,port=0x0,chassis=6,addr=2.2"
1020 " -device pcie-root-port,id=rphptgt3,port=0x0,chassis=7,addr=2.3"
1021 " -device pci-testdev,bus=pcie.0,addr=2.4"
1022 " -device pci-testdev,bus=pcie.0,addr=5.0"
1023 " -device pci-testdev,bus=rp0,addr=0.0"
1024 " -device pci-testdev,bus=br1", &data
);
1026 /* hotplugged bridges section */
1027 qtest_qmp_device_add(data
.qts
, "pci-bridge", "hpbr1",
1028 "{'bus': 'br1', 'addr': '6.0', 'chassis_nr': 128 }");
1029 qtest_qmp_device_add(data
.qts
, "pci-bridge", "hpbr2-multiif",
1030 "{ 'bus': 'br1', 'addr': '2.2', 'chassis_nr': 129 }");
1031 qtest_qmp_device_add(data
.qts
, "pcie-pci-bridge", "hpbr3",
1032 "{'bus': 'rphptgt1', 'addr': '0.0' }");
1033 qtest_qmp_device_add(data
.qts
, "pcie-root-port", "hprp",
1034 "{'bus': 'rphptgt2', 'addr': '0.0' }");
1035 qtest_qmp_device_add(data
.qts
, "pci-testdev", "hpnic",
1036 "{'bus': 'rphptgt3', 'addr': '0.0' }");
1037 qtest_qmp_send(data
.qts
, "{'execute':'cont' }");
1038 qtest_qmp_eventwait(data
.qts
, "RESUME");
1040 process_acpi_tables_noexit(&data
);
1041 free_test_data(&data
);
1043 /* check that reboot/reset doesn't change any ACPI tables */
1044 qtest_qmp_send(data
.qts
, "{'execute':'system_reset' }");
1045 process_acpi_tables(&data
);
1046 free_test_data(&data
);
1049 static void test_acpi_q35_tcg_mmio64(void)
1052 .machine
= MACHINE_Q35
,
1053 .variant
= ".mmio64",
1054 .required_struct_types
= base_required_struct_types
,
1055 .required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
)
1058 test_acpi_one("-m 128M,slots=1,maxmem=2G "
1059 "-object memory-backend-ram,id=ram0,size=128M "
1060 "-numa node,memdev=ram0 "
1061 "-device pci-testdev,membar=2G",
1063 free_test_data(&data
);
1066 static void test_acpi_piix4_tcg_cphp(void)
1070 memset(&data
, 0, sizeof(data
));
1071 data
.machine
= MACHINE_PC
;
1072 data
.variant
= ".cphp";
1073 test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6"
1074 " -object memory-backend-ram,id=ram0,size=64M"
1075 " -object memory-backend-ram,id=ram1,size=64M"
1076 " -numa node,memdev=ram0 -numa node,memdev=ram1"
1077 " -numa dist,src=0,dst=1,val=21",
1079 free_test_data(&data
);
1082 static void test_acpi_q35_tcg_cphp(void)
1086 memset(&data
, 0, sizeof(data
));
1087 data
.machine
= MACHINE_Q35
;
1088 data
.variant
= ".cphp";
1089 test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
1090 " -object memory-backend-ram,id=ram0,size=64M"
1091 " -object memory-backend-ram,id=ram1,size=64M"
1092 " -numa node,memdev=ram0 -numa node,memdev=ram1"
1093 " -numa dist,src=0,dst=1,val=21",
1095 free_test_data(&data
);
1098 static uint8_t ipmi_required_struct_types
[] = {
1099 0, 1, 3, 4, 16, 17, 19, 32, 38, 127
1102 static void test_acpi_q35_tcg_ipmi(void)
1106 memset(&data
, 0, sizeof(data
));
1107 data
.machine
= MACHINE_Q35
;
1108 data
.variant
= ".ipmibt";
1109 data
.required_struct_types
= ipmi_required_struct_types
;
1110 data
.required_struct_types_len
= ARRAY_SIZE(ipmi_required_struct_types
);
1111 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
1112 " -device isa-ipmi-bt,bmc=bmc0",
1114 free_test_data(&data
);
1117 static void test_acpi_q35_tcg_smbus_ipmi(void)
1121 memset(&data
, 0, sizeof(data
));
1122 data
.machine
= MACHINE_Q35
;
1123 data
.variant
= ".ipmismbus";
1124 data
.required_struct_types
= ipmi_required_struct_types
;
1125 data
.required_struct_types_len
= ARRAY_SIZE(ipmi_required_struct_types
);
1126 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
1127 " -device smbus-ipmi,bmc=bmc0",
1129 free_test_data(&data
);
1132 static void test_acpi_piix4_tcg_ipmi(void)
1136 /* Supplying -machine accel argument overrides the default (qtest).
1137 * This is to make guest actually run.
1139 memset(&data
, 0, sizeof(data
));
1140 data
.machine
= MACHINE_PC
;
1141 data
.variant
= ".ipmikcs";
1142 data
.required_struct_types
= ipmi_required_struct_types
;
1143 data
.required_struct_types_len
= ARRAY_SIZE(ipmi_required_struct_types
);
1144 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
1145 " -device isa-ipmi-kcs,irq=0,bmc=bmc0",
1147 free_test_data(&data
);
1150 static void test_acpi_q35_tcg_memhp(void)
1154 memset(&data
, 0, sizeof(data
));
1155 data
.machine
= MACHINE_Q35
;
1156 data
.variant
= ".memhp";
1157 test_acpi_one(" -m 128,slots=3,maxmem=1G"
1158 " -object memory-backend-ram,id=ram0,size=64M"
1159 " -object memory-backend-ram,id=ram1,size=64M"
1160 " -numa node,memdev=ram0 -numa node,memdev=ram1"
1161 " -numa dist,src=0,dst=1,val=21",
1163 free_test_data(&data
);
1166 static void test_acpi_piix4_tcg_memhp(void)
1170 memset(&data
, 0, sizeof(data
));
1171 data
.machine
= MACHINE_PC
;
1172 data
.variant
= ".memhp";
1173 test_acpi_one(" -m 128,slots=3,maxmem=1G"
1174 " -object memory-backend-ram,id=ram0,size=64M"
1175 " -object memory-backend-ram,id=ram1,size=64M"
1176 " -numa node,memdev=ram0 -numa node,memdev=ram1"
1177 " -numa dist,src=0,dst=1,val=21",
1179 free_test_data(&data
);
1182 static void test_acpi_piix4_tcg_nosmm(void)
1186 memset(&data
, 0, sizeof(data
));
1187 data
.machine
= MACHINE_PC
;
1188 data
.variant
= ".nosmm";
1189 test_acpi_one("-machine smm=off", &data
);
1190 free_test_data(&data
);
1193 static void test_acpi_piix4_tcg_smm_compat(void)
1197 memset(&data
, 0, sizeof(data
));
1198 data
.machine
= MACHINE_PC
;
1199 data
.variant
= ".smm-compat";
1200 test_acpi_one("-global PIIX4_PM.smm-compat=on", &data
);
1201 free_test_data(&data
);
1204 static void test_acpi_piix4_tcg_smm_compat_nosmm(void)
1208 memset(&data
, 0, sizeof(data
));
1209 data
.machine
= MACHINE_PC
;
1210 data
.variant
= ".smm-compat-nosmm";
1211 test_acpi_one("-global PIIX4_PM.smm-compat=on -machine smm=off", &data
);
1212 free_test_data(&data
);
1215 static void test_acpi_piix4_tcg_nohpet(void)
1219 memset(&data
, 0, sizeof(data
));
1220 data
.machine
= MACHINE_PC
;
1221 data
.machine_param
= ",hpet=off";
1222 data
.variant
= ".nohpet";
1223 test_acpi_one(NULL
, &data
);
1224 free_test_data(&data
);
1227 static void test_acpi_q35_tcg_numamem(void)
1231 memset(&data
, 0, sizeof(data
));
1232 data
.machine
= MACHINE_Q35
;
1233 data
.variant
= ".numamem";
1234 test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
1235 " -numa node -numa node,memdev=ram0", &data
);
1236 free_test_data(&data
);
1239 static void test_acpi_q35_kvm_xapic(void)
1243 memset(&data
, 0, sizeof(data
));
1244 data
.machine
= MACHINE_Q35
;
1245 data
.variant
= ".xapic";
1246 test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
1247 " -numa node -numa node,memdev=ram0"
1248 " -machine kernel-irqchip=on -smp 1,maxcpus=288", &data
);
1249 free_test_data(&data
);
1252 static void test_acpi_q35_tcg_nosmm(void)
1256 memset(&data
, 0, sizeof(data
));
1257 data
.machine
= MACHINE_Q35
;
1258 data
.variant
= ".nosmm";
1259 test_acpi_one("-machine smm=off", &data
);
1260 free_test_data(&data
);
1263 static void test_acpi_q35_tcg_smm_compat(void)
1267 memset(&data
, 0, sizeof(data
));
1268 data
.machine
= MACHINE_Q35
;
1269 data
.variant
= ".smm-compat";
1270 test_acpi_one("-global ICH9-LPC.smm-compat=on", &data
);
1271 free_test_data(&data
);
1274 static void test_acpi_q35_tcg_smm_compat_nosmm(void)
1278 memset(&data
, 0, sizeof(data
));
1279 data
.machine
= MACHINE_Q35
;
1280 data
.variant
= ".smm-compat-nosmm";
1281 test_acpi_one("-global ICH9-LPC.smm-compat=on -machine smm=off", &data
);
1282 free_test_data(&data
);
1285 static void test_acpi_q35_tcg_nohpet(void)
1289 memset(&data
, 0, sizeof(data
));
1290 data
.machine
= MACHINE_Q35
;
1291 data
.machine_param
= ",hpet=off";
1292 data
.variant
= ".nohpet";
1293 test_acpi_one(NULL
, &data
);
1294 free_test_data(&data
);
1297 static void test_acpi_q35_kvm_dmar(void)
1301 memset(&data
, 0, sizeof(data
));
1302 data
.machine
= MACHINE_Q35
;
1303 data
.variant
= ".dmar";
1304 test_acpi_one("-machine kernel-irqchip=split -accel kvm"
1305 " -device intel-iommu,intremap=on,device-iotlb=on", &data
);
1306 free_test_data(&data
);
1309 static void test_acpi_q35_tcg_ivrs(void)
1313 memset(&data
, 0, sizeof(data
));
1314 data
.machine
= MACHINE_Q35
;
1315 data
.variant
= ".ivrs";
1316 data
.tcg_only
= true,
1317 test_acpi_one(" -device amd-iommu", &data
);
1318 free_test_data(&data
);
1321 static void test_acpi_piix4_tcg_numamem(void)
1325 memset(&data
, 0, sizeof(data
));
1326 data
.machine
= MACHINE_PC
;
1327 data
.variant
= ".numamem";
1328 test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
1329 " -numa node -numa node,memdev=ram0", &data
);
1330 free_test_data(&data
);
1333 uint64_t tpm_tis_base_addr
;
1335 static void test_acpi_tcg_tpm(const char *machine
, const char *tpm_if
,
1336 uint64_t base
, enum TPMVersion tpm_version
)
1338 gchar
*tmp_dir_name
= g_strdup_printf("qemu-test_acpi_%s_tcg_%s.XXXXXX",
1340 char *tmp_path
= g_dir_make_tmp(tmp_dir_name
, NULL
);
1344 const char *suffix
= tpm_version
== TPM_VERSION_2_0
? "tpm2" : "tpm12";
1345 char *args
, *variant
= g_strdup_printf(".%s.%s", tpm_if
, suffix
);
1347 tpm_tis_base_addr
= base
;
1349 module_call_init(MODULE_INIT_QOM
);
1351 test
.addr
= g_new0(SocketAddress
, 1);
1352 test
.addr
->type
= SOCKET_ADDRESS_TYPE_UNIX
;
1353 test
.addr
->u
.q_unix
.path
= g_build_filename(tmp_path
, "sock", NULL
);
1354 g_mutex_init(&test
.data_mutex
);
1355 g_cond_init(&test
.data_cond
);
1356 test
.data_cond_signal
= false;
1357 test
.tpm_version
= tpm_version
;
1359 thread
= g_thread_new(NULL
, tpm_emu_ctrl_thread
, &test
);
1360 tpm_emu_test_wait_cond(&test
);
1362 memset(&data
, 0, sizeof(data
));
1363 data
.machine
= machine
;
1364 data
.variant
= variant
;
1366 args
= g_strdup_printf(
1367 " -chardev socket,id=chr,path=%s"
1368 " -tpmdev emulator,id=dev,chardev=chr"
1369 " -device tpm-%s,tpmdev=dev",
1370 test
.addr
->u
.q_unix
.path
, tpm_if
);
1372 test_acpi_one(args
, &data
);
1374 g_thread_join(thread
);
1375 g_unlink(test
.addr
->u
.q_unix
.path
);
1376 qapi_free_SocketAddress(test
.addr
);
1380 g_free(tmp_dir_name
);
1382 free_test_data(&data
);
1385 static void test_acpi_q35_tcg_tpm2_tis(void)
1387 test_acpi_tcg_tpm("q35", "tis", 0xFED40000, TPM_VERSION_2_0
);
1390 static void test_acpi_q35_tcg_tpm12_tis(void)
1392 test_acpi_tcg_tpm("q35", "tis", 0xFED40000, TPM_VERSION_1_2
);
1395 static void test_acpi_tcg_dimm_pxm(const char *machine
)
1399 memset(&data
, 0, sizeof(data
));
1400 data
.machine
= machine
;
1401 data
.variant
= ".dimmpxm";
1402 test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu"
1404 " -m 128M,slots=3,maxmem=1G"
1405 " -object memory-backend-ram,id=ram0,size=32M"
1406 " -object memory-backend-ram,id=ram1,size=32M"
1407 " -object memory-backend-ram,id=ram2,size=32M"
1408 " -object memory-backend-ram,id=ram3,size=32M"
1409 " -numa node,memdev=ram0,nodeid=0"
1410 " -numa node,memdev=ram1,nodeid=1"
1411 " -numa node,memdev=ram2,nodeid=2"
1412 " -numa node,memdev=ram3,nodeid=3"
1413 " -numa cpu,node-id=0,socket-id=0"
1414 " -numa cpu,node-id=1,socket-id=1"
1415 " -numa cpu,node-id=2,socket-id=2"
1416 " -numa cpu,node-id=3,socket-id=3"
1417 " -object memory-backend-ram,id=ram4,size=128M"
1418 " -object memory-backend-ram,id=nvm0,size=128M"
1419 " -device pc-dimm,id=dimm0,memdev=ram4,node=1"
1420 " -device nvdimm,id=dimm1,memdev=nvm0,node=2",
1422 free_test_data(&data
);
1425 static void test_acpi_q35_tcg_dimm_pxm(void)
1427 test_acpi_tcg_dimm_pxm(MACHINE_Q35
);
1430 static void test_acpi_piix4_tcg_dimm_pxm(void)
1432 test_acpi_tcg_dimm_pxm(MACHINE_PC
);
1435 static void test_acpi_virt_tcg_memhp(void)
1440 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
1441 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
1442 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1443 .ram_start
= 0x40000000ULL
,
1444 .scan_len
= 256ULL * 1024 * 1024,
1447 data
.variant
= ".memhp";
1448 test_acpi_one(" -machine nvdimm=on"
1450 " -m 256M,slots=3,maxmem=1G"
1451 " -object memory-backend-ram,id=ram0,size=128M"
1452 " -object memory-backend-ram,id=ram1,size=128M"
1453 " -numa node,memdev=ram0 -numa node,memdev=ram1"
1454 " -numa dist,src=0,dst=1,val=21"
1455 " -object memory-backend-ram,id=ram2,size=128M"
1456 " -object memory-backend-ram,id=nvm0,size=128M"
1457 " -device pc-dimm,id=dimm0,memdev=ram2,node=0"
1458 " -device nvdimm,id=dimm1,memdev=nvm0,node=1",
1461 free_test_data(&data
);
1465 static void test_acpi_microvm_prepare(test_data
*data
)
1467 memset(data
, 0, sizeof(*data
));
1468 data
->machine
= "microvm";
1469 data
->required_struct_types
= NULL
; /* no smbios */
1470 data
->required_struct_types_len
= 0;
1471 data
->blkdev
= "virtio-blk-device";
1474 static void test_acpi_microvm_tcg(void)
1478 test_acpi_microvm_prepare(&data
);
1479 test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=off",
1481 free_test_data(&data
);
1484 static void test_acpi_microvm_usb_tcg(void)
1488 test_acpi_microvm_prepare(&data
);
1489 data
.variant
= ".usb";
1490 test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,usb=on,rtc=off",
1492 free_test_data(&data
);
1495 static void test_acpi_microvm_rtc_tcg(void)
1499 test_acpi_microvm_prepare(&data
);
1500 data
.variant
= ".rtc";
1501 test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=on",
1503 free_test_data(&data
);
1506 static void test_acpi_microvm_pcie_tcg(void)
1510 test_acpi_microvm_prepare(&data
);
1511 data
.variant
= ".pcie";
1512 data
.tcg_only
= true; /* need constant host-phys-bits */
1513 test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=off,pcie=on",
1515 free_test_data(&data
);
1518 static void test_acpi_microvm_ioapic2_tcg(void)
1522 test_acpi_microvm_prepare(&data
);
1523 data
.variant
= ".ioapic2";
1524 test_acpi_one(" -machine microvm,acpi=on,ioapic2=on,rtc=off",
1526 free_test_data(&data
);
1529 static void test_acpi_virt_tcg_numamem(void)
1534 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
1535 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
1536 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1537 .ram_start
= 0x40000000ULL
,
1538 .scan_len
= 128ULL * 1024 * 1024,
1541 data
.variant
= ".numamem";
1542 test_acpi_one(" -cpu cortex-a57"
1543 " -object memory-backend-ram,id=ram0,size=128M"
1544 " -numa node,memdev=ram0",
1547 free_test_data(&data
);
1551 static void test_acpi_virt_tcg_pxb(void)
1556 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
1557 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
1558 .ram_start
= 0x40000000ULL
,
1559 .scan_len
= 128ULL * 1024 * 1024,
1562 * While using -cdrom, the cdrom would auto plugged into pxb-pcie,
1563 * the reason is the bus of pxb-pcie is also root bus, it would lead
1564 * to the error only PCI/PCIE bridge could plug onto pxb.
1565 * Therefore,thr cdrom is defined and plugged onto the scsi controller
1566 * to solve the conflicts.
1568 data
.variant
= ".pxb";
1569 test_acpi_one(" -device pcie-root-port,chassis=1,id=pci.1"
1570 " -device virtio-scsi-pci,id=scsi0,bus=pci.1"
1572 "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2,"
1573 "if=none,media=cdrom,id=drive-scsi0-0-0-1,readonly=on"
1574 " -device scsi-cd,bus=scsi0.0,scsi-id=0,"
1575 "drive=drive-scsi0-0-0-1,id=scsi0-0-0-1,bootindex=1"
1577 " -device pxb-pcie,bus_nr=128",
1580 free_test_data(&data
);
1583 static void test_acpi_tcg_acpi_hmat(const char *machine
)
1587 memset(&data
, 0, sizeof(data
));
1588 data
.machine
= machine
;
1589 data
.variant
= ".acpihmat";
1590 test_acpi_one(" -machine hmat=on"
1592 " -m 128M,slots=2,maxmem=1G"
1593 " -object memory-backend-ram,size=64M,id=m0"
1594 " -object memory-backend-ram,size=64M,id=m1"
1595 " -numa node,nodeid=0,memdev=m0"
1596 " -numa node,nodeid=1,memdev=m1,initiator=0"
1597 " -numa cpu,node-id=0,socket-id=0"
1598 " -numa cpu,node-id=0,socket-id=1"
1599 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1600 "data-type=access-latency,latency=1"
1601 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1602 "data-type=access-bandwidth,bandwidth=65534M"
1603 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1604 "data-type=access-latency,latency=65534"
1605 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1606 "data-type=access-bandwidth,bandwidth=32767M"
1607 " -numa hmat-cache,node-id=0,size=10K,level=1,"
1608 "associativity=direct,policy=write-back,line=8"
1609 " -numa hmat-cache,node-id=1,size=10K,level=1,"
1610 "associativity=direct,policy=write-back,line=8",
1612 free_test_data(&data
);
1615 static void test_acpi_q35_tcg_acpi_hmat(void)
1617 test_acpi_tcg_acpi_hmat(MACHINE_Q35
);
1620 static void test_acpi_piix4_tcg_acpi_hmat(void)
1622 test_acpi_tcg_acpi_hmat(MACHINE_PC
);
1625 static void test_acpi_virt_tcg_acpi_hmat(void)
1630 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
1631 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
1632 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1633 .ram_start
= 0x40000000ULL
,
1634 .scan_len
= 128ULL * 1024 * 1024,
1637 data
.variant
= ".acpihmatvirt";
1639 test_acpi_one(" -machine hmat=on"
1643 " -object memory-backend-ram,size=64M,id=ram0"
1644 " -object memory-backend-ram,size=64M,id=ram1"
1645 " -object memory-backend-ram,size=128M,id=ram2"
1646 " -numa node,nodeid=0,memdev=ram0"
1647 " -numa node,nodeid=1,memdev=ram1"
1648 " -numa node,nodeid=2,memdev=ram2"
1649 " -numa cpu,node-id=0,socket-id=0"
1650 " -numa cpu,node-id=0,socket-id=0"
1651 " -numa cpu,node-id=1,socket-id=1"
1652 " -numa cpu,node-id=1,socket-id=1"
1653 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1654 "data-type=access-latency,latency=10"
1655 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1656 "data-type=access-bandwidth,bandwidth=10485760"
1657 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1658 "data-type=access-latency,latency=20"
1659 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1660 "data-type=access-bandwidth,bandwidth=5242880"
1661 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1662 "data-type=access-latency,latency=30"
1663 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1664 "data-type=access-bandwidth,bandwidth=1048576"
1665 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1666 "data-type=access-latency,latency=20"
1667 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1668 "data-type=access-bandwidth,bandwidth=5242880"
1669 " -numa hmat-lb,initiator=1,target=1,hierarchy=memory,"
1670 "data-type=access-latency,latency=10"
1671 " -numa hmat-lb,initiator=1,target=1,hierarchy=memory,"
1672 "data-type=access-bandwidth,bandwidth=10485760"
1673 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1674 "data-type=access-latency,latency=30"
1675 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1676 "data-type=access-bandwidth,bandwidth=1048576",
1679 free_test_data(&data
);
1682 static void test_acpi_q35_tcg_acpi_hmat_noinitiator(void)
1686 memset(&data
, 0, sizeof(data
));
1687 data
.machine
= MACHINE_Q35
;
1688 data
.variant
= ".acpihmat-noinitiator";
1689 test_acpi_one(" -machine hmat=on"
1692 " -object memory-backend-ram,size=32M,id=ram0"
1693 " -object memory-backend-ram,size=32M,id=ram1"
1694 " -object memory-backend-ram,size=64M,id=ram2"
1695 " -numa node,nodeid=0,memdev=ram0"
1696 " -numa node,nodeid=1,memdev=ram1"
1697 " -numa node,nodeid=2,memdev=ram2"
1698 " -numa cpu,node-id=0,socket-id=0"
1699 " -numa cpu,node-id=0,socket-id=0"
1700 " -numa cpu,node-id=1,socket-id=1"
1701 " -numa cpu,node-id=1,socket-id=1"
1702 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1703 "data-type=access-latency,latency=10"
1704 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1705 "data-type=access-bandwidth,bandwidth=10485760"
1706 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1707 "data-type=access-latency,latency=20"
1708 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1709 "data-type=access-bandwidth,bandwidth=5242880"
1710 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1711 "data-type=access-latency,latency=30"
1712 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1713 "data-type=access-bandwidth,bandwidth=1048576"
1714 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1715 "data-type=access-latency,latency=20"
1716 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1717 "data-type=access-bandwidth,bandwidth=5242880"
1718 " -numa hmat-lb,initiator=1,target=1,hierarchy=memory,"
1719 "data-type=access-latency,latency=10"
1720 " -numa hmat-lb,initiator=1,target=1,hierarchy=memory,"
1721 "data-type=access-bandwidth,bandwidth=10485760"
1722 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1723 "data-type=access-latency,latency=30"
1724 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1725 "data-type=access-bandwidth,bandwidth=1048576",
1727 free_test_data(&data
);
1731 static void test_acpi_erst(const char *machine
)
1733 gchar
*tmp_path
= g_dir_make_tmp("qemu-test-erst.XXXXXX", NULL
);
1737 memset(&data
, 0, sizeof(data
));
1738 data
.machine
= machine
;
1739 data
.variant
= ".acpierst";
1740 params
= g_strdup_printf(
1741 " -object memory-backend-file,id=erstnvram,"
1742 "mem-path=%s,size=0x10000,share=on"
1743 " -device acpi-erst,memdev=erstnvram", tmp_path
);
1744 test_acpi_one(params
, &data
);
1745 free_test_data(&data
);
1747 g_assert(g_rmdir(tmp_path
) == 0);
1751 static void test_acpi_piix4_acpi_erst(void)
1753 test_acpi_erst(MACHINE_PC
);
1756 static void test_acpi_q35_acpi_erst(void)
1758 test_acpi_erst(MACHINE_Q35
);
1761 static void test_acpi_microvm_acpi_erst(void)
1763 gchar
*tmp_path
= g_dir_make_tmp("qemu-test-erst.XXXXXX", NULL
);
1767 test_acpi_microvm_prepare(&data
);
1768 data
.variant
= ".pcie";
1769 data
.tcg_only
= true; /* need constant host-phys-bits */
1770 params
= g_strdup_printf(" -machine microvm,"
1771 "acpi=on,ioapic2=off,rtc=off,pcie=on"
1772 " -object memory-backend-file,id=erstnvram,"
1773 "mem-path=%s,size=0x10000,share=on"
1774 " -device acpi-erst,memdev=erstnvram", tmp_path
);
1775 test_acpi_one(params
, &data
);
1777 g_assert(g_rmdir(tmp_path
) == 0);
1779 free_test_data(&data
);
1781 #endif /* CONFIG_POSIX */
1783 static void test_acpi_virt_tcg(void)
1788 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
1789 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
1790 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1791 .ram_start
= 0x40000000ULL
,
1792 .scan_len
= 128ULL * 1024 * 1024,
1795 data
.smbios_cpu_max_speed
= 2900;
1796 data
.smbios_cpu_curr_speed
= 2700;
1797 test_acpi_one("-cpu cortex-a57 "
1798 "-smbios type=4,max-speed=2900,current-speed=2700", &data
);
1799 free_test_data(&data
);
1802 static void test_acpi_virt_tcg_topology(void)
1806 .variant
= ".topology",
1808 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
1809 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
1810 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1811 .ram_start
= 0x40000000ULL
,
1812 .scan_len
= 128ULL * 1024 * 1024,
1815 test_acpi_one("-cpu cortex-a57 "
1816 "-smp sockets=1,clusters=2,cores=2,threads=2", &data
);
1817 free_test_data(&data
);
1820 static void test_acpi_q35_viot(void)
1823 .machine
= MACHINE_Q35
,
1828 * To keep things interesting, two buses bypass the IOMMU.
1829 * VIOT should only describes the other two buses.
1831 test_acpi_one("-machine default_bus_bypass_iommu=on "
1832 "-device virtio-iommu-pci "
1833 "-device pxb-pcie,bus_nr=0x10,id=pcie.100,bus=pcie.0 "
1834 "-device pxb-pcie,bus_nr=0x20,id=pcie.200,bus=pcie.0,bypass_iommu=on "
1835 "-device pxb-pcie,bus_nr=0x30,id=pcie.300,bus=pcie.0",
1837 free_test_data(&data
);
1841 static void test_acpi_q35_cxl(void)
1843 gchar
*tmp_path
= g_dir_make_tmp("qemu-test-cxl.XXXXXX", NULL
);
1847 .machine
= MACHINE_Q35
,
1851 * A complex CXL setup.
1853 params
= g_strdup_printf(" -machine cxl=on"
1854 " -object memory-backend-file,id=cxl-mem1,mem-path=%s,size=256M"
1855 " -object memory-backend-file,id=cxl-mem2,mem-path=%s,size=256M"
1856 " -object memory-backend-file,id=cxl-mem3,mem-path=%s,size=256M"
1857 " -object memory-backend-file,id=cxl-mem4,mem-path=%s,size=256M"
1858 " -object memory-backend-file,id=lsa1,mem-path=%s,size=256M"
1859 " -object memory-backend-file,id=lsa2,mem-path=%s,size=256M"
1860 " -object memory-backend-file,id=lsa3,mem-path=%s,size=256M"
1861 " -object memory-backend-file,id=lsa4,mem-path=%s,size=256M"
1862 " -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1"
1863 " -device pxb-cxl,bus_nr=222,bus=pcie.0,id=cxl.2"
1864 " -device cxl-rp,port=0,bus=cxl.1,id=rp1,chassis=0,slot=2"
1865 " -device cxl-type3,bus=rp1,memdev=cxl-mem1,lsa=lsa1"
1866 " -device cxl-rp,port=1,bus=cxl.1,id=rp2,chassis=0,slot=3"
1867 " -device cxl-type3,bus=rp2,memdev=cxl-mem2,lsa=lsa2"
1868 " -device cxl-rp,port=0,bus=cxl.2,id=rp3,chassis=0,slot=5"
1869 " -device cxl-type3,bus=rp3,memdev=cxl-mem3,lsa=lsa3"
1870 " -device cxl-rp,port=1,bus=cxl.2,id=rp4,chassis=0,slot=6"
1871 " -device cxl-type3,bus=rp4,memdev=cxl-mem4,lsa=lsa4"
1872 " -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=8k,"
1873 "cxl-fmw.1.targets.0=cxl.1,cxl-fmw.1.targets.1=cxl.2,cxl-fmw.1.size=4G,cxl-fmw.1.interleave-granularity=8k",
1874 tmp_path
, tmp_path
, tmp_path
, tmp_path
,
1875 tmp_path
, tmp_path
, tmp_path
, tmp_path
);
1876 test_acpi_one(params
, &data
);
1879 g_assert(g_rmdir(tmp_path
) == 0);
1881 free_test_data(&data
);
1883 #endif /* CONFIG_POSIX */
1885 static void test_acpi_virt_viot(void)
1890 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
1891 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
1892 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1893 .ram_start
= 0x40000000ULL
,
1894 .scan_len
= 128ULL * 1024 * 1024,
1897 test_acpi_one("-cpu cortex-a57 "
1898 "-device virtio-iommu-pci", &data
);
1899 free_test_data(&data
);
1903 # define DEV_NULL "/dev/null"
1905 # define DEV_NULL "nul"
1908 static void test_acpi_q35_slic(void)
1911 .machine
= MACHINE_Q35
,
1915 test_acpi_one("-acpitable sig=SLIC,oem_id=\"CRASH \",oem_table_id=ME,"
1916 "oem_rev=00002210,asl_compiler_id=qemu,"
1917 "asl_compiler_rev=00000000,data=" DEV_NULL
,
1919 free_test_data(&data
);
1922 static void test_acpi_q35_applesmc(void)
1925 .machine
= MACHINE_Q35
,
1926 .variant
= ".applesmc",
1929 /* supply fake 64-byte OSK to silence missing key warning */
1930 test_acpi_one("-device isa-applesmc,osk=any64characterfakeoskisenough"
1931 "topreventinvalidkeywarningsonstderr", &data
);
1932 free_test_data(&data
);
1935 static void test_acpi_q35_pvpanic_isa(void)
1938 .machine
= MACHINE_Q35
,
1939 .variant
= ".pvpanic-isa",
1942 test_acpi_one("-device pvpanic", &data
);
1943 free_test_data(&data
);
1946 static void test_oem_fields(test_data
*data
)
1950 for (i
= 0; i
< data
->tables
->len
; ++i
) {
1953 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
1954 /* FACS doesn't have OEMID and OEMTABLEID fields */
1955 if (compare_signature(sdt
, "FACS")) {
1959 g_assert(strncmp((char *)sdt
->aml
+ 10, OEM_ID
, 6) == 0);
1960 g_assert(strncmp((char *)sdt
->aml
+ 16, OEM_TABLE_ID
, 8) == 0);
1964 static void test_acpi_piix4_oem_fields(void)
1969 memset(&data
, 0, sizeof(data
));
1970 data
.machine
= MACHINE_PC
;
1971 data
.required_struct_types
= base_required_struct_types
;
1972 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
1974 args
= test_acpi_create_args(&data
, OEM_TEST_ARGS
);
1975 data
.qts
= qtest_init(args
);
1976 test_acpi_load_tables(&data
);
1977 test_oem_fields(&data
);
1978 qtest_quit(data
.qts
);
1979 free_test_data(&data
);
1983 static void test_acpi_q35_oem_fields(void)
1988 memset(&data
, 0, sizeof(data
));
1989 data
.machine
= MACHINE_Q35
;
1990 data
.required_struct_types
= base_required_struct_types
;
1991 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
1993 args
= test_acpi_create_args(&data
, OEM_TEST_ARGS
);
1994 data
.qts
= qtest_init(args
);
1995 test_acpi_load_tables(&data
);
1996 test_oem_fields(&data
);
1997 qtest_quit(data
.qts
);
1998 free_test_data(&data
);
2002 static void test_acpi_microvm_oem_fields(void)
2007 test_acpi_microvm_prepare(&data
);
2009 args
= test_acpi_create_args(&data
,
2010 OEM_TEST_ARGS
",acpi=on");
2011 data
.qts
= qtest_init(args
);
2012 test_acpi_load_tables(&data
);
2013 test_oem_fields(&data
);
2014 qtest_quit(data
.qts
);
2015 free_test_data(&data
);
2019 static void test_acpi_virt_oem_fields(void)
2024 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
2025 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
2026 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
2027 .ram_start
= 0x40000000ULL
,
2028 .scan_len
= 128ULL * 1024 * 1024,
2032 args
= test_acpi_create_args(&data
, "-cpu cortex-a57 "OEM_TEST_ARGS
);
2033 data
.qts
= qtest_init(args
);
2034 test_acpi_load_tables(&data
);
2035 test_oem_fields(&data
);
2036 qtest_quit(data
.qts
);
2037 free_test_data(&data
);
2042 int main(int argc
, char *argv
[])
2044 const char *arch
= qtest_get_arch();
2045 const bool has_kvm
= qtest_has_accel("kvm");
2046 const bool has_tcg
= qtest_has_accel("tcg");
2047 char *v_env
= getenv("V");
2051 verbosity_level
= atoi(v_env
);
2054 g_test_init(&argc
, &argv
, NULL
);
2056 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
2057 ret
= boot_sector_init(disk
);
2061 if (qtest_has_machine(MACHINE_PC
)) {
2062 qtest_add_func("acpi/piix4", test_acpi_piix4_tcg
);
2063 qtest_add_func("acpi/piix4/oem-fields", test_acpi_piix4_oem_fields
);
2064 qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge
);
2065 qtest_add_func("acpi/piix4/pci-hotplug/no_root_hotplug",
2066 test_acpi_piix4_no_root_hotplug
);
2067 qtest_add_func("acpi/piix4/pci-hotplug/no_bridge_hotplug",
2068 test_acpi_piix4_no_bridge_hotplug
);
2069 qtest_add_func("acpi/piix4/pci-hotplug/off",
2070 test_acpi_piix4_no_acpi_pci_hotplug
);
2071 qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi
);
2072 qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp
);
2073 qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp
);
2074 qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem
);
2075 qtest_add_func("acpi/piix4/nosmm", test_acpi_piix4_tcg_nosmm
);
2076 qtest_add_func("acpi/piix4/smm-compat",
2077 test_acpi_piix4_tcg_smm_compat
);
2078 qtest_add_func("acpi/piix4/smm-compat-nosmm",
2079 test_acpi_piix4_tcg_smm_compat_nosmm
);
2080 qtest_add_func("acpi/piix4/nohpet", test_acpi_piix4_tcg_nohpet
);
2081 qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm
);
2082 qtest_add_func("acpi/piix4/acpihmat",
2083 test_acpi_piix4_tcg_acpi_hmat
);
2085 qtest_add_func("acpi/piix4/acpierst", test_acpi_piix4_acpi_erst
);
2088 if (qtest_has_machine(MACHINE_Q35
)) {
2089 qtest_add_func("acpi/q35", test_acpi_q35_tcg
);
2090 qtest_add_func("acpi/q35/oem-fields", test_acpi_q35_oem_fields
);
2091 if (tpm_model_is_available("-machine q35", "tpm-tis")) {
2092 qtest_add_func("acpi/q35/tpm2-tis", test_acpi_q35_tcg_tpm2_tis
);
2093 qtest_add_func("acpi/q35/tpm12-tis",
2094 test_acpi_q35_tcg_tpm12_tis
);
2096 qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge
);
2097 qtest_add_func("acpi/q35/multif-bridge",
2098 test_acpi_q35_multif_bridge
);
2099 qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64
);
2100 qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi
);
2101 qtest_add_func("acpi/q35/smbus/ipmi", test_acpi_q35_tcg_smbus_ipmi
);
2102 qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp
);
2103 qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp
);
2104 qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem
);
2105 qtest_add_func("acpi/q35/nosmm", test_acpi_q35_tcg_nosmm
);
2106 qtest_add_func("acpi/q35/smm-compat",
2107 test_acpi_q35_tcg_smm_compat
);
2108 qtest_add_func("acpi/q35/smm-compat-nosmm",
2109 test_acpi_q35_tcg_smm_compat_nosmm
);
2110 qtest_add_func("acpi/q35/nohpet", test_acpi_q35_tcg_nohpet
);
2111 qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm
);
2112 qtest_add_func("acpi/q35/acpihmat", test_acpi_q35_tcg_acpi_hmat
);
2113 qtest_add_func("acpi/q35/acpihmat-noinitiator",
2114 test_acpi_q35_tcg_acpi_hmat_noinitiator
);
2116 qtest_add_func("acpi/q35/acpierst", test_acpi_q35_acpi_erst
);
2118 qtest_add_func("acpi/q35/applesmc", test_acpi_q35_applesmc
);
2119 qtest_add_func("acpi/q35/pvpanic-isa", test_acpi_q35_pvpanic_isa
);
2121 qtest_add_func("acpi/q35/ivrs", test_acpi_q35_tcg_ivrs
);
2124 qtest_add_func("acpi/q35/kvm/xapic", test_acpi_q35_kvm_xapic
);
2125 qtest_add_func("acpi/q35/kvm/dmar", test_acpi_q35_kvm_dmar
);
2126 qtest_add_func("acpi/q35/core-count2",
2127 test_acpi_q35_tcg_core_count2
);
2129 qtest_add_func("acpi/q35/viot", test_acpi_q35_viot
);
2131 qtest_add_func("acpi/q35/cxl", test_acpi_q35_cxl
);
2133 qtest_add_func("acpi/q35/slic", test_acpi_q35_slic
);
2135 if (qtest_has_machine("microvm")) {
2136 qtest_add_func("acpi/microvm", test_acpi_microvm_tcg
);
2137 qtest_add_func("acpi/microvm/usb", test_acpi_microvm_usb_tcg
);
2138 qtest_add_func("acpi/microvm/rtc", test_acpi_microvm_rtc_tcg
);
2139 qtest_add_func("acpi/microvm/ioapic2",
2140 test_acpi_microvm_ioapic2_tcg
);
2141 qtest_add_func("acpi/microvm/oem-fields",
2142 test_acpi_microvm_oem_fields
);
2144 if (strcmp(arch
, "x86_64") == 0) {
2145 qtest_add_func("acpi/microvm/pcie",
2146 test_acpi_microvm_pcie_tcg
);
2148 qtest_add_func("acpi/microvm/acpierst",
2149 test_acpi_microvm_acpi_erst
);
2154 } else if (strcmp(arch
, "aarch64") == 0) {
2156 qtest_add_func("acpi/virt", test_acpi_virt_tcg
);
2157 qtest_add_func("acpi/virt/acpihmatvirt",
2158 test_acpi_virt_tcg_acpi_hmat
);
2159 qtest_add_func("acpi/virt/topology", test_acpi_virt_tcg_topology
);
2160 qtest_add_func("acpi/virt/numamem", test_acpi_virt_tcg_numamem
);
2161 qtest_add_func("acpi/virt/memhp", test_acpi_virt_tcg_memhp
);
2162 qtest_add_func("acpi/virt/pxb", test_acpi_virt_tcg_pxb
);
2163 qtest_add_func("acpi/virt/oem-fields", test_acpi_virt_oem_fields
);
2164 qtest_add_func("acpi/virt/viot", test_acpi_virt_viot
);
2168 boot_sector_cleanup(disk
);