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

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

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/prog_tests/map_ops.c
Extension
.c
Size
3126 bytes
Lines
163
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) 2023 Meta Platforms, Inc. and affiliates. */

#include <errno.h>
#include <sys/syscall.h>
#include <unistd.h>

#include "test_map_ops.skel.h"
#include "test_progs.h"

static void map_update(void)
{
	(void)syscall(__NR_getpid);
}

static void map_delete(void)
{
	(void)syscall(__NR_getppid);
}

static void map_push(void)
{
	(void)syscall(__NR_getuid);
}

static void map_pop(void)
{
	(void)syscall(__NR_geteuid);
}

static void map_peek(void)
{
	(void)syscall(__NR_getgid);
}

static void map_for_each_pass(void)
{
	(void)syscall(__NR_gettid);
}

static void map_for_each_fail(void)
{
	(void)syscall(__NR_getpgid);
}

static int setup(struct test_map_ops **skel)
{
	int err = 0;

	if (!skel)
		return -1;

	*skel = test_map_ops__open();
	if (!ASSERT_OK_PTR(*skel, "test_map_ops__open"))
		return -1;

	(*skel)->rodata->pid = getpid();

	err = test_map_ops__load(*skel);
	if (!ASSERT_OK(err, "test_map_ops__load"))
		return err;

	err = test_map_ops__attach(*skel);
	if (!ASSERT_OK(err, "test_map_ops__attach"))
		return err;

	return err;
}

static void teardown(struct test_map_ops **skel)
{
	if (skel && *skel)
		test_map_ops__destroy(*skel);
}

static void map_ops_update_delete_subtest(void)
{
	struct test_map_ops *skel;

	if (setup(&skel))
		goto teardown;

	map_update();
	ASSERT_OK(skel->bss->err, "map_update_initial");

	map_update();
	ASSERT_LT(skel->bss->err, 0, "map_update_existing");
	ASSERT_EQ(skel->bss->err, -EEXIST, "map_update_existing");

	map_delete();

Annotation

Implementation Notes