tools/testing/selftests/bpf/prog_tests/bloom_filter_map.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/bloom_filter_map.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/bloom_filter_map.c- Extension
.c- Size
- 6283 bytes
- Lines
- 225
- 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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sys/syscall.hlimits.htest_progs.hbloom_filter_map.skel.h
Detected Declarations
function test_fail_casesfunction test_success_casesfunction check_bloomfunction test_inner_mapfunction setup_progsfunction test_bloom_filter_map
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2021 Facebook */
#include <sys/syscall.h>
#include <limits.h>
#include <test_progs.h>
#include "bloom_filter_map.skel.h"
#ifndef NUMA_NO_NODE
#define NUMA_NO_NODE (-1)
#endif
static void test_fail_cases(void)
{
LIBBPF_OPTS(bpf_map_create_opts, opts);
__u32 value = 0;
int fd, err;
/* Invalid key size */
fd = bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, NULL, 4, sizeof(value), 100, NULL);
if (!ASSERT_LT(fd, 0, "bpf_map_create bloom filter invalid key size"))
close(fd);
/* Invalid value size */
fd = bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, NULL, 0, 0, 100, NULL);
if (!ASSERT_LT(fd, 0, "bpf_map_create bloom filter invalid value size 0"))
close(fd);
/* Invalid value size: too big */
fd = bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, NULL, 0, INT32_MAX, 100, NULL);
if (!ASSERT_LT(fd, 0, "bpf_map_create bloom filter invalid value too large"))
close(fd);
/* Invalid max entries size */
fd = bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, NULL, 0, sizeof(value), 0, NULL);
if (!ASSERT_LT(fd, 0, "bpf_map_create bloom filter invalid max entries size"))
close(fd);
/* Bloom filter maps do not support BPF_F_NO_PREALLOC */
opts.map_flags = BPF_F_NO_PREALLOC;
fd = bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, NULL, 0, sizeof(value), 100, &opts);
if (!ASSERT_LT(fd, 0, "bpf_map_create bloom filter invalid flags"))
close(fd);
fd = bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, NULL, 0, sizeof(value), 100, NULL);
if (!ASSERT_GE(fd, 0, "bpf_map_create bloom filter"))
return;
/* Test invalid flags */
err = bpf_map_update_elem(fd, NULL, &value, -1);
ASSERT_EQ(err, -EINVAL, "bpf_map_update_elem bloom filter invalid flags");
err = bpf_map_update_elem(fd, NULL, &value, BPF_EXIST);
ASSERT_EQ(err, -EINVAL, "bpf_map_update_elem bloom filter invalid flags");
err = bpf_map_update_elem(fd, NULL, &value, BPF_F_LOCK);
ASSERT_EQ(err, -EINVAL, "bpf_map_update_elem bloom filter invalid flags");
err = bpf_map_update_elem(fd, NULL, &value, BPF_NOEXIST);
ASSERT_EQ(err, -EINVAL, "bpf_map_update_elem bloom filter invalid flags");
err = bpf_map_update_elem(fd, NULL, &value, 10000);
ASSERT_EQ(err, -EINVAL, "bpf_map_update_elem bloom filter invalid flags");
close(fd);
}
static void test_success_cases(void)
{
LIBBPF_OPTS(bpf_map_create_opts, opts);
char value[11];
int fd, err;
/* Create a map */
opts.map_flags = BPF_F_ZERO_SEED | BPF_F_NUMA_NODE;
opts.numa_node = NUMA_NO_NODE;
fd = bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, NULL, 0, sizeof(value), 100, &opts);
if (!ASSERT_GE(fd, 0, "bpf_map_create bloom filter success case"))
return;
/* Add a value to the bloom filter */
err = bpf_map_update_elem(fd, NULL, &value, 0);
if (!ASSERT_OK(err, "bpf_map_update_elem bloom filter success case"))
goto done;
/* Lookup a value in the bloom filter */
err = bpf_map_lookup_elem(fd, NULL, &value);
ASSERT_OK(err, "bpf_map_update_elem bloom filter success case");
done:
Annotation
- Immediate include surface: `sys/syscall.h`, `limits.h`, `test_progs.h`, `bloom_filter_map.skel.h`.
- Detected declarations: `function test_fail_cases`, `function test_success_cases`, `function check_bloom`, `function test_inner_map`, `function setup_progs`, `function test_bloom_filter_map`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.