diff mbox series

[SRU,J,v2,1/3] selftests/harness: allow tests to be skipped during setup

Message ID 20230823202010.652027-2-magali.lemes@canonical.com
State New
Headers show
Series Fix failing net selftests | expand

Commit Message

Magali Lemes Aug. 23, 2023, 8:20 p.m. UTC
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@kernel.org>
Signed-off-by: Magali Lemes <magali.lemes@canonical.com>
Signed-off-by: Jakub Kicinski <kuba@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@canonical.com>
---
 tools/testing/selftests/kselftest_harness.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

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); \