xref: /openbmc/qemu/tests/qtest/bios-tables-test.c (revision e6b5a071)
1 /*
2  * Boot order test cases.
3  *
4  * Copyright (c) 2013 Red Hat Inc.
5  *
6  * Authors:
7  *  Michael S. Tsirkin <mst@redhat.com>,
8  *
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.
11  */
12 
13 /*
14  * How to add or update the tests or commit changes that affect ACPI tables:
15  * Contributor:
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
19  *
20  * Contributor or ACPI Maintainer (steps 4-7 need to be redone to resolve conflicts
21  * in binary commit created in step 6):
22  *
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:
26  * 4. Run
27  *      make check V=1
28  * this will produce a bunch of warnings about differences
29  * beween actual and expected ACPI tables. If you have IASL installed,
30  * they will also be disassembled so you can look at the disassembled
31  * output. If not - disassemble them yourself in any way you like.
32  * Look at the differences - make sure they make sense and match what the
33  * changes you are merging are supposed to do.
34  * Save the changes, preferably in form of ASL diff for the commit log in
35  * step 6.
36  *
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
40  *    in commit log.
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
45  *    disassembly).
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.
50  *
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
56  */
57 
58 #include "qemu/osdep.h"
59 #include <glib/gstdio.h>
60 #include "qemu-common.h"
61 #include "hw/firmware/smbios.h"
62 #include "qemu/bitmap.h"
63 #include "acpi-utils.h"
64 #include "boot-sector.h"
65 #include "tpm-emu.h"
66 #include "hw/acpi/tpm.h"
67 
68 
69 #define MACHINE_PC "pc"
70 #define MACHINE_Q35 "q35"
71 
72 #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
73 
74 typedef struct {
75     bool tcg_only;
76     const char *machine;
77     const char *variant;
78     const char *uefi_fl1;
79     const char *uefi_fl2;
80     const char *blkdev;
81     const char *cd;
82     const uint64_t ram_start;
83     const uint64_t scan_len;
84     uint64_t rsdp_addr;
85     uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */];
86     GArray *tables;
87     uint32_t smbios_ep_addr;
88     struct smbios_21_entry_point smbios_ep_table;
89     uint16_t smbios_cpu_max_speed;
90     uint16_t smbios_cpu_curr_speed;
91     uint8_t *required_struct_types;
92     int required_struct_types_len;
93     QTestState *qts;
94 } test_data;
95 
96 static char disk[] = "tests/acpi-test-disk-XXXXXX";
97 static const char *data_dir = "tests/data/acpi";
98 #ifdef CONFIG_IASL
99 static const char *iasl = CONFIG_IASL;
100 #else
101 static const char *iasl;
102 #endif
103 
104 static bool compare_signature(const AcpiSdtTable *sdt, const char *signature)
105 {
106    return !memcmp(sdt->aml, signature, 4);
107 }
108 
109 static void cleanup_table_descriptor(AcpiSdtTable *table)
110 {
111     g_free(table->aml);
112     if (table->aml_file &&
113         !table->tmp_files_retain &&
114         g_strstr_len(table->aml_file, -1, "aml-")) {
115         unlink(table->aml_file);
116     }
117     g_free(table->aml_file);
118     g_free(table->asl);
119     if (table->asl_file &&
120         !table->tmp_files_retain) {
121         unlink(table->asl_file);
122     }
123     g_free(table->asl_file);
124 }
125 
126 static void free_test_data(test_data *data)
127 {
128     int i;
129 
130     for (i = 0; i < data->tables->len; ++i) {
131         cleanup_table_descriptor(&g_array_index(data->tables, AcpiSdtTable, i));
132     }
133 
134     g_array_free(data->tables, true);
135 }
136 
137 static void test_acpi_rsdp_table(test_data *data)
138 {
139     uint8_t *rsdp_table = data->rsdp_table;
140 
141     acpi_fetch_rsdp_table(data->qts, data->rsdp_addr, rsdp_table);
142 
143     switch (rsdp_table[15 /* Revision offset */]) {
144     case 0: /* ACPI 1.0 RSDP */
145         /* With rev 1, checksum is only for the first 20 bytes */
146         g_assert(!acpi_calc_checksum(rsdp_table,  20));
147         break;
148     case 2: /* ACPI 2.0+ RSDP */
149         /* With revision 2, we have 2 checksums */
150         g_assert(!acpi_calc_checksum(rsdp_table, 20));
151         g_assert(!acpi_calc_checksum(rsdp_table, 36));
152         break;
153     default:
154         g_assert_not_reached();
155     }
156 }
157 
158 static void test_acpi_rxsdt_table(test_data *data)
159 {
160     const char *sig = "RSDT";
161     AcpiSdtTable rsdt = {};
162     int entry_size = 4;
163     int addr_off = 16 /* RsdtAddress */;
164     uint8_t *ent;
165 
166     if (data->rsdp_table[15 /* Revision offset */] != 0) {
167         addr_off = 24 /* XsdtAddress */;
168         entry_size = 8;
169         sig = "XSDT";
170     }
171     /* read [RX]SDT table */
172     acpi_fetch_table(data->qts, &rsdt.aml, &rsdt.aml_len,
173                      &data->rsdp_table[addr_off], entry_size, sig, true);
174 
175     /* Load all tables and add to test list directly RSDT referenced tables */
176     ACPI_FOREACH_RSDT_ENTRY(rsdt.aml, rsdt.aml_len, ent, entry_size) {
177         AcpiSdtTable ssdt_table = {};
178 
179         acpi_fetch_table(data->qts, &ssdt_table.aml, &ssdt_table.aml_len, ent,
180                          entry_size, NULL, true);
181         /* Add table to ASL test tables list */
182         g_array_append_val(data->tables, ssdt_table);
183     }
184     cleanup_table_descriptor(&rsdt);
185 }
186 
187 static void test_acpi_fadt_table(test_data *data)
188 {
189     /* FADT table is 1st */
190     AcpiSdtTable table = g_array_index(data->tables, typeof(table), 0);
191     uint8_t *fadt_aml = table.aml;
192     uint32_t fadt_len = table.aml_len;
193     uint32_t val;
194     int dsdt_offset = 40 /* DSDT */;
195     int dsdt_entry_size = 4;
196 
197     g_assert(compare_signature(&table, "FACP"));
198 
199     /* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */
200     memcpy(&val, fadt_aml + 112 /* Flags */, 4);
201     val = le32_to_cpu(val);
202     if (!(val & 1UL << 20 /* HW_REDUCED_ACPI */)) {
203         acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
204                          fadt_aml + 36 /* FIRMWARE_CTRL */, 4, "FACS", false);
205         g_array_append_val(data->tables, table);
206     }
207 
208     memcpy(&val, fadt_aml + dsdt_offset, 4);
209     val = le32_to_cpu(val);
210     if (!val) {
211         dsdt_offset = 140 /* X_DSDT */;
212         dsdt_entry_size = 8;
213     }
214     acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
215                      fadt_aml + dsdt_offset, dsdt_entry_size, "DSDT", true);
216     g_array_append_val(data->tables, table);
217 
218     memset(fadt_aml + 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */
219     memset(fadt_aml + 40, 0, 4); /* sanitize DSDT ptr */
220     if (fadt_aml[8 /* FADT Major Version */] >= 3) {
221         memset(fadt_aml + 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr */
222         memset(fadt_aml + 140, 0, 8); /* sanitize X_DSDT ptr */
223     }
224 
225     /* update checksum */
226     fadt_aml[9 /* Checksum */] = 0;
227     fadt_aml[9 /* Checksum */] -= acpi_calc_checksum(fadt_aml, fadt_len);
228 }
229 
230 static void dump_aml_files(test_data *data, bool rebuild)
231 {
232     AcpiSdtTable *sdt;
233     GError *error = NULL;
234     gchar *aml_file = NULL;
235     gint fd;
236     ssize_t ret;
237     int i;
238 
239     for (i = 0; i < data->tables->len; ++i) {
240         const char *ext = data->variant ? data->variant : "";
241         sdt = &g_array_index(data->tables, AcpiSdtTable, i);
242         g_assert(sdt->aml);
243 
244         if (rebuild) {
245             aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
246                                        sdt->aml, ext);
247             fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT,
248                         S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
249             if (fd < 0) {
250                 perror(aml_file);
251             }
252             g_assert(fd >= 0);
253         } else {
254             fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
255             g_assert_no_error(error);
256         }
257 
258         ret = qemu_write_full(fd, sdt->aml, sdt->aml_len);
259         g_assert(ret == sdt->aml_len);
260 
261         close(fd);
262 
263         g_free(aml_file);
264     }
265 }
266 
267 static bool load_asl(GArray *sdts, AcpiSdtTable *sdt)
268 {
269     AcpiSdtTable *temp;
270     GError *error = NULL;
271     GString *command_line = g_string_new(iasl);
272     gint fd;
273     gchar *out, *out_err;
274     gboolean ret;
275     int i;
276 
277     fd = g_file_open_tmp("asl-XXXXXX.dsl", &sdt->asl_file, &error);
278     g_assert_no_error(error);
279     close(fd);
280 
281     /* build command line */
282     g_string_append_printf(command_line, " -p %s ", sdt->asl_file);
283     if (compare_signature(sdt, "DSDT") ||
284         compare_signature(sdt, "SSDT")) {
285         for (i = 0; i < sdts->len; ++i) {
286             temp = &g_array_index(sdts, AcpiSdtTable, i);
287             if (compare_signature(temp, "DSDT") ||
288                 compare_signature(temp, "SSDT")) {
289                 g_string_append_printf(command_line, "-e %s ", temp->aml_file);
290             }
291         }
292     }
293     g_string_append_printf(command_line, "-d %s", sdt->aml_file);
294 
295     /* pass 'out' and 'out_err' in order to be redirected */
296     ret = g_spawn_command_line_sync(command_line->str, &out, &out_err, NULL, &error);
297     g_assert_no_error(error);
298     if (ret) {
299         ret = g_file_get_contents(sdt->asl_file, &sdt->asl,
300                                   &sdt->asl_len, &error);
301         g_assert(ret);
302         g_assert_no_error(error);
303         ret = (sdt->asl_len > 0);
304     }
305 
306     g_free(out);
307     g_free(out_err);
308     g_string_free(command_line, true);
309 
310     return !ret;
311 }
312 
313 #define COMMENT_END "*/"
314 #define DEF_BLOCK "DefinitionBlock ("
315 #define BLOCK_NAME_END ","
316 
317 static GString *normalize_asl(gchar *asl_code)
318 {
319     GString *asl = g_string_new(asl_code);
320     gchar *comment, *block_name;
321 
322     /* strip comments (different generation days) */
323     comment = g_strstr_len(asl->str, asl->len, COMMENT_END);
324     if (comment) {
325         comment += strlen(COMMENT_END);
326         while (*comment == '\n') {
327             comment++;
328         }
329         asl = g_string_erase(asl, 0, comment - asl->str);
330     }
331 
332     /* strip def block name (it has file path in it) */
333     if (g_str_has_prefix(asl->str, DEF_BLOCK)) {
334         block_name = g_strstr_len(asl->str, asl->len, BLOCK_NAME_END);
335         g_assert(block_name);
336         asl = g_string_erase(asl, 0,
337                              block_name + sizeof(BLOCK_NAME_END) - asl->str);
338     }
339 
340     return asl;
341 }
342 
343 static GArray *load_expected_aml(test_data *data)
344 {
345     int i;
346     AcpiSdtTable *sdt;
347     GError *error = NULL;
348     gboolean ret;
349     gsize aml_len;
350 
351     GArray *exp_tables = g_array_new(false, true, sizeof(AcpiSdtTable));
352     if (getenv("V")) {
353         fputc('\n', stderr);
354     }
355     for (i = 0; i < data->tables->len; ++i) {
356         AcpiSdtTable exp_sdt;
357         gchar *aml_file = NULL;
358         const char *ext = data->variant ? data->variant : "";
359 
360         sdt = &g_array_index(data->tables, AcpiSdtTable, i);
361 
362         memset(&exp_sdt, 0, sizeof(exp_sdt));
363 
364 try_again:
365         aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
366                                    sdt->aml, ext);
367         if (getenv("V")) {
368             fprintf(stderr, "Looking for expected file '%s'\n", aml_file);
369         }
370         if (g_file_test(aml_file, G_FILE_TEST_EXISTS)) {
371             exp_sdt.aml_file = aml_file;
372         } else if (*ext != '\0') {
373             /* try fallback to generic (extension less) expected file */
374             ext = "";
375             g_free(aml_file);
376             goto try_again;
377         }
378         g_assert(exp_sdt.aml_file);
379         if (getenv("V")) {
380             fprintf(stderr, "Using expected file '%s'\n", aml_file);
381         }
382         ret = g_file_get_contents(aml_file, (gchar **)&exp_sdt.aml,
383                                   &aml_len, &error);
384         exp_sdt.aml_len = aml_len;
385         g_assert(ret);
386         g_assert_no_error(error);
387         g_assert(exp_sdt.aml);
388         if (!exp_sdt.aml_len) {
389             fprintf(stderr, "Warning! zero length expected file '%s'\n",
390                     aml_file);
391         }
392 
393         g_array_append_val(exp_tables, exp_sdt);
394     }
395 
396     return exp_tables;
397 }
398 
399 static bool test_acpi_find_diff_allowed(AcpiSdtTable *sdt)
400 {
401     const gchar *allowed_diff_file[] = {
402 #include "bios-tables-test-allowed-diff.h"
403         NULL
404     };
405     const gchar **f;
406 
407     for (f = allowed_diff_file; *f; ++f) {
408         if (!g_strcmp0(sdt->aml_file, *f)) {
409             return true;
410         }
411     }
412     return false;
413 }
414 
415 /* test the list of tables in @data->tables against reference tables */
416 static void test_acpi_asl(test_data *data)
417 {
418     int i;
419     AcpiSdtTable *sdt, *exp_sdt;
420     test_data exp_data;
421     gboolean exp_err, err, all_tables_match = true;
422 
423     memset(&exp_data, 0, sizeof(exp_data));
424     exp_data.tables = load_expected_aml(data);
425     dump_aml_files(data, false);
426     for (i = 0; i < data->tables->len; ++i) {
427         GString *asl, *exp_asl;
428 
429         sdt = &g_array_index(data->tables, AcpiSdtTable, i);
430         exp_sdt = &g_array_index(exp_data.tables, AcpiSdtTable, i);
431 
432         if (sdt->aml_len == exp_sdt->aml_len &&
433             !memcmp(sdt->aml, exp_sdt->aml, sdt->aml_len)) {
434             /* Identical table binaries: no need to disassemble. */
435             continue;
436         }
437 
438         fprintf(stderr,
439                 "acpi-test: Warning! %.4s binary file mismatch. "
440                 "Actual [aml:%s], Expected [aml:%s].\n"
441                 "See source file tests/qtest/bios-tables-test.c "
442                 "for instructions on how to update expected files.\n",
443                 exp_sdt->aml, sdt->aml_file, exp_sdt->aml_file);
444 
445         all_tables_match = all_tables_match &&
446             test_acpi_find_diff_allowed(exp_sdt);
447 
448         /*
449          *  don't try to decompile if IASL isn't present, in this case user
450          * will just 'get binary file mismatch' warnings and test failure
451          */
452         if (!iasl) {
453             continue;
454         }
455 
456         err = load_asl(data->tables, sdt);
457         asl = normalize_asl(sdt->asl);
458 
459         exp_err = load_asl(exp_data.tables, exp_sdt);
460         exp_asl = normalize_asl(exp_sdt->asl);
461 
462         /* TODO: check for warnings */
463         g_assert(!err || exp_err);
464 
465         if (g_strcmp0(asl->str, exp_asl->str)) {
466             sdt->tmp_files_retain = true;
467             if (exp_err) {
468                 fprintf(stderr,
469                         "Warning! iasl couldn't parse the expected aml\n");
470             } else {
471                 exp_sdt->tmp_files_retain = true;
472                 fprintf(stderr,
473                         "acpi-test: Warning! %.4s mismatch. "
474                         "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
475                         exp_sdt->aml, sdt->asl_file, sdt->aml_file,
476                         exp_sdt->asl_file, exp_sdt->aml_file);
477                 fflush(stderr);
478                 if (getenv("V")) {
479                     const char *diff_env = getenv("DIFF");
480                     const char *diff_cmd = diff_env ? diff_env : "diff -U 16";
481                     char *diff = g_strdup_printf("%s %s %s", diff_cmd,
482                                                  exp_sdt->asl_file, sdt->asl_file);
483                     int out = dup(STDOUT_FILENO);
484                     int ret G_GNUC_UNUSED;
485 
486                     dup2(STDERR_FILENO, STDOUT_FILENO);
487                     ret = system(diff) ;
488                     dup2(out, STDOUT_FILENO);
489                     close(out);
490                     g_free(diff);
491                 }
492             }
493         }
494         g_string_free(asl, true);
495         g_string_free(exp_asl, true);
496     }
497     if (!iasl && !all_tables_match) {
498         fprintf(stderr, "to see ASL diff between mismatched files install IASL,"
499                 " rebuild QEMU from scratch and re-run tests with V=1"
500                 " environment variable set");
501     }
502     g_assert(all_tables_match);
503 
504     free_test_data(&exp_data);
505 }
506 
507 static bool smbios_ep_table_ok(test_data *data)
508 {
509     struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
510     uint32_t addr = data->smbios_ep_addr;
511 
512     qtest_memread(data->qts, addr, ep_table, sizeof(*ep_table));
513     if (memcmp(ep_table->anchor_string, "_SM_", 4)) {
514         return false;
515     }
516     if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) {
517         return false;
518     }
519     if (ep_table->structure_table_length == 0) {
520         return false;
521     }
522     if (ep_table->number_of_structures == 0) {
523         return false;
524     }
525     if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) ||
526         acpi_calc_checksum((uint8_t *)ep_table + 0x10,
527                            sizeof *ep_table - 0x10)) {
528         return false;
529     }
530     return true;
531 }
532 
533 static void test_smbios_entry_point(test_data *data)
534 {
535     uint32_t off;
536 
537     /* find smbios entry point structure */
538     for (off = 0xf0000; off < 0x100000; off += 0x10) {
539         uint8_t sig[] = "_SM_";
540         int i;
541 
542         for (i = 0; i < sizeof sig - 1; ++i) {
543             sig[i] = qtest_readb(data->qts, off + i);
544         }
545 
546         if (!memcmp(sig, "_SM_", sizeof sig)) {
547             /* signature match, but is this a valid entry point? */
548             data->smbios_ep_addr = off;
549             if (smbios_ep_table_ok(data)) {
550                 break;
551             }
552         }
553     }
554 
555     g_assert_cmphex(off, <, 0x100000);
556 }
557 
558 static inline bool smbios_single_instance(uint8_t type)
559 {
560     switch (type) {
561     case 0:
562     case 1:
563     case 2:
564     case 3:
565     case 16:
566     case 32:
567     case 127:
568         return true;
569     default:
570         return false;
571     }
572 }
573 
574 static bool smbios_cpu_test(test_data *data, uint32_t addr)
575 {
576     uint16_t expect_speed[2];
577     uint16_t real;
578     int offset[2];
579     int i;
580 
581     /* Check CPU speed for backward compatibility */
582     offset[0] = offsetof(struct smbios_type_4, max_speed);
583     offset[1] = offsetof(struct smbios_type_4, current_speed);
584     expect_speed[0] = data->smbios_cpu_max_speed ? : 2000;
585     expect_speed[1] = data->smbios_cpu_curr_speed ? : 2000;
586 
587     for (i = 0; i < 2; i++) {
588         real = qtest_readw(data->qts, addr + offset[i]);
589         if (real != expect_speed[i]) {
590             fprintf(stderr, "Unexpected SMBIOS CPU speed: real %u expect %u\n",
591                     real, expect_speed[i]);
592             return false;
593         }
594     }
595 
596     return true;
597 }
598 
599 static void test_smbios_structs(test_data *data)
600 {
601     DECLARE_BITMAP(struct_bitmap, SMBIOS_MAX_TYPE+1) = { 0 };
602     struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
603     uint32_t addr = le32_to_cpu(ep_table->structure_table_address);
604     int i, len, max_len = 0;
605     uint8_t type, prv, crt;
606 
607     /* walk the smbios tables */
608     for (i = 0; i < le16_to_cpu(ep_table->number_of_structures); i++) {
609 
610         /* grab type and formatted area length from struct header */
611         type = qtest_readb(data->qts, addr);
612         g_assert_cmpuint(type, <=, SMBIOS_MAX_TYPE);
613         len = qtest_readb(data->qts, addr + 1);
614 
615         /* single-instance structs must not have been encountered before */
616         if (smbios_single_instance(type)) {
617             g_assert(!test_bit(type, struct_bitmap));
618         }
619         set_bit(type, struct_bitmap);
620 
621         if (type == 4) {
622             g_assert(smbios_cpu_test(data, addr));
623         }
624 
625         /* seek to end of unformatted string area of this struct ("\0\0") */
626         prv = crt = 1;
627         while (prv || crt) {
628             prv = crt;
629             crt = qtest_readb(data->qts, addr + len);
630             len++;
631         }
632 
633         /* keep track of max. struct size */
634         if (max_len < len) {
635             max_len = len;
636             g_assert_cmpuint(max_len, <=, ep_table->max_structure_size);
637         }
638 
639         /* start of next structure */
640         addr += len;
641     }
642 
643     /* total table length and max struct size must match entry point values */
644     g_assert_cmpuint(le16_to_cpu(ep_table->structure_table_length), ==,
645                      addr - le32_to_cpu(ep_table->structure_table_address));
646     g_assert_cmpuint(le16_to_cpu(ep_table->max_structure_size), ==, max_len);
647 
648     /* required struct types must all be present */
649     for (i = 0; i < data->required_struct_types_len; i++) {
650         g_assert(test_bit(data->required_struct_types[i], struct_bitmap));
651     }
652 }
653 
654 static void test_acpi_one(const char *params, test_data *data)
655 {
656     char *args;
657     bool use_uefi = data->uefi_fl1 && data->uefi_fl2;
658 
659     if (use_uefi) {
660         /*
661          * TODO: convert '-drive if=pflash' to new syntax (see e33763be7cd3)
662          * when arm/virt boad starts to support it.
663          */
664         args = g_strdup_printf("-machine %s %s -accel tcg -nodefaults -nographic "
665             "-drive if=pflash,format=raw,file=%s,readonly "
666             "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s",
667             data->machine, data->tcg_only ? "" : "-accel kvm",
668             data->uefi_fl1, data->uefi_fl2, data->cd, params ? params : "");
669 
670     } else {
671         args = g_strdup_printf("-machine %s %s -accel tcg "
672             "-net none -display none %s "
673             "-drive id=hd0,if=none,file=%s,format=raw "
674             "-device %s,drive=hd0 ",
675              data->machine, data->tcg_only ? "" : "-accel kvm",
676              params ? params : "", disk,
677              data->blkdev ?: "ide-hd");
678     }
679 
680     data->qts = qtest_init(args);
681 
682     if (use_uefi) {
683         g_assert(data->scan_len);
684         data->rsdp_addr = acpi_find_rsdp_address_uefi(data->qts,
685             data->ram_start, data->scan_len);
686     } else {
687         boot_sector_test(data->qts);
688         data->rsdp_addr = acpi_find_rsdp_address(data->qts);
689         g_assert_cmphex(data->rsdp_addr, <, 0x100000);
690     }
691 
692     data->tables = g_array_new(false, true, sizeof(AcpiSdtTable));
693     test_acpi_rsdp_table(data);
694     test_acpi_rxsdt_table(data);
695     test_acpi_fadt_table(data);
696 
697     if (getenv(ACPI_REBUILD_EXPECTED_AML)) {
698         dump_aml_files(data, true);
699     } else {
700         test_acpi_asl(data);
701     }
702 
703     /*
704      * TODO: make SMBIOS tests work with UEFI firmware,
705      * Bug on uefi-test-tools to provide entry point:
706      * https://bugs.launchpad.net/qemu/+bug/1821884
707      */
708     if (!use_uefi) {
709         test_smbios_entry_point(data);
710         test_smbios_structs(data);
711     }
712 
713     qtest_quit(data->qts);
714     g_free(args);
715 }
716 
717 static uint8_t base_required_struct_types[] = {
718     0, 1, 3, 4, 16, 17, 19, 32, 127
719 };
720 
721 static void test_acpi_piix4_tcg(void)
722 {
723     test_data data;
724 
725     /* Supplying -machine accel argument overrides the default (qtest).
726      * This is to make guest actually run.
727      */
728     memset(&data, 0, sizeof(data));
729     data.machine = MACHINE_PC;
730     data.required_struct_types = base_required_struct_types;
731     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
732     test_acpi_one(NULL, &data);
733     free_test_data(&data);
734 }
735 
736 static void test_acpi_piix4_tcg_bridge(void)
737 {
738     test_data data;
739 
740     memset(&data, 0, sizeof(data));
741     data.machine = MACHINE_PC;
742     data.variant = ".bridge";
743     data.required_struct_types = base_required_struct_types;
744     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
745     test_acpi_one("-device pci-bridge,chassis_nr=1", &data);
746     free_test_data(&data);
747 }
748 
749 static void test_acpi_piix4_no_root_hotplug(void)
750 {
751     test_data data;
752 
753     memset(&data, 0, sizeof(data));
754     data.machine = MACHINE_PC;
755     data.variant = ".roothp";
756     data.required_struct_types = base_required_struct_types;
757     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
758     test_acpi_one("-global PIIX4_PM.acpi-root-pci-hotplug=off "
759                   "-device pci-bridge,chassis_nr=1", &data);
760     free_test_data(&data);
761 }
762 
763 static void test_acpi_piix4_no_bridge_hotplug(void)
764 {
765     test_data data;
766 
767     memset(&data, 0, sizeof(data));
768     data.machine = MACHINE_PC;
769     data.variant = ".hpbridge";
770     data.required_struct_types = base_required_struct_types;
771     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
772     test_acpi_one("-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off "
773                   "-device pci-bridge,chassis_nr=1", &data);
774     free_test_data(&data);
775 }
776 
777 static void test_acpi_piix4_no_acpi_pci_hotplug(void)
778 {
779     test_data data;
780 
781     memset(&data, 0, sizeof(data));
782     data.machine = MACHINE_PC;
783     data.variant = ".hpbrroot";
784     data.required_struct_types = base_required_struct_types;
785     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
786     test_acpi_one("-global PIIX4_PM.acpi-root-pci-hotplug=off "
787                   "-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off "
788                   "-device pci-bridge,chassis_nr=1", &data);
789     free_test_data(&data);
790 }
791 
792 static void test_acpi_q35_tcg(void)
793 {
794     test_data data;
795 
796     memset(&data, 0, sizeof(data));
797     data.machine = MACHINE_Q35;
798     data.required_struct_types = base_required_struct_types;
799     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
800     test_acpi_one(NULL, &data);
801     free_test_data(&data);
802 
803     data.smbios_cpu_max_speed = 3000;
804     data.smbios_cpu_curr_speed = 2600;
805     test_acpi_one("-smbios type=4,max-speed=3000,current-speed=2600", &data);
806     free_test_data(&data);
807 }
808 
809 static void test_acpi_q35_tcg_bridge(void)
810 {
811     test_data data;
812 
813     memset(&data, 0, sizeof(data));
814     data.machine = MACHINE_Q35;
815     data.variant = ".bridge";
816     data.required_struct_types = base_required_struct_types;
817     data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
818     test_acpi_one("-device pci-bridge,chassis_nr=1",
819                   &data);
820     free_test_data(&data);
821 }
822 
823 static void test_acpi_q35_tcg_mmio64(void)
824 {
825     test_data data = {
826         .machine = MACHINE_Q35,
827         .variant = ".mmio64",
828         .required_struct_types = base_required_struct_types,
829         .required_struct_types_len = ARRAY_SIZE(base_required_struct_types)
830     };
831 
832     test_acpi_one("-m 128M,slots=1,maxmem=2G "
833                   "-object memory-backend-ram,id=ram0,size=128M "
834                   "-numa node,memdev=ram0 "
835                   "-device pci-testdev,membar=2G",
836                   &data);
837     free_test_data(&data);
838 }
839 
840 static void test_acpi_piix4_tcg_cphp(void)
841 {
842     test_data data;
843 
844     memset(&data, 0, sizeof(data));
845     data.machine = MACHINE_PC;
846     data.variant = ".cphp";
847     test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6"
848                   " -object memory-backend-ram,id=ram0,size=64M"
849                   " -object memory-backend-ram,id=ram1,size=64M"
850                   " -numa node,memdev=ram0 -numa node,memdev=ram1"
851                   " -numa dist,src=0,dst=1,val=21",
852                   &data);
853     free_test_data(&data);
854 }
855 
856 static void test_acpi_q35_tcg_cphp(void)
857 {
858     test_data data;
859 
860     memset(&data, 0, sizeof(data));
861     data.machine = MACHINE_Q35;
862     data.variant = ".cphp";
863     test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
864                   " -object memory-backend-ram,id=ram0,size=64M"
865                   " -object memory-backend-ram,id=ram1,size=64M"
866                   " -numa node,memdev=ram0 -numa node,memdev=ram1"
867                   " -numa dist,src=0,dst=1,val=21",
868                   &data);
869     free_test_data(&data);
870 }
871 
872 static uint8_t ipmi_required_struct_types[] = {
873     0, 1, 3, 4, 16, 17, 19, 32, 38, 127
874 };
875 
876 static void test_acpi_q35_tcg_ipmi(void)
877 {
878     test_data data;
879 
880     memset(&data, 0, sizeof(data));
881     data.machine = MACHINE_Q35;
882     data.variant = ".ipmibt";
883     data.required_struct_types = ipmi_required_struct_types;
884     data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
885     test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
886                   " -device isa-ipmi-bt,bmc=bmc0",
887                   &data);
888     free_test_data(&data);
889 }
890 
891 static void test_acpi_piix4_tcg_ipmi(void)
892 {
893     test_data data;
894 
895     /* Supplying -machine accel argument overrides the default (qtest).
896      * This is to make guest actually run.
897      */
898     memset(&data, 0, sizeof(data));
899     data.machine = MACHINE_PC;
900     data.variant = ".ipmikcs";
901     data.required_struct_types = ipmi_required_struct_types;
902     data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
903     test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
904                   " -device isa-ipmi-kcs,irq=0,bmc=bmc0",
905                   &data);
906     free_test_data(&data);
907 }
908 
909 static void test_acpi_q35_tcg_memhp(void)
910 {
911     test_data data;
912 
913     memset(&data, 0, sizeof(data));
914     data.machine = MACHINE_Q35;
915     data.variant = ".memhp";
916     test_acpi_one(" -m 128,slots=3,maxmem=1G"
917                   " -object memory-backend-ram,id=ram0,size=64M"
918                   " -object memory-backend-ram,id=ram1,size=64M"
919                   " -numa node,memdev=ram0 -numa node,memdev=ram1"
920                   " -numa dist,src=0,dst=1,val=21",
921                   &data);
922     free_test_data(&data);
923 }
924 
925 static void test_acpi_piix4_tcg_memhp(void)
926 {
927     test_data data;
928 
929     memset(&data, 0, sizeof(data));
930     data.machine = MACHINE_PC;
931     data.variant = ".memhp";
932     test_acpi_one(" -m 128,slots=3,maxmem=1G"
933                   " -object memory-backend-ram,id=ram0,size=64M"
934                   " -object memory-backend-ram,id=ram1,size=64M"
935                   " -numa node,memdev=ram0 -numa node,memdev=ram1"
936                   " -numa dist,src=0,dst=1,val=21",
937                   &data);
938     free_test_data(&data);
939 }
940 
941 static void test_acpi_q35_tcg_numamem(void)
942 {
943     test_data data;
944 
945     memset(&data, 0, sizeof(data));
946     data.machine = MACHINE_Q35;
947     data.variant = ".numamem";
948     test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
949                   " -numa node -numa node,memdev=ram0", &data);
950     free_test_data(&data);
951 }
952 
953 static void test_acpi_piix4_tcg_numamem(void)
954 {
955     test_data data;
956 
957     memset(&data, 0, sizeof(data));
958     data.machine = MACHINE_PC;
959     data.variant = ".numamem";
960     test_acpi_one(" -object memory-backend-ram,id=ram0,size=128M"
961                   " -numa node -numa node,memdev=ram0", &data);
962     free_test_data(&data);
963 }
964 
965 uint64_t tpm_tis_base_addr;
966 
967 static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if,
968                               uint64_t base)
969 {
970 #ifdef CONFIG_TPM
971     gchar *tmp_dir_name = g_strdup_printf("qemu-test_acpi_%s_tcg_%s.XXXXXX",
972                                           machine, tpm_if);
973     char *tmp_path = g_dir_make_tmp(tmp_dir_name, NULL);
974     TestState test;
975     test_data data;
976     GThread *thread;
977     char *args, *variant = g_strdup_printf(".%s", tpm_if);
978 
979     tpm_tis_base_addr = base;
980 
981     module_call_init(MODULE_INIT_QOM);
982 
983     test.addr = g_new0(SocketAddress, 1);
984     test.addr->type = SOCKET_ADDRESS_TYPE_UNIX;
985     test.addr->u.q_unix.path = g_build_filename(tmp_path, "sock", NULL);
986     g_mutex_init(&test.data_mutex);
987     g_cond_init(&test.data_cond);
988     test.data_cond_signal = false;
989 
990     thread = g_thread_new(NULL, tpm_emu_ctrl_thread, &test);
991     tpm_emu_test_wait_cond(&test);
992 
993     memset(&data, 0, sizeof(data));
994     data.machine = machine;
995     data.variant = variant;
996 
997     args = g_strdup_printf(
998         " -chardev socket,id=chr,path=%s"
999         " -tpmdev emulator,id=dev,chardev=chr"
1000         " -device tpm-%s,tpmdev=dev",
1001         test.addr->u.q_unix.path, tpm_if);
1002 
1003     test_acpi_one(args, &data);
1004 
1005     g_thread_join(thread);
1006     g_unlink(test.addr->u.q_unix.path);
1007     qapi_free_SocketAddress(test.addr);
1008     g_rmdir(tmp_path);
1009     g_free(variant);
1010     g_free(tmp_path);
1011     g_free(tmp_dir_name);
1012     g_free(args);
1013     free_test_data(&data);
1014 #else
1015     g_test_skip("TPM disabled");
1016 #endif
1017 }
1018 
1019 static void test_acpi_q35_tcg_tpm_tis(void)
1020 {
1021     test_acpi_tcg_tpm("q35", "tis", 0xFED40000);
1022 }
1023 
1024 static void test_acpi_tcg_dimm_pxm(const char *machine)
1025 {
1026     test_data data;
1027 
1028     memset(&data, 0, sizeof(data));
1029     data.machine = machine;
1030     data.variant = ".dimmpxm";
1031     test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu"
1032                   " -smp 4,sockets=4"
1033                   " -m 128M,slots=3,maxmem=1G"
1034                   " -object memory-backend-ram,id=ram0,size=32M"
1035                   " -object memory-backend-ram,id=ram1,size=32M"
1036                   " -object memory-backend-ram,id=ram2,size=32M"
1037                   " -object memory-backend-ram,id=ram3,size=32M"
1038                   " -numa node,memdev=ram0,nodeid=0"
1039                   " -numa node,memdev=ram1,nodeid=1"
1040                   " -numa node,memdev=ram2,nodeid=2"
1041                   " -numa node,memdev=ram3,nodeid=3"
1042                   " -numa cpu,node-id=0,socket-id=0"
1043                   " -numa cpu,node-id=1,socket-id=1"
1044                   " -numa cpu,node-id=2,socket-id=2"
1045                   " -numa cpu,node-id=3,socket-id=3"
1046                   " -object memory-backend-ram,id=ram4,size=128M"
1047                   " -object memory-backend-ram,id=nvm0,size=128M"
1048                   " -device pc-dimm,id=dimm0,memdev=ram4,node=1"
1049                   " -device nvdimm,id=dimm1,memdev=nvm0,node=2",
1050                   &data);
1051     free_test_data(&data);
1052 }
1053 
1054 static void test_acpi_q35_tcg_dimm_pxm(void)
1055 {
1056     test_acpi_tcg_dimm_pxm(MACHINE_Q35);
1057 }
1058 
1059 static void test_acpi_piix4_tcg_dimm_pxm(void)
1060 {
1061     test_acpi_tcg_dimm_pxm(MACHINE_PC);
1062 }
1063 
1064 static void test_acpi_virt_tcg_memhp(void)
1065 {
1066     test_data data = {
1067         .machine = "virt",
1068         .tcg_only = true,
1069         .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1070         .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1071         .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1072         .ram_start = 0x40000000ULL,
1073         .scan_len = 256ULL * 1024 * 1024,
1074     };
1075 
1076     data.variant = ".memhp";
1077     test_acpi_one(" -machine nvdimm=on"
1078                   " -cpu cortex-a57"
1079                   " -m 256M,slots=3,maxmem=1G"
1080                   " -object memory-backend-ram,id=ram0,size=128M"
1081                   " -object memory-backend-ram,id=ram1,size=128M"
1082                   " -numa node,memdev=ram0 -numa node,memdev=ram1"
1083                   " -numa dist,src=0,dst=1,val=21"
1084                   " -object memory-backend-ram,id=ram2,size=128M"
1085                   " -object memory-backend-ram,id=nvm0,size=128M"
1086                   " -device pc-dimm,id=dimm0,memdev=ram2,node=0"
1087                   " -device nvdimm,id=dimm1,memdev=nvm0,node=1",
1088                   &data);
1089 
1090     free_test_data(&data);
1091 
1092 }
1093 
1094 static void test_acpi_microvm_prepare(test_data *data)
1095 {
1096     memset(data, 0, sizeof(*data));
1097     data->machine = "microvm";
1098     data->required_struct_types = NULL; /* no smbios */
1099     data->required_struct_types_len = 0;
1100     data->blkdev = "virtio-blk-device";
1101 }
1102 
1103 static void test_acpi_microvm_tcg(void)
1104 {
1105     test_data data;
1106 
1107     test_acpi_microvm_prepare(&data);
1108     test_acpi_one(" -machine microvm,acpi=on,rtc=off",
1109                   &data);
1110     free_test_data(&data);
1111 }
1112 
1113 static void test_acpi_microvm_pcie_tcg(void)
1114 {
1115     test_data data;
1116 
1117     test_acpi_microvm_prepare(&data);
1118     data.variant = ".pcie";
1119     data.tcg_only = true; /* need constant host-phys-bits */
1120     test_acpi_one(" -machine microvm,acpi=on,rtc=off,pcie=on",
1121                   &data);
1122     free_test_data(&data);
1123 }
1124 
1125 static void test_acpi_virt_tcg_numamem(void)
1126 {
1127     test_data data = {
1128         .machine = "virt",
1129         .tcg_only = true,
1130         .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1131         .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1132         .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1133         .ram_start = 0x40000000ULL,
1134         .scan_len = 128ULL * 1024 * 1024,
1135     };
1136 
1137     data.variant = ".numamem";
1138     test_acpi_one(" -cpu cortex-a57"
1139                   " -object memory-backend-ram,id=ram0,size=128M"
1140                   " -numa node,memdev=ram0",
1141                   &data);
1142 
1143     free_test_data(&data);
1144 
1145 }
1146 
1147 static void test_acpi_tcg_acpi_hmat(const char *machine)
1148 {
1149     test_data data;
1150 
1151     memset(&data, 0, sizeof(data));
1152     data.machine = machine;
1153     data.variant = ".acpihmat";
1154     test_acpi_one(" -machine hmat=on"
1155                   " -smp 2,sockets=2"
1156                   " -m 128M,slots=2,maxmem=1G"
1157                   " -object memory-backend-ram,size=64M,id=m0"
1158                   " -object memory-backend-ram,size=64M,id=m1"
1159                   " -numa node,nodeid=0,memdev=m0"
1160                   " -numa node,nodeid=1,memdev=m1,initiator=0"
1161                   " -numa cpu,node-id=0,socket-id=0"
1162                   " -numa cpu,node-id=0,socket-id=1"
1163                   " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1164                   "data-type=access-latency,latency=1"
1165                   " -numa hmat-lb,initiator=0,target=0,hierarchy=memory,"
1166                   "data-type=access-bandwidth,bandwidth=65534M"
1167                   " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1168                   "data-type=access-latency,latency=65534"
1169                   " -numa hmat-lb,initiator=0,target=1,hierarchy=memory,"
1170                   "data-type=access-bandwidth,bandwidth=32767M"
1171                   " -numa hmat-cache,node-id=0,size=10K,level=1,"
1172                   "associativity=direct,policy=write-back,line=8"
1173                   " -numa hmat-cache,node-id=1,size=10K,level=1,"
1174                   "associativity=direct,policy=write-back,line=8",
1175                   &data);
1176     free_test_data(&data);
1177 }
1178 
1179 static void test_acpi_q35_tcg_acpi_hmat(void)
1180 {
1181     test_acpi_tcg_acpi_hmat(MACHINE_Q35);
1182 }
1183 
1184 static void test_acpi_piix4_tcg_acpi_hmat(void)
1185 {
1186     test_acpi_tcg_acpi_hmat(MACHINE_PC);
1187 }
1188 
1189 static void test_acpi_virt_tcg(void)
1190 {
1191     test_data data = {
1192         .machine = "virt",
1193         .tcg_only = true,
1194         .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
1195         .uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
1196         .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
1197         .ram_start = 0x40000000ULL,
1198         .scan_len = 128ULL * 1024 * 1024,
1199     };
1200 
1201     test_acpi_one("-cpu cortex-a57", &data);
1202     free_test_data(&data);
1203 
1204     data.smbios_cpu_max_speed = 2900;
1205     data.smbios_cpu_curr_speed = 2700;
1206     test_acpi_one("-cpu cortex-a57 "
1207                   "-smbios type=4,max-speed=2900,current-speed=2700", &data);
1208     free_test_data(&data);
1209 }
1210 
1211 int main(int argc, char *argv[])
1212 {
1213     const char *arch = qtest_get_arch();
1214     int ret;
1215 
1216     g_test_init(&argc, &argv, NULL);
1217 
1218     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
1219         ret = boot_sector_init(disk);
1220         if (ret) {
1221             return ret;
1222         }
1223 
1224         qtest_add_func("acpi/q35/tpm-tis", test_acpi_q35_tcg_tpm_tis);
1225         qtest_add_func("acpi/piix4", test_acpi_piix4_tcg);
1226         qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge);
1227         qtest_add_func("acpi/piix4/pci-hotplug/no_root_hotplug",
1228                        test_acpi_piix4_no_root_hotplug);
1229         qtest_add_func("acpi/piix4/pci-hotplug/no_bridge_hotplug",
1230                        test_acpi_piix4_no_bridge_hotplug);
1231         qtest_add_func("acpi/piix4/pci-hotplug/off",
1232                        test_acpi_piix4_no_acpi_pci_hotplug);
1233         qtest_add_func("acpi/q35", test_acpi_q35_tcg);
1234         qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge);
1235         qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64);
1236         qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi);
1237         qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi);
1238         qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp);
1239         qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp);
1240         qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp);
1241         qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp);
1242         qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem);
1243         qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
1244         qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm);
1245         qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
1246         qtest_add_func("acpi/piix4/acpihmat", test_acpi_piix4_tcg_acpi_hmat);
1247         qtest_add_func("acpi/q35/acpihmat", test_acpi_q35_tcg_acpi_hmat);
1248         qtest_add_func("acpi/microvm", test_acpi_microvm_tcg);
1249         if (strcmp(arch, "x86_64") == 0) {
1250             qtest_add_func("acpi/microvm/pcie", test_acpi_microvm_pcie_tcg);
1251         }
1252     } else if (strcmp(arch, "aarch64") == 0) {
1253         qtest_add_func("acpi/virt", test_acpi_virt_tcg);
1254         qtest_add_func("acpi/virt/numamem", test_acpi_virt_tcg_numamem);
1255         qtest_add_func("acpi/virt/memhp", test_acpi_virt_tcg_memhp);
1256     }
1257     ret = g_test_run();
1258     boot_sector_cleanup(disk);
1259     return ret;
1260 }
1261