tools/testing/selftests/cgroup/test_pids.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/cgroup/test_pids.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/cgroup/test_pids.c
Extension
.c
Size
3617 bytes
Lines
182
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 pids_test {
	int (*fn)(const char *root);
	const char *name;
} tests[] = {
	T(test_pids_max),
	T(test_pids_events),
};
#undef T

int main(int argc, char **argv)
{
	char root[PATH_MAX];

	ksft_print_header();
	ksft_set_plan(ARRAY_SIZE(tests));
	if (cg_find_unified_root(root, sizeof(root), NULL))
		ksft_exit_skip("cgroup v2 isn't mounted\n");

	/*
	 * Check that pids controller is available:
	 * pids is listed in cgroup.controllers
	 */
	if (cg_read_strstr(root, "cgroup.controllers", "pids"))
		ksft_exit_skip("pids controller isn't available\n");

	if (cg_read_strstr(root, "cgroup.subtree_control", "pids"))
		if (cg_write(root, "cgroup.subtree_control", "+pids"))
			ksft_exit_skip("Failed to set pids controller\n");

	for (int i = 0; i < ARRAY_SIZE(tests); i++) {
		switch (tests[i].fn(root)) {
		case KSFT_PASS:
			ksft_test_result_pass("%s\n", tests[i].name);
			break;
		case KSFT_SKIP:
			ksft_test_result_skip("%s\n", tests[i].name);
			break;
		default:
			ksft_test_result_fail("%s\n", tests[i].name);
			break;
		}
	}

	ksft_finished();
}

Annotation

Implementation Notes