tests: remove obsolete 'debian' dockerfile
[qemu/ar7.git] / tests / bios-tables-test.c
blobd455b2abfceea77cbef21dbace0751d8c6eb4304
1 /*
2 * Boot order test cases.
4 * Copyright (c) 2013 Red Hat Inc.
6 * Authors:
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"
16 #include "hw/firmware/smbios.h"
17 #include "qemu/bitmap.h"
18 #include "acpi-utils.h"
19 #include "boot-sector.h"
21 #define MACHINE_PC "pc"
22 #define MACHINE_Q35 "q35"
24 #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
26 typedef struct {
27 const char *machine;
28 const char *variant;
29 uint32_t rsdp_addr;
30 uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */];
31 AcpiRsdtDescriptorRev1 rsdt_table;
32 uint32_t dsdt_addr;
33 uint32_t facs_addr;
34 AcpiFacsDescriptorRev1 facs_table;
35 uint32_t *rsdt_tables_addr;
36 int rsdt_tables_nr;
37 GArray *tables;
38 uint32_t smbios_ep_addr;
39 struct smbios_21_entry_point smbios_ep_table;
40 uint8_t *required_struct_types;
41 int required_struct_types_len;
42 QTestState *qts;
43 } test_data;
45 static char disk[] = "tests/acpi-test-disk-XXXXXX";
46 static const char *data_dir = "tests/data/acpi";
47 #ifdef CONFIG_IASL
48 static const char *iasl = stringify(CONFIG_IASL);
49 #else
50 static const char *iasl;
51 #endif
53 static void free_test_data(test_data *data)
55 AcpiSdtTable *temp;
56 int i;
58 g_free(data->rsdt_tables_addr);
60 for (i = 0; i < data->tables->len; ++i) {
61 temp = &g_array_index(data->tables, AcpiSdtTable, i);
62 g_free(temp->aml);
63 if (temp->aml_file &&
64 !temp->tmp_files_retain &&
65 g_strstr_len(temp->aml_file, -1, "aml-")) {
66 unlink(temp->aml_file);
68 g_free(temp->aml_file);
69 g_free(temp->asl);
70 if (temp->asl_file &&
71 !temp->tmp_files_retain) {
72 unlink(temp->asl_file);
74 g_free(temp->asl_file);
77 g_array_free(data->tables, true);
80 static void test_acpi_rsdp_address(test_data *data)
82 uint32_t off = acpi_find_rsdp_address(data->qts);
83 g_assert_cmphex(off, <, 0x100000);
84 data->rsdp_addr = off;
87 static void test_acpi_rsdp_table(test_data *data)
89 uint8_t *rsdp_table = data->rsdp_table, revision;
90 uint32_t addr = data->rsdp_addr;
92 acpi_parse_rsdp_table(data->qts, addr, rsdp_table);
93 revision = rsdp_table[15 /* Revision offset */];
95 switch (revision) {
96 case 0: /* ACPI 1.0 RSDP */
97 /* With rev 1, checksum is only for the first 20 bytes */
98 g_assert(!acpi_calc_checksum(rsdp_table, 20));
99 break;
100 case 2: /* ACPI 2.0+ RSDP */
101 /* With revision 2, we have 2 checksums */
102 g_assert(!acpi_calc_checksum(rsdp_table, 20));
103 g_assert(!acpi_calc_checksum(rsdp_table, 36));
104 break;
105 default:
106 g_assert_not_reached();
110 static void test_acpi_rsdt_table(test_data *data)
112 AcpiRsdtDescriptorRev1 *rsdt_table = &data->rsdt_table;
113 uint32_t addr = acpi_get_rsdt_address(data->rsdp_table);
114 uint32_t *tables;
115 int tables_nr;
116 uint8_t checksum;
117 uint32_t rsdt_table_length;
119 /* read the header */
120 ACPI_READ_TABLE_HEADER(data->qts, rsdt_table, addr);
121 ACPI_ASSERT_CMP(rsdt_table->signature, "RSDT");
123 rsdt_table_length = le32_to_cpu(rsdt_table->length);
125 /* compute the table entries in rsdt */
126 tables_nr = (rsdt_table_length - sizeof(AcpiRsdtDescriptorRev1)) /
127 sizeof(uint32_t);
128 g_assert(tables_nr > 0);
130 /* get the addresses of the tables pointed by rsdt */
131 tables = g_new0(uint32_t, tables_nr);
132 ACPI_READ_ARRAY_PTR(data->qts, tables, tables_nr, addr);
134 checksum = acpi_calc_checksum((uint8_t *)rsdt_table, rsdt_table_length) +
135 acpi_calc_checksum((uint8_t *)tables,
136 tables_nr * sizeof(uint32_t));
137 g_assert(!checksum);
139 /* SSDT tables after FADT */
140 data->rsdt_tables_addr = tables;
141 data->rsdt_tables_nr = tables_nr;
144 static void fadt_fetch_facs_and_dsdt_ptrs(test_data *data)
146 uint32_t addr;
147 AcpiTableHeader hdr;
149 /* FADT table comes first */
150 addr = le32_to_cpu(data->rsdt_tables_addr[0]);
151 ACPI_READ_TABLE_HEADER(data->qts, &hdr, addr);
152 ACPI_ASSERT_CMP(hdr.signature, "FACP");
154 ACPI_READ_FIELD(data->qts, data->facs_addr, addr);
155 ACPI_READ_FIELD(data->qts, data->dsdt_addr, addr);
158 static void sanitize_fadt_ptrs(test_data *data)
160 /* fixup pointers in FADT */
161 int i;
163 for (i = 0; i < data->tables->len; i++) {
164 AcpiSdtTable *sdt = &g_array_index(data->tables, AcpiSdtTable, i);
166 if (memcmp(&sdt->header.signature, "FACP", 4)) {
167 continue;
170 /* check original FADT checksum before sanitizing table */
171 g_assert(!(uint8_t)(
172 acpi_calc_checksum((uint8_t *)sdt, sizeof(AcpiTableHeader)) +
173 acpi_calc_checksum((uint8_t *)sdt->aml, sdt->aml_len)
176 /* sdt->aml field offset := spec offset - header size */
177 memset(sdt->aml + 0, 0, 4); /* sanitize FIRMWARE_CTRL(36) ptr */
178 memset(sdt->aml + 4, 0, 4); /* sanitize DSDT(40) ptr */
179 if (sdt->header.revision >= 3) {
180 memset(sdt->aml + 96, 0, 8); /* sanitize X_FIRMWARE_CTRL(132) ptr */
181 memset(sdt->aml + 104, 0, 8); /* sanitize X_DSDT(140) ptr */
184 /* update checksum */
185 sdt->header.checksum = 0;
186 sdt->header.checksum -=
187 acpi_calc_checksum((uint8_t *)sdt, sizeof(AcpiTableHeader)) +
188 acpi_calc_checksum((uint8_t *)sdt->aml, sdt->aml_len);
189 break;
193 static void test_acpi_facs_table(test_data *data)
195 AcpiFacsDescriptorRev1 *facs_table = &data->facs_table;
196 uint32_t addr = le32_to_cpu(data->facs_addr);
198 ACPI_READ_FIELD(data->qts, facs_table->signature, addr);
199 ACPI_READ_FIELD(data->qts, facs_table->length, addr);
200 ACPI_READ_FIELD(data->qts, facs_table->hardware_signature, addr);
201 ACPI_READ_FIELD(data->qts, facs_table->firmware_waking_vector, addr);
202 ACPI_READ_FIELD(data->qts, facs_table->global_lock, addr);
203 ACPI_READ_FIELD(data->qts, facs_table->flags, addr);
204 ACPI_READ_ARRAY(data->qts, facs_table->resverved3, addr);
206 ACPI_ASSERT_CMP(facs_table->signature, "FACS");
209 /** fetch_table
210 * load ACPI table at @addr into table descriptor @sdt_table
211 * and check that header checksum matches actual one.
213 static void fetch_table(QTestState *qts, AcpiSdtTable *sdt_table, uint32_t addr)
215 uint8_t checksum;
217 memset(sdt_table, 0, sizeof(*sdt_table));
218 ACPI_READ_TABLE_HEADER(qts, &sdt_table->header, addr);
220 sdt_table->aml_len = le32_to_cpu(sdt_table->header.length)
221 - sizeof(AcpiTableHeader);
222 sdt_table->aml = g_malloc0(sdt_table->aml_len);
223 ACPI_READ_ARRAY_PTR(qts, sdt_table->aml, sdt_table->aml_len, addr);
225 checksum = acpi_calc_checksum((uint8_t *)sdt_table,
226 sizeof(AcpiTableHeader)) +
227 acpi_calc_checksum((uint8_t *)sdt_table->aml,
228 sdt_table->aml_len);
229 g_assert(!checksum);
232 static void test_acpi_dsdt_table(test_data *data)
234 AcpiSdtTable dsdt_table;
235 uint32_t addr = le32_to_cpu(data->dsdt_addr);
237 fetch_table(data->qts, &dsdt_table, addr);
238 ACPI_ASSERT_CMP(dsdt_table.header.signature, "DSDT");
240 /* Since DSDT isn't in RSDT, add DSDT to ASL test tables list manually */
241 g_array_append_val(data->tables, dsdt_table);
244 /* Load all tables and add to test list directly RSDT referenced tables */
245 static void fetch_rsdt_referenced_tables(test_data *data)
247 int tables_nr = data->rsdt_tables_nr;
248 int i;
250 for (i = 0; i < tables_nr; i++) {
251 AcpiSdtTable ssdt_table;
252 uint32_t addr;
254 addr = le32_to_cpu(data->rsdt_tables_addr[i]);
255 fetch_table(data->qts, &ssdt_table, addr);
257 /* Add table to ASL test tables list */
258 g_array_append_val(data->tables, ssdt_table);
262 static void dump_aml_files(test_data *data, bool rebuild)
264 AcpiSdtTable *sdt;
265 GError *error = NULL;
266 gchar *aml_file = NULL;
267 gint fd;
268 ssize_t ret;
269 int i;
271 for (i = 0; i < data->tables->len; ++i) {
272 const char *ext = data->variant ? data->variant : "";
273 sdt = &g_array_index(data->tables, AcpiSdtTable, i);
274 g_assert(sdt->aml);
276 if (rebuild) {
277 aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
278 (gchar *)&sdt->header.signature, ext);
279 fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT,
280 S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
281 } else {
282 fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
283 g_assert_no_error(error);
285 g_assert(fd >= 0);
287 ret = qemu_write_full(fd, sdt, sizeof(AcpiTableHeader));
288 g_assert(ret == sizeof(AcpiTableHeader));
289 ret = qemu_write_full(fd, sdt->aml, sdt->aml_len);
290 g_assert(ret == sdt->aml_len);
292 close(fd);
294 g_free(aml_file);
298 static bool compare_signature(AcpiSdtTable *sdt, const char *signature)
300 return !memcmp(&sdt->header.signature, signature, 4);
303 static bool load_asl(GArray *sdts, AcpiSdtTable *sdt)
305 AcpiSdtTable *temp;
306 GError *error = NULL;
307 GString *command_line = g_string_new(iasl);
308 gint fd;
309 gchar *out, *out_err;
310 gboolean ret;
311 int i;
313 fd = g_file_open_tmp("asl-XXXXXX.dsl", &sdt->asl_file, &error);
314 g_assert_no_error(error);
315 close(fd);
317 /* build command line */
318 g_string_append_printf(command_line, " -p %s ", sdt->asl_file);
319 if (compare_signature(sdt, "DSDT") ||
320 compare_signature(sdt, "SSDT")) {
321 for (i = 0; i < sdts->len; ++i) {
322 temp = &g_array_index(sdts, AcpiSdtTable, i);
323 if (compare_signature(temp, "DSDT") ||
324 compare_signature(temp, "SSDT")) {
325 g_string_append_printf(command_line, "-e %s ", temp->aml_file);
329 g_string_append_printf(command_line, "-d %s", sdt->aml_file);
331 /* pass 'out' and 'out_err' in order to be redirected */
332 ret = g_spawn_command_line_sync(command_line->str, &out, &out_err, NULL, &error);
333 g_assert_no_error(error);
334 if (ret) {
335 ret = g_file_get_contents(sdt->asl_file, &sdt->asl,
336 &sdt->asl_len, &error);
337 g_assert(ret);
338 g_assert_no_error(error);
339 ret = (sdt->asl_len > 0);
342 g_free(out);
343 g_free(out_err);
344 g_string_free(command_line, true);
346 return !ret;
349 #define COMMENT_END "*/"
350 #define DEF_BLOCK "DefinitionBlock ("
351 #define BLOCK_NAME_END ","
353 static GString *normalize_asl(gchar *asl_code)
355 GString *asl = g_string_new(asl_code);
356 gchar *comment, *block_name;
358 /* strip comments (different generation days) */
359 comment = g_strstr_len(asl->str, asl->len, COMMENT_END);
360 if (comment) {
361 comment += strlen(COMMENT_END);
362 while (*comment == '\n') {
363 comment++;
365 asl = g_string_erase(asl, 0, comment - asl->str);
368 /* strip def block name (it has file path in it) */
369 if (g_str_has_prefix(asl->str, DEF_BLOCK)) {
370 block_name = g_strstr_len(asl->str, asl->len, BLOCK_NAME_END);
371 g_assert(block_name);
372 asl = g_string_erase(asl, 0,
373 block_name + sizeof(BLOCK_NAME_END) - asl->str);
376 return asl;
379 static GArray *load_expected_aml(test_data *data)
381 int i;
382 AcpiSdtTable *sdt;
383 GError *error = NULL;
384 gboolean ret;
386 GArray *exp_tables = g_array_new(false, true, sizeof(AcpiSdtTable));
387 if (getenv("V")) {
388 fputc('\n', stderr);
390 for (i = 0; i < data->tables->len; ++i) {
391 AcpiSdtTable exp_sdt;
392 gchar *aml_file = NULL;
393 const char *ext = data->variant ? data->variant : "";
395 sdt = &g_array_index(data->tables, AcpiSdtTable, i);
397 memset(&exp_sdt, 0, sizeof(exp_sdt));
398 exp_sdt.header.signature = sdt->header.signature;
400 try_again:
401 aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
402 (gchar *)&sdt->header.signature, ext);
403 if (getenv("V")) {
404 fprintf(stderr, "Looking for expected file '%s'\n", aml_file);
406 if (g_file_test(aml_file, G_FILE_TEST_EXISTS)) {
407 exp_sdt.aml_file = aml_file;
408 } else if (*ext != '\0') {
409 /* try fallback to generic (extension less) expected file */
410 ext = "";
411 g_free(aml_file);
412 goto try_again;
414 g_assert(exp_sdt.aml_file);
415 if (getenv("V")) {
416 fprintf(stderr, "Using expected file '%s'\n", aml_file);
418 ret = g_file_get_contents(aml_file, &exp_sdt.aml,
419 &exp_sdt.aml_len, &error);
420 g_assert(ret);
421 g_assert_no_error(error);
422 g_assert(exp_sdt.aml);
423 g_assert(exp_sdt.aml_len);
425 g_array_append_val(exp_tables, exp_sdt);
428 return exp_tables;
431 /* test the list of tables in @data->tables against reference tables */
432 static void test_acpi_asl(test_data *data)
434 int i;
435 AcpiSdtTable *sdt, *exp_sdt;
436 test_data exp_data;
437 gboolean exp_err, err;
439 memset(&exp_data, 0, sizeof(exp_data));
440 exp_data.tables = load_expected_aml(data);
441 dump_aml_files(data, false);
442 for (i = 0; i < data->tables->len; ++i) {
443 GString *asl, *exp_asl;
445 sdt = &g_array_index(data->tables, AcpiSdtTable, i);
446 exp_sdt = &g_array_index(exp_data.tables, AcpiSdtTable, i);
448 err = load_asl(data->tables, sdt);
449 asl = normalize_asl(sdt->asl);
451 exp_err = load_asl(exp_data.tables, exp_sdt);
452 exp_asl = normalize_asl(exp_sdt->asl);
454 /* TODO: check for warnings */
455 g_assert(!err || exp_err);
457 if (g_strcmp0(asl->str, exp_asl->str)) {
458 if (exp_err) {
459 fprintf(stderr,
460 "Warning! iasl couldn't parse the expected aml\n");
461 } else {
462 uint32_t signature = cpu_to_le32(exp_sdt->header.signature);
463 sdt->tmp_files_retain = true;
464 exp_sdt->tmp_files_retain = true;
465 fprintf(stderr,
466 "acpi-test: Warning! %.4s mismatch. "
467 "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
468 (gchar *)&signature,
469 sdt->asl_file, sdt->aml_file,
470 exp_sdt->asl_file, exp_sdt->aml_file);
471 if (getenv("V")) {
472 const char *diff_cmd = getenv("DIFF");
473 if (diff_cmd) {
474 int ret G_GNUC_UNUSED;
475 char *diff = g_strdup_printf("%s %s %s", diff_cmd,
476 exp_sdt->asl_file, sdt->asl_file);
477 ret = system(diff) ;
478 g_free(diff);
479 } else {
480 fprintf(stderr, "acpi-test: Warning. not showing "
481 "difference since no diff utility is specified. "
482 "Set 'DIFF' environment variable to a preferred "
483 "diff utility and run 'make V=1 check' again to "
484 "see ASL difference.");
489 g_string_free(asl, true);
490 g_string_free(exp_asl, true);
493 free_test_data(&exp_data);
496 static bool smbios_ep_table_ok(test_data *data)
498 struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
499 uint32_t addr = data->smbios_ep_addr;
501 ACPI_READ_ARRAY(data->qts, ep_table->anchor_string, addr);
502 if (memcmp(ep_table->anchor_string, "_SM_", 4)) {
503 return false;
505 ACPI_READ_FIELD(data->qts, ep_table->checksum, addr);
506 ACPI_READ_FIELD(data->qts, ep_table->length, addr);
507 ACPI_READ_FIELD(data->qts, ep_table->smbios_major_version, addr);
508 ACPI_READ_FIELD(data->qts, ep_table->smbios_minor_version, addr);
509 ACPI_READ_FIELD(data->qts, ep_table->max_structure_size, addr);
510 ACPI_READ_FIELD(data->qts, ep_table->entry_point_revision, addr);
511 ACPI_READ_ARRAY(data->qts, ep_table->formatted_area, addr);
512 ACPI_READ_ARRAY(data->qts, ep_table->intermediate_anchor_string, addr);
513 if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) {
514 return false;
516 ACPI_READ_FIELD(data->qts, ep_table->intermediate_checksum, addr);
517 ACPI_READ_FIELD(data->qts, ep_table->structure_table_length, addr);
518 if (ep_table->structure_table_length == 0) {
519 return false;
521 ACPI_READ_FIELD(data->qts, ep_table->structure_table_address, addr);
522 ACPI_READ_FIELD(data->qts, ep_table->number_of_structures, addr);
523 if (ep_table->number_of_structures == 0) {
524 return false;
526 ACPI_READ_FIELD(data->qts, ep_table->smbios_bcd_revision, addr);
527 if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) ||
528 acpi_calc_checksum((uint8_t *)ep_table + 0x10,
529 sizeof *ep_table - 0x10)) {
530 return false;
532 return true;
535 static void test_smbios_entry_point(test_data *data)
537 uint32_t off;
539 /* find smbios entry point structure */
540 for (off = 0xf0000; off < 0x100000; off += 0x10) {
541 uint8_t sig[] = "_SM_";
542 int i;
544 for (i = 0; i < sizeof sig - 1; ++i) {
545 sig[i] = qtest_readb(data->qts, off + i);
548 if (!memcmp(sig, "_SM_", sizeof sig)) {
549 /* signature match, but is this a valid entry point? */
550 data->smbios_ep_addr = off;
551 if (smbios_ep_table_ok(data)) {
552 break;
557 g_assert_cmphex(off, <, 0x100000);
560 static inline bool smbios_single_instance(uint8_t type)
562 switch (type) {
563 case 0:
564 case 1:
565 case 2:
566 case 3:
567 case 16:
568 case 32:
569 case 127:
570 return true;
571 default:
572 return false;
576 static void test_smbios_structs(test_data *data)
578 DECLARE_BITMAP(struct_bitmap, SMBIOS_MAX_TYPE+1) = { 0 };
579 struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
580 uint32_t addr = le32_to_cpu(ep_table->structure_table_address);
581 int i, len, max_len = 0;
582 uint8_t type, prv, crt;
584 /* walk the smbios tables */
585 for (i = 0; i < le16_to_cpu(ep_table->number_of_structures); i++) {
587 /* grab type and formatted area length from struct header */
588 type = qtest_readb(data->qts, addr);
589 g_assert_cmpuint(type, <=, SMBIOS_MAX_TYPE);
590 len = qtest_readb(data->qts, addr + 1);
592 /* single-instance structs must not have been encountered before */
593 if (smbios_single_instance(type)) {
594 g_assert(!test_bit(type, struct_bitmap));
596 set_bit(type, struct_bitmap);
598 /* seek to end of unformatted string area of this struct ("\0\0") */
599 prv = crt = 1;
600 while (prv || crt) {
601 prv = crt;
602 crt = qtest_readb(data->qts, addr + len);
603 len++;
606 /* keep track of max. struct size */
607 if (max_len < len) {
608 max_len = len;
609 g_assert_cmpuint(max_len, <=, ep_table->max_structure_size);
612 /* start of next structure */
613 addr += len;
616 /* total table length and max struct size must match entry point values */
617 g_assert_cmpuint(le16_to_cpu(ep_table->structure_table_length), ==,
618 addr - le32_to_cpu(ep_table->structure_table_address));
619 g_assert_cmpuint(le16_to_cpu(ep_table->max_structure_size), ==, max_len);
621 /* required struct types must all be present */
622 for (i = 0; i < data->required_struct_types_len; i++) {
623 g_assert(test_bit(data->required_struct_types[i], struct_bitmap));
627 static void test_acpi_one(const char *params, test_data *data)
629 char *args;
631 /* Disable kernel irqchip to be able to override apic irq0. */
632 args = g_strdup_printf("-machine %s,accel=%s,kernel-irqchip=off "
633 "-net none -display none %s "
634 "-drive id=hd0,if=none,file=%s,format=raw "
635 "-device ide-hd,drive=hd0 ",
636 data->machine, "kvm:tcg",
637 params ? params : "", disk);
639 data->qts = qtest_init(args);
641 boot_sector_test(data->qts);
643 data->tables = g_array_new(false, true, sizeof(AcpiSdtTable));
644 test_acpi_rsdp_address(data);
645 test_acpi_rsdp_table(data);
646 test_acpi_rsdt_table(data);
647 fadt_fetch_facs_and_dsdt_ptrs(data);
648 test_acpi_facs_table(data);
649 test_acpi_dsdt_table(data);
650 fetch_rsdt_referenced_tables(data);
652 sanitize_fadt_ptrs(data);
654 if (iasl) {
655 if (getenv(ACPI_REBUILD_EXPECTED_AML)) {
656 dump_aml_files(data, true);
657 } else {
658 test_acpi_asl(data);
662 test_smbios_entry_point(data);
663 test_smbios_structs(data);
665 assert(!global_qtest);
666 qtest_quit(data->qts);
667 g_free(args);
670 static uint8_t base_required_struct_types[] = {
671 0, 1, 3, 4, 16, 17, 19, 32, 127
674 static void test_acpi_piix4_tcg(void)
676 test_data data;
678 /* Supplying -machine accel argument overrides the default (qtest).
679 * This is to make guest actually run.
681 memset(&data, 0, sizeof(data));
682 data.machine = MACHINE_PC;
683 data.required_struct_types = base_required_struct_types;
684 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
685 test_acpi_one(NULL, &data);
686 free_test_data(&data);
689 static void test_acpi_piix4_tcg_bridge(void)
691 test_data data;
693 memset(&data, 0, sizeof(data));
694 data.machine = MACHINE_PC;
695 data.variant = ".bridge";
696 data.required_struct_types = base_required_struct_types;
697 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
698 test_acpi_one("-device pci-bridge,chassis_nr=1", &data);
699 free_test_data(&data);
702 static void test_acpi_q35_tcg(void)
704 test_data data;
706 memset(&data, 0, sizeof(data));
707 data.machine = MACHINE_Q35;
708 data.required_struct_types = base_required_struct_types;
709 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
710 test_acpi_one(NULL, &data);
711 free_test_data(&data);
714 static void test_acpi_q35_tcg_bridge(void)
716 test_data data;
718 memset(&data, 0, sizeof(data));
719 data.machine = MACHINE_Q35;
720 data.variant = ".bridge";
721 data.required_struct_types = base_required_struct_types;
722 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
723 test_acpi_one("-device pci-bridge,chassis_nr=1",
724 &data);
725 free_test_data(&data);
728 static void test_acpi_q35_tcg_mmio64(void)
730 test_data data = {
731 .machine = MACHINE_Q35,
732 .variant = ".mmio64",
733 .required_struct_types = base_required_struct_types,
734 .required_struct_types_len = ARRAY_SIZE(base_required_struct_types)
737 test_acpi_one("-m 128M,slots=1,maxmem=2G "
738 "-device pci-testdev,membar=2G",
739 &data);
740 free_test_data(&data);
743 static void test_acpi_piix4_tcg_cphp(void)
745 test_data data;
747 memset(&data, 0, sizeof(data));
748 data.machine = MACHINE_PC;
749 data.variant = ".cphp";
750 test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6"
751 " -numa node -numa node"
752 " -numa dist,src=0,dst=1,val=21",
753 &data);
754 free_test_data(&data);
757 static void test_acpi_q35_tcg_cphp(void)
759 test_data data;
761 memset(&data, 0, sizeof(data));
762 data.machine = MACHINE_Q35;
763 data.variant = ".cphp";
764 test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
765 " -numa node -numa node"
766 " -numa dist,src=0,dst=1,val=21",
767 &data);
768 free_test_data(&data);
771 static uint8_t ipmi_required_struct_types[] = {
772 0, 1, 3, 4, 16, 17, 19, 32, 38, 127
775 static void test_acpi_q35_tcg_ipmi(void)
777 test_data data;
779 memset(&data, 0, sizeof(data));
780 data.machine = MACHINE_Q35;
781 data.variant = ".ipmibt";
782 data.required_struct_types = ipmi_required_struct_types;
783 data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
784 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
785 " -device isa-ipmi-bt,bmc=bmc0",
786 &data);
787 free_test_data(&data);
790 static void test_acpi_piix4_tcg_ipmi(void)
792 test_data data;
794 /* Supplying -machine accel argument overrides the default (qtest).
795 * This is to make guest actually run.
797 memset(&data, 0, sizeof(data));
798 data.machine = MACHINE_PC;
799 data.variant = ".ipmikcs";
800 data.required_struct_types = ipmi_required_struct_types;
801 data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
802 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
803 " -device isa-ipmi-kcs,irq=0,bmc=bmc0",
804 &data);
805 free_test_data(&data);
808 static void test_acpi_q35_tcg_memhp(void)
810 test_data data;
812 memset(&data, 0, sizeof(data));
813 data.machine = MACHINE_Q35;
814 data.variant = ".memhp";
815 test_acpi_one(" -m 128,slots=3,maxmem=1G"
816 " -numa node -numa node"
817 " -numa dist,src=0,dst=1,val=21",
818 &data);
819 free_test_data(&data);
822 static void test_acpi_piix4_tcg_memhp(void)
824 test_data data;
826 memset(&data, 0, sizeof(data));
827 data.machine = MACHINE_PC;
828 data.variant = ".memhp";
829 test_acpi_one(" -m 128,slots=3,maxmem=1G"
830 " -numa node -numa node"
831 " -numa dist,src=0,dst=1,val=21",
832 &data);
833 free_test_data(&data);
836 static void test_acpi_q35_tcg_numamem(void)
838 test_data data;
840 memset(&data, 0, sizeof(data));
841 data.machine = MACHINE_Q35;
842 data.variant = ".numamem";
843 test_acpi_one(" -numa node -numa node,mem=128", &data);
844 free_test_data(&data);
847 static void test_acpi_piix4_tcg_numamem(void)
849 test_data data;
851 memset(&data, 0, sizeof(data));
852 data.machine = MACHINE_PC;
853 data.variant = ".numamem";
854 test_acpi_one(" -numa node -numa node,mem=128", &data);
855 free_test_data(&data);
858 static void test_acpi_tcg_dimm_pxm(const char *machine)
860 test_data data;
862 memset(&data, 0, sizeof(data));
863 data.machine = machine;
864 data.variant = ".dimmpxm";
865 test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu"
866 " -smp 4,sockets=4"
867 " -m 128M,slots=3,maxmem=1G"
868 " -numa node,mem=32M,nodeid=0"
869 " -numa node,mem=32M,nodeid=1"
870 " -numa node,mem=32M,nodeid=2"
871 " -numa node,mem=32M,nodeid=3"
872 " -numa cpu,node-id=0,socket-id=0"
873 " -numa cpu,node-id=1,socket-id=1"
874 " -numa cpu,node-id=2,socket-id=2"
875 " -numa cpu,node-id=3,socket-id=3"
876 " -object memory-backend-ram,id=ram0,size=128M"
877 " -object memory-backend-ram,id=nvm0,size=128M"
878 " -device pc-dimm,id=dimm0,memdev=ram0,node=1"
879 " -device nvdimm,id=dimm1,memdev=nvm0,node=2",
880 &data);
881 free_test_data(&data);
884 static void test_acpi_q35_tcg_dimm_pxm(void)
886 test_acpi_tcg_dimm_pxm(MACHINE_Q35);
889 static void test_acpi_piix4_tcg_dimm_pxm(void)
891 test_acpi_tcg_dimm_pxm(MACHINE_PC);
894 int main(int argc, char *argv[])
896 const char *arch = qtest_get_arch();
897 int ret;
899 ret = boot_sector_init(disk);
900 if(ret)
901 return ret;
903 g_test_init(&argc, &argv, NULL);
905 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
906 qtest_add_func("acpi/piix4", test_acpi_piix4_tcg);
907 qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge);
908 qtest_add_func("acpi/q35", test_acpi_q35_tcg);
909 qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge);
910 qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64);
911 qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi);
912 qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi);
913 qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp);
914 qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp);
915 qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp);
916 qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp);
917 qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem);
918 qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
919 qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm);
920 qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
922 ret = g_test_run();
923 boot_sector_cleanup(disk);
924 return ret;