]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test: dm: add test for phandle access functions
authorPatrick Delaunay <patrick.delaunay@st.com>
Fri, 25 Sep 2020 07:41:16 +0000 (09:41 +0200)
committerSimon Glass <sjg@chromium.org>
Tue, 6 Oct 2020 15:07:54 +0000 (09:07 -0600)
Add unitary test for phandle access functions
- ofnode_count_phandle_with_args
- ofnode_parse_phandle_with_args
- dev_count_phandle_with_args
- dev_read_phandle_with_args

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
arch/sandbox/dts/test.dts
test/dm/ofnode.c
test/dm/test-fdt.c

index e6da47d5928c2d6d20cf2512d32fbdb232bf321f..cc372806a009980ba153996b3ae8c63e1957622c 100644 (file)
                str-value = "test string";
                interrupts-extended = <&irq 3 0>;
                acpi,name = "GHIJ";
+               phandle-value = <&gpio_c 10>, <0xFFFFFFFF 20>, <&gpio_a 30>;
        };
 
        junk {
index 4ae8d281a70fa90c4a8afc9d81d4904c6ff23169..01ac3c2094c8f31c151478caf89e6940518f090c 100644 (file)
@@ -103,6 +103,81 @@ static int dm_test_ofnode_read(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_ofnode_read, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
 
+static int dm_test_ofnode_phandle(struct unit_test_state *uts)
+{
+       struct ofnode_phandle_args args;
+       ofnode node;
+       int ret;
+       const char prop[] = "test-gpios";
+       const char cell[] = "#gpio-cells";
+       const char prop2[] = "phandle-value";
+
+       node = ofnode_path("/a-test");
+       ut_assert(ofnode_valid(node));
+
+       /* Test ofnode_count_phandle_with_args with cell name */
+       ret = ofnode_count_phandle_with_args(node, "missing", cell, 0);
+       ut_asserteq(-ENOENT, ret);
+       ret = ofnode_count_phandle_with_args(node, prop, "#invalid", 0);
+       ut_asserteq(-EINVAL, ret);
+       ret = ofnode_count_phandle_with_args(node, prop, cell, 0);
+       ut_asserteq(5, ret);
+
+       /* Test ofnode_parse_phandle_with_args with cell name */
+       ret = ofnode_parse_phandle_with_args(node, "missing", cell, 0, 0,
+                                            &args);
+       ut_asserteq(-ENOENT, ret);
+       ret = ofnode_parse_phandle_with_args(node, prop, "#invalid", 0, 0,
+                                            &args);
+       ut_asserteq(-EINVAL, ret);
+       ret = ofnode_parse_phandle_with_args(node, prop, cell, 0, 0, &args);
+       ut_assertok(ret);
+       ut_asserteq(1, args.args_count);
+       ut_asserteq(1, args.args[0]);
+       ret = ofnode_parse_phandle_with_args(node, prop, cell, 0, 1, &args);
+       ut_assertok(ret);
+       ut_asserteq(1, args.args_count);
+       ut_asserteq(4, args.args[0]);
+       ret = ofnode_parse_phandle_with_args(node, prop, cell, 0, 2, &args);
+       ut_assertok(ret);
+       ut_asserteq(5, args.args_count);
+       ut_asserteq(5, args.args[0]);
+       ut_asserteq(1, args.args[4]);
+       ret = ofnode_parse_phandle_with_args(node, prop, cell, 0, 3, &args);
+       ut_asserteq(-ENOENT, ret);
+       ret = ofnode_parse_phandle_with_args(node, prop, cell, 0, 4, &args);
+       ut_assertok(ret);
+       ut_asserteq(1, args.args_count);
+       ut_asserteq(12, args.args[0]);
+       ret = ofnode_parse_phandle_with_args(node, prop, cell, 0, 5, &args);
+       ut_asserteq(-ENOENT, ret);
+
+       /* Test ofnode_count_phandle_with_args with cell count */
+       ret = ofnode_count_phandle_with_args(node, "missing", NULL, 2);
+       ut_asserteq(-ENOENT, ret);
+       ret = ofnode_count_phandle_with_args(node, prop2, NULL, 1);
+       ut_asserteq(3, ret);
+
+       /* Test ofnode_parse_phandle_with_args with cell count */
+       ret = ofnode_parse_phandle_with_args(node, prop2, NULL, 1, 0, &args);
+       ut_assertok(ret);
+       ut_asserteq(1, ofnode_valid(args.node));
+       ut_asserteq(1, args.args_count);
+       ut_asserteq(10, args.args[0]);
+       ret = ofnode_parse_phandle_with_args(node, prop2, NULL, 1, 1, &args);
+       ut_asserteq(-EINVAL, ret);
+       ret = ofnode_parse_phandle_with_args(node, prop2, NULL, 1, 2, &args);
+       ut_assertok(ret);
+       ut_asserteq(1, ofnode_valid(args.node));
+       ut_asserteq(1, args.args_count);
+       ut_asserteq(30, args.args[0]);
+       ret = ofnode_parse_phandle_with_args(node, prop2, NULL, 1, 3, &args);
+       ut_asserteq(-ENOENT, ret);
+
+       return 0;
+}
+DM_TEST(dm_test_ofnode_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
 static int dm_test_ofnode_read_chosen(struct unit_test_state *uts)
 {
        const char *str;
index 26d57f40d14f6aad9a1b197651feb00bd25a3d08..cc12419ea0f39f396d944109ed66dcdb5de1f0d8 100644 (file)
@@ -968,6 +968,71 @@ static int dm_test_read_int_index(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_read_int_index, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
 
+static int dm_test_read_phandle(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+       struct ofnode_phandle_args args;
+       int ret;
+       const char prop[] = "test-gpios";
+       const char cell[] = "#gpio-cells";
+       const char prop2[] = "phandle-value";
+
+       ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
+       ut_asserteq_str("a-test", dev->name);
+
+       /* Test dev_count_phandle_with_args with cell name */
+       ret = dev_count_phandle_with_args(dev, "missing", cell, 0);
+       ut_asserteq(-ENOENT, ret);
+       ret = dev_count_phandle_with_args(dev, prop, "#invalid", 0);
+       ut_asserteq(-EINVAL, ret);
+       ut_asserteq(5, dev_count_phandle_with_args(dev, prop, cell, 0));
+
+       /* Test dev_read_phandle_with_args with cell name */
+       ret = dev_read_phandle_with_args(dev, "missing", cell, 0, 0, &args);
+       ut_asserteq(-ENOENT, ret);
+       ret = dev_read_phandle_with_args(dev, prop, "#invalid", 0, 0, &args);
+       ut_asserteq(-EINVAL, ret);
+       ut_assertok(dev_read_phandle_with_args(dev, prop, cell, 0, 0, &args));
+       ut_asserteq(1, args.args_count);
+       ut_asserteq(1, args.args[0]);
+       ut_assertok(dev_read_phandle_with_args(dev, prop, cell, 0, 1, &args));
+       ut_asserteq(1, args.args_count);
+       ut_asserteq(4, args.args[0]);
+       ut_assertok(dev_read_phandle_with_args(dev, prop, cell, 0, 2, &args));
+       ut_asserteq(5, args.args_count);
+       ut_asserteq(5, args.args[0]);
+       ut_asserteq(1, args.args[4]);
+       ret = dev_read_phandle_with_args(dev, prop, cell, 0, 3, &args);
+       ut_asserteq(-ENOENT, ret);
+       ut_assertok(dev_read_phandle_with_args(dev, prop, cell, 0, 4, &args));
+       ut_asserteq(1, args.args_count);
+       ut_asserteq(12, args.args[0]);
+       ret = dev_read_phandle_with_args(dev, prop, cell, 0, 5, &args);
+       ut_asserteq(-ENOENT, ret);
+
+       /* Test dev_count_phandle_with_args with cell count */
+       ret = dev_count_phandle_with_args(dev, "missing", NULL, 2);
+       ut_asserteq(-ENOENT, ret);
+       ut_asserteq(3, dev_count_phandle_with_args(dev, prop2, NULL, 1));
+
+       /* Test dev_read_phandle_with_args with cell count */
+       ut_assertok(dev_read_phandle_with_args(dev, prop2, NULL, 1, 0, &args));
+       ut_asserteq(1, ofnode_valid(args.node));
+       ut_asserteq(1, args.args_count);
+       ut_asserteq(10, args.args[0]);
+       ret = dev_read_phandle_with_args(dev, prop2, NULL, 1, 1, &args);
+       ut_asserteq(-EINVAL, ret);
+       ut_assertok(dev_read_phandle_with_args(dev, prop2, NULL, 1, 2, &args));
+       ut_asserteq(1, ofnode_valid(args.node));
+       ut_asserteq(1, args.args_count);
+       ut_asserteq(30, args.args[0]);
+       ret = dev_read_phandle_with_args(dev, prop2, NULL, 1, 3, &args);
+       ut_asserteq(-ENOENT, ret);
+
+       return 0;
+}
+DM_TEST(dm_test_read_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
 /* Test iteration through devices by drvdata */
 static int dm_test_uclass_drvdata(struct unit_test_state *uts)
 {