acpi: Add a simple sandbox test
authorSimon Glass <sjg@chromium.org>
Wed, 8 Apr 2020 22:57:34 +0000 (16:57 -0600)
committerBin Meng <bmeng.cn@gmail.com>
Thu, 16 Apr 2020 06:36:28 +0000 (14:36 +0800)
Add a sandbox test for the basic ACPI functionality we have so far.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
arch/sandbox/dts/test.dts
arch/sandbox/include/asm/acpi_table.h [new file with mode: 0644]
include/dm/uclass-id.h
test/dm/Makefile
test/dm/acpi.c [new file with mode: 0644]

index 4a277934a711383add30ef3b9facec4a0ff24539..5fa951ad4b6e971353ce8765ecad27083b4ce5c6 100644 (file)
                compatible = "denx,u-boot-devres-test";
        };
 
+       acpi-test {
+               compatible = "denx,u-boot-acpi-test";
+       };
+
        clocks {
                clk_fixed: clk-fixed {
                        compatible = "fixed-clock";
diff --git a/arch/sandbox/include/asm/acpi_table.h b/arch/sandbox/include/asm/acpi_table.h
new file mode 100644 (file)
index 0000000..921c7f4
--- /dev/null
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2019 Google LLC
+ */
+
+#ifndef __ASM_ACPI_TABLE_H__
+#define __ASM_ACPI_TABLE_H__
+
+#endif /* __ASM_ACPI_TABLE_H__ */
index 598f65ea7a32ecc5eaada566e7c55284fbef3db9..37ada51f9f7ae7ed80b316c952b5ecbbf914cfac 100644 (file)
@@ -20,6 +20,7 @@ enum uclass_id {
        UCLASS_TEST_PROBE,
        UCLASS_TEST_DUMMY,
        UCLASS_TEST_DEVRES,
+       UCLASS_TEST_ACPI,
        UCLASS_SPI_EMUL,        /* sandbox SPI device emulator */
        UCLASS_I2C_EMUL,        /* sandbox I2C device emulator */
        UCLASS_I2C_EMUL_PARENT, /* parent for I2C device emulators */
index dd1ceff86c0cc4412d85ef736b221138045fe309..3daf8a544ea018473828e02739d70a2262dd8367 100644 (file)
@@ -13,6 +13,7 @@ obj-$(CONFIG_UT_DM) += test-uclass.o
 # subsystem you must add sandbox tests here.
 obj-$(CONFIG_UT_DM) += core.o
 ifneq ($(CONFIG_SANDBOX),)
+obj-$(CONFIG_ACPIGEN) += acpi.o
 obj-$(CONFIG_SOUND) += audio.o
 obj-$(CONFIG_BLK) += blk.o
 obj-$(CONFIG_BOARD) += board.o
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
new file mode 100644 (file)
index 0000000..3677cdd
--- /dev/null
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for ACPI table generation
+ *
+ * Copyright 2019 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/acpi.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+#define ACPI_TEST_DEV_NAME     "ABCD"
+
+static int testacpi_get_name(const struct udevice *dev, char *out_name)
+{
+       return acpi_copy_name(out_name, ACPI_TEST_DEV_NAME);
+}
+
+struct acpi_ops testacpi_ops = {
+       .get_name       = testacpi_get_name,
+};
+
+static const struct udevice_id testacpi_ids[] = {
+       { .compatible = "denx,u-boot-acpi-test" },
+       { }
+};
+
+U_BOOT_DRIVER(testacpi_drv) = {
+       .name   = "testacpi_drv",
+       .of_match       = testacpi_ids,
+       .id     = UCLASS_TEST_ACPI,
+       ACPI_OPS_PTR(&testacpi_ops)
+};
+
+UCLASS_DRIVER(testacpi) = {
+       .name           = "testacpi",
+       .id             = UCLASS_TEST_ACPI,
+};
+
+/* Test ACPI get_name() */
+static int dm_test_acpi_get_name(struct unit_test_state *uts)
+{
+       char name[ACPI_NAME_MAX];
+       struct udevice *dev;
+
+       ut_assertok(uclass_first_device_err(UCLASS_TEST_ACPI, &dev));
+       ut_assertok(acpi_get_name(dev, name));
+       ut_asserteq_str(ACPI_TEST_DEV_NAME, name);
+
+       return 0;
+}
+DM_TEST(dm_test_acpi_get_name, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);