lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:   Tue, 14 Apr 2020 14:01:42 -0700
From:   Brendan Higgins <brendanhiggins@...gle.com>
To:     gregkh@...uxfoundation.org, rafael@...nel.org,
        Dmitry Torokhov <dmitry.torokhov@...il.com>
Cc:     linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
        kunit-dev@...glegroups.com,
        Brendan Higgins <brendanhiggins@...gle.com>
Subject: [RFC v1] software: node: test: add test to exercise parent child add/remove

Add test which adds a tree of software_nodes, checks that the nodes
exist, and then removes the tree. This exercises a bug reported by
Naresh Kamboju <naresh.kamboju@...aro.org>, and pretty much just takes a
test case from the test_printf Kselftest module and refocusses it on
adding and then removing a tree of software_nodes.

Signed-off-by: Brendan Higgins <brendanhiggins@...gle.com>
---

I am not sure if this should be rolled into the property entry test, or
should be moved somewhere else; nevertheless, testing the software node
API seems like a good idea and this seems like a good place to start.

---
 drivers/base/test/Kconfig              | 14 ++++++++
 drivers/base/test/Makefile             |  2 ++
 drivers/base/test/software-node-test.c | 46 ++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)
 create mode 100644 drivers/base/test/software-node-test.c

diff --git a/drivers/base/test/Kconfig b/drivers/base/test/Kconfig
index 305c7751184a..b42f385fe233 100644
--- a/drivers/base/test/Kconfig
+++ b/drivers/base/test/Kconfig
@@ -11,3 +11,17 @@ config TEST_ASYNC_DRIVER_PROBE
 config KUNIT_DRIVER_PE_TEST
 	bool "KUnit Tests for property entry API"
 	depends on KUNIT=y
+config KUNIT_DRIVER_SOFTWARE_NODE_TEST
+	bool "KUnit Tests for software node API"
+	depends on KUNIT=y
+	help
+	  This builds the software node API tests.
+
+	  KUnit tests run during boot and output the results to the debug log
+	  in TAP format (http://testanything.org/). Only useful for kernel devs
+	  and are not for inclusion into a production build.
+
+	  For more information on KUnit and unit tests in general please refer
+	  to the KUnit documentation in Documentation/dev-tools/kunit/.
+
+	  If unsure, say N.
diff --git a/drivers/base/test/Makefile b/drivers/base/test/Makefile
index 3ca56367c84b..63325e8a5288 100644
--- a/drivers/base/test/Makefile
+++ b/drivers/base/test/Makefile
@@ -2,3 +2,5 @@
 obj-$(CONFIG_TEST_ASYNC_DRIVER_PROBE)	+= test_async_driver_probe.o
 
 obj-$(CONFIG_KUNIT_DRIVER_PE_TEST) += property-entry-test.o
+
+obj-$(CONFIG_KUNIT_DRIVER_SOFTWARE_NODE_TEST) += software-node-test.o
diff --git a/drivers/base/test/software-node-test.c b/drivers/base/test/software-node-test.c
new file mode 100644
index 000000000000..0609cbd9aa0a
--- /dev/null
+++ b/drivers/base/test/software-node-test.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0
+// Unit tests for software node API
+//
+// Copyright 2020 Google LLC.
+
+#include <kunit/test.h>
+#include <linux/property.h>
+#include <linux/types.h>
+
+static void software_node_test_register_nodes(struct kunit *test)
+{
+	const struct software_node softnodes[] = {
+		{ .name = "first", },
+		{ .name = "second", .parent = &softnodes[0], },
+		{ .name = "third", .parent = &softnodes[1], },
+		{}
+	};
+	const char * const full_name = "first/second/third";
+	char *buf;
+
+	buf = kunit_kzalloc(test, strlen(full_name), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+
+	KUNIT_ASSERT_EQ(test, software_node_register_nodes(softnodes), 0);
+
+	/* Check that all the nodes exist. */
+	KUNIT_ASSERT_EQ(test,
+			(size_t)sprintf(buf, "%pfw",
+					software_node_fwnode(&softnodes[2])),
+			strlen(full_name));
+	KUNIT_EXPECT_STREQ(test, buf, full_name);
+
+	software_node_unregister_nodes(softnodes);
+}
+
+static struct kunit_case software_node_test_cases[] = {
+	KUNIT_CASE(software_node_test_register_nodes),
+	{}
+};
+
+static struct kunit_suite software_node_test_suite = {
+	.name = "software-node",
+	.test_cases = software_node_test_cases,
+};
+
+kunit_test_suite(software_node_test_suite);

base-commit: 8632e9b5645bbc2331d21d892b0d6961c1a08429
-- 
2.26.0.110.g2183baf09c-goog

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ