Skip to content

Commit c6126f3

Browse files
jeromemarchandKernel Patches Daemon
authored andcommitted
selftests/bpf: Convert test_sysctl to prog_tests
Convert test_sysctl test to prog_tests with minimal change to the tests themselves. Signed-off-by: Jerome Marchand <[email protected]> Acked-by: Yonghong Song <[email protected]>
1 parent 6b1935d commit c6126f3

File tree

3 files changed

+10
-33
lines changed

3 files changed

+10
-33
lines changed

tools/testing/selftests/bpf/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ test_lirc_mode2_user
2121
flow_dissector_load
2222
test_tcpnotify_user
2323
test_libbpf
24-
test_sysctl
2524
xdping
2625
test_cpp
2726
*.d

tools/testing/selftests/bpf/Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ endif
7373
# Order correspond to 'make run_tests' order
7474
TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_progs \
7575
test_sockmap \
76-
test_tcpnotify_user test_sysctl \
76+
test_tcpnotify_user \
7777
test_progs-no_alu32
7878
TEST_INST_SUBDIRS := no_alu32
7979

@@ -220,7 +220,7 @@ ifeq ($(VMLINUX_BTF),)
220220
$(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)")
221221
endif
222222

223-
# Define simple and short `make test_progs`, `make test_sysctl`, etc targets
223+
# Define simple and short `make test_progs`, `make test_maps`, etc targets
224224
# to build individual tests.
225225
# NOTE: Semicolon at the end is critical to override lib.mk's default static
226226
# rule for binaries.
@@ -329,7 +329,6 @@ NETWORK_HELPERS := $(OUTPUT)/network_helpers.o
329329
$(OUTPUT)/test_sockmap: $(CGROUP_HELPERS) $(TESTING_HELPERS)
330330
$(OUTPUT)/test_tcpnotify_user: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(TRACE_HELPERS)
331331
$(OUTPUT)/test_sock_fields: $(CGROUP_HELPERS) $(TESTING_HELPERS)
332-
$(OUTPUT)/test_sysctl: $(CGROUP_HELPERS) $(TESTING_HELPERS)
333332
$(OUTPUT)/test_tag: $(TESTING_HELPERS)
334333
$(OUTPUT)/test_lirc_mode2_user: $(TESTING_HELPERS)
335334
$(OUTPUT)/xdping: $(TESTING_HELPERS)

tools/testing/selftests/bpf/test_sysctl.c renamed to tools/testing/selftests/bpf/prog_tests/test_sysctl.c

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
// SPDX-License-Identifier: GPL-2.0
22
// Copyright (c) 2019 Facebook
33

4-
#include <fcntl.h>
5-
#include <stdint.h>
6-
#include <stdio.h>
7-
#include <stdlib.h>
8-
#include <string.h>
9-
#include <unistd.h>
10-
11-
#include <linux/filter.h>
12-
13-
#include <bpf/bpf.h>
14-
#include <bpf/libbpf.h>
15-
16-
#include <bpf/bpf_endian.h>
17-
#include "bpf_util.h"
4+
#include "test_progs.h"
185
#include "cgroup_helpers.h"
19-
#include "testing_helpers.h"
206

217
#define CG_PATH "/foo"
228
#define MAX_INSNS 512
@@ -1608,26 +1594,19 @@ static int run_tests(int cgfd)
16081594
return fails ? -1 : 0;
16091595
}
16101596

1611-
int main(int argc, char **argv)
1597+
void test_sysctl(void)
16121598
{
1613-
int cgfd = -1;
1614-
int err = 0;
1599+
int cgfd;
16151600

16161601
cgfd = cgroup_setup_and_join(CG_PATH);
1617-
if (cgfd < 0)
1618-
goto err;
1602+
if (!ASSERT_OK_FD(cgfd < 0, "create_cgroup"))
1603+
goto out;
16191604

1620-
/* Use libbpf 1.0 API mode */
1621-
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
1605+
if (!ASSERT_OK(run_tests(cgfd), "run_tests"))
1606+
goto out;
16221607

1623-
if (run_tests(cgfd))
1624-
goto err;
1625-
1626-
goto out;
1627-
err:
1628-
err = -1;
16291608
out:
16301609
close(cgfd);
16311610
cleanup_cgroup_environment();
1632-
return err;
1611+
return;
16331612
}

0 commit comments

Comments
 (0)