Files
cubelinux-kernel/tools/testing/selftests/kselftest_harness/harness-selftest.c
T
Greg Kroah-Hartman 598cf27219 Linux 6.19.3
Link: https://lore.kernel.org/r/20260217200002.683975158@linuxfoundation.org
Tested-by: Florian Fainelli <florian.fainelli@broadcom.com>
Tested-by: Takeshi Ogasawara <takeshi.ogasawara@futuring-girl.com>
Tested-by: Peter Schneider <pschneider1968@googlemail.com>
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Tested-by: Salvatore Bonaccorso <carnil@debian.org>
Tested-by: Brett A C Sheffield <bacs@librecast.net>
Tested-by: Mark Brown <broonie@kernel.org>
Tested-by: Luna Jernberg <droidbittin@gmail.com>
Tested-by: Ronald Warsow <rwarsow@gmx.de>
Tested-by: Justin M. Forbes <jforbes@fedoraproject.org>
Tested-by: Ron Economos <re@w6rz.net>
Tested-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-02-19 16:33:27 +01:00

137 lines
2.3 KiB
C

// SPDX-License-Identifier: GPL-2.0
#include <stdio.h>
#include <sys/resource.h>
#include <sys/prctl.h>
/* Avoid any inconsistencies */
#define TH_LOG_STREAM stdout
#include "kselftest_harness.h"
static void test_helper(struct __test_metadata *_metadata)
{
ASSERT_EQ(0, 0);
}
TEST(standalone_pass) {
TH_LOG("before");
ASSERT_EQ(0, 0);
EXPECT_EQ(0, 0);
test_helper(_metadata);
TH_LOG("after");
}
TEST(standalone_fail) {
TH_LOG("before");
EXPECT_EQ(0, 0);
EXPECT_EQ(0, 1);
ASSERT_EQ(0, 1);
TH_LOG("after");
}
TEST_SIGNAL(signal_pass, SIGUSR1) {
TH_LOG("before");
ASSERT_EQ(0, 0);
TH_LOG("after");
kill(getpid(), SIGUSR1);
}
TEST_SIGNAL(signal_fail, SIGUSR1) {
TH_LOG("before");
ASSERT_EQ(0, 1);
TH_LOG("after");
kill(getpid(), SIGUSR1);
}
FIXTURE(fixture) {
pid_t testpid;
};
FIXTURE_SETUP(fixture) {
TH_LOG("setup");
self->testpid = getpid();
}
FIXTURE_TEARDOWN(fixture) {
TH_LOG("teardown same-process=%d", self->testpid == getpid());
}
TEST_F(fixture, pass) {
TH_LOG("before");
ASSERT_EQ(0, 0);
test_helper(_metadata);
standalone_pass(_metadata);
TH_LOG("after");
}
TEST_F(fixture, fail) {
TH_LOG("before");
ASSERT_EQ(0, 1);
fixture_pass(_metadata, self, variant);
TH_LOG("after");
}
TEST_F_TIMEOUT(fixture, timeout, 1) {
TH_LOG("before");
sleep(2);
TH_LOG("after");
}
FIXTURE(fixture_parent) {
pid_t testpid;
};
FIXTURE_SETUP(fixture_parent) {
TH_LOG("setup");
self->testpid = getpid();
}
FIXTURE_TEARDOWN_PARENT(fixture_parent) {
TH_LOG("teardown same-process=%d", self->testpid == getpid());
}
TEST_F(fixture_parent, pass) {
TH_LOG("before");
ASSERT_EQ(0, 0);
TH_LOG("after");
}
FIXTURE(fixture_setup_failure) {
pid_t testpid;
};
FIXTURE_SETUP(fixture_setup_failure) {
TH_LOG("setup");
self->testpid = getpid();
ASSERT_EQ(0, 1);
}
FIXTURE_TEARDOWN(fixture_setup_failure) {
TH_LOG("teardown same-process=%d", self->testpid == getpid());
}
TEST_F(fixture_setup_failure, pass) {
TH_LOG("before");
ASSERT_EQ(0, 0);
TH_LOG("after");
}
int main(int argc, char **argv)
{
/*
* The harness uses abort() to signal assertion failures, which triggers coredumps.
* This may be useful to debug real failures but not for this selftest, disable them.
*/
struct rlimit rlimit = {
.rlim_cur = 0,
.rlim_max = 0,
};
prctl(PR_SET_DUMPABLE, 0, 0, 0, 0);
setrlimit(RLIMIT_CORE, &rlimit);
return test_harness_run(argc, argv);
}