]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: test: add test case for dev_read_u64 function
authorDario Binacchi <dariobin@libero.it>
Sun, 29 Mar 2020 16:04:40 +0000 (18:04 +0200)
committerSimon Glass <sjg@chromium.org>
Thu, 16 Apr 2020 14:07:58 +0000 (08:07 -0600)
Add test case to cover dev_read_u64 and dev_read_u64_default functions.

Signed-off-by: Dario Binacchi <dariobin@libero.it>
Reviewed-by: Simon Glass <sjg@chromium.org>
arch/sandbox/dts/test.dts
include/test/ut.h
test/dm/test-fdt.c

index 2338064df7745b07e3febdccd96f7c8a64baf263..8c6a48d195ed00ae7e5e2d1af866547f91928913 100644 (file)
@@ -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>;
        };
 
index 04df8ba3af319d5c2dde28e1dd979825b7ecd7a3..ab861588a84a097b4b00b395beb6da09620763e3 100644 (file)
@@ -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);                  \
index 3500ab1b46c0d57aa51d15077a8002c19896e313..b39777f082c224bfb8a30b0aabc8057f066c030c 100644 (file)
@@ -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);