summaryrefslogtreecommitdiff
path: root/test/dm
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-12-10 10:37:37 -0700
committerSimon Glass <sjg@chromium.org>2018-12-13 16:32:49 -0700
commita1b17e4f4c820c5ffe77ffa0c716e8b3b5d69866 (patch)
tree7487cc794f79e8bc32e1ee6c366d3b4e22466924 /test/dm
parentd4901898654b664c41d8a03afc0e0fbf531b5812 (diff)
dm: core: Add a function to read into a unsigned int
The current dev_read...() functions use s32 and u32 which are convenient for device tree but not so useful for normal code, which often wants to use normal integers for values. Add a helper which supports returning an unsigned int. Also add signed versions of the unsigned readers. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test/dm')
-rw-r--r--test/dm/test-fdt.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index 96d2528acc..984b80c02c 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -736,3 +736,38 @@ static int dm_test_first_child(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_first_child, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test integer functions in dm_read_...() */
+static int dm_test_read_int(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ u32 val32;
+ s32 sval;
+ uint val;
+
+ ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
+ ut_asserteq_str("a-test", dev->name);
+ ut_assertok(dev_read_u32(dev, "int-value", &val32));
+ ut_asserteq(1234, val32);
+
+ ut_asserteq(-EINVAL, dev_read_u32(dev, "missing", &val32));
+ ut_asserteq(6, dev_read_u32_default(dev, "missing", 6));
+
+ ut_asserteq(1234, dev_read_u32_default(dev, "int-value", 6));
+ ut_asserteq(1234, val32);
+
+ ut_asserteq(-EINVAL, dev_read_s32(dev, "missing", &sval));
+ ut_asserteq(6, dev_read_s32_default(dev, "missing", 6));
+
+ ut_asserteq(-1234, dev_read_s32_default(dev, "uint-value", 6));
+ ut_assertok(dev_read_s32(dev, "uint-value", &sval));
+ ut_asserteq(-1234, sval);
+
+ val = 0;
+ ut_asserteq(-EINVAL, dev_read_u32u(dev, "missing", &val));
+ ut_assertok(dev_read_u32u(dev, "uint-value", &val));
+ ut_asserteq(-1234, val);
+
+ return 0;
+}
+DM_TEST(dm_test_read_int, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);