1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
// 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);
}
|