tools/testing/selftests/bpf/prog_tests/libarena.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/libarena.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/prog_tests/libarena.c
Extension
.c
Size
6501 bytes
Lines
254
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 (!ASSERT_LT(ret, sizeof(tdname), "test worker name")) {
			err = -ENAMETOOLONG;
			break;
		}

		/* 
		 * We enumerate the worker threads for a given test with __0, __1,
		 * and so on. The suffixes always start from 0 and are contiguous,
		 * so if we don't find a program with the requested name we have
		 * discovered all available worker programs.
		 */
		tdprog = bpf_object__find_program_by_name(skel->obj, tdname);
		if (!tdprog)
			break;

		/* Bump the alloc array to accommodate the new thread. */
		tmp_threads = realloc(threads, (nthreads + 1) * sizeof(*threads));
		if (!ASSERT_TRUE(tmp_threads, "realloc")) {
			err = -ENOMEM;
			break;
		}
		threads = tmp_threads;

		ret = pthread_create(&threads[nthreads], NULL,
				     run_libarena_parallel_prog,
				     tdprog);
		if (!ASSERT_OK(ret, "pthread_create")) {
			err = ret;
			break;
		}
	}


	for (i = 0; i < nthreads; i++) {
		ret = pthread_join(threads[i], &thread_ret);
		if (!ASSERT_OK(ret, "pthread_join")) {
			err = err ?: ret;
			continue;
		}

		err = err ?: (long)thread_ret;
	}

	free(threads);

	return err;
}

static bool libarena_parallel_test_enabled(struct libarena *skel,
					   const char *prefix,
					   size_t prefixlen)
{
	struct bpf_program *prog;
	char progname[MAX_PARTEST_NAME];
	int ret;

	ret = snprintf(progname, sizeof(progname), "%.*s__enabled", (int)prefixlen,
		       prefix);
	if (!ASSERT_LT(ret, sizeof(progname), "partest enabled name"))
		return false;

	prog = bpf_object__find_program_by_name(skel->obj, progname);
	if (!prog)
		return true;

	ret = libarena_run_prog(bpf_program__fd(prog));
	if (ret == -EOPNOTSUPP)
		return false;
	if (!ASSERT_OK(ret, progname))
		return false;
	return true;
}

static void run_libarena_parallel_test(struct libarena *skel, struct bpf_program *prog,
		const char *name)
{
	char testname[MAX_PARTEST_NAME];
	size_t prefixlen;
	const char *pos;
	int ret;

	/*
	 * We annotate the initialization prog with __init. If the current prog does
	 * not match, it is one of the parallel threads instead and is ignored.
	 *
	 * We assume the test writer knows what they are doing and do not add __init
	 * randomly in the middle of a test name.
	 */
	pos = strstr(name, "__init");
	if (!pos)

Annotation

Implementation Notes