selftests/harness: allow tests to be skipped during setup
authorMagali Lemes <magali.lemes@canonical.com>
Tue, 13 Jun 2023 12:32:19 +0000 (09:32 -0300)
committerJakub Kicinski <kuba@kernel.org>
Fri, 16 Jun 2023 05:24:01 +0000 (22:24 -0700)
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>
tools/testing/selftests/kselftest_harness.h

index d8bff20..5fd49ad 100644 (file)
 
 /**
  * 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
  *
 
 /**
  * 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
  *
                if (setjmp(_metadata->env) == 0) { \
                        fixture_name##_setup(_metadata, &self, variant->data); \
                        /* Let setup failure terminate early. */ \
-                       if (!_metadata->passed) \
+                       if (!_metadata->passed || _metadata->skip) \
                                return; \
                        _metadata->setup_completed = true; \
                        fixture_name##_##test_name(_metadata, &self, variant->data); \