summaryrefslogtreecommitdiff
path: root/lib/kunit/attributes.c
diff options
context:
space:
mode:
authorRae Moar <rmoar@google.com>2023-07-25 21:25:14 +0000
committerShuah Khan <skhan@linuxfoundation.org>2023-07-26 13:29:09 -0600
commita00a72709175a4d53096301a8792b8171d1223e5 (patch)
tree40eafdbbc2e0416eea039b758d3addb63667a86f /lib/kunit/attributes.c
parent02c2d0c2a84172c3c7ec0229c61db55d23dd4730 (diff)
kunit: Add module attribute
Add module attribute to the test attribute API. This attribute stores the module name associated with the test using KBUILD_MODNAME. The name of a test suite and the module name often do not match. A reference to the module name associated with the suite could be extremely helpful in running tests as modules without needing to check the codebase. This attribute will be printed for each suite. Reviewed-by: David Gow <davidgow@google.com> Signed-off-by: Rae Moar <rmoar@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'lib/kunit/attributes.c')
-rw-r--r--lib/kunit/attributes.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/kunit/attributes.c b/lib/kunit/attributes.c
index ffd0d692b334..9dce4f4d726c 100644
--- a/lib/kunit/attributes.c
+++ b/lib/kunit/attributes.c
@@ -61,6 +61,12 @@ static const char *attr_speed_to_string(void *attr, bool *to_free)
return attr_enum_to_string(attr, speed_str_list, to_free);
}
+static const char *attr_string_to_string(void *attr, bool *to_free)
+{
+ *to_free = false;
+ return (char *) attr;
+}
+
/* Get Attribute Methods */
static void *attr_speed_get(void *test_or_suite, bool is_test)
@@ -74,6 +80,18 @@ static void *attr_speed_get(void *test_or_suite, bool is_test)
return ((void *) suite->attr.speed);
}
+static void *attr_module_get(void *test_or_suite, bool is_test)
+{
+ struct kunit_suite *suite = is_test ? NULL : test_or_suite;
+ struct kunit_case *test = is_test ? test_or_suite : NULL;
+
+ // Suites get their module attribute from their first test_case
+ if (test)
+ return ((void *) test->module_name);
+ else
+ return ((void *) suite->test_cases[0].module_name);
+}
+
/* List of all Test Attributes */
static struct kunit_attr kunit_attr_list[] = {
@@ -84,6 +102,13 @@ static struct kunit_attr kunit_attr_list[] = {
.attr_default = (void *)KUNIT_SPEED_NORMAL,
.print = PRINT_ALWAYS,
},
+ {
+ .name = "module",
+ .get_attr = attr_module_get,
+ .to_string = attr_string_to_string,
+ .attr_default = (void *)"",
+ .print = PRINT_SUITE,
+ }
};
/* Helper Functions to Access Attributes */