tools/testing/selftests/kselftest_harness.h

Source file repositories/reference/linux-study-clean/tools/testing/selftests/kselftest_harness.h

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/kselftest_harness.h
Extension
.h
Size
36224 bytes
Lines
1333
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

struct __test_results {
	char reason[1024];	/* Reason for test result */
};

struct __test_metadata;
struct __fixture_variant_metadata;

/* Contains all the information about a fixture. */
struct __fixture_metadata {
	const char *name;
	struct __test_metadata *tests;
	struct __fixture_variant_metadata *variant;
	struct __fixture_metadata *prev, *next;
} _fixture_global __attribute__((unused)) = {
	.name = "global",
	.prev = &_fixture_global,
};

struct __test_xfail {
	struct __fixture_metadata *fixture;
	struct __fixture_variant_metadata *variant;
	struct __test_metadata *test;
	struct __test_xfail *prev, *next;
};

/**
 * XFAIL_ADD() - mark variant + test case combination as expected to fail
 * @fixture_name: name of the fixture
 * @variant_name: name of the variant
 * @test_name: name of the test case
 *
 * Mark a combination of variant + test case for a given fixture as expected
 * to fail. Tests marked this way will report XPASS / XFAIL return codes,
 * instead of PASS / FAIL,and use respective counters.
 */
#define XFAIL_ADD(fixture_name, variant_name, test_name) \
	static struct __test_xfail \
		_##fixture_name##_##variant_name##_##test_name##_xfail = \
	{ \
		.fixture = &_##fixture_name##_fixture_object, \
		.variant = &_##fixture_name##_##variant_name##_object, \
	}; \
	static void __attribute__((constructor(KSELFTEST_PRIO_XFAIL))) \
		_register_##fixture_name##_##variant_name##_##test_name##_xfail(void) \
	{ \
		_##fixture_name##_##variant_name##_##test_name##_xfail.test = \
			_##fixture_name##_##test_name##_object; \
		__register_xfail(&_##fixture_name##_##variant_name##_##test_name##_xfail); \
	}

static struct __fixture_metadata *__fixture_list = &_fixture_global;
static bool __constructor_order_forward;

static inline void __register_fixture(struct __fixture_metadata *f)
{
	__LIST_APPEND(__fixture_list, f);
}

struct __fixture_variant_metadata {
	const char *name;
	const void *data;
	struct __test_xfail *xfails;
	struct __fixture_variant_metadata *prev, *next;
};

static inline void
__register_fixture_variant(struct __fixture_metadata *f,
			   struct __fixture_variant_metadata *variant)
{
	__LIST_APPEND(f->variant, variant);
}

/* Contains all the information for test execution and status checking. */
struct __test_metadata {
	const char *name;
	void (*fn)(struct __test_metadata *,
		   struct __fixture_variant_metadata *);
	pid_t pid;	/* pid of test when being run */
	struct __fixture_metadata *fixture;
	void (*teardown_fn)(bool in_parent, struct __test_metadata *_metadata,
			    void *self, const void *variant);
	int termsig;
	int exit_code;
	int trigger; /* extra handler after the evaluation */
	int timeout;	/* seconds to wait for test timeout */
	bool aborted;	/* stopped test due to failed ASSERT */
	bool *no_teardown; /* fixture needs teardown */
	void *self;
	const void *variant;
	struct __test_results *results;

Annotation

Implementation Notes