提交 79ee8aa3 编写于 作者: W Willem de Bruijn 提交者: Shuah Khan

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: NWillem de Bruijn <willemb@google.com>
Reviewed-by: NJakub Kicinski <kuba@kernel.org>
Acked-by: NKees Cook <keescook@chromium.org>
Signed-off-by: NKees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20201210231010.420298-1-willemdebruijn.kernel@gmail.comSigned-off-by: NShuah Khan <skhan@linuxfoundation.org>
上级 63e6b2a4
...@@ -291,7 +291,9 @@ ...@@ -291,7 +291,9 @@
#define FIXTURE_TEARDOWN(fixture_name) \ #define FIXTURE_TEARDOWN(fixture_name) \
void fixture_name##_teardown( \ void fixture_name##_teardown( \
struct __test_metadata __attribute__((unused)) *_metadata, \ struct __test_metadata __attribute__((unused)) *_metadata, \
FIXTURE_DATA(fixture_name) __attribute__((unused)) *self) FIXTURE_DATA(fixture_name) __attribute__((unused)) *self, \
const FIXTURE_VARIANT(fixture_name) \
__attribute__((unused)) *variant)
/** /**
* FIXTURE_VARIANT() - Optionally called once per fixture * FIXTURE_VARIANT() - Optionally called once per fixture
...@@ -306,9 +308,9 @@ ...@@ -306,9 +308,9 @@
* ... * ...
* }; * };
* *
* Defines type of constant parameters provided to FIXTURE_SETUP() and TEST_F() * Defines type of constant parameters provided to FIXTURE_SETUP(), TEST_F() and
* as *variant*. Variants allow the same tests to be run with different * FIXTURE_TEARDOWN as *variant*. Variants allow the same tests to be run with
* arguments. * different arguments.
*/ */
#define FIXTURE_VARIANT(fixture_name) struct _fixture_variant_##fixture_name #define FIXTURE_VARIANT(fixture_name) struct _fixture_variant_##fixture_name
...@@ -391,7 +393,7 @@ ...@@ -391,7 +393,7 @@
fixture_name##_##test_name(_metadata, &self, variant->data); \ fixture_name##_##test_name(_metadata, &self, variant->data); \
} \ } \
if (_metadata->setup_completed) \ if (_metadata->setup_completed) \
fixture_name##_teardown(_metadata, &self); \ fixture_name##_teardown(_metadata, &self, variant->data); \
__test_check_assert(_metadata); \ __test_check_assert(_metadata); \
} \ } \
static struct __test_metadata \ static struct __test_metadata \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册