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"
15 #include <glib/gstdio.h>
16 #include "qemu-common.h"
18 #include "hw/acpi/acpi-defs.h"
19 #include "hw/smbios/smbios.h"
20 #include "qemu/bitmap.h"
21 #include "boot-sector.h"
23 #define MACHINE_PC "pc"
24 #define MACHINE_Q35 "q35"
26 #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
28 /* DSDT and SSDTs format */
30 AcpiTableHeader header
;
31 gchar
*aml
; /* aml bytecode from guest */
34 gchar
*asl
; /* asl code generated from aml */
37 bool tmp_files_retain
; /* do not delete the temp asl/aml */
38 } QEMU_PACKED AcpiSdtTable
;
44 AcpiRsdpDescriptor rsdp_table
;
45 AcpiRsdtDescriptorRev1 rsdt_table
;
46 AcpiFadtDescriptorRev1 fadt_table
;
47 AcpiFacsDescriptorRev1 facs_table
;
48 uint32_t *rsdt_tables_addr
;
51 uint32_t smbios_ep_addr
;
52 struct smbios_21_entry_point smbios_ep_table
;
55 #define ACPI_READ_FIELD(field, addr) \
57 switch (sizeof(field)) { \
59 field = readb(addr); \
62 field = readw(addr); \
65 field = readl(addr); \
68 field = readq(addr); \
73 addr += sizeof(field); \
76 #define ACPI_READ_ARRAY_PTR(arr, length, addr) \
79 for (idx = 0; idx < length; ++idx) { \
80 ACPI_READ_FIELD(arr[idx], addr); \
84 #define ACPI_READ_ARRAY(arr, addr) \
85 ACPI_READ_ARRAY_PTR(arr, sizeof(arr)/sizeof(arr[0]), addr)
87 #define ACPI_READ_TABLE_HEADER(table, addr) \
89 ACPI_READ_FIELD((table)->signature, addr); \
90 ACPI_READ_FIELD((table)->length, addr); \
91 ACPI_READ_FIELD((table)->revision, addr); \
92 ACPI_READ_FIELD((table)->checksum, addr); \
93 ACPI_READ_ARRAY((table)->oem_id, addr); \
94 ACPI_READ_ARRAY((table)->oem_table_id, addr); \
95 ACPI_READ_FIELD((table)->oem_revision, addr); \
96 ACPI_READ_ARRAY((table)->asl_compiler_id, addr); \
97 ACPI_READ_FIELD((table)->asl_compiler_revision, addr); \
100 #define ACPI_ASSERT_CMP(actual, expected) do { \
101 uint32_t ACPI_ASSERT_CMP_le = cpu_to_le32(actual); \
102 char ACPI_ASSERT_CMP_str[5] = {}; \
103 memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 4); \
104 g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
107 #define ACPI_ASSERT_CMP64(actual, expected) do { \
108 uint64_t ACPI_ASSERT_CMP_le = cpu_to_le64(actual); \
109 char ACPI_ASSERT_CMP_str[9] = {}; \
110 memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 8); \
111 g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
114 static const char *disk
= "tests/acpi-test-disk.raw";
115 static const char *data_dir
= "tests/acpi-test-data";
117 static const char *iasl
= stringify(CONFIG_IASL
);
119 static const char *iasl
;
122 static void free_test_data(test_data
*data
)
127 g_free(data
->rsdt_tables_addr
);
129 for (i
= 0; i
< data
->tables
->len
; ++i
) {
130 temp
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
132 if (temp
->aml_file
&&
133 !temp
->tmp_files_retain
&&
134 g_strstr_len(temp
->aml_file
, -1, "aml-")) {
135 unlink(temp
->aml_file
);
137 g_free(temp
->aml_file
);
139 if (temp
->asl_file
&&
140 !temp
->tmp_files_retain
) {
141 unlink(temp
->asl_file
);
143 g_free(temp
->asl_file
);
146 g_array_free(data
->tables
, false);
149 static uint8_t acpi_checksum(const uint8_t *data
, int len
)
154 for (i
= 0; i
< len
; i
++) {
161 static void test_acpi_rsdp_address(test_data
*data
)
165 /* OK, now find RSDP */
166 for (off
= 0xf0000; off
< 0x100000; off
+= 0x10) {
167 uint8_t sig
[] = "RSD PTR ";
170 for (i
= 0; i
< sizeof sig
- 1; ++i
) {
171 sig
[i
] = readb(off
+ i
);
174 if (!memcmp(sig
, "RSD PTR ", sizeof sig
)) {
179 g_assert_cmphex(off
, <, 0x100000);
180 data
->rsdp_addr
= off
;
183 static void test_acpi_rsdp_table(test_data
*data
)
185 AcpiRsdpDescriptor
*rsdp_table
= &data
->rsdp_table
;
186 uint32_t addr
= data
->rsdp_addr
;
188 ACPI_READ_FIELD(rsdp_table
->signature
, addr
);
189 ACPI_ASSERT_CMP64(rsdp_table
->signature
, "RSD PTR ");
191 ACPI_READ_FIELD(rsdp_table
->checksum
, addr
);
192 ACPI_READ_ARRAY(rsdp_table
->oem_id
, addr
);
193 ACPI_READ_FIELD(rsdp_table
->revision
, addr
);
194 ACPI_READ_FIELD(rsdp_table
->rsdt_physical_address
, addr
);
195 ACPI_READ_FIELD(rsdp_table
->length
, addr
);
197 /* rsdp checksum is not for the whole table, but for the first 20 bytes */
198 g_assert(!acpi_checksum((uint8_t *)rsdp_table
, 20));
201 static void test_acpi_rsdt_table(test_data
*data
)
203 AcpiRsdtDescriptorRev1
*rsdt_table
= &data
->rsdt_table
;
204 uint32_t addr
= data
->rsdp_table
.rsdt_physical_address
;
209 /* read the header */
210 ACPI_READ_TABLE_HEADER(rsdt_table
, addr
);
211 ACPI_ASSERT_CMP(rsdt_table
->signature
, "RSDT");
213 /* compute the table entries in rsdt */
214 tables_nr
= (rsdt_table
->length
- sizeof(AcpiRsdtDescriptorRev1
)) /
216 g_assert_cmpint(tables_nr
, >, 0);
218 /* get the addresses of the tables pointed by rsdt */
219 tables
= g_new0(uint32_t, tables_nr
);
220 ACPI_READ_ARRAY_PTR(tables
, tables_nr
, addr
);
222 checksum
= acpi_checksum((uint8_t *)rsdt_table
, rsdt_table
->length
) +
223 acpi_checksum((uint8_t *)tables
, tables_nr
* sizeof(uint32_t));
226 /* SSDT tables after FADT */
227 data
->rsdt_tables_addr
= tables
;
228 data
->rsdt_tables_nr
= tables_nr
;
231 static void test_acpi_fadt_table(test_data
*data
)
233 AcpiFadtDescriptorRev1
*fadt_table
= &data
->fadt_table
;
236 /* FADT table comes first */
237 addr
= data
->rsdt_tables_addr
[0];
238 ACPI_READ_TABLE_HEADER(fadt_table
, addr
);
240 ACPI_READ_FIELD(fadt_table
->firmware_ctrl
, addr
);
241 ACPI_READ_FIELD(fadt_table
->dsdt
, addr
);
242 ACPI_READ_FIELD(fadt_table
->model
, addr
);
243 ACPI_READ_FIELD(fadt_table
->reserved1
, addr
);
244 ACPI_READ_FIELD(fadt_table
->sci_int
, addr
);
245 ACPI_READ_FIELD(fadt_table
->smi_cmd
, addr
);
246 ACPI_READ_FIELD(fadt_table
->acpi_enable
, addr
);
247 ACPI_READ_FIELD(fadt_table
->acpi_disable
, addr
);
248 ACPI_READ_FIELD(fadt_table
->S4bios_req
, addr
);
249 ACPI_READ_FIELD(fadt_table
->reserved2
, addr
);
250 ACPI_READ_FIELD(fadt_table
->pm1a_evt_blk
, addr
);
251 ACPI_READ_FIELD(fadt_table
->pm1b_evt_blk
, addr
);
252 ACPI_READ_FIELD(fadt_table
->pm1a_cnt_blk
, addr
);
253 ACPI_READ_FIELD(fadt_table
->pm1b_cnt_blk
, addr
);
254 ACPI_READ_FIELD(fadt_table
->pm2_cnt_blk
, addr
);
255 ACPI_READ_FIELD(fadt_table
->pm_tmr_blk
, addr
);
256 ACPI_READ_FIELD(fadt_table
->gpe0_blk
, addr
);
257 ACPI_READ_FIELD(fadt_table
->gpe1_blk
, addr
);
258 ACPI_READ_FIELD(fadt_table
->pm1_evt_len
, addr
);
259 ACPI_READ_FIELD(fadt_table
->pm1_cnt_len
, addr
);
260 ACPI_READ_FIELD(fadt_table
->pm2_cnt_len
, addr
);
261 ACPI_READ_FIELD(fadt_table
->pm_tmr_len
, addr
);
262 ACPI_READ_FIELD(fadt_table
->gpe0_blk_len
, addr
);
263 ACPI_READ_FIELD(fadt_table
->gpe1_blk_len
, addr
);
264 ACPI_READ_FIELD(fadt_table
->gpe1_base
, addr
);
265 ACPI_READ_FIELD(fadt_table
->reserved3
, addr
);
266 ACPI_READ_FIELD(fadt_table
->plvl2_lat
, addr
);
267 ACPI_READ_FIELD(fadt_table
->plvl3_lat
, addr
);
268 ACPI_READ_FIELD(fadt_table
->flush_size
, addr
);
269 ACPI_READ_FIELD(fadt_table
->flush_stride
, addr
);
270 ACPI_READ_FIELD(fadt_table
->duty_offset
, addr
);
271 ACPI_READ_FIELD(fadt_table
->duty_width
, addr
);
272 ACPI_READ_FIELD(fadt_table
->day_alrm
, addr
);
273 ACPI_READ_FIELD(fadt_table
->mon_alrm
, addr
);
274 ACPI_READ_FIELD(fadt_table
->century
, addr
);
275 ACPI_READ_FIELD(fadt_table
->reserved4
, addr
);
276 ACPI_READ_FIELD(fadt_table
->reserved4a
, addr
);
277 ACPI_READ_FIELD(fadt_table
->reserved4b
, addr
);
278 ACPI_READ_FIELD(fadt_table
->flags
, addr
);
280 ACPI_ASSERT_CMP(fadt_table
->signature
, "FACP");
281 g_assert(!acpi_checksum((uint8_t *)fadt_table
, fadt_table
->length
));
284 static void test_acpi_facs_table(test_data
*data
)
286 AcpiFacsDescriptorRev1
*facs_table
= &data
->facs_table
;
287 uint32_t addr
= data
->fadt_table
.firmware_ctrl
;
289 ACPI_READ_FIELD(facs_table
->signature
, addr
);
290 ACPI_READ_FIELD(facs_table
->length
, addr
);
291 ACPI_READ_FIELD(facs_table
->hardware_signature
, addr
);
292 ACPI_READ_FIELD(facs_table
->firmware_waking_vector
, addr
);
293 ACPI_READ_FIELD(facs_table
->global_lock
, addr
);
294 ACPI_READ_FIELD(facs_table
->flags
, addr
);
295 ACPI_READ_ARRAY(facs_table
->resverved3
, addr
);
297 ACPI_ASSERT_CMP(facs_table
->signature
, "FACS");
300 static void test_dst_table(AcpiSdtTable
*sdt_table
, uint32_t addr
)
304 ACPI_READ_TABLE_HEADER(&sdt_table
->header
, addr
);
306 sdt_table
->aml_len
= sdt_table
->header
.length
- sizeof(AcpiTableHeader
);
307 sdt_table
->aml
= g_malloc0(sdt_table
->aml_len
);
308 ACPI_READ_ARRAY_PTR(sdt_table
->aml
, sdt_table
->aml_len
, addr
);
310 checksum
= acpi_checksum((uint8_t *)sdt_table
, sizeof(AcpiTableHeader
)) +
311 acpi_checksum((uint8_t *)sdt_table
->aml
, sdt_table
->aml_len
);
315 static void test_acpi_dsdt_table(test_data
*data
)
317 AcpiSdtTable dsdt_table
;
318 uint32_t addr
= data
->fadt_table
.dsdt
;
320 memset(&dsdt_table
, 0, sizeof(dsdt_table
));
321 data
->tables
= g_array_new(false, true, sizeof(AcpiSdtTable
));
323 test_dst_table(&dsdt_table
, addr
);
324 ACPI_ASSERT_CMP(dsdt_table
.header
.signature
, "DSDT");
326 /* Place DSDT first */
327 g_array_append_val(data
->tables
, dsdt_table
);
330 static void test_acpi_tables(test_data
*data
)
332 int tables_nr
= data
->rsdt_tables_nr
- 1; /* fadt is first */
335 for (i
= 0; i
< tables_nr
; i
++) {
336 AcpiSdtTable ssdt_table
;
338 memset(&ssdt_table
, 0 , sizeof(ssdt_table
));
339 uint32_t addr
= data
->rsdt_tables_addr
[i
+ 1]; /* fadt is first */
340 test_dst_table(&ssdt_table
, addr
);
341 g_array_append_val(data
->tables
, ssdt_table
);
345 static void dump_aml_files(test_data
*data
, bool rebuild
)
348 GError
*error
= NULL
;
349 gchar
*aml_file
= NULL
;
354 for (i
= 0; i
< data
->tables
->len
; ++i
) {
355 const char *ext
= data
->variant
? data
->variant
: "";
356 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
360 uint32_t signature
= cpu_to_le32(sdt
->header
.signature
);
361 aml_file
= g_strdup_printf("%s/%s/%.4s%s", data_dir
, data
->machine
,
362 (gchar
*)&signature
, ext
);
363 fd
= g_open(aml_file
, O_WRONLY
|O_TRUNC
|O_CREAT
,
364 S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IWGRP
|S_IROTH
);
366 fd
= g_file_open_tmp("aml-XXXXXX", &sdt
->aml_file
, &error
);
367 g_assert_no_error(error
);
371 ret
= qemu_write_full(fd
, sdt
, sizeof(AcpiTableHeader
));
372 g_assert(ret
== sizeof(AcpiTableHeader
));
373 ret
= qemu_write_full(fd
, sdt
->aml
, sdt
->aml_len
);
374 g_assert(ret
== sdt
->aml_len
);
382 static bool compare_signature(AcpiSdtTable
*sdt
, const char *signature
)
384 return !memcmp(&sdt
->header
.signature
, signature
, 4);
387 static bool load_asl(GArray
*sdts
, AcpiSdtTable
*sdt
)
390 GError
*error
= NULL
;
391 GString
*command_line
= g_string_new(iasl
);
393 gchar
*out
, *out_err
;
397 fd
= g_file_open_tmp("asl-XXXXXX.dsl", &sdt
->asl_file
, &error
);
398 g_assert_no_error(error
);
401 /* build command line */
402 g_string_append_printf(command_line
, " -p %s ", sdt
->asl_file
);
403 if (compare_signature(sdt
, "DSDT") ||
404 compare_signature(sdt
, "SSDT")) {
405 for (i
= 0; i
< sdts
->len
; ++i
) {
406 temp
= &g_array_index(sdts
, AcpiSdtTable
, i
);
407 if (compare_signature(temp
, "DSDT") ||
408 compare_signature(temp
, "SSDT")) {
409 g_string_append_printf(command_line
, "-e %s ", temp
->aml_file
);
413 g_string_append_printf(command_line
, "-d %s", sdt
->aml_file
);
415 /* pass 'out' and 'out_err' in order to be redirected */
416 ret
= g_spawn_command_line_sync(command_line
->str
, &out
, &out_err
, NULL
, &error
);
417 g_assert_no_error(error
);
419 ret
= g_file_get_contents(sdt
->asl_file
, (gchar
**)&sdt
->asl
,
420 &sdt
->asl_len
, &error
);
422 g_assert_no_error(error
);
423 ret
= (sdt
->asl_len
> 0);
428 g_string_free(command_line
, true);
433 #define COMMENT_END "*/"
434 #define DEF_BLOCK "DefinitionBlock ("
435 #define BLOCK_NAME_END ","
437 static GString
*normalize_asl(gchar
*asl_code
)
439 GString
*asl
= g_string_new(asl_code
);
440 gchar
*comment
, *block_name
;
442 /* strip comments (different generation days) */
443 comment
= g_strstr_len(asl
->str
, asl
->len
, COMMENT_END
);
445 comment
+= strlen(COMMENT_END
);
446 while (*comment
== '\n') {
449 asl
= g_string_erase(asl
, 0, comment
- asl
->str
);
452 /* strip def block name (it has file path in it) */
453 if (g_str_has_prefix(asl
->str
, DEF_BLOCK
)) {
454 block_name
= g_strstr_len(asl
->str
, asl
->len
, BLOCK_NAME_END
);
455 g_assert(block_name
);
456 asl
= g_string_erase(asl
, 0,
457 block_name
+ sizeof(BLOCK_NAME_END
) - asl
->str
);
463 static GArray
*load_expected_aml(test_data
*data
)
467 gchar
*aml_file
= NULL
;
468 GError
*error
= NULL
;
471 GArray
*exp_tables
= g_array_new(false, true, sizeof(AcpiSdtTable
));
472 for (i
= 0; i
< data
->tables
->len
; ++i
) {
473 AcpiSdtTable exp_sdt
;
475 const char *ext
= data
->variant
? data
->variant
: "";
477 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
479 memset(&exp_sdt
, 0, sizeof(exp_sdt
));
480 exp_sdt
.header
.signature
= sdt
->header
.signature
;
482 signature
= cpu_to_le32(sdt
->header
.signature
);
485 aml_file
= g_strdup_printf("%s/%s/%.4s%s", data_dir
, data
->machine
,
486 (gchar
*)&signature
, ext
);
487 if (data
->variant
&& !g_file_test(aml_file
, G_FILE_TEST_EXISTS
)) {
492 exp_sdt
.aml_file
= aml_file
;
493 g_assert(g_file_test(aml_file
, G_FILE_TEST_EXISTS
));
494 ret
= g_file_get_contents(aml_file
, &exp_sdt
.aml
,
495 &exp_sdt
.aml_len
, &error
);
497 g_assert_no_error(error
);
498 g_assert(exp_sdt
.aml
);
499 g_assert(exp_sdt
.aml_len
);
501 g_array_append_val(exp_tables
, exp_sdt
);
507 static void test_acpi_asl(test_data
*data
)
510 AcpiSdtTable
*sdt
, *exp_sdt
;
512 gboolean exp_err
, err
;
514 memset(&exp_data
, 0, sizeof(exp_data
));
515 exp_data
.tables
= load_expected_aml(data
);
516 dump_aml_files(data
, false);
517 for (i
= 0; i
< data
->tables
->len
; ++i
) {
518 GString
*asl
, *exp_asl
;
520 sdt
= &g_array_index(data
->tables
, AcpiSdtTable
, i
);
521 exp_sdt
= &g_array_index(exp_data
.tables
, AcpiSdtTable
, i
);
523 err
= load_asl(data
->tables
, sdt
);
524 asl
= normalize_asl(sdt
->asl
);
526 exp_err
= load_asl(exp_data
.tables
, exp_sdt
);
527 exp_asl
= normalize_asl(exp_sdt
->asl
);
529 /* TODO: check for warnings */
530 g_assert(!err
|| exp_err
);
532 if (g_strcmp0(asl
->str
, exp_asl
->str
)) {
535 "Warning! iasl couldn't parse the expected aml\n");
537 uint32_t signature
= cpu_to_le32(exp_sdt
->header
.signature
);
538 sdt
->tmp_files_retain
= true;
539 exp_sdt
->tmp_files_retain
= true;
541 "acpi-test: Warning! %.4s mismatch. "
542 "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
544 sdt
->asl_file
, sdt
->aml_file
,
545 exp_sdt
->asl_file
, exp_sdt
->aml_file
);
547 const char *diff_cmd
= getenv("DIFF");
549 int ret G_GNUC_UNUSED
;
550 char *diff
= g_strdup_printf("%s %s %s", diff_cmd
,
551 exp_sdt
->asl_file
, sdt
->asl_file
);
555 fprintf(stderr
, "acpi-test: Warning. not showing "
556 "difference since no diff utility is specified. "
557 "Set 'DIFF' environment variable to a preferred "
558 "diff utility and run 'make V=1 check' again to "
559 "see ASL difference.");
564 g_string_free(asl
, true);
565 g_string_free(exp_asl
, true);
568 free_test_data(&exp_data
);
571 static bool smbios_ep_table_ok(test_data
*data
)
573 struct smbios_21_entry_point
*ep_table
= &data
->smbios_ep_table
;
574 uint32_t addr
= data
->smbios_ep_addr
;
576 ACPI_READ_ARRAY(ep_table
->anchor_string
, addr
);
577 if (memcmp(ep_table
->anchor_string
, "_SM_", 4)) {
580 ACPI_READ_FIELD(ep_table
->checksum
, addr
);
581 ACPI_READ_FIELD(ep_table
->length
, addr
);
582 ACPI_READ_FIELD(ep_table
->smbios_major_version
, addr
);
583 ACPI_READ_FIELD(ep_table
->smbios_minor_version
, addr
);
584 ACPI_READ_FIELD(ep_table
->max_structure_size
, addr
);
585 ACPI_READ_FIELD(ep_table
->entry_point_revision
, addr
);
586 ACPI_READ_ARRAY(ep_table
->formatted_area
, addr
);
587 ACPI_READ_ARRAY(ep_table
->intermediate_anchor_string
, addr
);
588 if (memcmp(ep_table
->intermediate_anchor_string
, "_DMI_", 5)) {
591 ACPI_READ_FIELD(ep_table
->intermediate_checksum
, addr
);
592 ACPI_READ_FIELD(ep_table
->structure_table_length
, addr
);
593 if (ep_table
->structure_table_length
== 0) {
596 ACPI_READ_FIELD(ep_table
->structure_table_address
, addr
);
597 ACPI_READ_FIELD(ep_table
->number_of_structures
, addr
);
598 if (ep_table
->number_of_structures
== 0) {
601 ACPI_READ_FIELD(ep_table
->smbios_bcd_revision
, addr
);
602 if (acpi_checksum((uint8_t *)ep_table
, sizeof *ep_table
) ||
603 acpi_checksum((uint8_t *)ep_table
+ 0x10, sizeof *ep_table
- 0x10)) {
609 static void test_smbios_entry_point(test_data
*data
)
613 /* find smbios entry point structure */
614 for (off
= 0xf0000; off
< 0x100000; off
+= 0x10) {
615 uint8_t sig
[] = "_SM_";
618 for (i
= 0; i
< sizeof sig
- 1; ++i
) {
619 sig
[i
] = readb(off
+ i
);
622 if (!memcmp(sig
, "_SM_", sizeof sig
)) {
623 /* signature match, but is this a valid entry point? */
624 data
->smbios_ep_addr
= off
;
625 if (smbios_ep_table_ok(data
)) {
631 g_assert_cmphex(off
, <, 0x100000);
634 static inline bool smbios_single_instance(uint8_t type
)
650 static void test_smbios_structs(test_data
*data
)
652 DECLARE_BITMAP(struct_bitmap
, SMBIOS_MAX_TYPE
+1) = { 0 };
653 struct smbios_21_entry_point
*ep_table
= &data
->smbios_ep_table
;
654 uint32_t addr
= ep_table
->structure_table_address
;
655 int i
, len
, max_len
= 0;
656 uint8_t type
, prv
, crt
;
657 uint8_t required_struct_types
[] = {0, 1, 3, 4, 16, 17, 19, 32, 127};
659 /* walk the smbios tables */
660 for (i
= 0; i
< ep_table
->number_of_structures
; i
++) {
662 /* grab type and formatted area length from struct header */
664 g_assert_cmpuint(type
, <=, SMBIOS_MAX_TYPE
);
665 len
= readb(addr
+ 1);
667 /* single-instance structs must not have been encountered before */
668 if (smbios_single_instance(type
)) {
669 g_assert(!test_bit(type
, struct_bitmap
));
671 set_bit(type
, struct_bitmap
);
673 /* seek to end of unformatted string area of this struct ("\0\0") */
677 crt
= readb(addr
+ len
);
681 /* keep track of max. struct size */
684 g_assert_cmpuint(max_len
, <=, ep_table
->max_structure_size
);
687 /* start of next structure */
691 /* total table length and max struct size must match entry point values */
692 g_assert_cmpuint(ep_table
->structure_table_length
, ==,
693 addr
- ep_table
->structure_table_address
);
694 g_assert_cmpuint(ep_table
->max_structure_size
, ==, max_len
);
696 /* required struct types must all be present */
697 for (i
= 0; i
< ARRAY_SIZE(required_struct_types
); i
++) {
698 g_assert(test_bit(required_struct_types
[i
], struct_bitmap
));
702 static void test_acpi_one(const char *params
, test_data
*data
)
706 args
= g_strdup_printf("-net none -display none %s "
707 "-drive id=hd0,if=none,file=%s,format=raw "
708 "-device ide-hd,drive=hd0 ",
709 params
? params
: "", disk
);
715 test_acpi_rsdp_address(data
);
716 test_acpi_rsdp_table(data
);
717 test_acpi_rsdt_table(data
);
718 test_acpi_fadt_table(data
);
719 test_acpi_facs_table(data
);
720 test_acpi_dsdt_table(data
);
721 test_acpi_tables(data
);
724 if (getenv(ACPI_REBUILD_EXPECTED_AML
)) {
725 dump_aml_files(data
, true);
731 test_smbios_entry_point(data
);
732 test_smbios_structs(data
);
734 qtest_quit(global_qtest
);
738 static void test_acpi_piix4_tcg(void)
742 /* Supplying -machine accel argument overrides the default (qtest).
743 * This is to make guest actually run.
745 memset(&data
, 0, sizeof(data
));
746 data
.machine
= MACHINE_PC
;
747 test_acpi_one("-machine accel=tcg", &data
);
748 free_test_data(&data
);
751 static void test_acpi_piix4_tcg_bridge(void)
755 memset(&data
, 0, sizeof(data
));
756 data
.machine
= MACHINE_PC
;
757 data
.variant
= ".bridge";
758 test_acpi_one("-machine accel=tcg -device pci-bridge,chassis_nr=1", &data
);
759 free_test_data(&data
);
762 static void test_acpi_q35_tcg(void)
766 memset(&data
, 0, sizeof(data
));
767 data
.machine
= MACHINE_Q35
;
768 test_acpi_one("-machine q35,accel=tcg", &data
);
769 free_test_data(&data
);
772 static void test_acpi_q35_tcg_bridge(void)
776 memset(&data
, 0, sizeof(data
));
777 data
.machine
= MACHINE_Q35
;
778 data
.variant
= ".bridge";
779 test_acpi_one("-machine q35,accel=tcg -device pci-bridge,chassis_nr=1",
781 free_test_data(&data
);
784 int main(int argc
, char *argv
[])
786 const char *arch
= qtest_get_arch();
789 ret
= boot_sector_init(disk
);
793 g_test_init(&argc
, &argv
, NULL
);
795 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
796 qtest_add_func("acpi/piix4/tcg", test_acpi_piix4_tcg
);
797 qtest_add_func("acpi/piix4/tcg/bridge", test_acpi_piix4_tcg_bridge
);
798 qtest_add_func("acpi/q35/tcg", test_acpi_q35_tcg
);
799 qtest_add_func("acpi/q35/tcg/bridge", test_acpi_q35_tcg_bridge
);
802 boot_sector_cleanup(disk
);