diff mbox series

dm: test: Add a test for dm_test_dev_read_addr_ptr()

Message ID 20200528082045.1.Ibd999a0382164a37d1e59c00c8c7a9ff92b8f53a@changeid
State New
Headers show
Series dm: test: Add a test for dm_test_dev_read_addr_ptr() | expand

Commit Message

Simon Glass May 28, 2020, 2:20 p.m. UTC
Check the behaviour of this function. Hopefully this is start of a
complete test suite for the dev_read...() functions.

Signed-off-by: Simon Glass <sjg at chromium.org>
---
Due to the nature of the test harness, this tests all cases:

1. CONFIG_OF_LIVE and livetree in use (normal sandbox test, gd->of_root is set)
2. CONFIG_OF_LIVE but livetree not yet in use (sandbox with gd->of_root = NULL)
3. !CONFIG_OF_LIVE (in sandbox_flattree)

The third one is tested by 'make qcheck' which calls test/run

 test/dm/Makefile |  1 +
 test/dm/read.c   | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
 create mode 100644 test/dm/read.c
diff mbox series

Patch

diff --git a/test/dm/Makefile b/test/dm/Makefile
index 6c18fd04ce..ad2d3547f5 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -4,6 +4,7 @@ 
 
 obj-$(CONFIG_UT_DM) += bus.o
 obj-$(CONFIG_UT_DM) += nop.o
+obj-$(CONFIG_UT_DM) += read.o
 obj-$(CONFIG_UT_DM) += test-driver.o
 obj-$(CONFIG_UT_DM) += test-fdt.o
 obj-$(CONFIG_UT_DM) += test-main.o
diff --git a/test/dm/read.c b/test/dm/read.c
new file mode 100644
index 0000000000..38b128b144
--- /dev/null
+++ b/test/dm/read.c
@@ -0,0 +1,34 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Livetree API
+ *
+ * Copyright 2020 Google LLC
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <mapmem.h>
+#include <syscon.h>
+#include <asm/test.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+/* Test that dev_read_addr_ptr() works in flattree and livetree */
+static int dm_test_dev_read_addr_ptr(struct unit_test_state *uts)
+{
+	struct udevice *gpio, *dev;
+	void *ptr;
+
+	/* Test for missing reg property */
+	ut_assertok(uclass_first_device_err(UCLASS_GPIO, &gpio));
+	ut_assertnull(dev_read_addr_ptr(gpio));
+
+	ut_assertok(syscon_get_by_driver_data(SYSCON0, &dev));
+	ptr = dev_read_addr_ptr(dev);
+	ut_asserteq(0x10, map_to_sysmem(ptr));
+
+	/* See dm_test_fdt_translation() which has more tests */
+
+	return 0;
+}
+DM_TEST(dm_test_dev_read_addr_ptr, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);