static int num_subtests(const struct test_suite *t)
{
+ int num;
+
if (t->subtest.get_nr)
return t->subtest.get_nr();
- return 0;
+ if (!t->test_cases)
+ return 0;
+
+ num = 0;
+ while (t->test_cases[num].name)
+ num++;
+
+ return num;
}
static bool has_subtests(const struct test_suite *t)
static const char *test_description(const struct test_suite *t, int subtest)
{
- if (subtest < 0 || !t->subtest.get_desc)
- return t->desc;
+ if (t->test_cases && subtest >= 0)
+ return t->test_cases[subtest].desc;
- return t->subtest.get_desc(subtest);
+ if (t->subtest.get_desc && subtest >= 0)
+ return t->subtest.get_desc(subtest);
+
+ return t->desc;
}
static bool is_supported(const struct test_suite *t)
return !t->is_supported || t->is_supported();
}
-static test_fnptr test_function(const struct test_suite *t, int subtest __maybe_unused)
+static test_fnptr test_function(const struct test_suite *t, int subtest)
{
- return t->func;
+ if (t->func)
+ return t->func;
+
+ if (subtest <= 0)
+ return t->test_cases[0].run_case;
+
+ return t->test_cases[subtest].run_case;
}
static bool perf_test__matches(const char *desc, int curr, int argc, const char *argv[])
typedef int (*test_fnptr)(struct test_suite *, int);
+struct test_case {
+ const char *name;
+ const char *desc;
+ test_fnptr run_case;
+};
+
struct test_suite {
const char *desc;
test_fnptr func;
const char *(*get_desc)(int subtest);
const char *(*skip_reason)(int subtest);
} subtest;
+ struct test_case *test_cases;
bool (*is_supported)(void);
void *priv;
};
#define DECLARE_SUITE(name) \
extern struct test_suite suite__##name;
-#define DEFINE_SUITE(description, name) \
- struct test_suite suite__##name = { \
- .desc = description, \
- .func = test__##name, \
+#define TEST_CASE(description, _name) \
+ { \
+ .name = #_name, \
+ .desc = description, \
+ .run_case = test__##_name, \
+ }
+
+#define DEFINE_SUITE(description, _name) \
+ struct test_case tests__##_name[] = { \
+ TEST_CASE(description, _name), \
+ { .name = NULL, } \
+ }; \
+ struct test_suite suite__##_name = { \
+ .desc = description, \
+ .test_cases = tests__##_name, \
}
/* Tests */