summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMario Six <mario.six@gdsys.cc>2018-07-31 14:24:14 +0200
committerAnatolij Gustschin <agust@denx.de>2018-08-11 16:00:38 +0200
commit004e67c21634d0184eb0b874cbd05d834cb79067 (patch)
tree6b99525bcd56d7f2cd470d3ffb12ecd877e2649a /test
parent440bc11f2e10dd80c7f5e717bc52daff73091bd5 (diff)
test: Add tests for misc uclass
Add a set of tests for the misc uclass. Signed-off-by: Mario Six <mario.six@gdsys.cc> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/dm/Makefile1
-rw-r--r--test/dm/misc.c83
2 files changed, 84 insertions, 0 deletions
diff --git a/test/dm/Makefile b/test/dm/Makefile
index d2ed96c615..ff0807873b 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_MISC) += misc.o
endif
diff --git a/test/dm/misc.c b/test/dm/misc.c
new file mode 100644
index 0000000000..61279665ef
--- /dev/null
+++ b/test/dm/misc.c
@@ -0,0 +1,83 @@
+// 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 <misc.h>
+#include <test/ut.h>
+
+static int dm_test_misc(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ u8 buf[16];
+ int id;
+ ulong last_ioctl;
+ bool enabled;
+
+ ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "misc-test", &dev));
+
+ /* Read / write tests */
+ ut_assertok(misc_write(dev, 0, "TEST", 4));
+ ut_assertok(misc_write(dev, 4, "WRITE", 5));
+ ut_assertok(misc_read(dev, 0, buf, 9));
+
+ ut_assertok(memcmp(buf, "TESTWRITE", 9));
+
+ /* Call tests */
+
+ id = 0;
+ ut_assertok(misc_call(dev, 0, &id, 4, buf, 16));
+ ut_assertok(memcmp(buf, "Zero", 4));
+
+ id = 2;
+ ut_assertok(misc_call(dev, 0, &id, 4, buf, 16));
+ ut_assertok(memcmp(buf, "Two", 3));
+
+ ut_assertok(misc_call(dev, 1, &id, 4, buf, 16));
+ ut_assertok(memcmp(buf, "Forty-two", 9));
+
+ id = 1;
+ ut_assertok(misc_call(dev, 1, &id, 4, buf, 16));
+ ut_assertok(memcmp(buf, "Forty-one", 9));
+
+ /* IOCTL tests */
+
+ ut_assertok(misc_ioctl(dev, 6, NULL));
+ /* Read back last issued ioctl */
+ ut_assertok(misc_call(dev, 2, NULL, 0, &last_ioctl,
+ sizeof(last_ioctl)));
+ ut_asserteq(6, last_ioctl)
+
+ ut_assertok(misc_ioctl(dev, 23, NULL));
+ /* Read back last issued ioctl */
+ ut_assertok(misc_call(dev, 2, NULL, 0, &last_ioctl,
+ sizeof(last_ioctl)));
+ ut_asserteq(23, last_ioctl)
+
+ /* Enable / disable tests */
+
+ /* Read back enable/disable status */
+ ut_assertok(misc_call(dev, 3, NULL, 0, &enabled,
+ sizeof(enabled)));
+ ut_asserteq(true, enabled);
+
+ ut_assertok(misc_set_enabled(dev, false));
+ /* Read back enable/disable status */
+ ut_assertok(misc_call(dev, 3, NULL, 0, &enabled,
+ sizeof(enabled)));
+ ut_asserteq(false, enabled);
+
+ ut_assertok(misc_set_enabled(dev, true));
+ /* Read back enable/disable status */
+ ut_assertok(misc_call(dev, 3, NULL, 0, &enabled,
+ sizeof(enabled)));
+ ut_asserteq(true, enabled);
+
+ return 0;
+}
+
+DM_TEST(dm_test_misc, DM_TESTF_SCAN_FDT);