diff mbox series

[v3,15/29] acpi: Add a simple sandbox test

Message ID 20200330171226.v3.15.Ife90d6e6cfa90e642e73328168a00804b1dc6fd4@changeid
State Superseded
Delegated to: Bin Meng
Headers show
Series dm: Add programmatic generation of ACPI tables (part A) | expand

Commit Message

Simon Glass March 30, 2020, 11:12 p.m. UTC
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>
---

Changes in v3: None
Changes in v2:
- Add in the acpi_table.h header file to this patch

 arch/sandbox/dts/test.dts             |  4 ++
 arch/sandbox/include/asm/acpi_table.h |  9 +++++
 include/dm/uclass-id.h                |  1 +
 test/dm/Makefile                      |  1 +
 test/dm/acpi.c                        | 55 +++++++++++++++++++++++++++
 5 files changed, 70 insertions(+)
 create mode 100644 arch/sandbox/include/asm/acpi_table.h
 create mode 100644 test/dm/acpi.c

Comments

Andy Shevchenko April 3, 2020, 12:51 p.m. UTC | #1
On Mon, Mar 30, 2020 at 05:12:51PM -0600, Simon Glass wrote:
> Add a sandbox test for the basic ACPI functionality we have so far.

> +U_BOOT_DRIVER(testacpi_drv) = {
> +	.name	= "testacpi_drv",
> +	.of_match	= testacpi_ids,
> +	.id	= UCLASS_TEST_ACPI,

> +	acpi_ops_ptr(&testacpi_ops)

I have noticed that this is not obvious why no comma here.
Perhaps, since apci_ops_ptr is a macro, you should upper case it.

> +};
Simon Glass April 8, 2020, 2:57 a.m. UTC | #2
Hi Andy,

On Fri, 3 Apr 2020 at 06:51, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Mon, Mar 30, 2020 at 05:12:51PM -0600, Simon Glass wrote:
> > Add a sandbox test for the basic ACPI functionality we have so far.
>
> > +U_BOOT_DRIVER(testacpi_drv) = {
> > +     .name   = "testacpi_drv",
> > +     .of_match       = testacpi_ids,
> > +     .id     = UCLASS_TEST_ACPI,
>
> > +     acpi_ops_ptr(&testacpi_ops)
>
> I have noticed that this is not obvious why no comma here.
> Perhaps, since apci_ops_ptr is a macro, you should upper case it.

This is a bit like of_match_ptr() which is a macro used by Linux.
Putting them in upper case makes them very hard to read. Admittedly
the lack of a comma is odd though. It is because the field doesn't
exist until ACPI is enabled (which it is not in SPL, for example).

Regards,
Simon
Andy Shevchenko April 8, 2020, 4:57 p.m. UTC | #3
On Tue, Apr 07, 2020 at 08:57:19PM -0600, Simon Glass wrote:
> Hi Andy,
> 
> On Fri, 3 Apr 2020 at 06:51, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > On Mon, Mar 30, 2020 at 05:12:51PM -0600, Simon Glass wrote:
> > > Add a sandbox test for the basic ACPI functionality we have so far.
> >
> > > +U_BOOT_DRIVER(testacpi_drv) = {
> > > +     .name   = "testacpi_drv",
> > > +     .of_match       = testacpi_ids,
> > > +     .id     = UCLASS_TEST_ACPI,
> >
> > > +     acpi_ops_ptr(&testacpi_ops)
> >
> > I have noticed that this is not obvious why no comma here.
> > Perhaps, since apci_ops_ptr is a macro, you should upper case it.
> 
> This is a bit like of_match_ptr() which is a macro used by Linux.

For ACPI there is capitalized, but...

> Putting them in upper case makes them very hard to read. Admittedly
> the lack of a comma is odd though. It is because the field doesn't
> exist until ACPI is enabled (which it is not in SPL, for example).

...and this puts them to different categories, like PM ops in Linux kernel,
where they are also capitalized, exactly to be used in struct definitions.
diff mbox series

Patch

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 4a277934a71..5fa951ad4b6 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -206,6 +206,10 @@ 
 		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
index 00000000000..921c7f4201d
--- /dev/null
+++ b/arch/sandbox/include/asm/acpi_table.h
@@ -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__ */
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index 598f65ea7a3..37ada51f9f7 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -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 */
diff --git a/test/dm/Makefile b/test/dm/Makefile
index dd1ceff86c0..3daf8a544ea 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 00000000000..429993b9cc0
--- /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);