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

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

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/prog_tests/fsession_test.c
Extension
.c
Size
3039 bytes
Lines
141
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
/* Copyright (c) 2025 ChinaTelecom */
#include <test_progs.h>
#include "fsession_test.skel.h"

static int check_result(struct fsession_test *skel)
{
	LIBBPF_OPTS(bpf_test_run_opts, topts);
	int err, prog_fd;

	/* Trigger test function calls */
	prog_fd = bpf_program__fd(skel->progs.test1);
	err = bpf_prog_test_run_opts(prog_fd, &topts);
	if (!ASSERT_OK(err, "test_run_opts err"))
		return err;
	if (!ASSERT_OK(topts.retval, "test_run_opts retval"))
		return topts.retval;

	for (int i = 0; i < sizeof(*skel->bss) / sizeof(__u64); i++) {
		if (!ASSERT_EQ(((__u64 *)skel->bss)[i], 1, "test_result"))
			return -EINVAL;
	}

	return 0;
}

static void test_fsession_basic(void)
{
	struct fsession_test *skel = NULL;
	int err;

	skel = fsession_test__open();
	if (!ASSERT_OK_PTR(skel, "fsession_test__open"))
		return;

	err = fsession_test__load(skel);
	if (err == -EOPNOTSUPP) {
		test__skip();
		goto cleanup;
	}
	if (!ASSERT_OK(err, "fsession_test__load"))
		goto cleanup;

	err = fsession_test__attach(skel);
	if (!ASSERT_OK(err, "fsession_attach"))
		goto cleanup;

	check_result(skel);
cleanup:
	fsession_test__destroy(skel);
}

static void test_fsession_reattach(void)
{
	struct fsession_test *skel = NULL;
	int err;

	skel = fsession_test__open();
	if (!ASSERT_OK_PTR(skel, "fsession_test__open"))
		return;

	err = fsession_test__load(skel);
	if (err == -EOPNOTSUPP) {
		test__skip();
		goto cleanup;
	}
	if (!ASSERT_OK(err, "fsession_test__load"))
		goto cleanup;

	/* first attach */
	err = fsession_test__attach(skel);
	if (!ASSERT_OK(err, "fsession_first_attach"))
		goto cleanup;

	if (check_result(skel))
		goto cleanup;

	/* detach */
	fsession_test__detach(skel);

	/* reset counters */
	memset(skel->bss, 0, sizeof(*skel->bss));

	/* second attach */
	err = fsession_test__attach(skel);
	if (!ASSERT_OK(err, "fsession_second_attach"))
		goto cleanup;

	if (check_result(skel))
		goto cleanup;

Annotation

Implementation Notes