diff options
author | Benjamin Berg <benjamin.berg@intel.com> | 2023-12-20 16:19:47 +0100 |
---|---|---|
committer | Johannes Berg <johannes.berg@intel.com> | 2024-01-03 15:35:04 +0100 |
commit | 292010ee509443a1383bb079a4fa80515aa89a7f (patch) | |
tree | 4185e49ceb3c01c4df61d6688ada2ed66ac427d5 /include/kunit | |
parent | a5bb4e1a3748e650e664e9d44feb30daa9851945 (diff) | |
download | linux-stable-292010ee509443a1383bb079a4fa80515aa89a7f.tar.gz linux-stable-292010ee509443a1383bb079a4fa80515aa89a7f.tar.bz2 linux-stable-292010ee509443a1383bb079a4fa80515aa89a7f.zip |
kunit: add parameter generation macro using description from array
The existing KUNIT_ARRAY_PARAM macro requires a separate function to
get the description. However, in a lot of cases the description can
just be copied directly from the array. Add a second macro that
avoids having to write a static function just for a single strscpy.
Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
Reviewed-by: David Gow <davidgow@google.com>
Link: https://msgid.link/20231220151952.415232-2-benjamin@sipsolutions.net
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'include/kunit')
-rw-r--r-- | include/kunit/test.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/kunit/test.h b/include/kunit/test.h index 20ed9f9275c9..2dfa851e1f88 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -1514,6 +1514,25 @@ do { \ return NULL; \ } +/** + * KUNIT_ARRAY_PARAM_DESC() - Define test parameter generator from an array. + * @name: prefix for the test parameter generator function. + * @array: array of test parameters. + * @desc_member: structure member from array element to use as description + * + * Define function @name_gen_params which uses @array to generate parameters. + */ +#define KUNIT_ARRAY_PARAM_DESC(name, array, desc_member) \ + static const void *name##_gen_params(const void *prev, char *desc) \ + { \ + typeof((array)[0]) *__next = prev ? ((typeof(__next)) prev) + 1 : (array); \ + if (__next - (array) < ARRAY_SIZE((array))) { \ + strscpy(desc, __next->desc_member, KUNIT_PARAM_DESC_SIZE); \ + return __next; \ + } \ + return NULL; \ + } + // TODO(dlatypov@google.com): consider eventually migrating users to explicitly // include resource.h themselves if they need it. #include <kunit/resource.h> |