]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test: dm: add tests for tag support
authorAKASHI Takahiro <takahiro.akashi@linaro.org>
Fri, 15 Apr 2022 07:15:37 +0000 (16:15 +0900)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sat, 23 Apr 2022 20:05:34 +0000 (22:05 +0200)
The new test covers all tag-related interfaces.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
test/dm/Makefile
test/dm/tag.c [new file with mode: 0644]

index 9a1a904d906aa7e91e622319544805faa97e5f5f..f0a7c97e3d17e8a76038fb182ea96d312d33413b 100644 (file)
@@ -102,6 +102,7 @@ obj-y += syscon.o
 obj-$(CONFIG_RESET_SYSCON) += syscon-reset.o
 obj-$(CONFIG_SYSINFO) += sysinfo.o
 obj-$(CONFIG_SYSINFO_GPIO) += sysinfo-gpio.o
+obj-$(CONFIG_UT_DM) += tag.o
 obj-$(CONFIG_TEE) += tee.o
 obj-$(CONFIG_TIMER) += timer.o
 obj-$(CONFIG_DM_USB) += usb.o
diff --git a/test/dm/tag.c b/test/dm/tag.c
new file mode 100644 (file)
index 0000000..8ae8a1f
--- /dev/null
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  DM tag test
+ *
+ *  Copyright (c) 2021 Linaro Limited
+ *  Author: AKASHI Takahiro
+ */
+
+#include <common.h>
+#include <dm/tag.h>
+#include <dm/test.h> /* DM_TEST() */
+#include <test/test.h> /* struct unit_test_state */
+#include <test/ut.h> /* assertions */
+
+/*
+ * Test dm_tag_ptr() API
+ */
+static int dm_test_tag_ptr(struct unit_test_state *uts)
+{
+       ulong val;
+       void *ptr = NULL;
+
+       ut_assertok(dev_tag_set_ptr(uts->root, DM_TAG_EFI, &val));
+
+       ut_assertok(dev_tag_get_ptr(uts->root, DM_TAG_EFI, &ptr));
+
+       ut_asserteq_ptr(&val, ptr);
+
+       ut_assertok(dev_tag_del(uts->root, DM_TAG_EFI));
+
+       return 0;
+}
+
+DM_TEST(dm_test_tag_ptr, 0);
+
+/*
+ * Test dm_tag_val() API
+ */
+static int dm_test_tag_val(struct unit_test_state *uts)
+{
+       ulong val1 = 0x12345678, val2 = 0;
+
+       ut_assertok(dev_tag_set_val(uts->root, DM_TAG_EFI, val1));
+
+       ut_assertok(dev_tag_get_val(uts->root, DM_TAG_EFI, &val2));
+
+       ut_asserteq_64(val1, val2);
+
+       ut_assertok(dev_tag_del(uts->root, DM_TAG_EFI));
+
+       return 0;
+}
+
+DM_TEST(dm_test_tag_val, 0);
+
+/*
+ * Test against an invalid tag
+ */
+static int dm_test_tag_inval(struct unit_test_state *uts)
+{
+       ulong val;
+
+       ut_asserteq(-EINVAL, dev_tag_set_ptr(uts->root, DM_TAG_COUNT, &val));
+
+       return 0;
+}
+
+DM_TEST(dm_test_tag_inval, 0);
+
+/*
+ * Test dm_tag_del_all() AP:
+ */
+static int dm_test_tag_del_all(struct unit_test_state *uts)
+{
+       ulong val;
+
+       ut_assertok(dev_tag_set_ptr(uts->root, DM_TAG_EFI, &val));
+
+       ut_assertok(dev_tag_del_all(uts->root));
+
+       return 0;
+}
+
+DM_TEST(dm_test_tag_del_all, 0);