summaryrefslogtreecommitdiff
path: root/test/dm
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2020-04-08 16:57:34 -0600
committerBin Meng <bmeng.cn@gmail.com>2020-04-16 14:36:28 +0800
commitf50cc9528850ed546b44894cdc7ab4ceb4b30550 (patch)
tree84c4156b4dbea5f6a6a7cb157fc62c945398f8df /test/dm
parent29db946cbfbc6d492e4c5466ee2a3080897b60b3 (diff)
acpi: Add a simple sandbox test
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>
Diffstat (limited to 'test/dm')
-rw-r--r--test/dm/Makefile1
-rw-r--r--test/dm/acpi.c55
2 files changed, 56 insertions, 0 deletions
diff --git a/test/dm/Makefile b/test/dm/Makefile
index dd1ceff86c..3daf8a544e 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -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
index 0000000000..3677cdd0cc
--- /dev/null
+++ b/test/dm/acpi.c
@@ -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);