kunit: Add speed attribute

Add speed attribute to the test attribute API. This attribute will allow
users to mark tests with a category of speed.

Currently the categories of speed proposed are: normal, slow, and very_slow
(outlined in enum kunit_speed). These are outlined in the enum kunit_speed.

The assumed default speed for tests is "normal". This indicates that the
test takes a relatively trivial amount of time (less than 1 second),
regardless of the machine it is running on. Any test slower than this could
be marked as "slow" or "very_slow".

Add the macro KUNIT_CASE_SLOW to set a test as slow, as this is likely a
common use of the attributes API.

Add an example of marking a slow test to kunit-example-test.c.

Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Rae Moar <rmoar@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
Rae Moar
2023-07-25 21:25:13 +00:00
committed by Shuah Khan
parent 39e92cb1e4
commit 02c2d0c2a8
3 changed files with 83 additions and 2 deletions

View File

@@ -63,8 +63,27 @@ enum kunit_status {
KUNIT_SKIPPED,
};
/* Attribute struct/enum definitions */
/*
* Speed Attribute is stored as an enum and separated into categories of
* speed: very_slowm, slow, and normal. These speeds are relative to
* other KUnit tests.
*
* Note: unset speed attribute acts as default of KUNIT_SPEED_NORMAL.
*/
enum kunit_speed {
KUNIT_SPEED_UNSET,
KUNIT_SPEED_VERY_SLOW,
KUNIT_SPEED_SLOW,
KUNIT_SPEED_NORMAL,
KUNIT_SPEED_MAX = KUNIT_SPEED_NORMAL,
};
/* Holds attributes for each test case and suite */
struct kunit_attributes {};
struct kunit_attributes {
enum kunit_speed speed;
};
/**
* struct kunit_case - represents an individual test case.
@@ -150,6 +169,17 @@ static inline char *kunit_status_to_ok_not_ok(enum kunit_status status)
{ .run_case = test_name, .name = #test_name, \
.attr = attributes }
/**
* KUNIT_CASE_SLOW - A helper for creating a &struct kunit_case
* with the slow attribute
*
* @test_name: a reference to a test case function.
*/
#define KUNIT_CASE_SLOW(test_name) \
{ .run_case = test_name, .name = #test_name, \
.attr.speed = KUNIT_SPEED_SLOW }
/**
* KUNIT_CASE_PARAM - A helper for creation a parameterized &struct kunit_case
*