[SRU][J][PATCH v2 1/3] selftests/harness: allow tests to be skipped during setup
Magali Lemes
magali.lemes at canonical.com
Wed Aug 23 20:20:08 UTC 2023
BugLink: https://bugs.launchpad.net/bugs/2019868
Before executing each test from a fixture, FIXTURE_SETUP is run once.
When SKIP is used in FIXTURE_SETUP, the setup function returns early
but the test still proceeds to run, unless another SKIP macro is used
within the test definition, leading to some code repetition. Therefore,
allow tests to be skipped directly from the setup function.
Suggested-by: Jakub Kicinski <kuba at kernel.org>
Signed-off-by: Magali Lemes <magali.lemes at canonical.com>
Signed-off-by: Jakub Kicinski <kuba at kernel.org>
(backported from commit 372b304c1e517c4d3e5b6ca6c9cfb20f027c3b03)
[magalilemes: a clean cherry-pick would require 63e6b2a4
("selftests/harness: Run TEARDOWN for ASSERT failures"). However,
it suffices to just manually change the if condition that conflicts.]
Signed-off-by: Magali Lemes <magali.lemes at canonical.com>
---
tools/testing/selftests/kselftest_harness.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 11779405dc80..72272272fac4 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -244,7 +244,7 @@
/**
* FIXTURE_SETUP() - Prepares the setup function for the fixture.
- * *_metadata* is included so that EXPECT_* and ASSERT_* work correctly.
+ * *_metadata* is included so that EXPECT_*, ASSERT_* etc. work correctly.
*
* @fixture_name: fixture name
*
@@ -270,7 +270,7 @@
/**
* FIXTURE_TEARDOWN()
- * *_metadata* is included so that EXPECT_* and ASSERT_* work correctly.
+ * *_metadata* is included so that EXPECT_*, ASSERT_* etc. work correctly.
*
* @fixture_name: fixture name
*
@@ -383,7 +383,7 @@
memset(&self, 0, sizeof(FIXTURE_DATA(fixture_name))); \
fixture_name##_setup(_metadata, &self, variant->data); \
/* Let setup failure terminate early. */ \
- if (!_metadata->passed) \
+ if (!_metadata->passed || _metadata->skip) \
return; \
fixture_name##_##test_name(_metadata, &self, variant->data); \
fixture_name##_teardown(_metadata, &self); \
--
2.34.1
More information about the kernel-team
mailing list