diff mbox series

[1/3] dm: test: add test case for dev_read_u64 function

Message ID 20200329160443.11518-2-dariobin@libero.it
State Accepted
Commit 70573c6c46be96d2e60497d8484b9afb119da8c1
Headers show
Series Support reading an u32 from a multi-value property | expand

Commit Message

Dario Binacchi March 29, 2020, 4:04 p.m. UTC
Add test case to cover dev_read_u64 and dev_read_u64_default functions.

Signed-off-by: Dario Binacchi <dariobin at libero.it>
---

 arch/sandbox/dts/test.dts |  1 +
 include/test/ut.h         | 16 ++++++++++++++++
 test/dm/test-fdt.c        | 10 ++++++++++
 3 files changed, 27 insertions(+)

Comments

Simon Glass March 30, 2020, 11:57 p.m. UTC | #1
On Sun, 29 Mar 2020 at 10:05, Dario Binacchi <dariobin at libero.it> wrote:
>
> Add test case to cover dev_read_u64 and dev_read_u64_default functions.
>
> Signed-off-by: Dario Binacchi <dariobin at libero.it>
> ---
>
>  arch/sandbox/dts/test.dts |  1 +
>  include/test/ut.h         | 16 ++++++++++++++++
>  test/dm/test-fdt.c        | 10 ++++++++++
>  3 files changed, 27 insertions(+)

Reviewed-by: Simon Glass <sjg at chromium.org>
diff mbox series

Patch

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 4a277934a7..6664adb385 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -93,6 +93,7 @@ 
 			<&gpio_b 9 0xc 3 2 1>;
 		int-value = <1234>;
 		uint-value = <(-1234)>;
+		int64-value = /bits/ 64 <0x1111222233334444>;
 		interrupts-extended = <&irq 3 0>;
 	};
 
diff --git a/include/test/ut.h b/include/test/ut.h
index 04df8ba3af..ab861588a8 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -104,6 +104,22 @@  int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 	}								\
 }
 
+/* Assert that two 64 int expressions are equal */
+#define ut_asserteq_64(expr1, expr2) {					\
+	u64 _val1 = (expr1), _val2 = (expr2);				\
+									\
+	if (_val1 != _val2) {						\
+		ut_failf(uts, __FILE__, __LINE__, __func__,		\
+			 #expr1 " == " #expr2,				\
+			 "Expected %#llx (%lld), got %#llx (%lld)",	\
+			 (unsigned long long)_val1,			\
+			 (unsigned long long)_val1,			\
+			 (unsigned long long)_val2,			\
+			 (unsigned long long)_val2);			\
+		return CMD_RET_FAILURE;					\
+	}								\
+}
+
 /* Assert that two string expressions are equal */
 #define ut_asserteq_str(expr1, expr2) {					\
 	const char *_val1 = (expr1), *_val2 = (expr2);			\
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index 75ae08081c..50bff4fdfb 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -867,6 +867,7 @@  static int dm_test_read_int(struct unit_test_state *uts)
 	u32 val32;
 	s32 sval;
 	uint val;
+	u64 val64;
 
 	ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
 	ut_asserteq_str("a-test", dev->name);
@@ -891,6 +892,15 @@  static int dm_test_read_int(struct unit_test_state *uts)
 	ut_assertok(dev_read_u32u(dev, "uint-value", &val));
 	ut_asserteq(-1234, val);
 
+	ut_assertok(dev_read_u64(dev, "int64-value", &val64));
+	ut_asserteq_64(0x1111222233334444, val64);
+
+	ut_asserteq_64(-EINVAL, dev_read_u64(dev, "missing", &val64));
+	ut_asserteq_64(6, dev_read_u64_default(dev, "missing", 6));
+
+	ut_asserteq_64(0x1111222233334444,
+		       dev_read_u64_default(dev, "int64-value", 6));
+
 	return 0;
 }
 DM_TEST(dm_test_read_int, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);