tools/testing/selftests/kselftest_harness/harness-selftest.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/kselftest_harness/harness-selftest.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/kselftest_harness/harness-selftest.c
Extension
.c
Size
2883 bytes
Lines
177
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

// 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();
}

Annotation

Implementation Notes