diff mbox series

[U-Boot,v4,15/17] test: Add tests for CPU uclass

Message ID 20180806082346.21211-15-mario.six@gdsys.cc
State Accepted
Delegated to: Simon Glass
Headers show
Series [U-Boot,v4,01/17] ram: Add driver for MPC83xx | expand

Commit Message

Mario Six Aug. 6, 2018, 8:23 a.m. UTC
Add a sandbox CPU driver, and some tests for the CPU uclass.

Signed-off-by: Mario Six <mario.six@gdsys.cc>
---

Notes:
    v3 -> v4:
    New in v4

 arch/sandbox/dts/test.dts | 12 ++++++++++
 drivers/cpu/Makefile      |  1 +
 drivers/cpu/cpu_sandbox.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++
 test/dm/Makefile          |  1 +
 test/dm/cpu.c             | 45 ++++++++++++++++++++++++++++++++++
 5 files changed, 120 insertions(+)
 create mode 100644 drivers/cpu/cpu_sandbox.c
 create mode 100644 test/dm/cpu.c

Comments

Simon Glass Sept. 28, 2018, 3:55 p.m. UTC | #1
On 6 August 2018 at 01:23, Mario Six <mario.six@gdsys.cc> wrote:
> Add a sandbox CPU driver, and some tests for the CPU uclass.
>
> Signed-off-by: Mario Six <mario.six@gdsys.cc>
> ---
>
> Notes:
>     v3 -> v4:
>     New in v4
>
>  arch/sandbox/dts/test.dts | 12 ++++++++++
>  drivers/cpu/Makefile      |  1 +
>  drivers/cpu/cpu_sandbox.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++
>  test/dm/Makefile          |  1 +
>  test/dm/cpu.c             | 45 ++++++++++++++++++++++++++++++++++
>  5 files changed, 120 insertions(+)
>  create mode 100644 drivers/cpu/cpu_sandbox.c
>  create mode 100644 test/dm/cpu.c'

Applied to u-boot-dm, and now in mainline, thanks!
diff mbox series

Patch

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 137679abea9..527af1aee11 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -283,6 +283,18 @@ 
 		mbox-names = "other", "test";
 	};
 
+	cpu-test1 {
+		compatible = "sandbox,cpu_sandbox";
+	};
+
+	cpu-test2 {
+		compatible = "sandbox,cpu_sandbox";
+	};
+
+	cpu-test3 {
+		compatible = "sandbox,cpu_sandbox";
+	};
+
 	mmc2 {
 		compatible = "sandbox,mmc";
 	};
diff --git a/drivers/cpu/Makefile b/drivers/cpu/Makefile
index db515f6f177..980c68f44d0 100644
--- a/drivers/cpu/Makefile
+++ b/drivers/cpu/Makefile
@@ -7,3 +7,4 @@ 
 obj-$(CONFIG_CPU) += cpu-uclass.o
 
 obj-$(CONFIG_ARCH_BMIPS) += bmips_cpu.o
+obj-$(CONFIG_SANDBOX) += cpu_sandbox.o
diff --git a/drivers/cpu/cpu_sandbox.c b/drivers/cpu/cpu_sandbox.c
new file mode 100644
index 00000000000..ff87e8adca3
--- /dev/null
+++ b/drivers/cpu/cpu_sandbox.c
@@ -0,0 +1,61 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2018
+ * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <cpu.h>
+
+int cpu_sandbox_get_desc(struct udevice *dev, char *buf, int size)
+{
+	snprintf(buf, size, "LEG Inc. SuperMegaUltraTurbo CPU No. 1");
+
+	return 0;
+}
+
+int cpu_sandbox_get_info(struct udevice *dev, struct cpu_info *info)
+{
+	info->cpu_freq = 42 * 42 * 42 * 42 * 42;
+	info->features = 0x42424242;
+
+	return 0;
+}
+
+int cpu_sandbox_get_count(struct udevice *dev)
+{
+	return 42;
+}
+
+int cpu_sandbox_get_vendor(struct udevice *dev, char *buf, int size)
+{
+	snprintf(buf, size, "Languid Example Garbage Inc.");
+
+	return 0;
+}
+
+static const struct cpu_ops cpu_sandbox_ops = {
+	.get_desc = cpu_sandbox_get_desc,
+	.get_info = cpu_sandbox_get_info,
+	.get_count = cpu_sandbox_get_count,
+	.get_vendor = cpu_sandbox_get_vendor,
+};
+
+int cpu_sandbox_probe(struct udevice *dev)
+{
+	return 0;
+}
+
+static const struct udevice_id cpu_sandbox_ids[] = {
+	{ .compatible = "sandbox,cpu_sandbox" },
+	{ }
+};
+
+U_BOOT_DRIVER(cpu_sandbox) = {
+	.name           = "cpu_sandbox",
+	.id             = UCLASS_CPU,
+	.ops		= &cpu_sandbox_ops,
+	.of_match       = cpu_sandbox_ids,
+	.probe          = cpu_sandbox_probe,
+};
diff --git a/test/dm/Makefile b/test/dm/Makefile
index d2ed96c6153..c3bb26bb974 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -44,4 +44,5 @@  obj-$(CONFIG_DM_VIDEO) += video.o
 obj-$(CONFIG_ADC) += adc.o
 obj-$(CONFIG_SPMI) += spmi.o
 obj-$(CONFIG_WDT) += wdt.o
+obj-$(CONFIG_CPU) += cpu.o
 endif
diff --git a/test/dm/cpu.c b/test/dm/cpu.c
new file mode 100644
index 00000000000..f5f1caef716
--- /dev/null
+++ b/test/dm/cpu.c
@@ -0,0 +1,45 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2018
+ * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/test.h>
+#include <dm/uclass-internal.h>
+#include <cpu.h>
+#include <test/ut.h>
+
+static int dm_test_cpu(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	char text[128];
+	struct cpu_info info;
+
+	ut_assertok(cpu_probe_all());
+
+	/* Check that cpu_probe_all really activated all CPUs */
+	for (uclass_find_first_device(UCLASS_CPU, &dev);
+	     dev;
+	     uclass_find_next_device(&dev))
+		ut_assert(dev->flags & DM_FLAG_ACTIVATED);
+
+	ut_assertok(uclass_get_device_by_name(UCLASS_CPU, "cpu-test1", &dev));
+
+	ut_assertok(cpu_get_desc(dev, text, sizeof(text)));
+	ut_assertok(strcmp(text, "LEG Inc. SuperMegaUltraTurbo CPU No. 1"));
+
+	ut_assertok(cpu_get_info(dev, &info));
+	ut_asserteq(info.cpu_freq, 42 * 42 * 42 * 42 * 42);
+	ut_asserteq(info.features, 0x42424242);
+
+	ut_asserteq(cpu_get_count(dev), 42);
+
+	ut_assertok(cpu_get_vendor(dev, text, sizeof(text)));
+	ut_assertok(strcmp(text, "Languid Example Garbage Inc."));
+
+	return 0;
+}
+
+DM_TEST(dm_test_cpu, DM_TESTF_SCAN_FDT);