linux/tools/testing/selftests/bpf/prog_tests/arena_strsearch.c
Alexei Starovoitov 63066b7a8e selftests/bpf: Convert glob_match() to bpf arena
Increase arena test coverage.
Convert glob_match() to bpf arena in two steps:
1.
Copy paste lib/glob.c into bpf_arena_strsearch.h
Copy paste lib/globtests.c into progs/arena_strsearch.c

2.
Add __arena to pointers
Add __arg_arena to global functions that accept arena pointers
Add cond_break to loops

The test also serves as a good example of what's possible
with bpf arena and how existing algorithms can be converted.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20251111032931.21430-1-alexei.starovoitov@gmail.com
2025-11-14 13:57:28 -08:00

31 lines
783 B
C

// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
#include <test_progs.h>
#include "arena_strsearch.skel.h"
static void test_arena_str(void)
{
LIBBPF_OPTS(bpf_test_run_opts, opts);
struct arena_strsearch *skel;
int ret;
skel = arena_strsearch__open_and_load();
if (!ASSERT_OK_PTR(skel, "arena_strsearch__open_and_load"))
return;
ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.arena_strsearch), &opts);
ASSERT_OK(ret, "ret_add");
ASSERT_OK(opts.retval, "retval");
if (skel->bss->skip) {
printf("%s:SKIP:compiler doesn't support arena_cast\n", __func__);
test__skip();
}
arena_strsearch__destroy(skel);
}
void test_arena_strsearch(void)
{
if (test__start_subtest("arena_strsearch"))
test_arena_str();
}