firewire: test: add KUnit test for device attributes
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sun, 24 Dec 2023 22:23:00 +0000 (07:23 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 8 Jan 2024 00:36:56 +0000 (09:36 +0900)
The traverse over CSR space results in attributes of node and unit
devices. Any test of the traverse is useful.

This commit adds a skeleton of KUnit test for the purpose.

Link: https://lore.kernel.org/r/20231221134849.603857-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
drivers/firewire/.kunitconfig
drivers/firewire/Kconfig
drivers/firewire/core-device.c
drivers/firewire/device-attribute-test.c [new file with mode: 0644]

index 1599e069395fc1abefbee6db34117fb0aeec5a1e..76444a2d5e1251d78d35d451e92b0b6bba268106 100644 (file)
@@ -2,3 +2,4 @@ CONFIG_KUNIT=y
 CONFIG_PCI=y
 CONFIG_FIREWIRE=y
 CONFIG_FIREWIRE_KUNIT_UAPI_TEST=y
+CONFIG_FIREWIRE_KUNIT_DEVICE_ATTRIBUTE_TEST=y
index 0a6596b027db9ab10a082a2b9bab59603dcaf150..552a39df8cbddb080e64952f0395ab32e37adf6f 100644 (file)
@@ -34,6 +34,22 @@ config FIREWIRE_KUNIT_UAPI_TEST
          For more information on KUnit and unit tests in general, refer
          to the KUnit documentation in Documentation/dev-tools/kunit/.
 
+config FIREWIRE_KUNIT_DEVICE_ATTRIBUTE_TEST
+       tristate "KUnit tests for device attributes" if !KUNIT_ALL_TESTS
+       depends on FIREWIRE && KUNIT
+       default KUNIT_ALL_TESTS
+       help
+         This builds the KUnit tests for device attribute for node and
+         unit.
+
+         KUnit tests run during boot and output the results to the debug
+         log in TAP format (https://testanything.org/). Only useful for
+         kernel devs running KUnit test harness and are not for inclusion
+         into a production build.
+
+         For more information on KUnit and unit tests in general, refer
+         to the KUnit documentation in Documentation/dev-tools/kunit/.
+
 config FIREWIRE_OHCI
        tristate "OHCI-1394 controllers"
        depends on PCI && FIREWIRE && MMU
index 2c7c38510da352dfe2b88f3a29eceb495f83fd83..37fdf820acf136031545f0664c3fed18b78a33a6 100644 (file)
@@ -1310,3 +1310,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
                break;
        }
 }
+
+#ifdef CONFIG_FIREWIRE_KUNIT_DEVICE_ATTRIBUTE_TEST
+#include "device-attribute-test.c"
+#endif
diff --git a/drivers/firewire/device-attribute-test.c b/drivers/firewire/device-attribute-test.c
new file mode 100644 (file)
index 0000000..87cfdf9
--- /dev/null
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+// device-attribute-test.c - An application of Kunit to test implementation for device attributes.
+//
+// Copyright (c) 2023 Takashi Sakamoto
+//
+// This file can not be built independently since it is intentionally included in core-device.c.
+
+#include <kunit/test.h>
+
+static struct kunit_case device_attr_test_cases[] = {
+       {}
+};
+
+static struct kunit_suite device_attr_test_suite = {
+       .name = "firewire-device-attribute",
+       .test_cases = device_attr_test_cases,
+};
+kunit_test_suite(device_attr_test_suite);