tools/testing/selftests/resctrl/resctrl_tests.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/resctrl/resctrl_tests.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/resctrl/resctrl_tests.c
Extension
.c
Size
9017 bytes
Lines
363
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

if (errno || *endptr != '\0') {
			free(fill_param);
			ksft_exit_skip("Unable to parse benchmark buffer size.\n");
		}
	} else {
		fill_param->buf_size = MINIMUM_SPAN;
	}

	if (uparams->benchmark_cmd[2] && *uparams->benchmark_cmd[2] != '\0') {
		errno = 0;
		fill_param->memflush = strtol(uparams->benchmark_cmd[2], &endptr, 10) != 0;
		if (errno || *endptr != '\0') {
			free(fill_param);
			ksft_exit_skip("Unable to parse benchmark memflush parameter.\n");
		}
	} else {
		fill_param->memflush = true;
	}

	if (uparams->benchmark_cmd[3] && *uparams->benchmark_cmd[3] != '\0') {
		if (strcmp(uparams->benchmark_cmd[3], "0")) {
			free(fill_param);
			ksft_exit_skip("Only read operations supported.\n");
		}
	}

	if (uparams->benchmark_cmd[4] && *uparams->benchmark_cmd[4] != '\0') {
		if (strcmp(uparams->benchmark_cmd[4], "false")) {
			free(fill_param);
			ksft_exit_skip("fill_buf is required to run until termination.\n");
		}
	}

	return fill_param;
}

static void init_user_params(struct user_params *uparams)
{
	memset(uparams, 0, sizeof(*uparams));

	uparams->cpu = 1;
	uparams->bits = 0;
}

int main(int argc, char **argv)
{
	struct fill_buf_param *fill_param = NULL;
	int tests = ARRAY_SIZE(resctrl_tests);
	bool test_param_seen = false;
	struct user_params uparams;
	int c, i;

	init_user_params(&uparams);

	while ((c = getopt(argc, argv, "ht:b:n:p:")) != -1) {
		char *token;

		switch (c) {
		case 'b':
			/*
			 * First move optind back to the (first) optarg and
			 * then build the benchmark command using the
			 * remaining arguments.
			 */
			optind--;
			if (argc - optind >= BENCHMARK_ARGS)
				ksft_exit_fail_msg("Too long benchmark command");

			/* Extract benchmark command from command line. */
			for (i = 0; i < argc - optind; i++)
				uparams.benchmark_cmd[i] = argv[i + optind];
			uparams.benchmark_cmd[i] = NULL;

			goto last_arg;
		case 't':
			token = strtok(optarg, ",");

			if (!test_param_seen) {
				for (i = 0; i < ARRAY_SIZE(resctrl_tests); i++)
					resctrl_tests[i]->disabled = true;
				tests = 0;
				test_param_seen = true;
			}
			while (token) {
				bool found = false;

				for (i = 0; i < ARRAY_SIZE(resctrl_tests); i++) {
					if (!strcasecmp(token, resctrl_tests[i]->name) ||
					    (resctrl_tests[i]->group &&
					     !strcasecmp(token, resctrl_tests[i]->group))) {

Annotation

Implementation Notes