1 // SPDX-License-Identifier: GPL-2.0+
3 * Tests for ACPI table generation
5 * Copyright 2019 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
11 #include <acpi/acpi_table.h>
16 #define ACPI_TEST_DEV_NAME "ABCD"
18 static int testacpi_get_name(const struct udevice *dev, char *out_name)
20 return acpi_copy_name(out_name, ACPI_TEST_DEV_NAME);
23 struct acpi_ops testacpi_ops = {
24 .get_name = testacpi_get_name,
27 static const struct udevice_id testacpi_ids[] = {
28 { .compatible = "denx,u-boot-acpi-test" },
32 U_BOOT_DRIVER(testacpi_drv) = {
33 .name = "testacpi_drv",
34 .of_match = testacpi_ids,
35 .id = UCLASS_TEST_ACPI,
36 ACPI_OPS_PTR(&testacpi_ops)
39 UCLASS_DRIVER(testacpi) = {
41 .id = UCLASS_TEST_ACPI,
44 /* Test ACPI get_name() */
45 static int dm_test_acpi_get_name(struct unit_test_state *uts)
47 char name[ACPI_NAME_MAX];
50 ut_assertok(uclass_first_device_err(UCLASS_TEST_ACPI, &dev));
51 ut_assertok(acpi_get_name(dev, name));
52 ut_asserteq_str(ACPI_TEST_DEV_NAME, name);
56 DM_TEST(dm_test_acpi_get_name, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
58 /* Test acpi_get_table_revision() */
59 static int dm_test_acpi_get_table_revision(struct unit_test_state *uts)
61 ut_asserteq(1, acpi_get_table_revision(ACPITAB_MCFG));
62 ut_asserteq(2, acpi_get_table_revision(ACPITAB_RSDP));
63 ut_asserteq(4, acpi_get_table_revision(ACPITAB_TPM2));
64 ut_asserteq(-EINVAL, acpi_get_table_revision(ACPITAB_COUNT));
68 DM_TEST(dm_test_acpi_get_table_revision,
69 DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
71 /* Temporary change to ensure bisectability */
72 #ifndef CONFIG_SANDBOX
73 /* Test acpi_create_dmar() */
74 static int dm_test_acpi_create_dmar(struct unit_test_state *uts)
76 struct acpi_dmar dmar;
78 ut_assertok(acpi_create_dmar(&dmar, DMAR_INTR_REMAP));
79 ut_asserteq(DMAR_INTR_REMAP, dmar.flags);
80 ut_asserteq(32 - 1, dmar.host_address_width);
84 DM_TEST(dm_test_acpi_create_dmar, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);