* [pm:bleeding-edge 6/7] drivers/base/test/property-entry-test.c:454:1: warning: the frame size of 2960 bytes is larger than 2048 bytes
@ 2019-12-04 1:07 kbuild test robot
2019-12-04 9:30 ` Rafael J. Wysocki
0 siblings, 1 reply; 7+ messages in thread
From: kbuild test robot @ 2019-12-04 1:07 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: kbuild-all, linux-acpi, devel, linux-pm, Rafael J. Wysocki
[-- Attachment #1: Type: text/plain, Size: 5172 bytes --]
tree: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git bleeding-edge
head: 88a29de6adffb9d4d1ac7f1b1d996c616ebda145
commit: 80e0582b1ab83ed08dedaad5a0cdb28457ccba4f [6/7] software node: add basic tests for property entries
config: arm64-randconfig-a001-20191203 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 7.5.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
git checkout 80e0582b1ab83ed08dedaad5a0cdb28457ccba4f
# save the attached .config to linux build tree
GCC_VERSION=7.5.0 make.cross ARCH=arm64
If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
drivers/base/test/property-entry-test.c: In function 'pe_test_reference':
>> drivers/base/test/property-entry-test.c:454:1: warning: the frame size of 2960 bytes is larger than 2048 bytes [-Wframe-larger-than=]
}
^
drivers/base/test/property-entry-test.c: In function 'pe_test_uint_arrays':
drivers/base/test/property-entry-test.c:214:1: warning: the frame size of 4288 bytes is larger than 2048 bytes [-Wframe-larger-than=]
}
^
drivers/base/test/property-entry-test.c: In function 'pe_test_uints':
drivers/base/test/property-entry-test.c:99:1: warning: the frame size of 2736 bytes is larger than 2048 bytes [-Wframe-larger-than=]
}
^
vim +454 drivers/base/test/property-entry-test.c
360
361 /* Handling of reference properties */
362 static void pe_test_reference(struct kunit *test)
363 {
364 const struct software_node nodes[] = {
365 { .name = "1", },
366 { .name = "2", },
367 };
368
369 const struct software_node_ref_args refs[] = {
370 {
371 .node = &nodes[0],
372 .nargs = 0,
373 },
374 {
375 .node = &nodes[1],
376 .nargs = 2,
377 .args = { 3, 4 },
378 },
379 };
380
381 const struct property_entry entries[] = {
382 PROPERTY_ENTRY_REF("ref-1", &nodes[0]),
383 PROPERTY_ENTRY_REF("ref-2", &nodes[1], 1, 2),
384 PROPERTY_ENTRY_REF_ARRAY("ref-3", refs),
385 { }
386 };
387
388 struct fwnode_handle *node;
389 struct fwnode_reference_args ref;
390 int error;
391
392 error = software_node_register_nodes(nodes);
393 KUNIT_ASSERT_EQ(test, error, 0);
394
395 node = fwnode_create_software_node(entries, NULL);
396 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
397
398 error = fwnode_property_get_reference_args(node, "ref-1", NULL,
399 0, 0, &ref);
400 KUNIT_ASSERT_EQ(test, error, 0);
401 KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[0]);
402 KUNIT_EXPECT_EQ(test, ref.nargs, 0U);
403
404 /* wrong index */
405 error = fwnode_property_get_reference_args(node, "ref-1", NULL,
406 0, 1, &ref);
407 KUNIT_EXPECT_NE(test, error, 0);
408
409 error = fwnode_property_get_reference_args(node, "ref-2", NULL,
410 1, 0, &ref);
411 KUNIT_ASSERT_EQ(test, error, 0);
412 KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[1]);
413 KUNIT_EXPECT_EQ(test, ref.nargs, 1U);
414 KUNIT_EXPECT_EQ(test, ref.args[0], 1LLU);
415
416 /* asking for more args, padded with zero data */
417 error = fwnode_property_get_reference_args(node, "ref-2", NULL,
418 3, 0, &ref);
419 KUNIT_ASSERT_EQ(test, error, 0);
420 KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[1]);
421 KUNIT_EXPECT_EQ(test, ref.nargs, 3U);
422 KUNIT_EXPECT_EQ(test, ref.args[0], 1LLU);
423 KUNIT_EXPECT_EQ(test, ref.args[1], 2LLU);
424 KUNIT_EXPECT_EQ(test, ref.args[2], 0LLU);
425
426 /* wrong index */
427 error = fwnode_property_get_reference_args(node, "ref-2", NULL,
428 2, 1, &ref);
429 KUNIT_EXPECT_NE(test, error, 0);
430
431 /* array of references */
432 error = fwnode_property_get_reference_args(node, "ref-3", NULL,
433 0, 0, &ref);
434 KUNIT_ASSERT_EQ(test, error, 0);
435 KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[0]);
436 KUNIT_EXPECT_EQ(test, ref.nargs, 0U);
437
438 /* second reference in the array */
439 error = fwnode_property_get_reference_args(node, "ref-3", NULL,
440 2, 1, &ref);
441 KUNIT_ASSERT_EQ(test, error, 0);
442 KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[1]);
443 KUNIT_EXPECT_EQ(test, ref.nargs, 2U);
444 KUNIT_EXPECT_EQ(test, ref.args[0], 3LLU);
445 KUNIT_EXPECT_EQ(test, ref.args[1], 4LLU);
446
447 /* wrong index */
448 error = fwnode_property_get_reference_args(node, "ref-1", NULL,
449 0, 2, &ref);
450 KUNIT_EXPECT_NE(test, error, 0);
451
452 fwnode_remove_software_node(node);
453 software_node_unregister_nodes(nodes);
> 454 }
455
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 38250 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [pm:bleeding-edge 6/7] drivers/base/test/property-entry-test.c:454:1: warning: the frame size of 2960 bytes is larger than 2048 bytes
2019-12-04 1:07 [pm:bleeding-edge 6/7] drivers/base/test/property-entry-test.c:454:1: warning: the frame size of 2960 bytes is larger than 2048 bytes kbuild test robot
@ 2019-12-04 9:30 ` Rafael J. Wysocki
2019-12-04 18:53 ` [PATCH v9] software node: add basic tests for property entries Dmitry Torokhov
0 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki @ 2019-12-04 9:30 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: kbuild-all, ACPI Devel Maling List, Linux PM, Rafael J. Wysocki,
kbuild test robot
On Wed, Dec 4, 2019 at 2:07 AM kbuild test robot <lkp@intel.com> wrote:
>
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git bleeding-edge
> head: 88a29de6adffb9d4d1ac7f1b1d996c616ebda145
> commit: 80e0582b1ab83ed08dedaad5a0cdb28457ccba4f [6/7] software node: add basic tests for property entries
> config: arm64-randconfig-a001-20191203 (attached as .config)
> compiler: aarch64-linux-gcc (GCC) 7.5.0
> reproduce:
> wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> git checkout 80e0582b1ab83ed08dedaad5a0cdb28457ccba4f
> # save the attached .config to linux build tree
> GCC_VERSION=7.5.0 make.cross ARCH=arm64
>
> If you fix the issue, kindly add following tag
> Reported-by: kbuild test robot <lkp@intel.com>
>
> All warnings (new ones prefixed by >>):
>
> drivers/base/test/property-entry-test.c: In function 'pe_test_reference':
> >> drivers/base/test/property-entry-test.c:454:1: warning: the frame size of 2960 bytes is larger than 2048 bytes [-Wframe-larger-than=]
> }
> ^
> drivers/base/test/property-entry-test.c: In function 'pe_test_uint_arrays':
> drivers/base/test/property-entry-test.c:214:1: warning: the frame size of 4288 bytes is larger than 2048 bytes [-Wframe-larger-than=]
> }
> ^
> drivers/base/test/property-entry-test.c: In function 'pe_test_uints':
> drivers/base/test/property-entry-test.c:99:1: warning: the frame size of 2736 bytes is larger than 2048 bytes [-Wframe-larger-than=]
> }
> ^
Dmitry, any comments on this?
Perhaps I should drop the tests patch until this is resolved or clarified?
> vim +454 drivers/base/test/property-entry-test.c
>
> 360
> 361 /* Handling of reference properties */
> 362 static void pe_test_reference(struct kunit *test)
> 363 {
> 364 const struct software_node nodes[] = {
> 365 { .name = "1", },
> 366 { .name = "2", },
> 367 };
> 368
> 369 const struct software_node_ref_args refs[] = {
> 370 {
> 371 .node = &nodes[0],
> 372 .nargs = 0,
> 373 },
> 374 {
> 375 .node = &nodes[1],
> 376 .nargs = 2,
> 377 .args = { 3, 4 },
> 378 },
> 379 };
> 380
> 381 const struct property_entry entries[] = {
> 382 PROPERTY_ENTRY_REF("ref-1", &nodes[0]),
> 383 PROPERTY_ENTRY_REF("ref-2", &nodes[1], 1, 2),
> 384 PROPERTY_ENTRY_REF_ARRAY("ref-3", refs),
> 385 { }
> 386 };
> 387
> 388 struct fwnode_handle *node;
> 389 struct fwnode_reference_args ref;
> 390 int error;
> 391
> 392 error = software_node_register_nodes(nodes);
> 393 KUNIT_ASSERT_EQ(test, error, 0);
> 394
> 395 node = fwnode_create_software_node(entries, NULL);
> 396 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
> 397
> 398 error = fwnode_property_get_reference_args(node, "ref-1", NULL,
> 399 0, 0, &ref);
> 400 KUNIT_ASSERT_EQ(test, error, 0);
> 401 KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[0]);
> 402 KUNIT_EXPECT_EQ(test, ref.nargs, 0U);
> 403
> 404 /* wrong index */
> 405 error = fwnode_property_get_reference_args(node, "ref-1", NULL,
> 406 0, 1, &ref);
> 407 KUNIT_EXPECT_NE(test, error, 0);
> 408
> 409 error = fwnode_property_get_reference_args(node, "ref-2", NULL,
> 410 1, 0, &ref);
> 411 KUNIT_ASSERT_EQ(test, error, 0);
> 412 KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[1]);
> 413 KUNIT_EXPECT_EQ(test, ref.nargs, 1U);
> 414 KUNIT_EXPECT_EQ(test, ref.args[0], 1LLU);
> 415
> 416 /* asking for more args, padded with zero data */
> 417 error = fwnode_property_get_reference_args(node, "ref-2", NULL,
> 418 3, 0, &ref);
> 419 KUNIT_ASSERT_EQ(test, error, 0);
> 420 KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[1]);
> 421 KUNIT_EXPECT_EQ(test, ref.nargs, 3U);
> 422 KUNIT_EXPECT_EQ(test, ref.args[0], 1LLU);
> 423 KUNIT_EXPECT_EQ(test, ref.args[1], 2LLU);
> 424 KUNIT_EXPECT_EQ(test, ref.args[2], 0LLU);
> 425
> 426 /* wrong index */
> 427 error = fwnode_property_get_reference_args(node, "ref-2", NULL,
> 428 2, 1, &ref);
> 429 KUNIT_EXPECT_NE(test, error, 0);
> 430
> 431 /* array of references */
> 432 error = fwnode_property_get_reference_args(node, "ref-3", NULL,
> 433 0, 0, &ref);
> 434 KUNIT_ASSERT_EQ(test, error, 0);
> 435 KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[0]);
> 436 KUNIT_EXPECT_EQ(test, ref.nargs, 0U);
> 437
> 438 /* second reference in the array */
> 439 error = fwnode_property_get_reference_args(node, "ref-3", NULL,
> 440 2, 1, &ref);
> 441 KUNIT_ASSERT_EQ(test, error, 0);
> 442 KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[1]);
> 443 KUNIT_EXPECT_EQ(test, ref.nargs, 2U);
> 444 KUNIT_EXPECT_EQ(test, ref.args[0], 3LLU);
> 445 KUNIT_EXPECT_EQ(test, ref.args[1], 4LLU);
> 446
> 447 /* wrong index */
> 448 error = fwnode_property_get_reference_args(node, "ref-1", NULL,
> 449 0, 2, &ref);
> 450 KUNIT_EXPECT_NE(test, error, 0);
> 451
> 452 fwnode_remove_software_node(node);
> 453 software_node_unregister_nodes(nodes);
> > 454 }
> 455
>
> ---
> 0-DAY kernel test infrastructure Open Source Technology Center
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org Intel Corporation
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v9] software node: add basic tests for property entries
2019-12-04 9:30 ` Rafael J. Wysocki
@ 2019-12-04 18:53 ` Dmitry Torokhov
2019-12-09 8:44 ` Rafael J. Wysocki
0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Torokhov @ 2019-12-04 18:53 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: kbuild-all, ACPI Devel Maling List, Linux PM, Rafael J. Wysocki,
kbuild test robot
This adds tests for creating software nodes with properties supplied by
PROPERTY_ENTRY_XXX() macros and fetching and validating data from said
nodes/properties.
We are using KUnit framework for the tests.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
- updated to reduce stack size below 2048 by declaring properties as
static const.
drivers/base/test/Makefile | 2 +
drivers/base/test/property-entry-test.c | 474 ++++++++++++++++++++++++
2 files changed, 476 insertions(+)
create mode 100644 drivers/base/test/property-entry-test.c
diff --git a/drivers/base/test/Makefile b/drivers/base/test/Makefile
index 0f1f7277a0139..22143102e5d21 100644
--- a/drivers/base/test/Makefile
+++ b/drivers/base/test/Makefile
@@ -1,2 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_TEST_ASYNC_DRIVER_PROBE) += test_async_driver_probe.o
+
+obj-$(CONFIG_KUNIT) += property-entry-test.o
diff --git a/drivers/base/test/property-entry-test.c b/drivers/base/test/property-entry-test.c
new file mode 100644
index 0000000000000..da812834b6316
--- /dev/null
+++ b/drivers/base/test/property-entry-test.c
@@ -0,0 +1,474 @@
+// SPDX-License-Identifier: GPL-2.0
+// Unit tests for property entries API
+//
+// Copyright 2019 Google LLC.
+
+#include <kunit/test.h>
+#include <linux/property.h>
+#include <linux/types.h>
+
+static void pe_test_uints(struct kunit *test)
+{
+ static const struct property_entry entries[] = {
+ PROPERTY_ENTRY_U8("prop-u8", 8),
+ PROPERTY_ENTRY_U16("prop-u16", 16),
+ PROPERTY_ENTRY_U32("prop-u32", 32),
+ PROPERTY_ENTRY_U64("prop-u64", 64),
+ { }
+ };
+
+ struct fwnode_handle *node;
+ u8 val_u8, array_u8[2];
+ u16 val_u16, array_u16[2];
+ u32 val_u32, array_u32[2];
+ u64 val_u64, array_u64[2];
+ int error;
+
+ node = fwnode_create_software_node(entries, NULL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+ error = fwnode_property_read_u8(node, "prop-u8", &val_u8);
+ KUNIT_EXPECT_EQ(test, error, 0);
+ KUNIT_EXPECT_EQ(test, (int)val_u8, 8);
+
+ 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);
+
+ error = fwnode_property_read_u8_array(node, "prop-u8", array_u8, 2);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u8(node, "no-prop-u8", &val_u8);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u8_array(node, "no-prop-u8", array_u8, 1);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u16(node, "prop-u16", &val_u16);
+ KUNIT_EXPECT_EQ(test, error, 0);
+ KUNIT_EXPECT_EQ(test, (int)val_u16, 16);
+
+ 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);
+
+ error = fwnode_property_read_u16_array(node, "prop-u16", array_u16, 2);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u16(node, "no-prop-u16", &val_u16);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u16_array(node, "no-prop-u16", array_u16, 1);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u32(node, "prop-u32", &val_u32);
+ KUNIT_EXPECT_EQ(test, error, 0);
+ KUNIT_EXPECT_EQ(test, (int)val_u32, 32);
+
+ 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);
+
+ error = fwnode_property_read_u32_array(node, "prop-u32", array_u32, 2);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u32(node, "no-prop-u32", &val_u32);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u32_array(node, "no-prop-u32", array_u32, 1);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u64(node, "prop-u64", &val_u64);
+ KUNIT_EXPECT_EQ(test, error, 0);
+ KUNIT_EXPECT_EQ(test, (int)val_u64, 64);
+
+ 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);
+
+ error = fwnode_property_read_u64_array(node, "prop-u64", array_u64, 2);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u64(node, "no-prop-u64", &val_u64);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u64_array(node, "no-prop-u64", array_u64, 1);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ 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 struct property_entry entries[] = {
+ PROPERTY_ENTRY_U8_ARRAY("prop-u8", a_u8),
+ PROPERTY_ENTRY_U16_ARRAY("prop-u16", a_u16),
+ PROPERTY_ENTRY_U32_ARRAY("prop-u32", a_u32),
+ PROPERTY_ENTRY_U64_ARRAY("prop-u64", a_u64),
+ { }
+ };
+
+ struct fwnode_handle *node;
+ u8 val_u8, array_u8[32];
+ u16 val_u16, array_u16[32];
+ u32 val_u32, array_u32[32];
+ u64 val_u64, array_u64[32];
+ int error;
+
+ node = fwnode_create_software_node(entries, NULL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+ error = fwnode_property_read_u8(node, "prop-u8", &val_u8);
+ KUNIT_EXPECT_EQ(test, error, 0);
+ KUNIT_EXPECT_EQ(test, (int)val_u8, 8);
+
+ 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);
+
+ error = fwnode_property_read_u8_array(node, "prop-u8", array_u8, 2);
+ KUNIT_EXPECT_EQ(test, error, 0);
+ KUNIT_EXPECT_EQ(test, (int)array_u8[0], 8);
+ KUNIT_EXPECT_EQ(test, (int)array_u8[1], 9);
+
+ error = fwnode_property_read_u8_array(node, "prop-u8", array_u8, 17);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u8(node, "no-prop-u8", &val_u8);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u8_array(node, "no-prop-u8", array_u8, 1);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u16(node, "prop-u16", &val_u16);
+ KUNIT_EXPECT_EQ(test, error, 0);
+ KUNIT_EXPECT_EQ(test, (int)val_u16, 16);
+
+ 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);
+
+ error = fwnode_property_read_u16_array(node, "prop-u16", array_u16, 2);
+ KUNIT_EXPECT_EQ(test, error, 0);
+ KUNIT_EXPECT_EQ(test, (int)array_u16[0], 16);
+ KUNIT_EXPECT_EQ(test, (int)array_u16[1], 17);
+
+ error = fwnode_property_read_u16_array(node, "prop-u16", array_u16, 17);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u16(node, "no-prop-u16", &val_u16);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u16_array(node, "no-prop-u16", array_u16, 1);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u32(node, "prop-u32", &val_u32);
+ KUNIT_EXPECT_EQ(test, error, 0);
+ KUNIT_EXPECT_EQ(test, (int)val_u32, 32);
+
+ 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);
+
+ error = fwnode_property_read_u32_array(node, "prop-u32", array_u32, 2);
+ KUNIT_EXPECT_EQ(test, error, 0);
+ KUNIT_EXPECT_EQ(test, (int)array_u32[0], 32);
+ KUNIT_EXPECT_EQ(test, (int)array_u32[1], 33);
+
+ error = fwnode_property_read_u32_array(node, "prop-u32", array_u32, 17);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u32(node, "no-prop-u32", &val_u32);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u32_array(node, "no-prop-u32", array_u32, 1);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u64(node, "prop-u64", &val_u64);
+ KUNIT_EXPECT_EQ(test, error, 0);
+ KUNIT_EXPECT_EQ(test, (int)val_u64, 64);
+
+ 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);
+
+ error = fwnode_property_read_u64_array(node, "prop-u64", array_u64, 2);
+ KUNIT_EXPECT_EQ(test, error, 0);
+ KUNIT_EXPECT_EQ(test, (int)array_u64[0], 64);
+ KUNIT_EXPECT_EQ(test, (int)array_u64[1], 65);
+
+ error = fwnode_property_read_u64_array(node, "prop-u64", array_u64, 17);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u64(node, "no-prop-u64", &val_u64);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_u64_array(node, "no-prop-u64", array_u64, 1);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ fwnode_remove_software_node(node);
+}
+
+static void pe_test_strings(struct kunit *test)
+{
+ static const char *strings[] = {
+ "string-a",
+ "string-b",
+ };
+
+ static const struct property_entry entries[] = {
+ PROPERTY_ENTRY_STRING("str", "single"),
+ PROPERTY_ENTRY_STRING("empty", ""),
+ PROPERTY_ENTRY_STRING_ARRAY("strs", strings),
+ { }
+ };
+
+ struct fwnode_handle *node;
+ const char *str;
+ const char *strs[10];
+ int error;
+
+ node = fwnode_create_software_node(entries, NULL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+ error = fwnode_property_read_string(node, "str", &str);
+ KUNIT_EXPECT_EQ(test, error, 0);
+ KUNIT_EXPECT_STREQ(test, str, "single");
+
+ error = fwnode_property_read_string_array(node, "str", strs, 1);
+ KUNIT_EXPECT_EQ(test, error, 1);
+ KUNIT_EXPECT_STREQ(test, strs[0], "single");
+
+ /* asking for more data returns what we have */
+ error = fwnode_property_read_string_array(node, "str", strs, 2);
+ KUNIT_EXPECT_EQ(test, error, 1);
+ KUNIT_EXPECT_STREQ(test, strs[0], "single");
+
+ error = fwnode_property_read_string(node, "no-str", &str);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_read_string_array(node, "no-str", strs, 1);
+ KUNIT_EXPECT_LT(test, error, 0);
+
+ error = fwnode_property_read_string(node, "empty", &str);
+ KUNIT_EXPECT_EQ(test, error, 0);
+ KUNIT_EXPECT_STREQ(test, str, "");
+
+ error = fwnode_property_read_string_array(node, "strs", strs, 3);
+ KUNIT_EXPECT_EQ(test, error, 2);
+ KUNIT_EXPECT_STREQ(test, strs[0], "string-a");
+ KUNIT_EXPECT_STREQ(test, strs[1], "string-b");
+
+ error = fwnode_property_read_string_array(node, "strs", strs, 1);
+ KUNIT_EXPECT_EQ(test, error, 1);
+ KUNIT_EXPECT_STREQ(test, strs[0], "string-a");
+
+ /* NULL argument -> returns size */
+ error = fwnode_property_read_string_array(node, "strs", NULL, 0);
+ KUNIT_EXPECT_EQ(test, error, 2);
+
+ /* accessing array as single value */
+ error = fwnode_property_read_string(node, "strs", &str);
+ KUNIT_EXPECT_EQ(test, error, 0);
+ KUNIT_EXPECT_STREQ(test, str, "string-a");
+
+ fwnode_remove_software_node(node);
+}
+
+static void pe_test_bool(struct kunit *test)
+{
+ static const struct property_entry entries[] = {
+ PROPERTY_ENTRY_BOOL("prop"),
+ { }
+ };
+
+ struct fwnode_handle *node;
+
+ node = fwnode_create_software_node(entries, NULL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+ KUNIT_EXPECT_TRUE(test, fwnode_property_read_bool(node, "prop"));
+ KUNIT_EXPECT_FALSE(test, fwnode_property_read_bool(node, "not-prop"));
+
+ fwnode_remove_software_node(node);
+}
+
+/* Verifies that small U8 array is stored inline when property is copied */
+static void pe_test_move_inline_u8(struct kunit *test)
+{
+ static const u8 u8_array_small[8] = { 1, 2, 3, 4 };
+ static const u8 u8_array_big[128] = { 5, 6, 7, 8 };
+ static const struct property_entry entries[] = {
+ PROPERTY_ENTRY_U8_ARRAY("small", u8_array_small),
+ PROPERTY_ENTRY_U8_ARRAY("big", u8_array_big),
+ { }
+ };
+
+ struct property_entry *copy;
+ const u8 *data_ptr;
+
+ copy = property_entries_dup(entries);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, copy);
+
+ KUNIT_EXPECT_TRUE(test, copy[0].is_inline);
+ data_ptr = (u8 *)©[0].value;
+ KUNIT_EXPECT_EQ(test, (int)data_ptr[0], 1);
+ KUNIT_EXPECT_EQ(test, (int)data_ptr[1], 2);
+
+ KUNIT_EXPECT_FALSE(test, copy[1].is_inline);
+ data_ptr = copy[1].pointer;
+ KUNIT_EXPECT_EQ(test, (int)data_ptr[0], 5);
+ KUNIT_EXPECT_EQ(test, (int)data_ptr[1], 6);
+
+ property_entries_free(copy);
+}
+
+/* Verifies that single string array is stored inline when property is copied */
+static void pe_test_move_inline_str(struct kunit *test)
+{
+ static char *str_array_small[] = { "a" };
+ static char *str_array_big[] = { "b", "c", "d", "e" };
+ static char *str_array_small_empty[] = { "" };
+ static struct property_entry entries[] = {
+ PROPERTY_ENTRY_STRING_ARRAY("small", str_array_small),
+ PROPERTY_ENTRY_STRING_ARRAY("big", str_array_big),
+ PROPERTY_ENTRY_STRING_ARRAY("small-empty", str_array_small_empty),
+ { }
+ };
+
+ struct property_entry *copy;
+ const char * const *data_ptr;
+
+ copy = property_entries_dup(entries);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, copy);
+
+ KUNIT_EXPECT_TRUE(test, copy[0].is_inline);
+ KUNIT_EXPECT_STREQ(test, copy[0].value.str[0], "a");
+
+ KUNIT_EXPECT_FALSE(test, copy[1].is_inline);
+ data_ptr = copy[1].pointer;
+ KUNIT_EXPECT_STREQ(test, data_ptr[0], "b");
+ KUNIT_EXPECT_STREQ(test, data_ptr[1], "c");
+
+ KUNIT_EXPECT_TRUE(test, copy[2].is_inline);
+ KUNIT_EXPECT_STREQ(test, copy[2].value.str[0], "");
+
+ property_entries_free(copy);
+}
+
+/* Handling of reference properties */
+static void pe_test_reference(struct kunit *test)
+{
+ static const struct software_node nodes[] = {
+ { .name = "1", },
+ { .name = "2", },
+ };
+
+ static const struct software_node_ref_args refs[] = {
+ {
+ .node = &nodes[0],
+ .nargs = 0,
+ },
+ {
+ .node = &nodes[1],
+ .nargs = 2,
+ .args = { 3, 4 },
+ },
+ };
+
+ const struct property_entry entries[] = {
+ PROPERTY_ENTRY_REF("ref-1", &nodes[0]),
+ PROPERTY_ENTRY_REF("ref-2", &nodes[1], 1, 2),
+ PROPERTY_ENTRY_REF_ARRAY("ref-3", refs),
+ { }
+ };
+
+ struct fwnode_handle *node;
+ struct fwnode_reference_args ref;
+ int error;
+
+ error = software_node_register_nodes(nodes);
+ KUNIT_ASSERT_EQ(test, error, 0);
+
+ node = fwnode_create_software_node(entries, NULL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+ error = fwnode_property_get_reference_args(node, "ref-1", NULL,
+ 0, 0, &ref);
+ KUNIT_ASSERT_EQ(test, error, 0);
+ KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[0]);
+ KUNIT_EXPECT_EQ(test, ref.nargs, 0U);
+
+ /* wrong index */
+ error = fwnode_property_get_reference_args(node, "ref-1", NULL,
+ 0, 1, &ref);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ error = fwnode_property_get_reference_args(node, "ref-2", NULL,
+ 1, 0, &ref);
+ KUNIT_ASSERT_EQ(test, error, 0);
+ KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[1]);
+ KUNIT_EXPECT_EQ(test, ref.nargs, 1U);
+ KUNIT_EXPECT_EQ(test, ref.args[0], 1LLU);
+
+ /* asking for more args, padded with zero data */
+ error = fwnode_property_get_reference_args(node, "ref-2", NULL,
+ 3, 0, &ref);
+ KUNIT_ASSERT_EQ(test, error, 0);
+ KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[1]);
+ KUNIT_EXPECT_EQ(test, ref.nargs, 3U);
+ KUNIT_EXPECT_EQ(test, ref.args[0], 1LLU);
+ KUNIT_EXPECT_EQ(test, ref.args[1], 2LLU);
+ KUNIT_EXPECT_EQ(test, ref.args[2], 0LLU);
+
+ /* wrong index */
+ error = fwnode_property_get_reference_args(node, "ref-2", NULL,
+ 2, 1, &ref);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ /* array of references */
+ error = fwnode_property_get_reference_args(node, "ref-3", NULL,
+ 0, 0, &ref);
+ KUNIT_ASSERT_EQ(test, error, 0);
+ KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[0]);
+ KUNIT_EXPECT_EQ(test, ref.nargs, 0U);
+
+ /* second reference in the array */
+ error = fwnode_property_get_reference_args(node, "ref-3", NULL,
+ 2, 1, &ref);
+ KUNIT_ASSERT_EQ(test, error, 0);
+ KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[1]);
+ KUNIT_EXPECT_EQ(test, ref.nargs, 2U);
+ KUNIT_EXPECT_EQ(test, ref.args[0], 3LLU);
+ KUNIT_EXPECT_EQ(test, ref.args[1], 4LLU);
+
+ /* wrong index */
+ error = fwnode_property_get_reference_args(node, "ref-1", NULL,
+ 0, 2, &ref);
+ KUNIT_EXPECT_NE(test, error, 0);
+
+ fwnode_remove_software_node(node);
+ software_node_unregister_nodes(nodes);
+}
+
+static struct kunit_case property_entry_test_cases[] = {
+ KUNIT_CASE(pe_test_uints),
+ KUNIT_CASE(pe_test_uint_arrays),
+ KUNIT_CASE(pe_test_strings),
+ KUNIT_CASE(pe_test_bool),
+ KUNIT_CASE(pe_test_move_inline_u8),
+ KUNIT_CASE(pe_test_move_inline_str),
+ KUNIT_CASE(pe_test_reference),
+ { }
+};
+
+static struct kunit_suite property_entry_test_suite = {
+ .name = "property-entry",
+ .test_cases = property_entry_test_cases,
+};
+
+kunit_test_suite(property_entry_test_suite);
--
2.24.0.393.g34dc348eaf-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v9] software node: add basic tests for property entries
2019-12-04 18:53 ` [PATCH v9] software node: add basic tests for property entries Dmitry Torokhov
@ 2019-12-09 8:44 ` Rafael J. Wysocki
2019-12-11 10:53 ` Rafael J. Wysocki
0 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki @ 2019-12-09 8:44 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Rafael J. Wysocki, kbuild-all, ACPI Devel Maling List, Linux PM,
Rafael J. Wysocki, kbuild test robot
On Wed, Dec 4, 2019 at 7:53 PM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
>
> This adds tests for creating software nodes with properties supplied by
> PROPERTY_ENTRY_XXX() macros and fetching and validating data from said
> nodes/properties.
>
> We are using KUnit framework for the tests.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Applied (as 5.5 material), thanks!
> ---
>
> - updated to reduce stack size below 2048 by declaring properties as
> static const.
>
> drivers/base/test/Makefile | 2 +
> drivers/base/test/property-entry-test.c | 474 ++++++++++++++++++++++++
> 2 files changed, 476 insertions(+)
> create mode 100644 drivers/base/test/property-entry-test.c
>
> diff --git a/drivers/base/test/Makefile b/drivers/base/test/Makefile
> index 0f1f7277a0139..22143102e5d21 100644
> --- a/drivers/base/test/Makefile
> +++ b/drivers/base/test/Makefile
> @@ -1,2 +1,4 @@
> # SPDX-License-Identifier: GPL-2.0
> obj-$(CONFIG_TEST_ASYNC_DRIVER_PROBE) += test_async_driver_probe.o
> +
> +obj-$(CONFIG_KUNIT) += property-entry-test.o
> diff --git a/drivers/base/test/property-entry-test.c b/drivers/base/test/property-entry-test.c
> new file mode 100644
> index 0000000000000..da812834b6316
> --- /dev/null
> +++ b/drivers/base/test/property-entry-test.c
> @@ -0,0 +1,474 @@
> +// SPDX-License-Identifier: GPL-2.0
> +// Unit tests for property entries API
> +//
> +// Copyright 2019 Google LLC.
> +
> +#include <kunit/test.h>
> +#include <linux/property.h>
> +#include <linux/types.h>
> +
> +static void pe_test_uints(struct kunit *test)
> +{
> + static const struct property_entry entries[] = {
> + PROPERTY_ENTRY_U8("prop-u8", 8),
> + PROPERTY_ENTRY_U16("prop-u16", 16),
> + PROPERTY_ENTRY_U32("prop-u32", 32),
> + PROPERTY_ENTRY_U64("prop-u64", 64),
> + { }
> + };
> +
> + struct fwnode_handle *node;
> + u8 val_u8, array_u8[2];
> + u16 val_u16, array_u16[2];
> + u32 val_u32, array_u32[2];
> + u64 val_u64, array_u64[2];
> + int error;
> +
> + node = fwnode_create_software_node(entries, NULL);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
> +
> + error = fwnode_property_read_u8(node, "prop-u8", &val_u8);
> + KUNIT_EXPECT_EQ(test, error, 0);
> + KUNIT_EXPECT_EQ(test, (int)val_u8, 8);
> +
> + 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);
> +
> + error = fwnode_property_read_u8_array(node, "prop-u8", array_u8, 2);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u8(node, "no-prop-u8", &val_u8);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u8_array(node, "no-prop-u8", array_u8, 1);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u16(node, "prop-u16", &val_u16);
> + KUNIT_EXPECT_EQ(test, error, 0);
> + KUNIT_EXPECT_EQ(test, (int)val_u16, 16);
> +
> + 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);
> +
> + error = fwnode_property_read_u16_array(node, "prop-u16", array_u16, 2);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u16(node, "no-prop-u16", &val_u16);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u16_array(node, "no-prop-u16", array_u16, 1);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u32(node, "prop-u32", &val_u32);
> + KUNIT_EXPECT_EQ(test, error, 0);
> + KUNIT_EXPECT_EQ(test, (int)val_u32, 32);
> +
> + 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);
> +
> + error = fwnode_property_read_u32_array(node, "prop-u32", array_u32, 2);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u32(node, "no-prop-u32", &val_u32);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u32_array(node, "no-prop-u32", array_u32, 1);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u64(node, "prop-u64", &val_u64);
> + KUNIT_EXPECT_EQ(test, error, 0);
> + KUNIT_EXPECT_EQ(test, (int)val_u64, 64);
> +
> + 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);
> +
> + error = fwnode_property_read_u64_array(node, "prop-u64", array_u64, 2);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u64(node, "no-prop-u64", &val_u64);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u64_array(node, "no-prop-u64", array_u64, 1);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + 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 struct property_entry entries[] = {
> + PROPERTY_ENTRY_U8_ARRAY("prop-u8", a_u8),
> + PROPERTY_ENTRY_U16_ARRAY("prop-u16", a_u16),
> + PROPERTY_ENTRY_U32_ARRAY("prop-u32", a_u32),
> + PROPERTY_ENTRY_U64_ARRAY("prop-u64", a_u64),
> + { }
> + };
> +
> + struct fwnode_handle *node;
> + u8 val_u8, array_u8[32];
> + u16 val_u16, array_u16[32];
> + u32 val_u32, array_u32[32];
> + u64 val_u64, array_u64[32];
> + int error;
> +
> + node = fwnode_create_software_node(entries, NULL);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
> +
> + error = fwnode_property_read_u8(node, "prop-u8", &val_u8);
> + KUNIT_EXPECT_EQ(test, error, 0);
> + KUNIT_EXPECT_EQ(test, (int)val_u8, 8);
> +
> + 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);
> +
> + error = fwnode_property_read_u8_array(node, "prop-u8", array_u8, 2);
> + KUNIT_EXPECT_EQ(test, error, 0);
> + KUNIT_EXPECT_EQ(test, (int)array_u8[0], 8);
> + KUNIT_EXPECT_EQ(test, (int)array_u8[1], 9);
> +
> + error = fwnode_property_read_u8_array(node, "prop-u8", array_u8, 17);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u8(node, "no-prop-u8", &val_u8);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u8_array(node, "no-prop-u8", array_u8, 1);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u16(node, "prop-u16", &val_u16);
> + KUNIT_EXPECT_EQ(test, error, 0);
> + KUNIT_EXPECT_EQ(test, (int)val_u16, 16);
> +
> + 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);
> +
> + error = fwnode_property_read_u16_array(node, "prop-u16", array_u16, 2);
> + KUNIT_EXPECT_EQ(test, error, 0);
> + KUNIT_EXPECT_EQ(test, (int)array_u16[0], 16);
> + KUNIT_EXPECT_EQ(test, (int)array_u16[1], 17);
> +
> + error = fwnode_property_read_u16_array(node, "prop-u16", array_u16, 17);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u16(node, "no-prop-u16", &val_u16);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u16_array(node, "no-prop-u16", array_u16, 1);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u32(node, "prop-u32", &val_u32);
> + KUNIT_EXPECT_EQ(test, error, 0);
> + KUNIT_EXPECT_EQ(test, (int)val_u32, 32);
> +
> + 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);
> +
> + error = fwnode_property_read_u32_array(node, "prop-u32", array_u32, 2);
> + KUNIT_EXPECT_EQ(test, error, 0);
> + KUNIT_EXPECT_EQ(test, (int)array_u32[0], 32);
> + KUNIT_EXPECT_EQ(test, (int)array_u32[1], 33);
> +
> + error = fwnode_property_read_u32_array(node, "prop-u32", array_u32, 17);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u32(node, "no-prop-u32", &val_u32);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u32_array(node, "no-prop-u32", array_u32, 1);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u64(node, "prop-u64", &val_u64);
> + KUNIT_EXPECT_EQ(test, error, 0);
> + KUNIT_EXPECT_EQ(test, (int)val_u64, 64);
> +
> + 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);
> +
> + error = fwnode_property_read_u64_array(node, "prop-u64", array_u64, 2);
> + KUNIT_EXPECT_EQ(test, error, 0);
> + KUNIT_EXPECT_EQ(test, (int)array_u64[0], 64);
> + KUNIT_EXPECT_EQ(test, (int)array_u64[1], 65);
> +
> + error = fwnode_property_read_u64_array(node, "prop-u64", array_u64, 17);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u64(node, "no-prop-u64", &val_u64);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_u64_array(node, "no-prop-u64", array_u64, 1);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + fwnode_remove_software_node(node);
> +}
> +
> +static void pe_test_strings(struct kunit *test)
> +{
> + static const char *strings[] = {
> + "string-a",
> + "string-b",
> + };
> +
> + static const struct property_entry entries[] = {
> + PROPERTY_ENTRY_STRING("str", "single"),
> + PROPERTY_ENTRY_STRING("empty", ""),
> + PROPERTY_ENTRY_STRING_ARRAY("strs", strings),
> + { }
> + };
> +
> + struct fwnode_handle *node;
> + const char *str;
> + const char *strs[10];
> + int error;
> +
> + node = fwnode_create_software_node(entries, NULL);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
> +
> + error = fwnode_property_read_string(node, "str", &str);
> + KUNIT_EXPECT_EQ(test, error, 0);
> + KUNIT_EXPECT_STREQ(test, str, "single");
> +
> + error = fwnode_property_read_string_array(node, "str", strs, 1);
> + KUNIT_EXPECT_EQ(test, error, 1);
> + KUNIT_EXPECT_STREQ(test, strs[0], "single");
> +
> + /* asking for more data returns what we have */
> + error = fwnode_property_read_string_array(node, "str", strs, 2);
> + KUNIT_EXPECT_EQ(test, error, 1);
> + KUNIT_EXPECT_STREQ(test, strs[0], "single");
> +
> + error = fwnode_property_read_string(node, "no-str", &str);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_read_string_array(node, "no-str", strs, 1);
> + KUNIT_EXPECT_LT(test, error, 0);
> +
> + error = fwnode_property_read_string(node, "empty", &str);
> + KUNIT_EXPECT_EQ(test, error, 0);
> + KUNIT_EXPECT_STREQ(test, str, "");
> +
> + error = fwnode_property_read_string_array(node, "strs", strs, 3);
> + KUNIT_EXPECT_EQ(test, error, 2);
> + KUNIT_EXPECT_STREQ(test, strs[0], "string-a");
> + KUNIT_EXPECT_STREQ(test, strs[1], "string-b");
> +
> + error = fwnode_property_read_string_array(node, "strs", strs, 1);
> + KUNIT_EXPECT_EQ(test, error, 1);
> + KUNIT_EXPECT_STREQ(test, strs[0], "string-a");
> +
> + /* NULL argument -> returns size */
> + error = fwnode_property_read_string_array(node, "strs", NULL, 0);
> + KUNIT_EXPECT_EQ(test, error, 2);
> +
> + /* accessing array as single value */
> + error = fwnode_property_read_string(node, "strs", &str);
> + KUNIT_EXPECT_EQ(test, error, 0);
> + KUNIT_EXPECT_STREQ(test, str, "string-a");
> +
> + fwnode_remove_software_node(node);
> +}
> +
> +static void pe_test_bool(struct kunit *test)
> +{
> + static const struct property_entry entries[] = {
> + PROPERTY_ENTRY_BOOL("prop"),
> + { }
> + };
> +
> + struct fwnode_handle *node;
> +
> + node = fwnode_create_software_node(entries, NULL);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
> +
> + KUNIT_EXPECT_TRUE(test, fwnode_property_read_bool(node, "prop"));
> + KUNIT_EXPECT_FALSE(test, fwnode_property_read_bool(node, "not-prop"));
> +
> + fwnode_remove_software_node(node);
> +}
> +
> +/* Verifies that small U8 array is stored inline when property is copied */
> +static void pe_test_move_inline_u8(struct kunit *test)
> +{
> + static const u8 u8_array_small[8] = { 1, 2, 3, 4 };
> + static const u8 u8_array_big[128] = { 5, 6, 7, 8 };
> + static const struct property_entry entries[] = {
> + PROPERTY_ENTRY_U8_ARRAY("small", u8_array_small),
> + PROPERTY_ENTRY_U8_ARRAY("big", u8_array_big),
> + { }
> + };
> +
> + struct property_entry *copy;
> + const u8 *data_ptr;
> +
> + copy = property_entries_dup(entries);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, copy);
> +
> + KUNIT_EXPECT_TRUE(test, copy[0].is_inline);
> + data_ptr = (u8 *)©[0].value;
> + KUNIT_EXPECT_EQ(test, (int)data_ptr[0], 1);
> + KUNIT_EXPECT_EQ(test, (int)data_ptr[1], 2);
> +
> + KUNIT_EXPECT_FALSE(test, copy[1].is_inline);
> + data_ptr = copy[1].pointer;
> + KUNIT_EXPECT_EQ(test, (int)data_ptr[0], 5);
> + KUNIT_EXPECT_EQ(test, (int)data_ptr[1], 6);
> +
> + property_entries_free(copy);
> +}
> +
> +/* Verifies that single string array is stored inline when property is copied */
> +static void pe_test_move_inline_str(struct kunit *test)
> +{
> + static char *str_array_small[] = { "a" };
> + static char *str_array_big[] = { "b", "c", "d", "e" };
> + static char *str_array_small_empty[] = { "" };
> + static struct property_entry entries[] = {
> + PROPERTY_ENTRY_STRING_ARRAY("small", str_array_small),
> + PROPERTY_ENTRY_STRING_ARRAY("big", str_array_big),
> + PROPERTY_ENTRY_STRING_ARRAY("small-empty", str_array_small_empty),
> + { }
> + };
> +
> + struct property_entry *copy;
> + const char * const *data_ptr;
> +
> + copy = property_entries_dup(entries);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, copy);
> +
> + KUNIT_EXPECT_TRUE(test, copy[0].is_inline);
> + KUNIT_EXPECT_STREQ(test, copy[0].value.str[0], "a");
> +
> + KUNIT_EXPECT_FALSE(test, copy[1].is_inline);
> + data_ptr = copy[1].pointer;
> + KUNIT_EXPECT_STREQ(test, data_ptr[0], "b");
> + KUNIT_EXPECT_STREQ(test, data_ptr[1], "c");
> +
> + KUNIT_EXPECT_TRUE(test, copy[2].is_inline);
> + KUNIT_EXPECT_STREQ(test, copy[2].value.str[0], "");
> +
> + property_entries_free(copy);
> +}
> +
> +/* Handling of reference properties */
> +static void pe_test_reference(struct kunit *test)
> +{
> + static const struct software_node nodes[] = {
> + { .name = "1", },
> + { .name = "2", },
> + };
> +
> + static const struct software_node_ref_args refs[] = {
> + {
> + .node = &nodes[0],
> + .nargs = 0,
> + },
> + {
> + .node = &nodes[1],
> + .nargs = 2,
> + .args = { 3, 4 },
> + },
> + };
> +
> + const struct property_entry entries[] = {
> + PROPERTY_ENTRY_REF("ref-1", &nodes[0]),
> + PROPERTY_ENTRY_REF("ref-2", &nodes[1], 1, 2),
> + PROPERTY_ENTRY_REF_ARRAY("ref-3", refs),
> + { }
> + };
> +
> + struct fwnode_handle *node;
> + struct fwnode_reference_args ref;
> + int error;
> +
> + error = software_node_register_nodes(nodes);
> + KUNIT_ASSERT_EQ(test, error, 0);
> +
> + node = fwnode_create_software_node(entries, NULL);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
> +
> + error = fwnode_property_get_reference_args(node, "ref-1", NULL,
> + 0, 0, &ref);
> + KUNIT_ASSERT_EQ(test, error, 0);
> + KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[0]);
> + KUNIT_EXPECT_EQ(test, ref.nargs, 0U);
> +
> + /* wrong index */
> + error = fwnode_property_get_reference_args(node, "ref-1", NULL,
> + 0, 1, &ref);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + error = fwnode_property_get_reference_args(node, "ref-2", NULL,
> + 1, 0, &ref);
> + KUNIT_ASSERT_EQ(test, error, 0);
> + KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[1]);
> + KUNIT_EXPECT_EQ(test, ref.nargs, 1U);
> + KUNIT_EXPECT_EQ(test, ref.args[0], 1LLU);
> +
> + /* asking for more args, padded with zero data */
> + error = fwnode_property_get_reference_args(node, "ref-2", NULL,
> + 3, 0, &ref);
> + KUNIT_ASSERT_EQ(test, error, 0);
> + KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[1]);
> + KUNIT_EXPECT_EQ(test, ref.nargs, 3U);
> + KUNIT_EXPECT_EQ(test, ref.args[0], 1LLU);
> + KUNIT_EXPECT_EQ(test, ref.args[1], 2LLU);
> + KUNIT_EXPECT_EQ(test, ref.args[2], 0LLU);
> +
> + /* wrong index */
> + error = fwnode_property_get_reference_args(node, "ref-2", NULL,
> + 2, 1, &ref);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + /* array of references */
> + error = fwnode_property_get_reference_args(node, "ref-3", NULL,
> + 0, 0, &ref);
> + KUNIT_ASSERT_EQ(test, error, 0);
> + KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[0]);
> + KUNIT_EXPECT_EQ(test, ref.nargs, 0U);
> +
> + /* second reference in the array */
> + error = fwnode_property_get_reference_args(node, "ref-3", NULL,
> + 2, 1, &ref);
> + KUNIT_ASSERT_EQ(test, error, 0);
> + KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[1]);
> + KUNIT_EXPECT_EQ(test, ref.nargs, 2U);
> + KUNIT_EXPECT_EQ(test, ref.args[0], 3LLU);
> + KUNIT_EXPECT_EQ(test, ref.args[1], 4LLU);
> +
> + /* wrong index */
> + error = fwnode_property_get_reference_args(node, "ref-1", NULL,
> + 0, 2, &ref);
> + KUNIT_EXPECT_NE(test, error, 0);
> +
> + fwnode_remove_software_node(node);
> + software_node_unregister_nodes(nodes);
> +}
> +
> +static struct kunit_case property_entry_test_cases[] = {
> + KUNIT_CASE(pe_test_uints),
> + KUNIT_CASE(pe_test_uint_arrays),
> + KUNIT_CASE(pe_test_strings),
> + KUNIT_CASE(pe_test_bool),
> + KUNIT_CASE(pe_test_move_inline_u8),
> + KUNIT_CASE(pe_test_move_inline_str),
> + KUNIT_CASE(pe_test_reference),
> + { }
> +};
> +
> +static struct kunit_suite property_entry_test_suite = {
> + .name = "property-entry",
> + .test_cases = property_entry_test_cases,
> +};
> +
> +kunit_test_suite(property_entry_test_suite);
> --
> 2.24.0.393.g34dc348eaf-goog
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v9] software node: add basic tests for property entries
2019-12-09 8:44 ` Rafael J. Wysocki
@ 2019-12-11 10:53 ` Rafael J. Wysocki
2019-12-13 0:18 ` Dmitry Torokhov
0 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki @ 2019-12-11 10:53 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: kbuild-all, ACPI Devel Maling List, Linux PM, kbuild test robot
On Monday, December 9, 2019 9:44:47 AM CET Rafael J. Wysocki wrote:
> On Wed, Dec 4, 2019 at 7:53 PM Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
> >
> > This adds tests for creating software nodes with properties supplied by
> > PROPERTY_ENTRY_XXX() macros and fetching and validating data from said
> > nodes/properties.
> >
> > We are using KUnit framework for the tests.
> >
> > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>
> Applied (as 5.5 material), thanks!
And dropped again, because 0-day still complains.
I'm going to push the rest of the series to Linus this week. The last patch
can wait, even though it would be good to have it.
Cheers!
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v9] software node: add basic tests for property entries
2019-12-11 10:53 ` Rafael J. Wysocki
@ 2019-12-13 0:18 ` Dmitry Torokhov
2019-12-13 10:15 ` Rafael J. Wysocki
0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Torokhov @ 2019-12-13 0:18 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: kbuild-all, ACPI Devel Maling List, Linux PM, kbuild test robot
On Wed, Dec 11, 2019 at 11:53:05AM +0100, Rafael J. Wysocki wrote:
> On Monday, December 9, 2019 9:44:47 AM CET Rafael J. Wysocki wrote:
> > On Wed, Dec 4, 2019 at 7:53 PM Dmitry Torokhov
> > <dmitry.torokhov@gmail.com> wrote:
> > >
> > > This adds tests for creating software nodes with properties supplied by
> > > PROPERTY_ENTRY_XXX() macros and fetching and validating data from said
> > > nodes/properties.
> > >
> > > We are using KUnit framework for the tests.
> > >
> > > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> >
> > Applied (as 5.5 material), thanks!
>
> And dropped again, because 0-day still complains.
>
> I'm going to push the rest of the series to Linus this week. The last patch
> can wait, even though it would be good to have it.
Could you point me to the 0-say compaint for the latest version as I did
not get it. I am still interested in sorting it all out.
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v9] software node: add basic tests for property entries
2019-12-13 0:18 ` Dmitry Torokhov
@ 2019-12-13 10:15 ` Rafael J. Wysocki
0 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2019-12-13 10:15 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: kbuild-all, ACPI Devel Maling List, Linux PM, kbuild test robot
On Friday, December 13, 2019 1:18:29 AM CET Dmitry Torokhov wrote:
> On Wed, Dec 11, 2019 at 11:53:05AM +0100, Rafael J. Wysocki wrote:
> > On Monday, December 9, 2019 9:44:47 AM CET Rafael J. Wysocki wrote:
> > > On Wed, Dec 4, 2019 at 7:53 PM Dmitry Torokhov
> > > <dmitry.torokhov@gmail.com> wrote:
> > > >
> > > > This adds tests for creating software nodes with properties supplied by
> > > > PROPERTY_ENTRY_XXX() macros and fetching and validating data from said
> > > > nodes/properties.
> > > >
> > > > We are using KUnit framework for the tests.
> > > >
> > > > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> > >
> > > Applied (as 5.5 material), thanks!
> >
> > And dropped again, because 0-day still complains.
> >
> > I'm going to push the rest of the series to Linus this week. The last patch
> > can wait, even though it would be good to have it.
>
> Could you point me to the 0-say compaint for the latest version as I did
> not get it. I am still interested in sorting it all out.
>
I have forwarded it to you: https://lore.kernel.org/linux-acpi/1860961.FledB3ecnK@kreacher/T/#u
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-12-13 10:15 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-04 1:07 [pm:bleeding-edge 6/7] drivers/base/test/property-entry-test.c:454:1: warning: the frame size of 2960 bytes is larger than 2048 bytes kbuild test robot
2019-12-04 9:30 ` Rafael J. Wysocki
2019-12-04 18:53 ` [PATCH v9] software node: add basic tests for property entries Dmitry Torokhov
2019-12-09 8:44 ` Rafael J. Wysocki
2019-12-11 10:53 ` Rafael J. Wysocki
2019-12-13 0:18 ` Dmitry Torokhov
2019-12-13 10:15 ` Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).