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 * between 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=" \
82 const char *machine_param
;
88 const uint64_t ram_start
;
89 const uint64_t scan_len
;
91 uint8_t rsdp_table
[36 /* ACPI 2.0+ RSDP size */];
93 uint64_t smbios_ep_addr
[SMBIOS_ENTRY_POINT_TYPE__MAX
];
94 SmbiosEntryPoint smbios_ep_table
;
95 uint16_t smbios_cpu_max_speed
;
96 uint16_t smbios_cpu_curr_speed
;
97 uint8_t smbios_core_count
;
98 uint16_t smbios_core_count2
;
99 uint8_t smbios_thread_count
;
100 uint16_t smbios_thread_count2
;
101 uint8_t *required_struct_types
;
102 int required_struct_types_len
;
107 static char disk
[] = "tests/acpi-test-disk-XXXXXX";
108 static const char *data_dir
= "tests/data/acpi";
110 static const char *iasl
= CONFIG_IASL
;
112 static const char *iasl
;
115 static int verbosity_level
;
116 static GArray
*load_expected_aml(test_data
*data
);
118 static bool compare_signature(const AcpiSdtTable
*sdt
, const char *signature
)
120 return !memcmp(sdt
->aml
, signature
, 4);
123 static void cleanup_table_descriptor(AcpiSdtTable
*table
)
126 if (table
->aml_file
&&
127 !table
->tmp_files_retain
&&
128 g_strstr_len(table
->aml_file
, -1, "aml-")) {
129 unlink(table
->aml_file
);
131 g_free(table
->aml_file
);
133 if (table
->asl_file
&&
134 !table
->tmp_files_retain
) {
135 unlink(table
->asl_file
);
137 g_free(table
->asl_file
);
140 static void free_test_data(test_data
*data
)
147 for (i
= 0; i
< data
->tables
->len
; ++i
) {
148 cleanup_table_descriptor(&g_array_index(data
->tables
, AcpiSdtTable
, i
));
151 g_array_free(data
->tables
, true);
154 static void test_acpi_rsdp_table(test_data
*data
)
156 uint8_t *rsdp_table
= data
->rsdp_table
;
158 acpi_fetch_rsdp_table(data
->qts
, data
->rsdp_addr
, rsdp_table
);
160 switch (rsdp_table
[15 /* Revision offset */]) {
161 case 0: /* ACPI 1.0 RSDP */
162 /* With rev 1, checksum is only for the first 20 bytes */
163 g_assert(!acpi_calc_checksum(rsdp_table
, 20));
165 case 2: /* ACPI 2.0+ RSDP */
166 /* With revision 2, we have 2 checksums */
167 g_assert(!acpi_calc_checksum(rsdp_table
, 20));
168 g_assert(!acpi_calc_checksum(rsdp_table
, 36));
171 g_assert_not_reached();
175 static void test_acpi_rxsdt_table(test_data
*data
)
177 const char *sig
= "RSDT";
178 AcpiSdtTable rsdt
= {};
180 int addr_off
= 16 /* RsdtAddress */;
183 if (data
->rsdp_table
[15 /* Revision offset */] != 0) {
184 addr_off
= 24 /* XsdtAddress */;
188 /* read [RX]SDT table */
189 acpi_fetch_table(data
->qts
, &rsdt
.aml
, &rsdt
.aml_len
,
190 &data
->rsdp_table
[addr_off
], entry_size
, sig
, true);
192 /* Load all tables and add to test list directly RSDT referenced tables */
193 ACPI_FOREACH_RSDT_ENTRY(rsdt
.aml
, rsdt
.aml_len
, ent
, entry_size
) {
194 AcpiSdtTable ssdt_table
= {};
196 acpi_fetch_table(data
->qts
, &ssdt_table
.aml
, &ssdt_table
.aml_len
, ent
,
197 entry_size
, NULL
, true);
198 /* Add table to ASL test tables list */
199 g_array_append_val(data
->tables
, ssdt_table
);
201 cleanup_table_descriptor(&rsdt
);
204 static void test_acpi_fadt_table(test_data
*data
)
206 /* FADT table is 1st */
207 AcpiSdtTable table
= g_array_index(data
->tables
, typeof(table
), 0);
208 uint8_t *fadt_aml
= table
.aml
;
209 uint32_t fadt_len
= table
.aml_len
;
211 int dsdt_offset
= 40 /* DSDT */;
212 int dsdt_entry_size
= 4;
214 g_assert(compare_signature(&table
, "FACP"));
216 /* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */
217 memcpy(&val
, fadt_aml
+ 112 /* Flags */, 4);
218 val
= le32_to_cpu(val
);
219 if (!(val
& 1UL << 20 /* HW_REDUCED_ACPI */)) {
220 acpi_fetch_table(data
->qts
, &table
.aml
, &table
.aml_len
,
221 fadt_aml
+ 36 /* FIRMWARE_CTRL */, 4, "FACS", false);
222 g_array_append_val(data
->tables
, table
);
225 memcpy(&val
, fadt_aml
+ dsdt_offset
, 4);
226 val
= le32_to_cpu(val
);
228 dsdt_offset
= 140 /* X_DSDT */;
231 acpi_fetch_table(data
->qts
, &table
.aml
, &table
.aml_len
,
232 fadt_aml
+ dsdt_offset
, dsdt_entry_size
, "DSDT", true);
233 g_array_append_val(data
->tables
, table
);
235 memset(fadt_aml
+ 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */
236 memset(fadt_aml
+ 40, 0, 4); /* sanitize DSDT ptr */
237 if (fadt_aml
[8 /* FADT Major Version */] >= 3) {
238 memset(fadt_aml
+ 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr */
239 memset(fadt_aml
+ 140, 0, 8); /* sanitize X_DSDT ptr */
242 /* update checksum */
243 fadt_aml
[9 /* Checksum */] = 0;
244 fadt_aml
[9 /* Checksum */] -= acpi_calc_checksum(fadt_aml
, fadt_len
);
247 static void dump_aml_files(test_data
*data
, bool rebuild
)
249 AcpiSdtTable
*sdt
, *exp_sdt
;
250 GError
*error
= NULL
;
251 gchar
*aml_file
= NULL
;
252 test_data exp_data
= {};
257 exp_data
.tables
= load_expected_aml(data
);
258 for (i
= 0; i
< data
->tables
->len
; ++i
) {
259 const char *ext
= data
->variant
? data
->variant
: "";
260 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
261 exp_sdt
= &g_array_index(exp_data
.tables
, AcpiSdtTable
, i
);
263 g_assert(exp_sdt
->aml
);
266 aml_file
= g_strdup_printf("%s/%s/%s/%.4s%s", data_dir
,
267 data
->arch
, data
->machine
,
271 * To keep test cases not failing before the DATA files are moved to
272 * ${arch}/${machine} folder, add this check as well.
274 if (!g_file_test(aml_file
, G_FILE_TEST_EXISTS
)) {
275 aml_file
= g_strdup_printf("%s/%s/%.4s%s", data_dir
,
276 data
->machine
, sdt
->aml
, ext
);
279 if (!g_file_test(aml_file
, G_FILE_TEST_EXISTS
) &&
280 sdt
->aml_len
== exp_sdt
->aml_len
&&
281 !memcmp(sdt
->aml
, exp_sdt
->aml
, sdt
->aml_len
)) {
282 /* identical tables, no need to write new files */
286 fd
= g_open(aml_file
, O_WRONLY
|O_TRUNC
|O_CREAT
,
287 S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IWGRP
|S_IROTH
);
293 fd
= g_file_open_tmp("aml-XXXXXX", &sdt
->aml_file
, &error
);
294 g_assert_no_error(error
);
297 ret
= qemu_write_full(fd
, sdt
->aml
, sdt
->aml_len
);
298 g_assert(ret
== sdt
->aml_len
);
306 static bool create_tmp_asl(AcpiSdtTable
*sdt
)
308 GError
*error
= NULL
;
311 fd
= g_file_open_tmp("asl-XXXXXX.dsl", &sdt
->asl_file
, &error
);
312 g_assert_no_error(error
);
318 static bool load_asl(GArray
*sdts
, AcpiSdtTable
*sdt
)
321 GError
*error
= NULL
;
322 GString
*command_line
= g_string_new(iasl
);
323 gchar
*out
, *out_err
;
329 /* build command line */
330 g_string_append_printf(command_line
, " -p %s ", sdt
->asl_file
);
331 if (compare_signature(sdt
, "DSDT") ||
332 compare_signature(sdt
, "SSDT")) {
333 for (i
= 0; i
< sdts
->len
; ++i
) {
334 temp
= &g_array_index(sdts
, AcpiSdtTable
, i
);
335 if (compare_signature(temp
, "DSDT") ||
336 compare_signature(temp
, "SSDT")) {
337 g_string_append_printf(command_line
, "-e %s ", temp
->aml_file
);
341 g_string_append_printf(command_line
, "-d %s", sdt
->aml_file
);
343 /* pass 'out' and 'out_err' in order to be redirected */
344 ret
= g_spawn_command_line_sync(command_line
->str
, &out
, &out_err
, NULL
, &error
);
345 g_assert_no_error(error
);
347 ret
= g_file_get_contents(sdt
->asl_file
, &sdt
->asl
,
348 &sdt
->asl_len
, &error
);
350 g_assert_no_error(error
);
351 ret
= (sdt
->asl_len
> 0);
356 g_string_free(command_line
, true);
361 #define COMMENT_END "*/"
362 #define DEF_BLOCK "DefinitionBlock ("
363 #define BLOCK_NAME_END ","
365 static GString
*normalize_asl(gchar
*asl_code
)
367 GString
*asl
= g_string_new(asl_code
);
368 gchar
*comment
, *block_name
;
370 /* strip comments (different generation days) */
371 comment
= g_strstr_len(asl
->str
, asl
->len
, COMMENT_END
);
373 comment
+= strlen(COMMENT_END
);
374 while (*comment
== '\n') {
377 asl
= g_string_erase(asl
, 0, comment
- asl
->str
);
380 /* strip def block name (it has file path in it) */
381 if (g_str_has_prefix(asl
->str
, DEF_BLOCK
)) {
382 block_name
= g_strstr_len(asl
->str
, asl
->len
, BLOCK_NAME_END
);
383 g_assert(block_name
);
384 asl
= g_string_erase(asl
, 0,
385 block_name
+ sizeof(BLOCK_NAME_END
) - asl
->str
);
391 static GArray
*load_expected_aml(test_data
*data
)
395 GError
*error
= NULL
;
399 GArray
*exp_tables
= g_array_new(false, true, sizeof(AcpiSdtTable
));
400 if (verbosity_level
>= 2) {
403 for (i
= 0; i
< data
->tables
->len
; ++i
) {
404 AcpiSdtTable exp_sdt
;
405 gchar
*aml_file
= NULL
;
406 const char *ext
= data
->variant
? data
->variant
: "";
408 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
410 memset(&exp_sdt
, 0, sizeof(exp_sdt
));
413 aml_file
= g_strdup_printf("%s/%s/%s/%.4s%s", data_dir
, data
->arch
,
414 data
->machine
, sdt
->aml
, ext
);
415 if (!g_file_test(aml_file
, G_FILE_TEST_EXISTS
)) {
416 aml_file
= g_strdup_printf("%s/%s/%.4s%s", data_dir
, data
->machine
,
420 if (verbosity_level
>= 2) {
421 fprintf(stderr
, "Looking for expected file '%s'\n", aml_file
);
423 if (g_file_test(aml_file
, G_FILE_TEST_EXISTS
)) {
424 exp_sdt
.aml_file
= aml_file
;
425 } else if (*ext
!= '\0') {
426 /* try fallback to generic (extension less) expected file */
431 g_assert(exp_sdt
.aml_file
);
432 if (verbosity_level
>= 2) {
433 fprintf(stderr
, "Using expected file '%s'\n", aml_file
);
435 ret
= g_file_get_contents(aml_file
, (gchar
**)&exp_sdt
.aml
,
437 exp_sdt
.aml_len
= aml_len
;
439 g_assert_no_error(error
);
440 g_assert(exp_sdt
.aml
);
441 if (!exp_sdt
.aml_len
) {
442 fprintf(stderr
, "Warning! zero length expected file '%s'\n",
446 g_array_append_val(exp_tables
, exp_sdt
);
452 static bool test_acpi_find_diff_allowed(AcpiSdtTable
*sdt
)
454 const gchar
*allowed_diff_file
[] = {
455 #include "bios-tables-test-allowed-diff.h"
460 for (f
= allowed_diff_file
; *f
; ++f
) {
461 if (!g_strcmp0(sdt
->aml_file
, *f
)) {
468 /* test the list of tables in @data->tables against reference tables */
469 static void test_acpi_asl(test_data
*data
)
472 AcpiSdtTable
*sdt
, *exp_sdt
;
473 test_data exp_data
= {};
474 gboolean exp_err
, err
, all_tables_match
= true;
476 exp_data
.tables
= load_expected_aml(data
);
477 dump_aml_files(data
, false);
478 for (i
= 0; i
< data
->tables
->len
; ++i
) {
479 GString
*asl
, *exp_asl
;
481 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
482 exp_sdt
= &g_array_index(exp_data
.tables
, AcpiSdtTable
, i
);
484 if (sdt
->aml_len
== exp_sdt
->aml_len
&&
485 !memcmp(sdt
->aml
, exp_sdt
->aml
, sdt
->aml_len
)) {
486 /* Identical table binaries: no need to disassemble. */
491 "acpi-test: Warning! %.4s binary file mismatch. "
492 "Actual [aml:%s], Expected [aml:%s].\n"
493 "See source file tests/qtest/bios-tables-test.c "
494 "for instructions on how to update expected files.\n",
495 exp_sdt
->aml
, sdt
->aml_file
, exp_sdt
->aml_file
);
497 all_tables_match
= all_tables_match
&&
498 test_acpi_find_diff_allowed(exp_sdt
);
501 * don't try to decompile if IASL isn't present, in this case user
502 * will just 'get binary file mismatch' warnings and test failure
508 err
= load_asl(data
->tables
, sdt
);
509 asl
= normalize_asl(sdt
->asl
);
512 * If expected file is empty - it's likely that it was a stub just
513 * created for step 1 above: we do want to decompile the actual one.
515 if (exp_sdt
->aml_len
) {
516 exp_err
= load_asl(exp_data
.tables
, exp_sdt
);
517 exp_asl
= normalize_asl(exp_sdt
->asl
);
519 exp_err
= create_tmp_asl(exp_sdt
);
520 exp_asl
= g_string_new("");
523 /* TODO: check for warnings */
524 g_assert(!err
|| exp_err
|| !exp_sdt
->aml_len
);
526 if (g_strcmp0(asl
->str
, exp_asl
->str
)) {
527 sdt
->tmp_files_retain
= true;
530 "Warning! iasl couldn't parse the expected aml\n");
532 exp_sdt
->tmp_files_retain
= true;
534 "acpi-test: Warning! %.4s mismatch. "
535 "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
536 exp_sdt
->aml
, sdt
->asl_file
, sdt
->aml_file
,
537 exp_sdt
->asl_file
, exp_sdt
->aml_file
);
539 if (verbosity_level
>= 1) {
540 const char *diff_env
= getenv("DIFF");
541 const char *diff_cmd
= diff_env
? diff_env
: "diff -U 16";
542 char *diff
= g_strdup_printf("%s %s %s", diff_cmd
,
543 exp_sdt
->asl_file
, sdt
->asl_file
);
544 int out
= dup(STDOUT_FILENO
);
545 int ret G_GNUC_UNUSED
;
549 dupret
= dup2(STDERR_FILENO
, STDOUT_FILENO
);
550 g_assert(dupret
>= 0);
552 dupret
= dup2(out
, STDOUT_FILENO
);
553 g_assert(dupret
>= 0);
559 g_string_free(asl
, true);
560 g_string_free(exp_asl
, true);
562 if (!iasl
&& !all_tables_match
) {
563 fprintf(stderr
, "to see ASL diff between mismatched files install IASL,"
564 " rebuild QEMU from scratch and re-run tests with V=1"
565 " environment variable set");
567 g_assert(all_tables_match
);
569 free_test_data(&exp_data
);
572 static bool smbios_ep2_table_ok(test_data
*data
, uint32_t addr
)
574 struct smbios_21_entry_point
*ep_table
= &data
->smbios_ep_table
.ep21
;
576 qtest_memread(data
->qts
, addr
, ep_table
, sizeof(*ep_table
));
577 if (memcmp(ep_table
->anchor_string
, "_SM_", 4)) {
580 if (memcmp(ep_table
->intermediate_anchor_string
, "_DMI_", 5)) {
583 if (ep_table
->structure_table_length
== 0) {
586 if (ep_table
->number_of_structures
== 0) {
589 if (acpi_calc_checksum((uint8_t *)ep_table
, sizeof *ep_table
) ||
590 acpi_calc_checksum((uint8_t *)ep_table
+ 0x10,
591 sizeof *ep_table
- 0x10)) {
597 static bool smbios_ep3_table_ok(test_data
*data
, uint64_t addr
)
599 struct smbios_30_entry_point
*ep_table
= &data
->smbios_ep_table
.ep30
;
601 qtest_memread(data
->qts
, addr
, ep_table
, sizeof(*ep_table
));
602 if (memcmp(ep_table
->anchor_string
, "_SM3_", 5)) {
606 if (acpi_calc_checksum((uint8_t *)ep_table
, sizeof *ep_table
)) {
613 static SmbiosEntryPointType
test_smbios_entry_point(test_data
*data
)
617 /* find smbios entry point structure */
618 for (off
= 0xf0000; off
< 0x100000; off
+= 0x10) {
619 uint8_t sig
[] = "_SM_", sig3
[] = "_SM3_";
622 for (i
= 0; i
< sizeof sig
- 1; ++i
) {
623 sig
[i
] = qtest_readb(data
->qts
, off
+ i
);
626 if (!memcmp(sig
, "_SM_", sizeof sig
)) {
627 /* signature match, but is this a valid entry point? */
628 if (smbios_ep2_table_ok(data
, off
)) {
629 data
->smbios_ep_addr
[SMBIOS_ENTRY_POINT_TYPE_32
] = off
;
633 for (i
= 0; i
< sizeof sig3
- 1; ++i
) {
634 sig3
[i
] = qtest_readb(data
->qts
, off
+ i
);
637 if (!memcmp(sig3
, "_SM3_", sizeof sig3
)) {
638 if (smbios_ep3_table_ok(data
, off
)) {
639 data
->smbios_ep_addr
[SMBIOS_ENTRY_POINT_TYPE_64
] = off
;
640 /* found 64-bit entry point, no need to look for 32-bit one */
646 /* found at least one entry point */
647 g_assert_true(data
->smbios_ep_addr
[SMBIOS_ENTRY_POINT_TYPE_32
] ||
648 data
->smbios_ep_addr
[SMBIOS_ENTRY_POINT_TYPE_64
]);
650 return data
->smbios_ep_addr
[SMBIOS_ENTRY_POINT_TYPE_64
] ?
651 SMBIOS_ENTRY_POINT_TYPE_64
: SMBIOS_ENTRY_POINT_TYPE_32
;
654 static inline bool smbios_single_instance(uint8_t type
)
670 static void smbios_cpu_test(test_data
*data
, uint32_t addr
,
671 SmbiosEntryPointType ep_type
)
673 uint8_t core_count
, expected_core_count
= data
->smbios_core_count
;
674 uint8_t thread_count
, expected_thread_count
= data
->smbios_thread_count
;
675 uint16_t speed
, expected_speed
[2];
676 uint16_t core_count2
, expected_core_count2
= data
->smbios_core_count2
;
677 uint16_t thread_count2
, expected_thread_count2
= data
->smbios_thread_count2
;
681 /* Check CPU speed for backward compatibility */
682 offset
[0] = offsetof(struct smbios_type_4
, max_speed
);
683 offset
[1] = offsetof(struct smbios_type_4
, current_speed
);
684 expected_speed
[0] = data
->smbios_cpu_max_speed
? : 2000;
685 expected_speed
[1] = data
->smbios_cpu_curr_speed
? : 2000;
687 for (i
= 0; i
< 2; i
++) {
688 speed
= qtest_readw(data
->qts
, addr
+ offset
[i
]);
689 g_assert_cmpuint(speed
, ==, expected_speed
[i
]);
692 core_count
= qtest_readb(data
->qts
,
693 addr
+ offsetof(struct smbios_type_4
, core_count
));
695 if (expected_core_count
) {
696 g_assert_cmpuint(core_count
, ==, expected_core_count
);
699 thread_count
= qtest_readb(data
->qts
,
700 addr
+ offsetof(struct smbios_type_4
, thread_count
));
702 if (expected_thread_count
) {
703 g_assert_cmpuint(thread_count
, ==, expected_thread_count
);
706 if (ep_type
== SMBIOS_ENTRY_POINT_TYPE_64
) {
707 core_count2
= qtest_readw(data
->qts
,
708 addr
+ offsetof(struct smbios_type_4
, core_count2
));
710 /* Core Count has reached its limit, checking Core Count 2 */
711 if (expected_core_count
== 0xFF && expected_core_count2
) {
712 g_assert_cmpuint(core_count2
, ==, expected_core_count2
);
715 thread_count2
= qtest_readw(data
->qts
,
716 addr
+ offsetof(struct smbios_type_4
,
719 /* Thread Count has reached its limit, checking Thread Count 2 */
720 if (expected_thread_count
== 0xFF && expected_thread_count2
) {
721 g_assert_cmpuint(thread_count2
, ==, expected_thread_count2
);
726 static void smbios_type4_count_test(test_data
*data
, int type4_count
)
728 int expected_type4_count
= data
->type4_count
;
730 if (expected_type4_count
) {
731 g_assert_cmpuint(type4_count
, ==, expected_type4_count
);
735 static void test_smbios_structs(test_data
*data
, SmbiosEntryPointType ep_type
)
737 DECLARE_BITMAP(struct_bitmap
, SMBIOS_MAX_TYPE
+1) = { 0 };
739 SmbiosEntryPoint
*ep_table
= &data
->smbios_ep_table
;
740 int i
= 0, len
, max_len
= 0, type4_count
= 0;
741 uint8_t type
, prv
, crt
;
744 if (ep_type
== SMBIOS_ENTRY_POINT_TYPE_32
) {
745 addr
= le32_to_cpu(ep_table
->ep21
.structure_table_address
);
747 addr
= le64_to_cpu(ep_table
->ep30
.structure_table_address
);
750 /* walk the smbios tables */
753 /* grab type and formatted area length from struct header */
754 type
= qtest_readb(data
->qts
, addr
);
755 g_assert_cmpuint(type
, <=, SMBIOS_MAX_TYPE
);
756 len
= qtest_readb(data
->qts
, addr
+ 1);
758 /* single-instance structs must not have been encountered before */
759 if (smbios_single_instance(type
)) {
760 g_assert(!test_bit(type
, struct_bitmap
));
762 set_bit(type
, struct_bitmap
);
765 smbios_cpu_test(data
, addr
, ep_type
);
769 /* seek to end of unformatted string area of this struct ("\0\0") */
773 crt
= qtest_readb(data
->qts
, addr
+ len
);
777 /* keep track of max. struct size */
778 if (ep_type
== SMBIOS_ENTRY_POINT_TYPE_32
&& max_len
< len
) {
780 g_assert_cmpuint(max_len
, <=, ep_table
->ep21
.max_structure_size
);
783 /* start of next structure */
787 * Until all structures have been scanned (ep21)
788 * or an EOF structure is found (ep30)
790 } while (ep_type
== SMBIOS_ENTRY_POINT_TYPE_32
?
791 ++i
< le16_to_cpu(ep_table
->ep21
.number_of_structures
) :
794 if (ep_type
== SMBIOS_ENTRY_POINT_TYPE_32
) {
796 * Total table length and max struct size
797 * must match entry point values
799 g_assert_cmpuint(le16_to_cpu(ep_table
->ep21
.structure_table_length
), ==,
800 addr
- le32_to_cpu(ep_table
->ep21
.structure_table_address
));
802 g_assert_cmpuint(le16_to_cpu(ep_table
->ep21
.max_structure_size
), ==,
806 /* required struct types must all be present */
807 for (i
= 0; i
< data
->required_struct_types_len
; i
++) {
808 g_assert(test_bit(data
->required_struct_types
[i
], struct_bitmap
));
811 smbios_type4_count_test(data
, type4_count
);
814 static void test_acpi_load_tables(test_data
*data
)
816 if (data
->uefi_fl1
&& data
->uefi_fl2
) { /* use UEFI */
817 g_assert(data
->scan_len
);
818 data
->rsdp_addr
= acpi_find_rsdp_address_uefi(data
->qts
,
819 data
->ram_start
, data
->scan_len
);
821 boot_sector_test(data
->qts
);
822 data
->rsdp_addr
= acpi_find_rsdp_address(data
->qts
);
823 g_assert_cmphex(data
->rsdp_addr
, <, 0x100000);
826 data
->tables
= g_array_new(false, true, sizeof(AcpiSdtTable
));
827 test_acpi_rsdp_table(data
);
828 test_acpi_rxsdt_table(data
);
829 test_acpi_fadt_table(data
);
832 static char *test_acpi_create_args(test_data
*data
, const char *params
)
836 if (data
->uefi_fl1
&& data
->uefi_fl2
) { /* use UEFI */
838 * TODO: convert '-drive if=pflash' to new syntax (see e33763be7cd3)
839 * when arm/virt boad starts to support it.
842 args
= g_strdup_printf("-machine %s%s %s -accel tcg "
843 "-nodefaults -nographic "
844 "-drive if=pflash,format=raw,file=%s,readonly=on "
845 "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s",
846 data
->machine
, data
->machine_param
?: "",
847 data
->tcg_only
? "" : "-accel kvm",
848 data
->uefi_fl1
, data
->uefi_fl2
, data
->cd
, params
? params
: "");
850 args
= g_strdup_printf("-machine %s%s %s -accel tcg "
851 "-nodefaults -nographic "
852 "-drive if=pflash,format=raw,file=%s,readonly=on "
853 "-drive if=pflash,format=raw,file=%s,snapshot=on %s",
854 data
->machine
, data
->machine_param
?: "",
855 data
->tcg_only
? "" : "-accel kvm",
856 data
->uefi_fl1
, data
->uefi_fl2
, params
? params
: "");
859 args
= g_strdup_printf("-machine %s%s %s -accel tcg "
861 "-drive id=hd0,if=none,file=%s,format=raw "
862 "-device %s,drive=hd0 ",
863 data
->machine
, data
->machine_param
?: "",
864 data
->tcg_only
? "" : "-accel kvm",
865 params
? params
: "", disk
,
866 data
->blkdev
?: "ide-hd");
871 static void test_vm_prepare(const char *params
, test_data
*data
)
873 char *args
= test_acpi_create_args(data
, params
);
874 data
->qts
= qtest_init(args
);
878 static void process_smbios_tables_noexit(test_data
*data
)
881 * TODO: make SMBIOS tests work with UEFI firmware,
882 * Bug on uefi-test-tools to provide entry point:
883 * https://bugs.launchpad.net/qemu/+bug/1821884
885 if (!(data
->uefi_fl1
&& data
->uefi_fl2
)) {
886 SmbiosEntryPointType ep_type
= test_smbios_entry_point(data
);
887 test_smbios_structs(data
, ep_type
);
891 static void test_smbios(const char *params
, test_data
*data
)
893 test_vm_prepare(params
, data
);
894 boot_sector_test(data
->qts
);
895 process_smbios_tables_noexit(data
);
896 qtest_quit(data
->qts
);
899 static void process_acpi_tables_noexit(test_data
*data
)
901 test_acpi_load_tables(data
);
903 if (getenv(ACPI_REBUILD_EXPECTED_AML
)) {
904 dump_aml_files(data
, true);
909 process_smbios_tables_noexit(data
);
912 static void process_acpi_tables(test_data
*data
)
914 process_acpi_tables_noexit(data
);
915 qtest_quit(data
->qts
);
918 static void test_acpi_one(const char *params
, test_data
*data
)
920 test_vm_prepare(params
, data
);
921 process_acpi_tables(data
);
924 static uint8_t base_required_struct_types
[] = {
925 0, 1, 3, 4, 16, 17, 19, 32, 127
928 static void test_acpi_piix4_tcg(void)
932 /* Supplying -machine accel argument overrides the default (qtest).
933 * This is to make guest actually run.
935 data
.machine
= MACHINE_PC
;
937 data
.required_struct_types
= base_required_struct_types
;
938 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
939 test_acpi_one(NULL
, &data
);
940 free_test_data(&data
);
943 static void test_acpi_piix4_tcg_bridge(void)
947 data
.machine
= MACHINE_PC
;
949 data
.variant
= ".bridge";
950 data
.required_struct_types
= base_required_struct_types
;
951 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
953 " -device pci-bridge,chassis_nr=1"
954 " -device pci-bridge,bus=pci.1,addr=1.0,chassis_nr=2"
955 " -device pci-testdev,bus=pci.0,addr=5.0"
956 " -device pci-testdev,bus=pci.1", &data
);
958 /* hotplugged bridges section */
959 qtest_qmp_device_add(data
.qts
, "pci-bridge", "hpbr",
960 "{'bus': 'pci.1', 'addr': '2.0', 'chassis_nr': 3 }");
961 qtest_qmp_device_add(data
.qts
, "pci-bridge", "hpbr_multifunc",
962 "{'bus': 'pci.1', 'addr': '0xf.1', 'chassis_nr': 4 }");
963 qtest_qmp_device_add(data
.qts
, "pci-bridge", "hpbrhost",
964 "{'bus': 'pci.0', 'addr': '4.0', 'chassis_nr': 5 }");
965 qtest_qmp_device_add(data
.qts
, "pci-testdev", "d1", "{'bus': 'pci.0' }");
966 qtest_qmp_device_add(data
.qts
, "pci-testdev", "d2", "{'bus': 'pci.1' }");
967 qtest_qmp_device_add(data
.qts
, "pci-testdev", "d3", "{'bus': 'hpbr', "
969 qtest_qmp_send(data
.qts
, "{'execute':'cont' }");
970 qtest_qmp_eventwait(data
.qts
, "RESUME");
972 process_acpi_tables_noexit(&data
);
973 free_test_data(&data
);
975 /* check that reboot/reset doesn't change any ACPI tables */
976 qtest_qmp_send(data
.qts
, "{'execute':'system_reset' }");
977 process_acpi_tables(&data
);
978 free_test_data(&data
);
981 static void test_acpi_piix4_no_root_hotplug(void)
985 data
.machine
= MACHINE_PC
;
987 data
.variant
= ".roothp";
988 data
.required_struct_types
= base_required_struct_types
;
989 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
990 test_acpi_one("-global PIIX4_PM.acpi-root-pci-hotplug=off "
991 "-device pci-bridge,chassis_nr=1 "
992 "-device pci-bridge,bus=pci.1,addr=1.0,chassis_nr=2 "
993 "-device pci-testdev,bus=pci.0 "
994 "-device pci-testdev,bus=pci.1", &data
);
995 free_test_data(&data
);
998 static void test_acpi_piix4_no_bridge_hotplug(void)
1000 test_data data
= {};
1002 data
.machine
= MACHINE_PC
;
1004 data
.variant
= ".hpbridge";
1005 data
.required_struct_types
= base_required_struct_types
;
1006 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
1007 test_acpi_one("-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off "
1008 "-device pci-bridge,chassis_nr=1 "
1009 "-device pci-bridge,bus=pci.1,addr=1.0,chassis_nr=2 "
1010 "-device pci-testdev,bus=pci.0 "
1011 "-device pci-testdev,bus=pci.1,addr=2.0", &data
);
1012 free_test_data(&data
);
1015 static void test_acpi_piix4_no_acpi_pci_hotplug(void)
1017 test_data data
= {};
1019 data
.machine
= MACHINE_PC
;
1021 data
.variant
= ".hpbrroot";
1022 data
.required_struct_types
= base_required_struct_types
;
1023 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
1024 test_acpi_one("-global PIIX4_PM.acpi-root-pci-hotplug=off "
1025 "-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off "
1026 "-device pci-bridge,chassis_nr=1,addr=4.0 "
1027 "-device pci-testdev,bus=pci.0,addr=5.0 "
1028 "-device pci-testdev,bus=pci.0,addr=6.0,acpi-index=101 "
1029 "-device pci-testdev,bus=pci.1,addr=1.0 "
1030 "-device pci-testdev,bus=pci.1,addr=2.0,acpi-index=201 "
1031 "-device pci-bridge,id=nhpbr,chassis_nr=2,shpc=off,addr=7.0 "
1032 "-device pci-testdev,bus=nhpbr,addr=1.0,acpi-index=301 "
1034 free_test_data(&data
);
1037 static void test_acpi_q35_tcg(void)
1039 test_data data
= {};
1041 data
.machine
= MACHINE_Q35
;
1043 data
.required_struct_types
= base_required_struct_types
;
1044 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
1045 test_acpi_one(NULL
, &data
);
1046 free_test_data(&data
);
1048 data
.smbios_cpu_max_speed
= 3000;
1049 data
.smbios_cpu_curr_speed
= 2600;
1050 test_acpi_one("-smbios type=4,max-speed=3000,current-speed=2600", &data
);
1051 free_test_data(&data
);
1054 static void test_acpi_q35_kvm_type4_count(void)
1057 .machine
= MACHINE_Q35
,
1059 .variant
= ".type4-count",
1060 .required_struct_types
= base_required_struct_types
,
1061 .required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
),
1065 test_acpi_one("-machine smbios-entry-point-type=64 "
1066 "-smp cpus=100,maxcpus=120,sockets=5,"
1067 "dies=2,cores=4,threads=3", &data
);
1068 free_test_data(&data
);
1071 static void test_acpi_q35_kvm_core_count(void)
1074 .machine
= MACHINE_Q35
,
1076 .variant
= ".core-count",
1077 .required_struct_types
= base_required_struct_types
,
1078 .required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
),
1079 .smbios_core_count
= 9,
1080 .smbios_core_count2
= 9,
1083 test_acpi_one("-machine smbios-entry-point-type=64 "
1084 "-smp 54,sockets=2,dies=3,cores=3,threads=3",
1086 free_test_data(&data
);
1089 static void test_acpi_q35_kvm_core_count2(void)
1092 .machine
= MACHINE_Q35
,
1094 .variant
= ".core-count2",
1095 .required_struct_types
= base_required_struct_types
,
1096 .required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
),
1097 .smbios_core_count
= 0xFF,
1098 .smbios_core_count2
= 260,
1101 test_acpi_one("-machine smbios-entry-point-type=64 "
1102 "-smp 260,dies=2,cores=130,threads=1",
1104 free_test_data(&data
);
1107 static void test_acpi_q35_kvm_thread_count(void)
1110 .machine
= MACHINE_Q35
,
1112 .variant
= ".thread-count",
1113 .required_struct_types
= base_required_struct_types
,
1114 .required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
),
1115 .smbios_thread_count
= 27,
1116 .smbios_thread_count2
= 27,
1119 test_acpi_one("-machine smbios-entry-point-type=64 "
1120 "-smp cpus=15,maxcpus=54,sockets=2,dies=3,cores=3,threads=3",
1122 free_test_data(&data
);
1125 static void test_acpi_q35_kvm_thread_count2(void)
1128 .machine
= MACHINE_Q35
,
1130 .variant
= ".thread-count2",
1131 .required_struct_types
= base_required_struct_types
,
1132 .required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
),
1133 .smbios_thread_count
= 0xFF,
1134 .smbios_thread_count2
= 260,
1137 test_acpi_one("-machine smbios-entry-point-type=64 "
1138 "-smp cpus=210,maxcpus=260,dies=2,cores=65,threads=2",
1140 free_test_data(&data
);
1143 static void test_acpi_q35_tcg_bridge(void)
1145 test_data data
= {};
1147 data
.machine
= MACHINE_Q35
;
1149 data
.variant
= ".bridge";
1150 data
.required_struct_types
= base_required_struct_types
;
1151 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
1152 test_acpi_one("-device pci-bridge,chassis_nr=1,id=br1"
1153 " -device pci-testdev,bus=pcie.0"
1154 " -device pci-testdev,bus=br1", &data
);
1155 free_test_data(&data
);
1158 static void test_acpi_q35_tcg_no_acpi_hotplug(void)
1160 test_data data
= {};
1162 data
.machine
= MACHINE_Q35
;
1164 data
.variant
= ".noacpihp";
1165 data
.required_struct_types
= base_required_struct_types
;
1166 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
1167 test_acpi_one("-global ICH9-LPC.acpi-pci-hotplug-with-bridge-support=off"
1168 " -device pci-testdev,bus=pcie.0,acpi-index=101,addr=3.0"
1169 " -device pci-bridge,chassis_nr=1,id=shpcbr,addr=4.0"
1170 " -device pci-testdev,bus=shpcbr,addr=1.0,acpi-index=201"
1171 " -device pci-bridge,chassis_nr=2,shpc=off,id=noshpcbr,addr=5.0"
1172 " -device pci-testdev,bus=noshpcbr,addr=1.0,acpi-index=301"
1173 " -device pcie-root-port,id=hprp,port=0x0,chassis=1,addr=6.0"
1174 " -device pci-testdev,bus=hprp,acpi-index=401"
1175 " -device pcie-root-port,id=nohprp,port=0x0,chassis=2,hotplug=off,"
1177 " -device pci-testdev,bus=nohprp,acpi-index=501"
1178 " -device pcie-root-port,id=nohprpint,port=0x0,chassis=3,hotplug=off,"
1179 "multifunction=on,addr=8.0"
1180 " -device pci-testdev,bus=nohprpint,acpi-index=601,addr=0.1"
1181 " -device pcie-root-port,id=hprp2,port=0x0,chassis=4,bus=nohprpint,"
1183 " -device pci-testdev,bus=hprp2,acpi-index=602"
1185 free_test_data(&data
);
1188 static void test_acpi_q35_multif_bridge(void)
1191 .machine
= MACHINE_Q35
,
1193 .variant
= ".multi-bridge",
1195 test_vm_prepare("-S"
1196 " -device virtio-balloon,id=balloon0,addr=0x4.0x2"
1197 " -device pcie-root-port,id=rp0,multifunction=on,"
1198 "port=0x0,chassis=1,addr=0x2"
1199 " -device pcie-root-port,id=rp1,port=0x1,chassis=2,addr=0x3.0x1"
1200 " -device pcie-root-port,id=rp2,port=0x0,chassis=3,bus=rp1,addr=0.0"
1201 " -device pci-bridge,bus=rp2,chassis_nr=4,id=br1"
1202 " -device pcie-root-port,id=rphptgt1,port=0x0,chassis=5,addr=2.1"
1203 " -device pcie-root-port,id=rphptgt2,port=0x0,chassis=6,addr=2.2"
1204 " -device pcie-root-port,id=rphptgt3,port=0x0,chassis=7,addr=2.3"
1205 " -device pci-testdev,bus=pcie.0,addr=2.4"
1206 " -device pci-testdev,bus=pcie.0,addr=2.5,acpi-index=102"
1207 " -device pci-testdev,bus=pcie.0,addr=5.0"
1208 " -device pci-testdev,bus=pcie.0,addr=0xf.0,acpi-index=101"
1209 " -device pci-testdev,bus=rp0,addr=0.0"
1210 " -device pci-testdev,bus=br1"
1211 " -device pcie-root-port,id=rpnohp,chassis=8,addr=0xA.0,hotplug=off"
1212 " -device pcie-root-port,id=rp3,chassis=9,bus=rpnohp"
1215 /* hotplugged bridges section */
1216 qtest_qmp_device_add(data
.qts
, "pci-bridge", "hpbr1",
1217 "{'bus': 'br1', 'addr': '6.0', 'chassis_nr': 128 }");
1218 qtest_qmp_device_add(data
.qts
, "pci-bridge", "hpbr2-multiif",
1219 "{ 'bus': 'br1', 'addr': '2.2', 'chassis_nr': 129 }");
1220 qtest_qmp_device_add(data
.qts
, "pcie-pci-bridge", "hpbr3",
1221 "{'bus': 'rphptgt1', 'addr': '0.0' }");
1222 qtest_qmp_device_add(data
.qts
, "pcie-root-port", "hprp",
1223 "{'bus': 'rphptgt2', 'addr': '0.0' }");
1224 qtest_qmp_device_add(data
.qts
, "pci-testdev", "hpnic",
1225 "{'bus': 'rphptgt3', 'addr': '0.0' }");
1226 qtest_qmp_send(data
.qts
, "{'execute':'cont' }");
1227 qtest_qmp_eventwait(data
.qts
, "RESUME");
1229 process_acpi_tables_noexit(&data
);
1230 free_test_data(&data
);
1232 /* check that reboot/reset doesn't change any ACPI tables */
1233 qtest_qmp_send(data
.qts
, "{'execute':'system_reset' }");
1234 process_acpi_tables(&data
);
1235 free_test_data(&data
);
1238 static void test_acpi_q35_tcg_mmio64(void)
1241 .machine
= MACHINE_Q35
,
1243 .variant
= ".mmio64",
1245 .required_struct_types
= base_required_struct_types
,
1246 .required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
)
1249 test_acpi_one("-m 128M,slots=1,maxmem=2G "
1251 "-object memory-backend-ram,id=ram0,size=128M "
1252 "-numa node,memdev=ram0 "
1253 "-device pci-testdev,membar=2G",
1255 free_test_data(&data
);
1258 static void test_acpi_piix4_tcg_cphp(void)
1260 test_data data
= {};
1262 data
.machine
= MACHINE_PC
;
1264 data
.variant
= ".cphp";
1265 test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6"
1266 " -object memory-backend-ram,id=ram0,size=64M"
1267 " -object memory-backend-ram,id=ram1,size=64M"
1268 " -numa node,memdev=ram0 -numa node,memdev=ram1"
1269 " -numa dist,src=0,dst=1,val=21",
1271 free_test_data(&data
);
1274 static void test_acpi_q35_tcg_cphp(void)
1276 test_data data
= {};
1278 data
.machine
= MACHINE_Q35
;
1280 data
.variant
= ".cphp";
1281 test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
1282 " -object memory-backend-ram,id=ram0,size=64M"
1283 " -object memory-backend-ram,id=ram1,size=64M"
1284 " -numa node,memdev=ram0 -numa node,memdev=ram1"
1285 " -numa dist,src=0,dst=1,val=21",
1287 free_test_data(&data
);
1290 static uint8_t ipmi_required_struct_types
[] = {
1291 0, 1, 3, 4, 16, 17, 19, 32, 38, 127
1294 static void test_acpi_q35_tcg_ipmi(void)
1296 test_data data
= {};
1298 data
.machine
= MACHINE_Q35
;
1300 data
.variant
= ".ipmibt";
1301 data
.required_struct_types
= ipmi_required_struct_types
;
1302 data
.required_struct_types_len
= ARRAY_SIZE(ipmi_required_struct_types
);
1303 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
1304 " -device isa-ipmi-bt,bmc=bmc0",
1306 free_test_data(&data
);
1309 static void test_acpi_q35_tcg_smbus_ipmi(void)
1311 test_data data
= {};
1313 data
.machine
= MACHINE_Q35
;
1315 data
.variant
= ".ipmismbus";
1316 data
.required_struct_types
= ipmi_required_struct_types
;
1317 data
.required_struct_types_len
= ARRAY_SIZE(ipmi_required_struct_types
);
1318 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
1319 " -device smbus-ipmi,bmc=bmc0",
1321 free_test_data(&data
);
1324 static void test_acpi_piix4_tcg_ipmi(void)
1326 test_data data
= {};
1328 /* Supplying -machine accel argument overrides the default (qtest).
1329 * This is to make guest actually run.
1331 data
.machine
= MACHINE_PC
;
1333 data
.variant
= ".ipmikcs";
1334 data
.required_struct_types
= ipmi_required_struct_types
;
1335 data
.required_struct_types_len
= ARRAY_SIZE(ipmi_required_struct_types
);
1336 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
1337 " -device isa-ipmi-kcs,irq=0,bmc=bmc0",
1339 free_test_data(&data
);
1342 static void test_acpi_q35_tcg_memhp(void)
1344 test_data data
= {};
1346 data
.machine
= MACHINE_Q35
;
1348 data
.variant
= ".memhp";
1349 test_acpi_one(" -m 128,slots=3,maxmem=1G"
1350 " -object memory-backend-ram,id=ram0,size=64M"
1351 " -object memory-backend-ram,id=ram1,size=64M"
1352 " -numa node,memdev=ram0 -numa node,memdev=ram1"
1353 " -numa dist,src=0,dst=1,val=21",
1355 free_test_data(&data
);
1358 static void test_acpi_piix4_tcg_memhp(void)
1360 test_data data
= {};
1362 data
.machine
= MACHINE_PC
;
1364 data
.variant
= ".memhp";
1365 test_acpi_one(" -m 128,slots=3,maxmem=1G"
1366 " -object memory-backend-ram,id=ram0,size=64M"
1367 " -object memory-backend-ram,id=ram1,size=64M"
1368 " -numa node,memdev=ram0 -numa node,memdev=ram1"
1369 " -numa dist,src=0,dst=1,val=21",
1371 free_test_data(&data
);
1374 static void test_acpi_piix4_tcg_nosmm(void)
1376 test_data data
= {};
1378 data
.machine
= MACHINE_PC
;
1380 data
.variant
= ".nosmm";
1381 test_acpi_one("-machine smm=off", &data
);
1382 free_test_data(&data
);
1385 static void test_acpi_piix4_tcg_smm_compat(void)
1387 test_data data
= {};
1389 data
.machine
= MACHINE_PC
;
1391 data
.variant
= ".smm-compat";
1392 test_acpi_one("-global PIIX4_PM.smm-compat=on", &data
);
1393 free_test_data(&data
);
1396 static void test_acpi_piix4_tcg_smm_compat_nosmm(void)
1398 test_data data
= {};
1400 data
.machine
= MACHINE_PC
;
1402 data
.variant
= ".smm-compat-nosmm";
1403 test_acpi_one("-global PIIX4_PM.smm-compat=on -machine smm=off", &data
);
1404 free_test_data(&data
);
1407 static void test_acpi_piix4_tcg_nohpet(void)
1409 test_data data
= {};
1411 data
.machine
= MACHINE_PC
;
1413 data
.machine_param
= ",hpet=off";
1414 data
.variant
= ".nohpet";
1415 test_acpi_one(NULL
, &data
);
1416 free_test_data(&data
);
1419 static void test_acpi_q35_tcg_numamem(void)
1421 test_data data
= {};
1423 data
.machine
= MACHINE_Q35
;
1425 data
.variant
= ".numamem";
1426 test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
1427 " -numa node -numa node,memdev=ram0", &data
);
1428 free_test_data(&data
);
1431 static void test_acpi_q35_kvm_xapic(void)
1433 test_data data
= {};
1435 data
.machine
= MACHINE_Q35
;
1437 data
.variant
= ".xapic";
1438 test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
1439 " -numa node -numa node,memdev=ram0"
1440 " -machine kernel-irqchip=on -smp 1,maxcpus=288", &data
);
1441 free_test_data(&data
);
1444 static void test_acpi_q35_tcg_nosmm(void)
1446 test_data data
= {};
1448 data
.machine
= MACHINE_Q35
;
1450 data
.variant
= ".nosmm";
1451 test_acpi_one("-machine smm=off", &data
);
1452 free_test_data(&data
);
1455 static void test_acpi_q35_tcg_smm_compat(void)
1457 test_data data
= {};
1459 data
.machine
= MACHINE_Q35
;
1461 data
.variant
= ".smm-compat";
1462 test_acpi_one("-global ICH9-LPC.smm-compat=on", &data
);
1463 free_test_data(&data
);
1466 static void test_acpi_q35_tcg_smm_compat_nosmm(void)
1468 test_data data
= {};
1470 data
.machine
= MACHINE_Q35
;
1472 data
.variant
= ".smm-compat-nosmm";
1473 test_acpi_one("-global ICH9-LPC.smm-compat=on -machine smm=off", &data
);
1474 free_test_data(&data
);
1477 static void test_acpi_q35_tcg_nohpet(void)
1479 test_data data
= {};
1481 data
.machine
= MACHINE_Q35
;
1483 data
.machine_param
= ",hpet=off";
1484 data
.variant
= ".nohpet";
1485 test_acpi_one(NULL
, &data
);
1486 free_test_data(&data
);
1489 static void test_acpi_q35_kvm_dmar(void)
1491 test_data data
= {};
1493 data
.machine
= MACHINE_Q35
;
1495 data
.variant
= ".dmar";
1496 test_acpi_one("-machine kernel-irqchip=split -accel kvm"
1497 " -device intel-iommu,intremap=on,device-iotlb=on", &data
);
1498 free_test_data(&data
);
1501 static void test_acpi_q35_tcg_ivrs(void)
1503 test_data data
= {};
1505 data
.machine
= MACHINE_Q35
;
1507 data
.variant
= ".ivrs";
1508 data
.tcg_only
= true,
1509 test_acpi_one(" -device amd-iommu", &data
);
1510 free_test_data(&data
);
1513 static void test_acpi_piix4_tcg_numamem(void)
1515 test_data data
= {};
1517 data
.machine
= MACHINE_PC
;
1519 data
.variant
= ".numamem";
1520 test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
1521 " -numa node -numa node,memdev=ram0", &data
);
1522 free_test_data(&data
);
1525 uint64_t tpm_tis_base_addr
;
1527 static void test_acpi_tcg_tpm(const char *machine
, const char *arch
,
1528 const char *tpm_if
, uint64_t base
,
1529 enum TPMVersion tpm_version
)
1531 gchar
*tmp_dir_name
= g_strdup_printf("qemu-test_acpi_%s_tcg_%s.XXXXXX",
1533 char *tmp_path
= g_dir_make_tmp(tmp_dir_name
, NULL
);
1535 test_data data
= {};
1537 const char *suffix
= tpm_version
== TPM_VERSION_2_0
? "tpm2" : "tpm12";
1538 char *args
, *variant
= g_strdup_printf(".%s.%s", tpm_if
, suffix
);
1540 tpm_tis_base_addr
= base
;
1542 module_call_init(MODULE_INIT_QOM
);
1544 test
.addr
= g_new0(SocketAddress
, 1);
1545 test
.addr
->type
= SOCKET_ADDRESS_TYPE_UNIX
;
1546 test
.addr
->u
.q_unix
.path
= g_build_filename(tmp_path
, "sock", NULL
);
1547 g_mutex_init(&test
.data_mutex
);
1548 g_cond_init(&test
.data_cond
);
1549 test
.data_cond_signal
= false;
1550 test
.tpm_version
= tpm_version
;
1552 thread
= g_thread_new(NULL
, tpm_emu_ctrl_thread
, &test
);
1553 tpm_emu_test_wait_cond(&test
);
1555 data
.machine
= machine
;
1557 data
.variant
= variant
;
1559 args
= g_strdup_printf(
1560 " -chardev socket,id=chr,path=%s"
1561 " -tpmdev emulator,id=dev,chardev=chr"
1562 " -device tpm-%s,tpmdev=dev",
1563 test
.addr
->u
.q_unix
.path
, tpm_if
);
1565 test_acpi_one(args
, &data
);
1567 g_thread_join(thread
);
1568 g_unlink(test
.addr
->u
.q_unix
.path
);
1569 qapi_free_SocketAddress(test
.addr
);
1573 g_free(tmp_dir_name
);
1575 free_test_data(&data
);
1578 static void test_acpi_q35_tcg_tpm2_tis(void)
1580 test_acpi_tcg_tpm("q35", "x86", "tis", 0xFED40000, TPM_VERSION_2_0
);
1583 static void test_acpi_q35_tcg_tpm12_tis(void)
1585 test_acpi_tcg_tpm("q35", "x86", "tis", 0xFED40000, TPM_VERSION_1_2
);
1588 static void test_acpi_tcg_dimm_pxm(const char *machine
, const char *arch
)
1590 test_data data
= {};
1592 data
.machine
= machine
;
1594 data
.variant
= ".dimmpxm";
1595 test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu"
1597 " -m 128M,slots=3,maxmem=1G"
1598 " -object memory-backend-ram,id=ram0,size=32M"
1599 " -object memory-backend-ram,id=ram1,size=32M"
1600 " -object memory-backend-ram,id=ram2,size=32M"
1601 " -object memory-backend-ram,id=ram3,size=32M"
1602 " -numa node,memdev=ram0,nodeid=0"
1603 " -numa node,memdev=ram1,nodeid=1"
1604 " -numa node,memdev=ram2,nodeid=2"
1605 " -numa node,memdev=ram3,nodeid=3"
1606 " -numa cpu,node-id=0,socket-id=0"
1607 " -numa cpu,node-id=1,socket-id=1"
1608 " -numa cpu,node-id=2,socket-id=2"
1609 " -numa cpu,node-id=3,socket-id=3"
1610 " -object memory-backend-ram,id=ram4,size=128M"
1611 " -object memory-backend-ram,id=nvm0,size=128M"
1612 " -device pc-dimm,id=dimm0,memdev=ram4,node=1"
1613 " -device nvdimm,id=dimm1,memdev=nvm0,node=2",
1615 free_test_data(&data
);
1618 static void test_acpi_q35_tcg_dimm_pxm(void)
1620 test_acpi_tcg_dimm_pxm(MACHINE_Q35
, "x86");
1623 static void test_acpi_piix4_tcg_dimm_pxm(void)
1625 test_acpi_tcg_dimm_pxm(MACHINE_PC
, "x86");
1628 static void test_acpi_aarch64_virt_tcg_memhp(void)
1634 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
1635 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
1636 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1637 .ram_start
= 0x40000000ULL
,
1638 .scan_len
= 256ULL * 1024 * 1024,
1641 data
.variant
= ".memhp";
1642 test_acpi_one(" -machine nvdimm=on"
1644 " -m 256M,slots=3,maxmem=1G"
1645 " -object memory-backend-ram,id=ram0,size=128M"
1646 " -object memory-backend-ram,id=ram1,size=128M"
1647 " -numa node,memdev=ram0 -numa node,memdev=ram1"
1648 " -numa dist,src=0,dst=1,val=21"
1649 " -object memory-backend-ram,id=ram2,size=128M"
1650 " -object memory-backend-ram,id=nvm0,size=128M"
1651 " -device pc-dimm,id=dimm0,memdev=ram2,node=0"
1652 " -device nvdimm,id=dimm1,memdev=nvm0,node=1",
1655 free_test_data(&data
);
1659 static void test_acpi_microvm_prepare(test_data
*data
)
1661 data
->machine
= "microvm";
1663 data
->required_struct_types
= NULL
; /* no smbios */
1664 data
->required_struct_types_len
= 0;
1665 data
->blkdev
= "virtio-blk-device";
1668 static void test_acpi_microvm_tcg(void)
1670 test_data data
= {};
1672 test_acpi_microvm_prepare(&data
);
1673 test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=off",
1675 free_test_data(&data
);
1678 static void test_acpi_microvm_usb_tcg(void)
1680 test_data data
= {};
1682 test_acpi_microvm_prepare(&data
);
1683 data
.variant
= ".usb";
1684 test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,usb=on,rtc=off",
1686 free_test_data(&data
);
1689 static void test_acpi_microvm_rtc_tcg(void)
1691 test_data data
= {};
1693 test_acpi_microvm_prepare(&data
);
1694 data
.variant
= ".rtc";
1695 test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=on",
1697 free_test_data(&data
);
1700 static void test_acpi_microvm_pcie_tcg(void)
1702 test_data data
= {};
1704 test_acpi_microvm_prepare(&data
);
1705 data
.variant
= ".pcie";
1706 data
.tcg_only
= true; /* need constant host-phys-bits */
1707 test_acpi_one(" -machine microvm,acpi=on,ioapic2=off,rtc=off,pcie=on",
1709 free_test_data(&data
);
1712 static void test_acpi_microvm_ioapic2_tcg(void)
1714 test_data data
= {};
1716 test_acpi_microvm_prepare(&data
);
1717 data
.variant
= ".ioapic2";
1718 test_acpi_one(" -machine microvm,acpi=on,ioapic2=on,rtc=off",
1720 free_test_data(&data
);
1723 static void test_acpi_aarch64_virt_tcg_numamem(void)
1729 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
1730 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
1731 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1732 .ram_start
= 0x40000000ULL
,
1733 .scan_len
= 128ULL * 1024 * 1024,
1736 data
.variant
= ".numamem";
1737 test_acpi_one(" -cpu cortex-a57"
1738 " -object memory-backend-ram,id=ram0,size=128M"
1739 " -numa node,memdev=ram0",
1742 free_test_data(&data
);
1746 static void test_acpi_aarch64_virt_tcg_pxb(void)
1752 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
1753 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
1754 .ram_start
= 0x40000000ULL
,
1755 .scan_len
= 128ULL * 1024 * 1024,
1758 * While using -cdrom, the cdrom would auto plugged into pxb-pcie,
1759 * the reason is the bus of pxb-pcie is also root bus, it would lead
1760 * to the error only PCI/PCIE bridge could plug onto pxb.
1761 * Therefore,thr cdrom is defined and plugged onto the scsi controller
1762 * to solve the conflicts.
1764 data
.variant
= ".pxb";
1765 test_acpi_one(" -device pcie-root-port,chassis=1,id=pci.1"
1766 " -device virtio-scsi-pci,id=scsi0,bus=pci.1"
1768 "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2,"
1769 "if=none,media=cdrom,id=drive-scsi0-0-0-1,readonly=on"
1770 " -device scsi-cd,bus=scsi0.0,scsi-id=0,"
1771 "drive=drive-scsi0-0-0-1,id=scsi0-0-0-1,bootindex=1"
1773 " -device pxb-pcie,bus_nr=128",
1776 free_test_data(&data
);
1779 static void test_acpi_tcg_acpi_hmat(const char *machine
, const char *arch
)
1781 test_data data
= {};
1783 data
.machine
= machine
;
1785 data
.variant
= ".acpihmat";
1786 test_acpi_one(" -machine hmat=on"
1788 " -m 128M,slots=2,maxmem=1G"
1789 " -object memory-backend-ram,size=64M,id=m0"
1790 " -object memory-backend-ram,size=64M,id=m1"
1791 " -numa node,nodeid=0,memdev=m0"
1792 " -numa node,nodeid=1,memdev=m1,initiator=0"
1793 " -numa cpu,node-id=0,socket-id=0"
1794 " -numa cpu,node-id=0,socket-id=1"
1795 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1796 "data-type=access-latency,latency=1"
1797 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1798 "data-type=access-bandwidth,bandwidth=65534M"
1799 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1800 "data-type=access-latency,latency=65534"
1801 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1802 "data-type=access-bandwidth,bandwidth=32767M"
1803 " -numa hmat-cache,node-id=0,size=10K,level=1,"
1804 "associativity=direct,policy=write-back,line=8"
1805 " -numa hmat-cache,node-id=1,size=10K,level=1,"
1806 "associativity=direct,policy=write-back,line=8",
1808 free_test_data(&data
);
1811 static void test_acpi_q35_tcg_acpi_hmat(void)
1813 test_acpi_tcg_acpi_hmat(MACHINE_Q35
, "x86");
1816 static void test_acpi_piix4_tcg_acpi_hmat(void)
1818 test_acpi_tcg_acpi_hmat(MACHINE_PC
, "x86");
1821 static void test_acpi_aarch64_virt_tcg_acpi_hmat(void)
1827 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
1828 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
1829 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1830 .ram_start
= 0x40000000ULL
,
1831 .scan_len
= 128ULL * 1024 * 1024,
1834 data
.variant
= ".acpihmatvirt";
1836 test_acpi_one(" -machine hmat=on"
1840 " -object memory-backend-ram,size=128M,id=ram0"
1841 " -object memory-backend-ram,size=128M,id=ram1"
1842 " -object memory-backend-ram,size=128M,id=ram2"
1843 " -numa node,nodeid=0,memdev=ram0"
1844 " -numa node,nodeid=1,memdev=ram1"
1845 " -numa node,nodeid=2,memdev=ram2"
1846 " -numa cpu,node-id=0,socket-id=0"
1847 " -numa cpu,node-id=0,socket-id=0"
1848 " -numa cpu,node-id=1,socket-id=1"
1849 " -numa cpu,node-id=1,socket-id=1"
1850 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1851 "data-type=access-latency,latency=10"
1852 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1853 "data-type=access-bandwidth,bandwidth=10485760"
1854 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1855 "data-type=access-latency,latency=20"
1856 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1857 "data-type=access-bandwidth,bandwidth=5242880"
1858 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1859 "data-type=access-latency,latency=30"
1860 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1861 "data-type=access-bandwidth,bandwidth=1048576"
1862 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1863 "data-type=access-latency,latency=20"
1864 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1865 "data-type=access-bandwidth,bandwidth=5242880"
1866 " -numa hmat-lb,initiator=1,target=1,hierarchy=memory,"
1867 "data-type=access-latency,latency=10"
1868 " -numa hmat-lb,initiator=1,target=1,hierarchy=memory,"
1869 "data-type=access-bandwidth,bandwidth=10485760"
1870 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1871 "data-type=access-latency,latency=30"
1872 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1873 "data-type=access-bandwidth,bandwidth=1048576",
1876 free_test_data(&data
);
1879 static void test_acpi_q35_tcg_acpi_hmat_noinitiator(void)
1881 test_data data
= {};
1883 data
.machine
= MACHINE_Q35
;
1885 data
.variant
= ".acpihmat-noinitiator";
1886 test_acpi_one(" -machine hmat=on"
1889 " -object memory-backend-ram,size=32M,id=ram0"
1890 " -object memory-backend-ram,size=32M,id=ram1"
1891 " -object memory-backend-ram,size=64M,id=ram2"
1892 " -numa node,nodeid=0,memdev=ram0"
1893 " -numa node,nodeid=1,memdev=ram1"
1894 " -numa node,nodeid=2,memdev=ram2"
1895 " -numa cpu,node-id=0,socket-id=0"
1896 " -numa cpu,node-id=0,socket-id=0"
1897 " -numa cpu,node-id=1,socket-id=1"
1898 " -numa cpu,node-id=1,socket-id=1"
1899 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1900 "data-type=access-latency,latency=10"
1901 " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1902 "data-type=access-bandwidth,bandwidth=10485760"
1903 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1904 "data-type=access-latency,latency=20"
1905 " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1906 "data-type=access-bandwidth,bandwidth=5242880"
1907 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1908 "data-type=access-latency,latency=30"
1909 " -numa hmat-lb,initiator=0,target=2,hierarchy=memory,"
1910 "data-type=access-bandwidth,bandwidth=1048576"
1911 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1912 "data-type=access-latency,latency=20"
1913 " -numa hmat-lb,initiator=1,target=0,hierarchy=memory,"
1914 "data-type=access-bandwidth,bandwidth=5242880"
1915 " -numa hmat-lb,initiator=1,target=1,hierarchy=memory,"
1916 "data-type=access-latency,latency=10"
1917 " -numa hmat-lb,initiator=1,target=1,hierarchy=memory,"
1918 "data-type=access-bandwidth,bandwidth=10485760"
1919 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1920 "data-type=access-latency,latency=30"
1921 " -numa hmat-lb,initiator=1,target=2,hierarchy=memory,"
1922 "data-type=access-bandwidth,bandwidth=1048576",
1924 free_test_data(&data
);
1928 static void test_acpi_erst(const char *machine
, const char *arch
)
1930 gchar
*tmp_path
= g_dir_make_tmp("qemu-test-erst.XXXXXX", NULL
);
1932 test_data data
= {};
1934 data
.machine
= machine
;
1936 data
.variant
= ".acpierst";
1937 params
= g_strdup_printf(
1938 " -object memory-backend-file,id=erstnvram,"
1939 "mem-path=%s,size=0x10000,share=on"
1940 " -device acpi-erst,memdev=erstnvram", tmp_path
);
1941 test_acpi_one(params
, &data
);
1942 free_test_data(&data
);
1944 g_assert(g_rmdir(tmp_path
) == 0);
1948 static void test_acpi_piix4_acpi_erst(void)
1950 test_acpi_erst(MACHINE_PC
, "x86");
1953 static void test_acpi_q35_acpi_erst(void)
1955 test_acpi_erst(MACHINE_Q35
, "x86");
1958 static void test_acpi_microvm_acpi_erst(void)
1960 gchar
*tmp_path
= g_dir_make_tmp("qemu-test-erst.XXXXXX", NULL
);
1962 test_data data
= {};
1964 test_acpi_microvm_prepare(&data
);
1965 data
.variant
= ".pcie";
1966 data
.tcg_only
= true; /* need constant host-phys-bits */
1967 params
= g_strdup_printf(" -machine microvm,"
1968 "acpi=on,ioapic2=off,rtc=off,pcie=on"
1969 " -object memory-backend-file,id=erstnvram,"
1970 "mem-path=%s,size=0x10000,share=on"
1971 " -device acpi-erst,memdev=erstnvram", tmp_path
);
1972 test_acpi_one(params
, &data
);
1974 g_assert(g_rmdir(tmp_path
) == 0);
1976 free_test_data(&data
);
1978 #endif /* CONFIG_POSIX */
1980 static void test_acpi_aarch64_virt_tcg(void)
1986 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
1987 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
1988 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1989 .ram_start
= 0x40000000ULL
,
1990 .scan_len
= 128ULL * 1024 * 1024,
1993 data
.smbios_cpu_max_speed
= 2900;
1994 data
.smbios_cpu_curr_speed
= 2700;
1995 test_acpi_one("-cpu cortex-a57 "
1996 "-smbios type=4,max-speed=2900,current-speed=2700", &data
);
1997 free_test_data(&data
);
2000 static void test_acpi_aarch64_virt_tcg_topology(void)
2005 .variant
= ".topology",
2007 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
2008 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
2009 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
2010 .ram_start
= 0x40000000ULL
,
2011 .scan_len
= 128ULL * 1024 * 1024,
2014 test_acpi_one("-cpu cortex-a57 "
2015 "-smp sockets=1,clusters=2,cores=2,threads=2", &data
);
2016 free_test_data(&data
);
2019 static void test_acpi_q35_viot(void)
2022 .machine
= MACHINE_Q35
,
2028 * To keep things interesting, two buses bypass the IOMMU.
2029 * VIOT should only describes the other two buses.
2031 test_acpi_one("-machine default_bus_bypass_iommu=on "
2032 "-device virtio-iommu-pci "
2033 "-device pxb-pcie,bus_nr=0x10,id=pcie.100,bus=pcie.0 "
2034 "-device pxb-pcie,bus_nr=0x20,id=pcie.200,bus=pcie.0,bypass_iommu=on "
2035 "-device pxb-pcie,bus_nr=0x30,id=pcie.300,bus=pcie.0",
2037 free_test_data(&data
);
2041 static void test_acpi_q35_cxl(void)
2043 gchar
*tmp_path
= g_dir_make_tmp("qemu-test-cxl.XXXXXX", NULL
);
2047 .machine
= MACHINE_Q35
,
2052 * A complex CXL setup.
2054 params
= g_strdup_printf(" -machine cxl=on"
2055 " -object memory-backend-file,id=cxl-mem1,mem-path=%s,size=256M"
2056 " -object memory-backend-file,id=cxl-mem2,mem-path=%s,size=256M"
2057 " -object memory-backend-file,id=cxl-mem3,mem-path=%s,size=256M"
2058 " -object memory-backend-file,id=cxl-mem4,mem-path=%s,size=256M"
2059 " -object memory-backend-file,id=lsa1,mem-path=%s,size=256M"
2060 " -object memory-backend-file,id=lsa2,mem-path=%s,size=256M"
2061 " -object memory-backend-file,id=lsa3,mem-path=%s,size=256M"
2062 " -object memory-backend-file,id=lsa4,mem-path=%s,size=256M"
2063 " -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1"
2064 " -device pxb-cxl,bus_nr=222,bus=pcie.0,id=cxl.2"
2065 " -device cxl-rp,port=0,bus=cxl.1,id=rp1,chassis=0,slot=2"
2066 " -device cxl-type3,bus=rp1,persistent-memdev=cxl-mem1,lsa=lsa1"
2067 " -device cxl-rp,port=1,bus=cxl.1,id=rp2,chassis=0,slot=3"
2068 " -device cxl-type3,bus=rp2,persistent-memdev=cxl-mem2,lsa=lsa2"
2069 " -device cxl-rp,port=0,bus=cxl.2,id=rp3,chassis=0,slot=5"
2070 " -device cxl-type3,bus=rp3,persistent-memdev=cxl-mem3,lsa=lsa3"
2071 " -device cxl-rp,port=1,bus=cxl.2,id=rp4,chassis=0,slot=6"
2072 " -device cxl-type3,bus=rp4,persistent-memdev=cxl-mem4,lsa=lsa4"
2073 " -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=8k,"
2074 "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",
2075 tmp_path
, tmp_path
, tmp_path
, tmp_path
,
2076 tmp_path
, tmp_path
, tmp_path
, tmp_path
);
2077 test_acpi_one(params
, &data
);
2080 g_assert(g_rmdir(tmp_path
) == 0);
2082 free_test_data(&data
);
2084 #endif /* CONFIG_POSIX */
2086 static void test_acpi_aarch64_virt_viot(void)
2092 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
2093 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
2094 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
2095 .ram_start
= 0x40000000ULL
,
2096 .scan_len
= 128ULL * 1024 * 1024,
2099 test_acpi_one("-cpu cortex-a57 "
2100 "-device virtio-iommu-pci", &data
);
2101 free_test_data(&data
);
2105 # define DEV_NULL "/dev/null"
2107 # define DEV_NULL "nul"
2110 static void test_acpi_q35_slic(void)
2113 .machine
= MACHINE_Q35
,
2118 test_acpi_one("-acpitable sig=SLIC,oem_id=\"CRASH \",oem_table_id=ME,"
2119 "oem_rev=00002210,asl_compiler_id=qemu,"
2120 "asl_compiler_rev=00000000,data=" DEV_NULL
,
2122 free_test_data(&data
);
2125 static void test_acpi_q35_applesmc(void)
2128 .machine
= MACHINE_Q35
,
2130 .variant
= ".applesmc",
2133 /* supply fake 64-byte OSK to silence missing key warning */
2134 test_acpi_one("-device isa-applesmc,osk=any64characterfakeoskisenough"
2135 "topreventinvalidkeywarningsonstderr", &data
);
2136 free_test_data(&data
);
2139 static void test_acpi_q35_pvpanic_isa(void)
2142 .machine
= MACHINE_Q35
,
2144 .variant
= ".pvpanic-isa",
2147 test_acpi_one("-device pvpanic", &data
);
2148 free_test_data(&data
);
2151 static void test_acpi_pc_smbios_options(void)
2153 uint8_t req_type11
[] = { 11 };
2155 .machine
= MACHINE_PC
,
2157 .variant
= ".pc_smbios_options",
2158 .required_struct_types
= req_type11
,
2159 .required_struct_types_len
= ARRAY_SIZE(req_type11
),
2162 test_smbios("-smbios type=11,value=TEST", &data
);
2163 free_test_data(&data
);
2166 static void test_acpi_pc_smbios_blob(void)
2168 uint8_t req_type11
[] = { 11 };
2170 .machine
= MACHINE_PC
,
2172 .variant
= ".pc_smbios_blob",
2173 .required_struct_types
= req_type11
,
2174 .required_struct_types_len
= ARRAY_SIZE(req_type11
),
2177 test_smbios("-machine smbios-entry-point-type=32 "
2178 "-smbios file=tests/data/smbios/type11_blob", &data
);
2179 free_test_data(&data
);
2182 static void test_acpi_isapc_smbios_legacy(void)
2184 uint8_t req_type11
[] = { 1, 11 };
2187 .variant
= ".pc_smbios_legacy",
2188 .required_struct_types
= req_type11
,
2189 .required_struct_types_len
= ARRAY_SIZE(req_type11
),
2192 test_smbios("-smbios file=tests/data/smbios/type11_blob.legacy "
2193 "-smbios type=1,family=TEST", &data
);
2194 free_test_data(&data
);
2197 static void test_oem_fields(test_data
*data
)
2201 for (i
= 0; i
< data
->tables
->len
; ++i
) {
2204 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
2205 /* FACS doesn't have OEMID and OEMTABLEID fields */
2206 if (compare_signature(sdt
, "FACS")) {
2210 g_assert(strncmp((char *)sdt
->aml
+ 10, OEM_ID
, 6) == 0);
2211 g_assert(strncmp((char *)sdt
->aml
+ 16, OEM_TABLE_ID
, 8) == 0);
2215 static void test_acpi_piix4_oem_fields(void)
2218 test_data data
= {};
2220 data
.machine
= MACHINE_PC
;
2222 data
.required_struct_types
= base_required_struct_types
;
2223 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
2225 args
= test_acpi_create_args(&data
, OEM_TEST_ARGS
);
2226 data
.qts
= qtest_init(args
);
2227 test_acpi_load_tables(&data
);
2228 test_oem_fields(&data
);
2229 qtest_quit(data
.qts
);
2230 free_test_data(&data
);
2234 static void test_acpi_q35_oem_fields(void)
2237 test_data data
= {};
2239 data
.machine
= MACHINE_Q35
;
2241 data
.required_struct_types
= base_required_struct_types
;
2242 data
.required_struct_types_len
= ARRAY_SIZE(base_required_struct_types
);
2244 args
= test_acpi_create_args(&data
, OEM_TEST_ARGS
);
2245 data
.qts
= qtest_init(args
);
2246 test_acpi_load_tables(&data
);
2247 test_oem_fields(&data
);
2248 qtest_quit(data
.qts
);
2249 free_test_data(&data
);
2253 static void test_acpi_microvm_oem_fields(void)
2255 test_data data
= {};
2258 test_acpi_microvm_prepare(&data
);
2260 args
= test_acpi_create_args(&data
,
2261 OEM_TEST_ARGS
",acpi=on");
2262 data
.qts
= qtest_init(args
);
2263 test_acpi_load_tables(&data
);
2264 test_oem_fields(&data
);
2265 qtest_quit(data
.qts
);
2266 free_test_data(&data
);
2270 static void test_acpi_aarch64_virt_oem_fields(void)
2276 .uefi_fl1
= "pc-bios/edk2-aarch64-code.fd",
2277 .uefi_fl2
= "pc-bios/edk2-arm-vars.fd",
2278 .cd
= "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
2279 .ram_start
= 0x40000000ULL
,
2280 .scan_len
= 128ULL * 1024 * 1024,
2284 args
= test_acpi_create_args(&data
, "-cpu cortex-a57 "OEM_TEST_ARGS
);
2285 data
.qts
= qtest_init(args
);
2286 test_acpi_load_tables(&data
);
2287 test_oem_fields(&data
);
2288 qtest_quit(data
.qts
);
2289 free_test_data(&data
);
2294 int main(int argc
, char *argv
[])
2296 const char *arch
= qtest_get_arch();
2297 bool has_kvm
, has_tcg
;
2298 char *v_env
= getenv("V");
2302 verbosity_level
= atoi(v_env
);
2305 g_test_init(&argc
, &argv
, NULL
);
2307 has_kvm
= qtest_has_accel("kvm");
2308 has_tcg
= qtest_has_accel("tcg");
2310 if (!has_tcg
&& !has_kvm
) {
2311 g_test_skip("No KVM or TCG accelerator available");
2315 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
2316 ret
= boot_sector_init(disk
);
2320 if (qtest_has_machine(MACHINE_PC
)) {
2321 qtest_add_func("acpi/piix4", test_acpi_piix4_tcg
);
2322 qtest_add_func("acpi/piix4/oem-fields", test_acpi_piix4_oem_fields
);
2323 qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge
);
2324 qtest_add_func("acpi/piix4/pci-hotplug/no_root_hotplug",
2325 test_acpi_piix4_no_root_hotplug
);
2326 qtest_add_func("acpi/piix4/pci-hotplug/no_bridge_hotplug",
2327 test_acpi_piix4_no_bridge_hotplug
);
2328 qtest_add_func("acpi/piix4/pci-hotplug/off",
2329 test_acpi_piix4_no_acpi_pci_hotplug
);
2330 qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi
);
2331 qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp
);
2332 qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem
);
2333 qtest_add_func("acpi/piix4/nosmm", test_acpi_piix4_tcg_nosmm
);
2334 qtest_add_func("acpi/piix4/smm-compat",
2335 test_acpi_piix4_tcg_smm_compat
);
2336 qtest_add_func("acpi/piix4/smm-compat-nosmm",
2337 test_acpi_piix4_tcg_smm_compat_nosmm
);
2338 qtest_add_func("acpi/piix4/nohpet", test_acpi_piix4_tcg_nohpet
);
2340 /* i386 does not support memory hotplug */
2341 if (strcmp(arch
, "i386")) {
2342 qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp
);
2343 qtest_add_func("acpi/piix4/dimmpxm",
2344 test_acpi_piix4_tcg_dimm_pxm
);
2345 qtest_add_func("acpi/piix4/acpihmat",
2346 test_acpi_piix4_tcg_acpi_hmat
);
2349 qtest_add_func("acpi/piix4/acpierst", test_acpi_piix4_acpi_erst
);
2351 qtest_add_func("acpi/piix4/smbios-options",
2352 test_acpi_pc_smbios_options
);
2353 qtest_add_func("acpi/piix4/smbios-blob",
2354 test_acpi_pc_smbios_blob
);
2355 qtest_add_func("acpi/piix4/smbios-legacy",
2356 test_acpi_isapc_smbios_legacy
);
2358 if (qtest_has_machine(MACHINE_Q35
)) {
2359 qtest_add_func("acpi/q35", test_acpi_q35_tcg
);
2360 qtest_add_func("acpi/q35/oem-fields", test_acpi_q35_oem_fields
);
2361 if (tpm_model_is_available("-machine q35", "tpm-tis")) {
2362 qtest_add_func("acpi/q35/tpm2-tis", test_acpi_q35_tcg_tpm2_tis
);
2363 qtest_add_func("acpi/q35/tpm12-tis",
2364 test_acpi_q35_tcg_tpm12_tis
);
2366 qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge
);
2367 qtest_add_func("acpi/q35/no-acpi-hotplug",
2368 test_acpi_q35_tcg_no_acpi_hotplug
);
2369 qtest_add_func("acpi/q35/multif-bridge",
2370 test_acpi_q35_multif_bridge
);
2371 qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi
);
2372 qtest_add_func("acpi/q35/smbus/ipmi", test_acpi_q35_tcg_smbus_ipmi
);
2373 qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp
);
2374 qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem
);
2375 qtest_add_func("acpi/q35/nosmm", test_acpi_q35_tcg_nosmm
);
2376 qtest_add_func("acpi/q35/smm-compat",
2377 test_acpi_q35_tcg_smm_compat
);
2378 qtest_add_func("acpi/q35/smm-compat-nosmm",
2379 test_acpi_q35_tcg_smm_compat_nosmm
);
2380 qtest_add_func("acpi/q35/nohpet", test_acpi_q35_tcg_nohpet
);
2381 qtest_add_func("acpi/q35/acpihmat-noinitiator",
2382 test_acpi_q35_tcg_acpi_hmat_noinitiator
);
2384 /* i386 does not support memory hotplug */
2385 if (strcmp(arch
, "i386")) {
2386 qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp
);
2387 qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm
);
2388 qtest_add_func("acpi/q35/acpihmat",
2389 test_acpi_q35_tcg_acpi_hmat
);
2390 qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64
);
2393 qtest_add_func("acpi/q35/acpierst", test_acpi_q35_acpi_erst
);
2395 qtest_add_func("acpi/q35/applesmc", test_acpi_q35_applesmc
);
2396 qtest_add_func("acpi/q35/pvpanic-isa", test_acpi_q35_pvpanic_isa
);
2398 qtest_add_func("acpi/q35/ivrs", test_acpi_q35_tcg_ivrs
);
2401 qtest_add_func("acpi/q35/kvm/xapic", test_acpi_q35_kvm_xapic
);
2402 qtest_add_func("acpi/q35/kvm/dmar", test_acpi_q35_kvm_dmar
);
2403 qtest_add_func("acpi/q35/type4-count",
2404 test_acpi_q35_kvm_type4_count
);
2405 qtest_add_func("acpi/q35/core-count",
2406 test_acpi_q35_kvm_core_count
);
2407 qtest_add_func("acpi/q35/core-count2",
2408 test_acpi_q35_kvm_core_count2
);
2409 qtest_add_func("acpi/q35/thread-count",
2410 test_acpi_q35_kvm_thread_count
);
2411 qtest_add_func("acpi/q35/thread-count2",
2412 test_acpi_q35_kvm_thread_count2
);
2414 if (qtest_has_device("virtio-iommu-pci")) {
2415 qtest_add_func("acpi/q35/viot", test_acpi_q35_viot
);
2418 qtest_add_func("acpi/q35/cxl", test_acpi_q35_cxl
);
2420 qtest_add_func("acpi/q35/slic", test_acpi_q35_slic
);
2422 if (qtest_has_machine("microvm")) {
2423 qtest_add_func("acpi/microvm", test_acpi_microvm_tcg
);
2424 qtest_add_func("acpi/microvm/usb", test_acpi_microvm_usb_tcg
);
2425 qtest_add_func("acpi/microvm/rtc", test_acpi_microvm_rtc_tcg
);
2426 qtest_add_func("acpi/microvm/ioapic2",
2427 test_acpi_microvm_ioapic2_tcg
);
2428 qtest_add_func("acpi/microvm/oem-fields",
2429 test_acpi_microvm_oem_fields
);
2431 if (strcmp(arch
, "x86_64") == 0) {
2432 qtest_add_func("acpi/microvm/pcie",
2433 test_acpi_microvm_pcie_tcg
);
2435 qtest_add_func("acpi/microvm/acpierst",
2436 test_acpi_microvm_acpi_erst
);
2441 } else if (strcmp(arch
, "aarch64") == 0) {
2442 if (has_tcg
&& qtest_has_device("virtio-blk-pci")) {
2443 qtest_add_func("acpi/virt", test_acpi_aarch64_virt_tcg
);
2444 qtest_add_func("acpi/virt/acpihmatvirt",
2445 test_acpi_aarch64_virt_tcg_acpi_hmat
);
2446 qtest_add_func("acpi/virt/topology",
2447 test_acpi_aarch64_virt_tcg_topology
);
2448 qtest_add_func("acpi/virt/numamem",
2449 test_acpi_aarch64_virt_tcg_numamem
);
2450 qtest_add_func("acpi/virt/memhp", test_acpi_aarch64_virt_tcg_memhp
);
2451 qtest_add_func("acpi/virt/pxb", test_acpi_aarch64_virt_tcg_pxb
);
2452 qtest_add_func("acpi/virt/oem-fields",
2453 test_acpi_aarch64_virt_oem_fields
);
2454 if (qtest_has_device("virtio-iommu-pci")) {
2455 qtest_add_func("acpi/virt/viot", test_acpi_aarch64_virt_viot
);
2460 boot_sector_cleanup(disk
);