Skip to content

Commit 79ee8aa

Browse files
wdebruijshuahkh
authored andcommitted
selftests/harness: Pass variant to teardown
FIXTURE_VARIANT data is passed to FIXTURE_SETUP and TEST_F as "variant". In some cases, the variant will change the setup, such that expectations also change on teardown. Also pass variant to FIXTURE_TEARDOWN. The new FIXTURE_TEARDOWN logic is identical to that in FIXTURE_SETUP, right above. Signed-off-by: Willem de Bruijn <willemb@google.com> Reviewed-by: Jakub Kicinski <kuba@kernel.org> Acked-by: Kees Cook <keescook@chromium.org> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20201210231010.420298-1-willemdebruijn.kernel@gmail.com Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 63e6b2a commit 79ee8aa

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

tools/testing/selftests/kselftest_harness.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@
291291
#define FIXTURE_TEARDOWN(fixture_name) \
292292
void fixture_name##_teardown( \
293293
struct __test_metadata __attribute__((unused)) *_metadata, \
294-
FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
294+
FIXTURE_DATA(fixture_name) __attribute__((unused)) *self, \
295+
const FIXTURE_VARIANT(fixture_name) \
296+
__attribute__((unused)) *variant)
295297

296298
/**
297299
* FIXTURE_VARIANT() - Optionally called once per fixture
@@ -306,9 +308,9 @@
306308
* ...
307309
* };
308310
*
309-
* Defines type of constant parameters provided to FIXTURE_SETUP() and TEST_F()
310-
* as *variant*. Variants allow the same tests to be run with different
311-
* arguments.
311+
* Defines type of constant parameters provided to FIXTURE_SETUP(), TEST_F() and
312+
* FIXTURE_TEARDOWN as *variant*. Variants allow the same tests to be run with
313+
* different arguments.
312314
*/
313315
#define FIXTURE_VARIANT(fixture_name) struct _fixture_variant_##fixture_name
314316

@@ -391,7 +393,7 @@
391393
fixture_name##_##test_name(_metadata, &self, variant->data); \
392394
} \
393395
if (_metadata->setup_completed) \
394-
fixture_name##_teardown(_metadata, &self); \
396+
fixture_name##_teardown(_metadata, &self, variant->data); \
395397
__test_check_assert(_metadata); \
396398
} \
397399
static struct __test_metadata \

0 commit comments

Comments
 (0)