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.
13 #include "qemu/osdep.h"
14 #include <glib/gstdio.h>
15 #include "qemu-common.h"
17 #include "hw/acpi/acpi-defs.h"
18 #include "hw/smbios/smbios.h"
19 #include "qemu/bitmap.h"
20 #include "boot-sector.h"
22 #define MACHINE_PC "pc"
23 #define MACHINE_Q35 "q35"
25 #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
27 /* DSDT and SSDTs format */
29 AcpiTableHeader header
;
30 gchar
*aml
; /* aml bytecode from guest */
33 gchar
*asl
; /* asl code generated from aml */
36 bool tmp_files_retain
; /* do not delete the temp asl/aml */
37 } QEMU_PACKED AcpiSdtTable
;
43 AcpiRsdpDescriptor rsdp_table
;
44 AcpiRsdtDescriptorRev1 rsdt_table
;
45 AcpiFadtDescriptorRev1 fadt_table
;
46 AcpiFacsDescriptorRev1 facs_table
;
47 uint32_t *rsdt_tables_addr
;
50 uint32_t smbios_ep_addr
;
51 struct smbios_21_entry_point smbios_ep_table
;
54 #define ACPI_READ_FIELD(field, addr) \
56 switch (sizeof(field)) { \
58 field = readb(addr); \
61 field = readw(addr); \
64 field = readl(addr); \
67 field = readq(addr); \
72 addr += sizeof(field); \
75 #define ACPI_READ_ARRAY_PTR(arr, length, addr) \
78 for (idx = 0; idx < length; ++idx) { \
79 ACPI_READ_FIELD(arr[idx], addr); \
83 #define ACPI_READ_ARRAY(arr, addr) \
84 ACPI_READ_ARRAY_PTR(arr, sizeof(arr)/sizeof(arr[0]), addr)
86 #define ACPI_READ_TABLE_HEADER(table, addr) \
88 ACPI_READ_FIELD((table)->signature, addr); \
89 ACPI_READ_FIELD((table)->length, addr); \
90 ACPI_READ_FIELD((table)->revision, addr); \
91 ACPI_READ_FIELD((table)->checksum, addr); \
92 ACPI_READ_ARRAY((table)->oem_id, addr); \
93 ACPI_READ_ARRAY((table)->oem_table_id, addr); \
94 ACPI_READ_FIELD((table)->oem_revision, addr); \
95 ACPI_READ_ARRAY((table)->asl_compiler_id, addr); \
96 ACPI_READ_FIELD((table)->asl_compiler_revision, addr); \
99 #define ACPI_ASSERT_CMP(actual, expected) do { \
100 uint32_t ACPI_ASSERT_CMP_le = cpu_to_le32(actual); \
101 char ACPI_ASSERT_CMP_str[5] = {}; \
102 memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 4); \
103 g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
106 #define ACPI_ASSERT_CMP64(actual, expected) do { \
107 uint64_t ACPI_ASSERT_CMP_le = cpu_to_le64(actual); \
108 char ACPI_ASSERT_CMP_str[9] = {}; \
109 memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 8); \
110 g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
113 static const char *disk
= "tests/acpi-test-disk.raw";
114 static const char *data_dir
= "tests/acpi-test-data";
116 static const char *iasl
= stringify(CONFIG_IASL
);
118 static const char *iasl
;
121 static void free_test_data(test_data
*data
)
126 g_free(data
->rsdt_tables_addr
);
128 for (i
= 0; i
< data
->tables
->len
; ++i
) {
129 temp
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
131 if (temp
->aml_file
&&
132 !temp
->tmp_files_retain
&&
133 g_strstr_len(temp
->aml_file
, -1, "aml-")) {
134 unlink(temp
->aml_file
);
136 g_free(temp
->aml_file
);
138 if (temp
->asl_file
&&
139 !temp
->tmp_files_retain
) {
140 unlink(temp
->asl_file
);
142 g_free(temp
->asl_file
);
145 g_array_free(data
->tables
, false);
148 static uint8_t acpi_checksum(const uint8_t *data
, int len
)
153 for (i
= 0; i
< len
; i
++) {
160 static void test_acpi_rsdp_address(test_data
*data
)
164 /* OK, now find RSDP */
165 for (off
= 0xf0000; off
< 0x100000; off
+= 0x10) {
166 uint8_t sig
[] = "RSD PTR ";
169 for (i
= 0; i
< sizeof sig
- 1; ++i
) {
170 sig
[i
] = readb(off
+ i
);
173 if (!memcmp(sig
, "RSD PTR ", sizeof sig
)) {
178 g_assert_cmphex(off
, <, 0x100000);
179 data
->rsdp_addr
= off
;
182 static void test_acpi_rsdp_table(test_data
*data
)
184 AcpiRsdpDescriptor
*rsdp_table
= &data
->rsdp_table
;
185 uint32_t addr
= data
->rsdp_addr
;
187 ACPI_READ_FIELD(rsdp_table
->signature
, addr
);
188 ACPI_ASSERT_CMP64(rsdp_table
->signature
, "RSD PTR ");
190 ACPI_READ_FIELD(rsdp_table
->checksum
, addr
);
191 ACPI_READ_ARRAY(rsdp_table
->oem_id
, addr
);
192 ACPI_READ_FIELD(rsdp_table
->revision
, addr
);
193 ACPI_READ_FIELD(rsdp_table
->rsdt_physical_address
, addr
);
194 ACPI_READ_FIELD(rsdp_table
->length
, addr
);
196 /* rsdp checksum is not for the whole table, but for the first 20 bytes */
197 g_assert(!acpi_checksum((uint8_t *)rsdp_table
, 20));
200 static void test_acpi_rsdt_table(test_data
*data
)
202 AcpiRsdtDescriptorRev1
*rsdt_table
= &data
->rsdt_table
;
203 uint32_t addr
= data
->rsdp_table
.rsdt_physical_address
;
208 /* read the header */
209 ACPI_READ_TABLE_HEADER(rsdt_table
, addr
);
210 ACPI_ASSERT_CMP(rsdt_table
->signature
, "RSDT");
212 /* compute the table entries in rsdt */
213 tables_nr
= (rsdt_table
->length
- sizeof(AcpiRsdtDescriptorRev1
)) /
215 g_assert_cmpint(tables_nr
, >, 0);
217 /* get the addresses of the tables pointed by rsdt */
218 tables
= g_new0(uint32_t, tables_nr
);
219 ACPI_READ_ARRAY_PTR(tables
, tables_nr
, addr
);
221 checksum
= acpi_checksum((uint8_t *)rsdt_table
, rsdt_table
->length
) +
222 acpi_checksum((uint8_t *)tables
, tables_nr
* sizeof(uint32_t));
225 /* SSDT tables after FADT */
226 data
->rsdt_tables_addr
= tables
;
227 data
->rsdt_tables_nr
= tables_nr
;
230 static void test_acpi_fadt_table(test_data
*data
)
232 AcpiFadtDescriptorRev1
*fadt_table
= &data
->fadt_table
;
235 /* FADT table comes first */
236 addr
= data
->rsdt_tables_addr
[0];
237 ACPI_READ_TABLE_HEADER(fadt_table
, addr
);
239 ACPI_READ_FIELD(fadt_table
->firmware_ctrl
, addr
);
240 ACPI_READ_FIELD(fadt_table
->dsdt
, addr
);
241 ACPI_READ_FIELD(fadt_table
->model
, addr
);
242 ACPI_READ_FIELD(fadt_table
->reserved1
, addr
);
243 ACPI_READ_FIELD(fadt_table
->sci_int
, addr
);
244 ACPI_READ_FIELD(fadt_table
->smi_cmd
, addr
);
245 ACPI_READ_FIELD(fadt_table
->acpi_enable
, addr
);
246 ACPI_READ_FIELD(fadt_table
->acpi_disable
, addr
);
247 ACPI_READ_FIELD(fadt_table
->S4bios_req
, addr
);
248 ACPI_READ_FIELD(fadt_table
->reserved2
, addr
);
249 ACPI_READ_FIELD(fadt_table
->pm1a_evt_blk
, addr
);
250 ACPI_READ_FIELD(fadt_table
->pm1b_evt_blk
, addr
);
251 ACPI_READ_FIELD(fadt_table
->pm1a_cnt_blk
, addr
);
252 ACPI_READ_FIELD(fadt_table
->pm1b_cnt_blk
, addr
);
253 ACPI_READ_FIELD(fadt_table
->pm2_cnt_blk
, addr
);
254 ACPI_READ_FIELD(fadt_table
->pm_tmr_blk
, addr
);
255 ACPI_READ_FIELD(fadt_table
->gpe0_blk
, addr
);
256 ACPI_READ_FIELD(fadt_table
->gpe1_blk
, addr
);
257 ACPI_READ_FIELD(fadt_table
->pm1_evt_len
, addr
);
258 ACPI_READ_FIELD(fadt_table
->pm1_cnt_len
, addr
);
259 ACPI_READ_FIELD(fadt_table
->pm2_cnt_len
, addr
);
260 ACPI_READ_FIELD(fadt_table
->pm_tmr_len
, addr
);
261 ACPI_READ_FIELD(fadt_table
->gpe0_blk_len
, addr
);
262 ACPI_READ_FIELD(fadt_table
->gpe1_blk_len
, addr
);
263 ACPI_READ_FIELD(fadt_table
->gpe1_base
, addr
);
264 ACPI_READ_FIELD(fadt_table
->reserved3
, addr
);
265 ACPI_READ_FIELD(fadt_table
->plvl2_lat
, addr
);
266 ACPI_READ_FIELD(fadt_table
->plvl3_lat
, addr
);
267 ACPI_READ_FIELD(fadt_table
->flush_size
, addr
);
268 ACPI_READ_FIELD(fadt_table
->flush_stride
, addr
);
269 ACPI_READ_FIELD(fadt_table
->duty_offset
, addr
);
270 ACPI_READ_FIELD(fadt_table
->duty_width
, addr
);
271 ACPI_READ_FIELD(fadt_table
->day_alrm
, addr
);
272 ACPI_READ_FIELD(fadt_table
->mon_alrm
, addr
);
273 ACPI_READ_FIELD(fadt_table
->century
, addr
);
274 ACPI_READ_FIELD(fadt_table
->reserved4
, addr
);
275 ACPI_READ_FIELD(fadt_table
->reserved4a
, addr
);
276 ACPI_READ_FIELD(fadt_table
->reserved4b
, addr
);
277 ACPI_READ_FIELD(fadt_table
->flags
, addr
);
279 ACPI_ASSERT_CMP(fadt_table
->signature
, "FACP");
280 g_assert(!acpi_checksum((uint8_t *)fadt_table
, fadt_table
->length
));
283 static void test_acpi_facs_table(test_data
*data
)
285 AcpiFacsDescriptorRev1
*facs_table
= &data
->facs_table
;
286 uint32_t addr
= data
->fadt_table
.firmware_ctrl
;
288 ACPI_READ_FIELD(facs_table
->signature
, addr
);
289 ACPI_READ_FIELD(facs_table
->length
, addr
);
290 ACPI_READ_FIELD(facs_table
->hardware_signature
, addr
);
291 ACPI_READ_FIELD(facs_table
->firmware_waking_vector
, addr
);
292 ACPI_READ_FIELD(facs_table
->global_lock
, addr
);
293 ACPI_READ_FIELD(facs_table
->flags
, addr
);
294 ACPI_READ_ARRAY(facs_table
->resverved3
, addr
);
296 ACPI_ASSERT_CMP(facs_table
->signature
, "FACS");
299 static void test_dst_table(AcpiSdtTable
*sdt_table
, uint32_t addr
)
303 ACPI_READ_TABLE_HEADER(&sdt_table
->header
, addr
);
305 sdt_table
->aml_len
= sdt_table
->header
.length
- sizeof(AcpiTableHeader
);
306 sdt_table
->aml
= g_malloc0(sdt_table
->aml_len
);
307 ACPI_READ_ARRAY_PTR(sdt_table
->aml
, sdt_table
->aml_len
, addr
);
309 checksum
= acpi_checksum((uint8_t *)sdt_table
, sizeof(AcpiTableHeader
)) +
310 acpi_checksum((uint8_t *)sdt_table
->aml
, sdt_table
->aml_len
);
314 static void test_acpi_dsdt_table(test_data
*data
)
316 AcpiSdtTable dsdt_table
;
317 uint32_t addr
= data
->fadt_table
.dsdt
;
319 memset(&dsdt_table
, 0, sizeof(dsdt_table
));
320 data
->tables
= g_array_new(false, true, sizeof(AcpiSdtTable
));
322 test_dst_table(&dsdt_table
, addr
);
323 ACPI_ASSERT_CMP(dsdt_table
.header
.signature
, "DSDT");
325 /* Place DSDT first */
326 g_array_append_val(data
->tables
, dsdt_table
);
329 static void test_acpi_tables(test_data
*data
)
331 int tables_nr
= data
->rsdt_tables_nr
- 1; /* fadt is first */
334 for (i
= 0; i
< tables_nr
; i
++) {
335 AcpiSdtTable ssdt_table
;
337 memset(&ssdt_table
, 0 , sizeof(ssdt_table
));
338 uint32_t addr
= data
->rsdt_tables_addr
[i
+ 1]; /* fadt is first */
339 test_dst_table(&ssdt_table
, addr
);
340 g_array_append_val(data
->tables
, ssdt_table
);
344 static void dump_aml_files(test_data
*data
, bool rebuild
)
347 GError
*error
= NULL
;
348 gchar
*aml_file
= NULL
;
353 for (i
= 0; i
< data
->tables
->len
; ++i
) {
354 const char *ext
= data
->variant
? data
->variant
: "";
355 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
359 uint32_t signature
= cpu_to_le32(sdt
->header
.signature
);
360 aml_file
= g_strdup_printf("%s/%s/%.4s%s", data_dir
, data
->machine
,
361 (gchar
*)&signature
, ext
);
362 fd
= g_open(aml_file
, O_WRONLY
|O_TRUNC
|O_CREAT
,
363 S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IWGRP
|S_IROTH
);
365 fd
= g_file_open_tmp("aml-XXXXXX", &sdt
->aml_file
, &error
);
366 g_assert_no_error(error
);
370 ret
= qemu_write_full(fd
, sdt
, sizeof(AcpiTableHeader
));
371 g_assert(ret
== sizeof(AcpiTableHeader
));
372 ret
= qemu_write_full(fd
, sdt
->aml
, sdt
->aml_len
);
373 g_assert(ret
== sdt
->aml_len
);
381 static bool compare_signature(AcpiSdtTable
*sdt
, const char *signature
)
383 return !memcmp(&sdt
->header
.signature
, signature
, 4);
386 static bool load_asl(GArray
*sdts
, AcpiSdtTable
*sdt
)
389 GError
*error
= NULL
;
390 GString
*command_line
= g_string_new(iasl
);
392 gchar
*out
, *out_err
;
396 fd
= g_file_open_tmp("asl-XXXXXX.dsl", &sdt
->asl_file
, &error
);
397 g_assert_no_error(error
);
400 /* build command line */
401 g_string_append_printf(command_line
, " -p %s ", sdt
->asl_file
);
402 if (compare_signature(sdt
, "DSDT") ||
403 compare_signature(sdt
, "SSDT")) {
404 for (i
= 0; i
< sdts
->len
; ++i
) {
405 temp
= &g_array_index(sdts
, AcpiSdtTable
, i
);
406 if (compare_signature(temp
, "DSDT") ||
407 compare_signature(temp
, "SSDT")) {
408 g_string_append_printf(command_line
, "-e %s ", temp
->aml_file
);
412 g_string_append_printf(command_line
, "-d %s", sdt
->aml_file
);
414 /* pass 'out' and 'out_err' in order to be redirected */
415 ret
= g_spawn_command_line_sync(command_line
->str
, &out
, &out_err
, NULL
, &error
);
416 g_assert_no_error(error
);
418 ret
= g_file_get_contents(sdt
->asl_file
, (gchar
**)&sdt
->asl
,
419 &sdt
->asl_len
, &error
);
421 g_assert_no_error(error
);
422 ret
= (sdt
->asl_len
> 0);
427 g_string_free(command_line
, true);
432 #define COMMENT_END "*/"
433 #define DEF_BLOCK "DefinitionBlock ("
434 #define BLOCK_NAME_END ","
436 static GString
*normalize_asl(gchar
*asl_code
)
438 GString
*asl
= g_string_new(asl_code
);
439 gchar
*comment
, *block_name
;
441 /* strip comments (different generation days) */
442 comment
= g_strstr_len(asl
->str
, asl
->len
, COMMENT_END
);
444 comment
+= strlen(COMMENT_END
);
445 while (*comment
== '\n') {
448 asl
= g_string_erase(asl
, 0, comment
- asl
->str
);
451 /* strip def block name (it has file path in it) */
452 if (g_str_has_prefix(asl
->str
, DEF_BLOCK
)) {
453 block_name
= g_strstr_len(asl
->str
, asl
->len
, BLOCK_NAME_END
);
454 g_assert(block_name
);
455 asl
= g_string_erase(asl
, 0,
456 block_name
+ sizeof(BLOCK_NAME_END
) - asl
->str
);
462 static GArray
*load_expected_aml(test_data
*data
)
466 GError
*error
= NULL
;
469 GArray
*exp_tables
= g_array_new(false, true, sizeof(AcpiSdtTable
));
470 for (i
= 0; i
< data
->tables
->len
; ++i
) {
471 AcpiSdtTable exp_sdt
;
473 gchar
*aml_file
= NULL
;
474 const char *ext
= data
->variant
? data
->variant
: "";
476 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
478 memset(&exp_sdt
, 0, sizeof(exp_sdt
));
479 exp_sdt
.header
.signature
= sdt
->header
.signature
;
481 signature
= cpu_to_le32(sdt
->header
.signature
);
484 aml_file
= g_strdup_printf("%s/%s/%.4s%s", data_dir
, data
->machine
,
485 (gchar
*)&signature
, ext
);
487 fprintf(stderr
, "\nLooking for expected file '%s'\n", aml_file
);
489 if (g_file_test(aml_file
, G_FILE_TEST_EXISTS
)) {
490 exp_sdt
.aml_file
= aml_file
;
491 } else if (*ext
!= '\0') {
492 /* try fallback to generic (extention less) expected file */
497 g_assert(exp_sdt
.aml_file
);
499 fprintf(stderr
, "\nUsing expected file '%s'\n", aml_file
);
501 ret
= g_file_get_contents(aml_file
, &exp_sdt
.aml
,
502 &exp_sdt
.aml_len
, &error
);
504 g_assert_no_error(error
);
505 g_assert(exp_sdt
.aml
);
506 g_assert(exp_sdt
.aml_len
);
508 g_array_append_val(exp_tables
, exp_sdt
);
514 static void test_acpi_asl(test_data
*data
)
517 AcpiSdtTable
*sdt
, *exp_sdt
;
519 gboolean exp_err
, err
;
521 memset(&exp_data
, 0, sizeof(exp_data
));
522 exp_data
.tables
= load_expected_aml(data
);
523 dump_aml_files(data
, false);
524 for (i
= 0; i
< data
->tables
->len
; ++i
) {
525 GString
*asl
, *exp_asl
;
527 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
528 exp_sdt
= &g_array_index(exp_data
.tables
, AcpiSdtTable
, i
);
530 err
= load_asl(data
->tables
, sdt
);
531 asl
= normalize_asl(sdt
->asl
);
533 exp_err
= load_asl(exp_data
.tables
, exp_sdt
);
534 exp_asl
= normalize_asl(exp_sdt
->asl
);
536 /* TODO: check for warnings */
537 g_assert(!err
|| exp_err
);
539 if (g_strcmp0(asl
->str
, exp_asl
->str
)) {
542 "Warning! iasl couldn't parse the expected aml\n");
544 uint32_t signature
= cpu_to_le32(exp_sdt
->header
.signature
);
545 sdt
->tmp_files_retain
= true;
546 exp_sdt
->tmp_files_retain
= true;
548 "acpi-test: Warning! %.4s mismatch. "
549 "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
551 sdt
->asl_file
, sdt
->aml_file
,
552 exp_sdt
->asl_file
, exp_sdt
->aml_file
);
554 const char *diff_cmd
= getenv("DIFF");
556 int ret G_GNUC_UNUSED
;
557 char *diff
= g_strdup_printf("%s %s %s", diff_cmd
,
558 exp_sdt
->asl_file
, sdt
->asl_file
);
562 fprintf(stderr
, "acpi-test: Warning. not showing "
563 "difference since no diff utility is specified. "
564 "Set 'DIFF' environment variable to a preferred "
565 "diff utility and run 'make V=1 check' again to "
566 "see ASL difference.");
571 g_string_free(asl
, true);
572 g_string_free(exp_asl
, true);
575 free_test_data(&exp_data
);
578 static bool smbios_ep_table_ok(test_data
*data
)
580 struct smbios_21_entry_point
*ep_table
= &data
->smbios_ep_table
;
581 uint32_t addr
= data
->smbios_ep_addr
;
583 ACPI_READ_ARRAY(ep_table
->anchor_string
, addr
);
584 if (memcmp(ep_table
->anchor_string
, "_SM_", 4)) {
587 ACPI_READ_FIELD(ep_table
->checksum
, addr
);
588 ACPI_READ_FIELD(ep_table
->length
, addr
);
589 ACPI_READ_FIELD(ep_table
->smbios_major_version
, addr
);
590 ACPI_READ_FIELD(ep_table
->smbios_minor_version
, addr
);
591 ACPI_READ_FIELD(ep_table
->max_structure_size
, addr
);
592 ACPI_READ_FIELD(ep_table
->entry_point_revision
, addr
);
593 ACPI_READ_ARRAY(ep_table
->formatted_area
, addr
);
594 ACPI_READ_ARRAY(ep_table
->intermediate_anchor_string
, addr
);
595 if (memcmp(ep_table
->intermediate_anchor_string
, "_DMI_", 5)) {
598 ACPI_READ_FIELD(ep_table
->intermediate_checksum
, addr
);
599 ACPI_READ_FIELD(ep_table
->structure_table_length
, addr
);
600 if (ep_table
->structure_table_length
== 0) {
603 ACPI_READ_FIELD(ep_table
->structure_table_address
, addr
);
604 ACPI_READ_FIELD(ep_table
->number_of_structures
, addr
);
605 if (ep_table
->number_of_structures
== 0) {
608 ACPI_READ_FIELD(ep_table
->smbios_bcd_revision
, addr
);
609 if (acpi_checksum((uint8_t *)ep_table
, sizeof *ep_table
) ||
610 acpi_checksum((uint8_t *)ep_table
+ 0x10, sizeof *ep_table
- 0x10)) {
616 static void test_smbios_entry_point(test_data
*data
)
620 /* find smbios entry point structure */
621 for (off
= 0xf0000; off
< 0x100000; off
+= 0x10) {
622 uint8_t sig
[] = "_SM_";
625 for (i
= 0; i
< sizeof sig
- 1; ++i
) {
626 sig
[i
] = readb(off
+ i
);
629 if (!memcmp(sig
, "_SM_", sizeof sig
)) {
630 /* signature match, but is this a valid entry point? */
631 data
->smbios_ep_addr
= off
;
632 if (smbios_ep_table_ok(data
)) {
638 g_assert_cmphex(off
, <, 0x100000);
641 static inline bool smbios_single_instance(uint8_t type
)
657 static void test_smbios_structs(test_data
*data
)
659 DECLARE_BITMAP(struct_bitmap
, SMBIOS_MAX_TYPE
+1) = { 0 };
660 struct smbios_21_entry_point
*ep_table
= &data
->smbios_ep_table
;
661 uint32_t addr
= ep_table
->structure_table_address
;
662 int i
, len
, max_len
= 0;
663 uint8_t type
, prv
, crt
;
664 uint8_t required_struct_types
[] = {0, 1, 3, 4, 16, 17, 19, 32, 127};
666 /* walk the smbios tables */
667 for (i
= 0; i
< ep_table
->number_of_structures
; i
++) {
669 /* grab type and formatted area length from struct header */
671 g_assert_cmpuint(type
, <=, SMBIOS_MAX_TYPE
);
672 len
= readb(addr
+ 1);
674 /* single-instance structs must not have been encountered before */
675 if (smbios_single_instance(type
)) {
676 g_assert(!test_bit(type
, struct_bitmap
));
678 set_bit(type
, struct_bitmap
);
680 /* seek to end of unformatted string area of this struct ("\0\0") */
684 crt
= readb(addr
+ len
);
688 /* keep track of max. struct size */
691 g_assert_cmpuint(max_len
, <=, ep_table
->max_structure_size
);
694 /* start of next structure */
698 /* total table length and max struct size must match entry point values */
699 g_assert_cmpuint(ep_table
->structure_table_length
, ==,
700 addr
- ep_table
->structure_table_address
);
701 g_assert_cmpuint(ep_table
->max_structure_size
, ==, max_len
);
703 /* required struct types must all be present */
704 for (i
= 0; i
< ARRAY_SIZE(required_struct_types
); i
++) {
705 g_assert(test_bit(required_struct_types
[i
], struct_bitmap
));
709 static void test_acpi_one(const char *params
, test_data
*data
)
713 args
= g_strdup_printf("-net none -display none %s "
714 "-drive id=hd0,if=none,file=%s,format=raw "
715 "-device ide-hd,drive=hd0 ",
716 params
? params
: "", disk
);
722 test_acpi_rsdp_address(data
);
723 test_acpi_rsdp_table(data
);
724 test_acpi_rsdt_table(data
);
725 test_acpi_fadt_table(data
);
726 test_acpi_facs_table(data
);
727 test_acpi_dsdt_table(data
);
728 test_acpi_tables(data
);
731 if (getenv(ACPI_REBUILD_EXPECTED_AML
)) {
732 dump_aml_files(data
, true);
738 test_smbios_entry_point(data
);
739 test_smbios_structs(data
);
741 qtest_quit(global_qtest
);
745 static void test_acpi_piix4_tcg(void)
749 /* Supplying -machine accel argument overrides the default (qtest).
750 * This is to make guest actually run.
752 memset(&data
, 0, sizeof(data
));
753 data
.machine
= MACHINE_PC
;
754 test_acpi_one("-machine accel=tcg", &data
);
755 free_test_data(&data
);
758 static void test_acpi_piix4_tcg_bridge(void)
762 memset(&data
, 0, sizeof(data
));
763 data
.machine
= MACHINE_PC
;
764 data
.variant
= ".bridge";
765 test_acpi_one("-machine accel=tcg -device pci-bridge,chassis_nr=1", &data
);
766 free_test_data(&data
);
769 static void test_acpi_q35_tcg(void)
773 memset(&data
, 0, sizeof(data
));
774 data
.machine
= MACHINE_Q35
;
775 test_acpi_one("-machine q35,accel=tcg", &data
);
776 free_test_data(&data
);
779 static void test_acpi_q35_tcg_bridge(void)
783 memset(&data
, 0, sizeof(data
));
784 data
.machine
= MACHINE_Q35
;
785 data
.variant
= ".bridge";
786 test_acpi_one("-machine q35,accel=tcg -device pci-bridge,chassis_nr=1",
788 free_test_data(&data
);
791 int main(int argc
, char *argv
[])
793 const char *arch
= qtest_get_arch();
796 ret
= boot_sector_init(disk
);
800 g_test_init(&argc
, &argv
, NULL
);
802 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
803 qtest_add_func("acpi/piix4/tcg", test_acpi_piix4_tcg
);
804 qtest_add_func("acpi/piix4/tcg/bridge", test_acpi_piix4_tcg_bridge
);
805 qtest_add_func("acpi/q35/tcg", test_acpi_q35_tcg
);
806 qtest_add_func("acpi/q35/tcg/bridge", test_acpi_q35_tcg_bridge
);
809 boot_sector_cleanup(disk
);