diff options
author | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2021-02-12 18:25:39 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2021-03-23 15:04:06 +0100 |
commit | 7f2fac70b729d68a34e5eba8d1fb68eb69b05169 (patch) | |
tree | 00db74472b2548a4c08d22a61e8a10c34859eb17 /drivers/base/test | |
parent | 0b8bf06f67191e6a3184802a690d3f521c6d7e78 (diff) |
device property: Add test cases for fwnode_property_count_*() APIs
Add test cases for fwnode_property_count_*() APIs.
While at it, modify the arrays of integers to be size of non-power-of-2
for better test coverage and decreasing stack usage.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20210212162539.86850-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base/test')
-rw-r--r-- | drivers/base/test/property-entry-test.c | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/drivers/base/test/property-entry-test.c b/drivers/base/test/property-entry-test.c index abe03315180f..3a4f755c483c 100644 --- a/drivers/base/test/property-entry-test.c +++ b/drivers/base/test/property-entry-test.c @@ -27,6 +27,9 @@ static void pe_test_uints(struct kunit *test) node = fwnode_create_software_node(entries, NULL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node); + error = fwnode_property_count_u8(node, "prop-u8"); + KUNIT_EXPECT_EQ(test, error, 1); + error = fwnode_property_read_u8(node, "prop-u8", &val_u8); KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_EQ(test, (int)val_u8, 8); @@ -48,6 +51,9 @@ static void pe_test_uints(struct kunit *test) KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_EQ(test, (int)val_u16, 16); + error = fwnode_property_count_u16(node, "prop-u16"); + KUNIT_EXPECT_EQ(test, error, 1); + error = fwnode_property_read_u16_array(node, "prop-u16", array_u16, 1); KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_EQ(test, (int)array_u16[0], 16); @@ -65,6 +71,9 @@ static void pe_test_uints(struct kunit *test) KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_EQ(test, (int)val_u32, 32); + error = fwnode_property_count_u32(node, "prop-u32"); + KUNIT_EXPECT_EQ(test, error, 1); + error = fwnode_property_read_u32_array(node, "prop-u32", array_u32, 1); KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_EQ(test, (int)array_u32[0], 32); @@ -82,6 +91,9 @@ static void pe_test_uints(struct kunit *test) KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_EQ(test, (int)val_u64, 64); + error = fwnode_property_count_u64(node, "prop-u64"); + KUNIT_EXPECT_EQ(test, error, 1); + error = fwnode_property_read_u64_array(node, "prop-u64", array_u64, 1); KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_EQ(test, (int)array_u64[0], 64); @@ -95,15 +107,19 @@ static void pe_test_uints(struct kunit *test) error = fwnode_property_read_u64_array(node, "no-prop-u64", array_u64, 1); KUNIT_EXPECT_NE(test, error, 0); + /* Count 64-bit values as 16-bit */ + error = fwnode_property_count_u16(node, "prop-u64"); + KUNIT_EXPECT_EQ(test, error, 4); + fwnode_remove_software_node(node); } static void pe_test_uint_arrays(struct kunit *test) { - static const u8 a_u8[16] = { 8, 9 }; - static const u16 a_u16[16] = { 16, 17 }; - static const u32 a_u32[16] = { 32, 33 }; - static const u64 a_u64[16] = { 64, 65 }; + static const u8 a_u8[10] = { 8, 9 }; + static const u16 a_u16[10] = { 16, 17 }; + static const u32 a_u32[10] = { 32, 33 }; + static const u64 a_u64[10] = { 64, 65 }; static const struct property_entry entries[] = { PROPERTY_ENTRY_U8_ARRAY("prop-u8", a_u8), PROPERTY_ENTRY_U16_ARRAY("prop-u16", a_u16), @@ -126,6 +142,9 @@ static void pe_test_uint_arrays(struct kunit *test) KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_EQ(test, (int)val_u8, 8); + error = fwnode_property_count_u8(node, "prop-u8"); + KUNIT_EXPECT_EQ(test, error, 10); + error = fwnode_property_read_u8_array(node, "prop-u8", array_u8, 1); KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_EQ(test, (int)array_u8[0], 8); @@ -148,6 +167,9 @@ static void pe_test_uint_arrays(struct kunit *test) KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_EQ(test, (int)val_u16, 16); + error = fwnode_property_count_u16(node, "prop-u16"); + KUNIT_EXPECT_EQ(test, error, 10); + error = fwnode_property_read_u16_array(node, "prop-u16", array_u16, 1); KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_EQ(test, (int)array_u16[0], 16); @@ -170,6 +192,9 @@ static void pe_test_uint_arrays(struct kunit *test) KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_EQ(test, (int)val_u32, 32); + error = fwnode_property_count_u32(node, "prop-u32"); + KUNIT_EXPECT_EQ(test, error, 10); + error = fwnode_property_read_u32_array(node, "prop-u32", array_u32, 1); KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_EQ(test, (int)array_u32[0], 32); @@ -192,6 +217,9 @@ static void pe_test_uint_arrays(struct kunit *test) KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_EQ(test, (int)val_u64, 64); + error = fwnode_property_count_u64(node, "prop-u64"); + KUNIT_EXPECT_EQ(test, error, 10); + error = fwnode_property_read_u64_array(node, "prop-u64", array_u64, 1); KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_EQ(test, (int)array_u64[0], 64); @@ -210,6 +238,14 @@ static void pe_test_uint_arrays(struct kunit *test) error = fwnode_property_read_u64_array(node, "no-prop-u64", array_u64, 1); KUNIT_EXPECT_NE(test, error, 0); + /* Count 64-bit values as 16-bit */ + error = fwnode_property_count_u16(node, "prop-u64"); + KUNIT_EXPECT_EQ(test, error, 40); + + /* Other way around */ + error = fwnode_property_count_u64(node, "prop-u16"); + KUNIT_EXPECT_EQ(test, error, 2); + fwnode_remove_software_node(node); } @@ -239,6 +275,9 @@ static void pe_test_strings(struct kunit *test) KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_STREQ(test, str, "single"); + error = fwnode_property_string_array_count(node, "str"); + KUNIT_EXPECT_EQ(test, error, 1); + error = fwnode_property_read_string_array(node, "str", strs, 1); KUNIT_EXPECT_EQ(test, error, 1); KUNIT_EXPECT_STREQ(test, strs[0], "single"); @@ -258,6 +297,9 @@ static void pe_test_strings(struct kunit *test) KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_STREQ(test, str, ""); + error = fwnode_property_string_array_count(node, "strs"); + KUNIT_EXPECT_EQ(test, error, 2); + error = fwnode_property_read_string_array(node, "strs", strs, 3); KUNIT_EXPECT_EQ(test, error, 2); KUNIT_EXPECT_STREQ(test, strs[0], "string-a"); |