]> git.proxmox.com Git - mirror_qemu.git/blob - tests/bios-tables-test.c
tests: acpi: squash sanitize_fadt_ptrs() into test_acpi_fadt_table()
[mirror_qemu.git] / tests / bios-tables-test.c
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 #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"
20
21 #define MACHINE_PC "pc"
22 #define MACHINE_Q35 "q35"
23
24 #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
25
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 GArray *tables;
32 uint32_t smbios_ep_addr;
33 struct smbios_21_entry_point smbios_ep_table;
34 uint8_t *required_struct_types;
35 int required_struct_types_len;
36 QTestState *qts;
37 } test_data;
38
39 static char disk[] = "tests/acpi-test-disk-XXXXXX";
40 static const char *data_dir = "tests/data/acpi";
41 #ifdef CONFIG_IASL
42 static const char *iasl = stringify(CONFIG_IASL);
43 #else
44 static const char *iasl;
45 #endif
46
47 static void cleanup_table_descriptor(AcpiSdtTable *table)
48 {
49 g_free(table->aml);
50 if (table->aml_file &&
51 !table->tmp_files_retain &&
52 g_strstr_len(table->aml_file, -1, "aml-")) {
53 unlink(table->aml_file);
54 }
55 g_free(table->aml_file);
56 g_free(table->asl);
57 if (table->asl_file &&
58 !table->tmp_files_retain) {
59 unlink(table->asl_file);
60 }
61 g_free(table->asl_file);
62 }
63
64 static void free_test_data(test_data *data)
65 {
66 int i;
67
68 for (i = 0; i < data->tables->len; ++i) {
69 cleanup_table_descriptor(&g_array_index(data->tables, AcpiSdtTable, i));
70 }
71
72 g_array_free(data->tables, true);
73 }
74
75 static void test_acpi_rsdp_address(test_data *data)
76 {
77 uint32_t off = acpi_find_rsdp_address(data->qts);
78 g_assert_cmphex(off, <, 0x100000);
79 data->rsdp_addr = off;
80 }
81
82 static void test_acpi_rsdp_table(test_data *data)
83 {
84 uint8_t *rsdp_table = data->rsdp_table, revision;
85 uint32_t addr = data->rsdp_addr;
86
87 acpi_parse_rsdp_table(data->qts, addr, rsdp_table);
88 revision = rsdp_table[15 /* Revision offset */];
89
90 switch (revision) {
91 case 0: /* ACPI 1.0 RSDP */
92 /* With rev 1, checksum is only for the first 20 bytes */
93 g_assert(!acpi_calc_checksum(rsdp_table, 20));
94 break;
95 case 2: /* ACPI 2.0+ RSDP */
96 /* With revision 2, we have 2 checksums */
97 g_assert(!acpi_calc_checksum(rsdp_table, 20));
98 g_assert(!acpi_calc_checksum(rsdp_table, 36));
99 break;
100 default:
101 g_assert_not_reached();
102 }
103 }
104
105 static void test_acpi_rsdt_table(test_data *data)
106 {
107 AcpiSdtTable rsdt = {};
108 uint8_t *ent;
109
110 /* read RSDT table */
111 acpi_fetch_table(data->qts, &rsdt.aml, &rsdt.aml_len,
112 &data->rsdp_table[16 /* RsdtAddress */], "RSDT", true);
113
114 /* Load all tables and add to test list directly RSDT referenced tables */
115 ACPI_FOREACH_RSDT_ENTRY(rsdt.aml, rsdt.aml_len, ent, 4 /* Entry size */) {
116 AcpiSdtTable ssdt_table = {};
117
118 acpi_fetch_table(data->qts, &ssdt_table.aml, &ssdt_table.aml_len, ent,
119 NULL, true);
120 /* Add table to ASL test tables list */
121 g_array_append_val(data->tables, ssdt_table);
122 }
123 cleanup_table_descriptor(&rsdt);
124 }
125
126 static void test_acpi_fadt_table(test_data *data)
127 {
128 /* FADT table is 1st */
129 AcpiSdtTable table = g_array_index(data->tables, typeof(table), 0);
130 uint8_t *fadt_aml = table.aml;
131 uint32_t fadt_len = table.aml_len;
132
133 ACPI_ASSERT_CMP(table.header->signature, "FACP");
134
135 /* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */
136 acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
137 fadt_aml + 36 /* FIRMWARE_CTRL */, "FACS", false);
138 g_array_append_val(data->tables, table);
139
140 acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
141 fadt_aml + 40 /* DSDT */, "DSDT", true);
142 g_array_append_val(data->tables, table);
143
144 memset(fadt_aml + 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */
145 memset(fadt_aml + 40, 0, 4); /* sanitize DSDT ptr */
146 if (fadt_aml[8 /* FADT Major Version */] >= 3) {
147 memset(fadt_aml + 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr */
148 memset(fadt_aml + 140, 0, 8); /* sanitize X_DSDT ptr */
149 }
150
151 /* update checksum */
152 fadt_aml[9 /* Checksum */] = 0;
153 fadt_aml[9 /* Checksum */] -= acpi_calc_checksum(fadt_aml, fadt_len);
154 }
155
156 static void dump_aml_files(test_data *data, bool rebuild)
157 {
158 AcpiSdtTable *sdt;
159 GError *error = NULL;
160 gchar *aml_file = NULL;
161 gint fd;
162 ssize_t ret;
163 int i;
164
165 for (i = 0; i < data->tables->len; ++i) {
166 const char *ext = data->variant ? data->variant : "";
167 sdt = &g_array_index(data->tables, AcpiSdtTable, i);
168 g_assert(sdt->aml);
169
170 if (rebuild) {
171 aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
172 (gchar *)&sdt->header->signature, ext);
173 fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT,
174 S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
175 } else {
176 fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
177 g_assert_no_error(error);
178 }
179 g_assert(fd >= 0);
180
181 ret = qemu_write_full(fd, sdt->aml, sdt->aml_len);
182 g_assert(ret == sdt->aml_len);
183
184 close(fd);
185
186 g_free(aml_file);
187 }
188 }
189
190 static bool compare_signature(AcpiSdtTable *sdt, const char *signature)
191 {
192 return !memcmp(&sdt->header->signature, signature, 4);
193 }
194
195 static bool load_asl(GArray *sdts, AcpiSdtTable *sdt)
196 {
197 AcpiSdtTable *temp;
198 GError *error = NULL;
199 GString *command_line = g_string_new(iasl);
200 gint fd;
201 gchar *out, *out_err;
202 gboolean ret;
203 int i;
204
205 fd = g_file_open_tmp("asl-XXXXXX.dsl", &sdt->asl_file, &error);
206 g_assert_no_error(error);
207 close(fd);
208
209 /* build command line */
210 g_string_append_printf(command_line, " -p %s ", sdt->asl_file);
211 if (compare_signature(sdt, "DSDT") ||
212 compare_signature(sdt, "SSDT")) {
213 for (i = 0; i < sdts->len; ++i) {
214 temp = &g_array_index(sdts, AcpiSdtTable, i);
215 if (compare_signature(temp, "DSDT") ||
216 compare_signature(temp, "SSDT")) {
217 g_string_append_printf(command_line, "-e %s ", temp->aml_file);
218 }
219 }
220 }
221 g_string_append_printf(command_line, "-d %s", sdt->aml_file);
222
223 /* pass 'out' and 'out_err' in order to be redirected */
224 ret = g_spawn_command_line_sync(command_line->str, &out, &out_err, NULL, &error);
225 g_assert_no_error(error);
226 if (ret) {
227 ret = g_file_get_contents(sdt->asl_file, &sdt->asl,
228 &sdt->asl_len, &error);
229 g_assert(ret);
230 g_assert_no_error(error);
231 ret = (sdt->asl_len > 0);
232 }
233
234 g_free(out);
235 g_free(out_err);
236 g_string_free(command_line, true);
237
238 return !ret;
239 }
240
241 #define COMMENT_END "*/"
242 #define DEF_BLOCK "DefinitionBlock ("
243 #define BLOCK_NAME_END ","
244
245 static GString *normalize_asl(gchar *asl_code)
246 {
247 GString *asl = g_string_new(asl_code);
248 gchar *comment, *block_name;
249
250 /* strip comments (different generation days) */
251 comment = g_strstr_len(asl->str, asl->len, COMMENT_END);
252 if (comment) {
253 comment += strlen(COMMENT_END);
254 while (*comment == '\n') {
255 comment++;
256 }
257 asl = g_string_erase(asl, 0, comment - asl->str);
258 }
259
260 /* strip def block name (it has file path in it) */
261 if (g_str_has_prefix(asl->str, DEF_BLOCK)) {
262 block_name = g_strstr_len(asl->str, asl->len, BLOCK_NAME_END);
263 g_assert(block_name);
264 asl = g_string_erase(asl, 0,
265 block_name + sizeof(BLOCK_NAME_END) - asl->str);
266 }
267
268 return asl;
269 }
270
271 static GArray *load_expected_aml(test_data *data)
272 {
273 int i;
274 AcpiSdtTable *sdt;
275 GError *error = NULL;
276 gboolean ret;
277 gsize aml_len;
278
279 GArray *exp_tables = g_array_new(false, true, sizeof(AcpiSdtTable));
280 if (getenv("V")) {
281 fputc('\n', stderr);
282 }
283 for (i = 0; i < data->tables->len; ++i) {
284 AcpiSdtTable exp_sdt;
285 gchar *aml_file = NULL;
286 const char *ext = data->variant ? data->variant : "";
287
288 sdt = &g_array_index(data->tables, AcpiSdtTable, i);
289
290 memset(&exp_sdt, 0, sizeof(exp_sdt));
291
292 try_again:
293 aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
294 (gchar *)&sdt->header->signature, ext);
295 if (getenv("V")) {
296 fprintf(stderr, "Looking for expected file '%s'\n", aml_file);
297 }
298 if (g_file_test(aml_file, G_FILE_TEST_EXISTS)) {
299 exp_sdt.aml_file = aml_file;
300 } else if (*ext != '\0') {
301 /* try fallback to generic (extension less) expected file */
302 ext = "";
303 g_free(aml_file);
304 goto try_again;
305 }
306 g_assert(exp_sdt.aml_file);
307 if (getenv("V")) {
308 fprintf(stderr, "Using expected file '%s'\n", aml_file);
309 }
310 ret = g_file_get_contents(aml_file, (gchar **)&exp_sdt.aml,
311 &aml_len, &error);
312 exp_sdt.aml_len = aml_len;
313 g_assert(ret);
314 g_assert_no_error(error);
315 g_assert(exp_sdt.aml);
316 g_assert(exp_sdt.aml_len);
317
318 g_array_append_val(exp_tables, exp_sdt);
319 }
320
321 return exp_tables;
322 }
323
324 /* test the list of tables in @data->tables against reference tables */
325 static void test_acpi_asl(test_data *data)
326 {
327 int i;
328 AcpiSdtTable *sdt, *exp_sdt;
329 test_data exp_data;
330 gboolean exp_err, err;
331
332 memset(&exp_data, 0, sizeof(exp_data));
333 exp_data.tables = load_expected_aml(data);
334 dump_aml_files(data, false);
335 for (i = 0; i < data->tables->len; ++i) {
336 GString *asl, *exp_asl;
337
338 sdt = &g_array_index(data->tables, AcpiSdtTable, i);
339 exp_sdt = &g_array_index(exp_data.tables, AcpiSdtTable, i);
340
341 err = load_asl(data->tables, sdt);
342 asl = normalize_asl(sdt->asl);
343
344 exp_err = load_asl(exp_data.tables, exp_sdt);
345 exp_asl = normalize_asl(exp_sdt->asl);
346
347 /* TODO: check for warnings */
348 g_assert(!err || exp_err);
349
350 if (g_strcmp0(asl->str, exp_asl->str)) {
351 if (exp_err) {
352 fprintf(stderr,
353 "Warning! iasl couldn't parse the expected aml\n");
354 } else {
355 uint32_t signature = cpu_to_le32(exp_sdt->header->signature);
356 sdt->tmp_files_retain = true;
357 exp_sdt->tmp_files_retain = true;
358 fprintf(stderr,
359 "acpi-test: Warning! %.4s mismatch. "
360 "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n",
361 (gchar *)&signature,
362 sdt->asl_file, sdt->aml_file,
363 exp_sdt->asl_file, exp_sdt->aml_file);
364 if (getenv("V")) {
365 const char *diff_cmd = getenv("DIFF");
366 if (diff_cmd) {
367 int ret G_GNUC_UNUSED;
368 char *diff = g_strdup_printf("%s %s %s", diff_cmd,
369 exp_sdt->asl_file, sdt->asl_file);
370 ret = system(diff) ;
371 g_free(diff);
372 } else {
373 fprintf(stderr, "acpi-test: Warning. not showing "
374 "difference since no diff utility is specified. "
375 "Set 'DIFF' environment variable to a preferred "
376 "diff utility and run 'make V=1 check' again to "
377 "see ASL difference.");
378 }
379 }
380 }
381 }
382 g_string_free(asl, true);
383 g_string_free(exp_asl, true);
384 }
385
386 free_test_data(&exp_data);
387 }
388
389 static bool smbios_ep_table_ok(test_data *data)
390 {
391 struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
392 uint32_t addr = data->smbios_ep_addr;
393
394 qtest_memread(data->qts, addr, ep_table, sizeof(*ep_table));
395 if (memcmp(ep_table->anchor_string, "_SM_", 4)) {
396 return false;
397 }
398 if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) {
399 return false;
400 }
401 if (ep_table->structure_table_length == 0) {
402 return false;
403 }
404 if (ep_table->number_of_structures == 0) {
405 return false;
406 }
407 if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) ||
408 acpi_calc_checksum((uint8_t *)ep_table + 0x10,
409 sizeof *ep_table - 0x10)) {
410 return false;
411 }
412 return true;
413 }
414
415 static void test_smbios_entry_point(test_data *data)
416 {
417 uint32_t off;
418
419 /* find smbios entry point structure */
420 for (off = 0xf0000; off < 0x100000; off += 0x10) {
421 uint8_t sig[] = "_SM_";
422 int i;
423
424 for (i = 0; i < sizeof sig - 1; ++i) {
425 sig[i] = qtest_readb(data->qts, off + i);
426 }
427
428 if (!memcmp(sig, "_SM_", sizeof sig)) {
429 /* signature match, but is this a valid entry point? */
430 data->smbios_ep_addr = off;
431 if (smbios_ep_table_ok(data)) {
432 break;
433 }
434 }
435 }
436
437 g_assert_cmphex(off, <, 0x100000);
438 }
439
440 static inline bool smbios_single_instance(uint8_t type)
441 {
442 switch (type) {
443 case 0:
444 case 1:
445 case 2:
446 case 3:
447 case 16:
448 case 32:
449 case 127:
450 return true;
451 default:
452 return false;
453 }
454 }
455
456 static void test_smbios_structs(test_data *data)
457 {
458 DECLARE_BITMAP(struct_bitmap, SMBIOS_MAX_TYPE+1) = { 0 };
459 struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
460 uint32_t addr = le32_to_cpu(ep_table->structure_table_address);
461 int i, len, max_len = 0;
462 uint8_t type, prv, crt;
463
464 /* walk the smbios tables */
465 for (i = 0; i < le16_to_cpu(ep_table->number_of_structures); i++) {
466
467 /* grab type and formatted area length from struct header */
468 type = qtest_readb(data->qts, addr);
469 g_assert_cmpuint(type, <=, SMBIOS_MAX_TYPE);
470 len = qtest_readb(data->qts, addr + 1);
471
472 /* single-instance structs must not have been encountered before */
473 if (smbios_single_instance(type)) {
474 g_assert(!test_bit(type, struct_bitmap));
475 }
476 set_bit(type, struct_bitmap);
477
478 /* seek to end of unformatted string area of this struct ("\0\0") */
479 prv = crt = 1;
480 while (prv || crt) {
481 prv = crt;
482 crt = qtest_readb(data->qts, addr + len);
483 len++;
484 }
485
486 /* keep track of max. struct size */
487 if (max_len < len) {
488 max_len = len;
489 g_assert_cmpuint(max_len, <=, ep_table->max_structure_size);
490 }
491
492 /* start of next structure */
493 addr += len;
494 }
495
496 /* total table length and max struct size must match entry point values */
497 g_assert_cmpuint(le16_to_cpu(ep_table->structure_table_length), ==,
498 addr - le32_to_cpu(ep_table->structure_table_address));
499 g_assert_cmpuint(le16_to_cpu(ep_table->max_structure_size), ==, max_len);
500
501 /* required struct types must all be present */
502 for (i = 0; i < data->required_struct_types_len; i++) {
503 g_assert(test_bit(data->required_struct_types[i], struct_bitmap));
504 }
505 }
506
507 static void test_acpi_one(const char *params, test_data *data)
508 {
509 char *args;
510
511 /* Disable kernel irqchip to be able to override apic irq0. */
512 args = g_strdup_printf("-machine %s,accel=%s,kernel-irqchip=off "
513 "-net none -display none %s "
514 "-drive id=hd0,if=none,file=%s,format=raw "
515 "-device ide-hd,drive=hd0 ",
516 data->machine, "kvm:tcg",
517 params ? params : "", disk);
518
519 data->qts = qtest_init(args);
520
521 boot_sector_test(data->qts);
522
523 data->tables = g_array_new(false, true, sizeof(AcpiSdtTable));
524 test_acpi_rsdp_address(data);
525 test_acpi_rsdp_table(data);
526 test_acpi_rsdt_table(data);
527 test_acpi_fadt_table(data);
528
529 if (iasl) {
530 if (getenv(ACPI_REBUILD_EXPECTED_AML)) {
531 dump_aml_files(data, true);
532 } else {
533 test_acpi_asl(data);
534 }
535 }
536
537 test_smbios_entry_point(data);
538 test_smbios_structs(data);
539
540 assert(!global_qtest);
541 qtest_quit(data->qts);
542 g_free(args);
543 }
544
545 static uint8_t base_required_struct_types[] = {
546 0, 1, 3, 4, 16, 17, 19, 32, 127
547 };
548
549 static void test_acpi_piix4_tcg(void)
550 {
551 test_data data;
552
553 /* Supplying -machine accel argument overrides the default (qtest).
554 * This is to make guest actually run.
555 */
556 memset(&data, 0, sizeof(data));
557 data.machine = MACHINE_PC;
558 data.required_struct_types = base_required_struct_types;
559 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
560 test_acpi_one(NULL, &data);
561 free_test_data(&data);
562 }
563
564 static void test_acpi_piix4_tcg_bridge(void)
565 {
566 test_data data;
567
568 memset(&data, 0, sizeof(data));
569 data.machine = MACHINE_PC;
570 data.variant = ".bridge";
571 data.required_struct_types = base_required_struct_types;
572 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
573 test_acpi_one("-device pci-bridge,chassis_nr=1", &data);
574 free_test_data(&data);
575 }
576
577 static void test_acpi_q35_tcg(void)
578 {
579 test_data data;
580
581 memset(&data, 0, sizeof(data));
582 data.machine = MACHINE_Q35;
583 data.required_struct_types = base_required_struct_types;
584 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
585 test_acpi_one(NULL, &data);
586 free_test_data(&data);
587 }
588
589 static void test_acpi_q35_tcg_bridge(void)
590 {
591 test_data data;
592
593 memset(&data, 0, sizeof(data));
594 data.machine = MACHINE_Q35;
595 data.variant = ".bridge";
596 data.required_struct_types = base_required_struct_types;
597 data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
598 test_acpi_one("-device pci-bridge,chassis_nr=1",
599 &data);
600 free_test_data(&data);
601 }
602
603 static void test_acpi_q35_tcg_mmio64(void)
604 {
605 test_data data = {
606 .machine = MACHINE_Q35,
607 .variant = ".mmio64",
608 .required_struct_types = base_required_struct_types,
609 .required_struct_types_len = ARRAY_SIZE(base_required_struct_types)
610 };
611
612 test_acpi_one("-m 128M,slots=1,maxmem=2G "
613 "-device pci-testdev,membar=2G",
614 &data);
615 free_test_data(&data);
616 }
617
618 static void test_acpi_piix4_tcg_cphp(void)
619 {
620 test_data data;
621
622 memset(&data, 0, sizeof(data));
623 data.machine = MACHINE_PC;
624 data.variant = ".cphp";
625 test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6"
626 " -numa node -numa node"
627 " -numa dist,src=0,dst=1,val=21",
628 &data);
629 free_test_data(&data);
630 }
631
632 static void test_acpi_q35_tcg_cphp(void)
633 {
634 test_data data;
635
636 memset(&data, 0, sizeof(data));
637 data.machine = MACHINE_Q35;
638 data.variant = ".cphp";
639 test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
640 " -numa node -numa node"
641 " -numa dist,src=0,dst=1,val=21",
642 &data);
643 free_test_data(&data);
644 }
645
646 static uint8_t ipmi_required_struct_types[] = {
647 0, 1, 3, 4, 16, 17, 19, 32, 38, 127
648 };
649
650 static void test_acpi_q35_tcg_ipmi(void)
651 {
652 test_data data;
653
654 memset(&data, 0, sizeof(data));
655 data.machine = MACHINE_Q35;
656 data.variant = ".ipmibt";
657 data.required_struct_types = ipmi_required_struct_types;
658 data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
659 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
660 " -device isa-ipmi-bt,bmc=bmc0",
661 &data);
662 free_test_data(&data);
663 }
664
665 static void test_acpi_piix4_tcg_ipmi(void)
666 {
667 test_data data;
668
669 /* Supplying -machine accel argument overrides the default (qtest).
670 * This is to make guest actually run.
671 */
672 memset(&data, 0, sizeof(data));
673 data.machine = MACHINE_PC;
674 data.variant = ".ipmikcs";
675 data.required_struct_types = ipmi_required_struct_types;
676 data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
677 test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
678 " -device isa-ipmi-kcs,irq=0,bmc=bmc0",
679 &data);
680 free_test_data(&data);
681 }
682
683 static void test_acpi_q35_tcg_memhp(void)
684 {
685 test_data data;
686
687 memset(&data, 0, sizeof(data));
688 data.machine = MACHINE_Q35;
689 data.variant = ".memhp";
690 test_acpi_one(" -m 128,slots=3,maxmem=1G"
691 " -numa node -numa node"
692 " -numa dist,src=0,dst=1,val=21",
693 &data);
694 free_test_data(&data);
695 }
696
697 static void test_acpi_piix4_tcg_memhp(void)
698 {
699 test_data data;
700
701 memset(&data, 0, sizeof(data));
702 data.machine = MACHINE_PC;
703 data.variant = ".memhp";
704 test_acpi_one(" -m 128,slots=3,maxmem=1G"
705 " -numa node -numa node"
706 " -numa dist,src=0,dst=1,val=21",
707 &data);
708 free_test_data(&data);
709 }
710
711 static void test_acpi_q35_tcg_numamem(void)
712 {
713 test_data data;
714
715 memset(&data, 0, sizeof(data));
716 data.machine = MACHINE_Q35;
717 data.variant = ".numamem";
718 test_acpi_one(" -numa node -numa node,mem=128", &data);
719 free_test_data(&data);
720 }
721
722 static void test_acpi_piix4_tcg_numamem(void)
723 {
724 test_data data;
725
726 memset(&data, 0, sizeof(data));
727 data.machine = MACHINE_PC;
728 data.variant = ".numamem";
729 test_acpi_one(" -numa node -numa node,mem=128", &data);
730 free_test_data(&data);
731 }
732
733 static void test_acpi_tcg_dimm_pxm(const char *machine)
734 {
735 test_data data;
736
737 memset(&data, 0, sizeof(data));
738 data.machine = machine;
739 data.variant = ".dimmpxm";
740 test_acpi_one(" -machine nvdimm=on,nvdimm-persistence=cpu"
741 " -smp 4,sockets=4"
742 " -m 128M,slots=3,maxmem=1G"
743 " -numa node,mem=32M,nodeid=0"
744 " -numa node,mem=32M,nodeid=1"
745 " -numa node,mem=32M,nodeid=2"
746 " -numa node,mem=32M,nodeid=3"
747 " -numa cpu,node-id=0,socket-id=0"
748 " -numa cpu,node-id=1,socket-id=1"
749 " -numa cpu,node-id=2,socket-id=2"
750 " -numa cpu,node-id=3,socket-id=3"
751 " -object memory-backend-ram,id=ram0,size=128M"
752 " -object memory-backend-ram,id=nvm0,size=128M"
753 " -device pc-dimm,id=dimm0,memdev=ram0,node=1"
754 " -device nvdimm,id=dimm1,memdev=nvm0,node=2",
755 &data);
756 free_test_data(&data);
757 }
758
759 static void test_acpi_q35_tcg_dimm_pxm(void)
760 {
761 test_acpi_tcg_dimm_pxm(MACHINE_Q35);
762 }
763
764 static void test_acpi_piix4_tcg_dimm_pxm(void)
765 {
766 test_acpi_tcg_dimm_pxm(MACHINE_PC);
767 }
768
769 int main(int argc, char *argv[])
770 {
771 const char *arch = qtest_get_arch();
772 int ret;
773
774 ret = boot_sector_init(disk);
775 if(ret)
776 return ret;
777
778 g_test_init(&argc, &argv, NULL);
779
780 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
781 qtest_add_func("acpi/piix4", test_acpi_piix4_tcg);
782 qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge);
783 qtest_add_func("acpi/q35", test_acpi_q35_tcg);
784 qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge);
785 qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64);
786 qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi);
787 qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi);
788 qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp);
789 qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp);
790 qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp);
791 qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp);
792 qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem);
793 qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
794 qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm);
795 qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
796 }
797 ret = g_test_run();
798 boot_sector_cleanup(disk);
799 return ret;
800 }