]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: inline TEST_TAG constants in test_loader.c
authorEduard Zingerman <eddyz87@gmail.com>
Sat, 11 Apr 2026 07:33:47 +0000 (00:33 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 11 Apr 2026 14:17:06 +0000 (07:17 -0700)
After str_has_pfx() refactoring each TEST_TAG_* / TEST_BTF_PATH
constant is used exactly once. Since constant definitions are not
shared between BPF-side bpf_misc.h and userspace side test_loader.c,
there is no need in the additional redirection layer.

Acked-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Reviewed-by: Puranjay Mohan <puranjay@kernel.org>
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20260410-selftests-global-tags-ordering-v2-4-c566ec9781bf@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/test_loader.c

index 066898d0c1236f678fa7e3664faf1e73019813f6..c4c34cae61027d8e1931e31535a41274c5312e3a 100644 (file)
@@ -21,34 +21,6 @@ static inline const char *str_has_pfx(const char *str, const char *pfx)
 
 #define TEST_LOADER_LOG_BUF_SZ 2097152
 
-#define TEST_TAG_EXPECT_FAILURE "test_expect_failure"
-#define TEST_TAG_EXPECT_SUCCESS "test_expect_success"
-#define TEST_TAG_EXPECT_MSG_PFX "test_expect_msg="
-#define TEST_TAG_EXPECT_NOT_MSG_PFX "test_expect_not_msg="
-#define TEST_TAG_EXPECT_XLATED_PFX "test_expect_xlated="
-#define TEST_TAG_EXPECT_FAILURE_UNPRIV "test_expect_failure_unpriv"
-#define TEST_TAG_EXPECT_SUCCESS_UNPRIV "test_expect_success_unpriv"
-#define TEST_TAG_EXPECT_MSG_PFX_UNPRIV "test_expect_msg_unpriv="
-#define TEST_TAG_EXPECT_NOT_MSG_PFX_UNPRIV "test_expect_not_msg_unpriv="
-#define TEST_TAG_EXPECT_XLATED_PFX_UNPRIV "test_expect_xlated_unpriv="
-#define TEST_TAG_LOG_LEVEL_PFX "test_log_level="
-#define TEST_TAG_PROG_FLAGS_PFX "test_prog_flags="
-#define TEST_TAG_DESCRIPTION_PFX "test_description="
-#define TEST_TAG_RETVAL_PFX "test_retval="
-#define TEST_TAG_RETVAL_PFX_UNPRIV "test_retval_unpriv="
-#define TEST_TAG_AUXILIARY "test_auxiliary"
-#define TEST_TAG_AUXILIARY_UNPRIV "test_auxiliary_unpriv"
-#define TEST_BTF_PATH "test_btf_path="
-#define TEST_TAG_ARCH "test_arch="
-#define TEST_TAG_JITED_PFX "test_jited="
-#define TEST_TAG_JITED_PFX_UNPRIV "test_jited_unpriv="
-#define TEST_TAG_CAPS_UNPRIV "test_caps_unpriv="
-#define TEST_TAG_LOAD_MODE_PFX "load_mode="
-#define TEST_TAG_EXPECT_STDERR_PFX "test_expect_stderr="
-#define TEST_TAG_EXPECT_STDERR_PFX_UNPRIV "test_expect_stderr_unpriv="
-#define TEST_TAG_EXPECT_STDOUT_PFX "test_expect_stdout="
-#define TEST_TAG_EXPECT_STDOUT_PFX_UNPRIV "test_expect_stdout_unpriv="
-#define TEST_TAG_LINEAR_SIZE "test_linear_size="
 
 /* Warning: duplicated in bpf_misc.h */
 #define POINTER_VALUE  0xbadcafe
@@ -478,49 +450,49 @@ static int parse_test_spec(struct test_loader *tester,
                s = skip_decl_tag_pfx(tags[i]);
                if (!s)
                        continue;
-               if ((val = str_has_pfx(s, TEST_TAG_DESCRIPTION_PFX))) {
+               if ((val = str_has_pfx(s, "test_description="))) {
                        description = val;
-               } else if (strcmp(s, TEST_TAG_EXPECT_FAILURE) == 0) {
+               } else if (strcmp(s, "test_expect_failure") == 0) {
                        spec->priv.expect_failure = true;
                        spec->mode_mask |= PRIV;
-               } else if (strcmp(s, TEST_TAG_EXPECT_SUCCESS) == 0) {
+               } else if (strcmp(s, "test_expect_success") == 0) {
                        spec->priv.expect_failure = false;
                        spec->mode_mask |= PRIV;
-               } else if (strcmp(s, TEST_TAG_EXPECT_FAILURE_UNPRIV) == 0) {
+               } else if (strcmp(s, "test_expect_failure_unpriv") == 0) {
                        spec->unpriv.expect_failure = true;
                        spec->mode_mask |= UNPRIV;
                        has_unpriv_result = true;
-               } else if (strcmp(s, TEST_TAG_EXPECT_SUCCESS_UNPRIV) == 0) {
+               } else if (strcmp(s, "test_expect_success_unpriv") == 0) {
                        spec->unpriv.expect_failure = false;
                        spec->mode_mask |= UNPRIV;
                        has_unpriv_result = true;
-               } else if (strcmp(s, TEST_TAG_AUXILIARY) == 0) {
+               } else if (strcmp(s, "test_auxiliary") == 0) {
                        spec->auxiliary = true;
                        spec->mode_mask |= PRIV;
-               } else if (strcmp(s, TEST_TAG_AUXILIARY_UNPRIV) == 0) {
+               } else if (strcmp(s, "test_auxiliary_unpriv") == 0) {
                        spec->auxiliary = true;
                        spec->mode_mask |= UNPRIV;
-               } else if ((msg = str_has_pfx(s, TEST_TAG_EXPECT_MSG_PFX))) {
+               } else if ((msg = str_has_pfx(s, "test_expect_msg="))) {
                        err = push_msg(msg, false, &spec->priv.expect_msgs);
                        if (err)
                                goto cleanup;
                        spec->mode_mask |= PRIV;
-               } else if ((msg = str_has_pfx(s, TEST_TAG_EXPECT_NOT_MSG_PFX))) {
+               } else if ((msg = str_has_pfx(s, "test_expect_not_msg="))) {
                        err = push_msg(msg, true, &spec->priv.expect_msgs);
                        if (err)
                                goto cleanup;
                        spec->mode_mask |= PRIV;
-               } else if ((msg = str_has_pfx(s, TEST_TAG_EXPECT_MSG_PFX_UNPRIV))) {
+               } else if ((msg = str_has_pfx(s, "test_expect_msg_unpriv="))) {
                        err = push_msg(msg, false, &spec->unpriv.expect_msgs);
                        if (err)
                                goto cleanup;
                        spec->mode_mask |= UNPRIV;
-               } else if ((msg = str_has_pfx(s, TEST_TAG_EXPECT_NOT_MSG_PFX_UNPRIV))) {
+               } else if ((msg = str_has_pfx(s, "test_expect_not_msg_unpriv="))) {
                        err = push_msg(msg, true, &spec->unpriv.expect_msgs);
                        if (err)
                                goto cleanup;
                        spec->mode_mask |= UNPRIV;
-               } else if ((msg = str_has_pfx(s, TEST_TAG_JITED_PFX))) {
+               } else if ((msg = str_has_pfx(s, "test_jited="))) {
                        if (arch_mask == 0) {
                                PRINT_FAIL("__jited used before __arch_*");
                                goto cleanup;
@@ -532,7 +504,7 @@ static int parse_test_spec(struct test_loader *tester,
                                        goto cleanup;
                                spec->mode_mask |= PRIV;
                        }
-               } else if ((msg = str_has_pfx(s, TEST_TAG_JITED_PFX_UNPRIV))) {
+               } else if ((msg = str_has_pfx(s, "test_jited_unpriv="))) {
                        if (arch_mask == 0) {
                                PRINT_FAIL("__unpriv_jited used before __arch_*");
                                goto cleanup;
@@ -544,36 +516,36 @@ static int parse_test_spec(struct test_loader *tester,
                                        goto cleanup;
                                spec->mode_mask |= UNPRIV;
                        }
-               } else if ((msg = str_has_pfx(s, TEST_TAG_EXPECT_XLATED_PFX))) {
+               } else if ((msg = str_has_pfx(s, "test_expect_xlated="))) {
                        err = push_disasm_msg(msg, &xlated_on_next_line,
                                              &spec->priv.expect_xlated);
                        if (err)
                                goto cleanup;
                        spec->mode_mask |= PRIV;
-               } else if ((msg = str_has_pfx(s, TEST_TAG_EXPECT_XLATED_PFX_UNPRIV))) {
+               } else if ((msg = str_has_pfx(s, "test_expect_xlated_unpriv="))) {
                        err = push_disasm_msg(msg, &unpriv_xlated_on_next_line,
                                              &spec->unpriv.expect_xlated);
                        if (err)
                                goto cleanup;
                        spec->mode_mask |= UNPRIV;
-               } else if ((val = str_has_pfx(s, TEST_TAG_RETVAL_PFX))) {
+               } else if ((val = str_has_pfx(s, "test_retval="))) {
                        err = parse_retval(val, &spec->priv.retval, "__retval");
                        if (err)
                                goto cleanup;
                        spec->priv.execute = true;
                        spec->mode_mask |= PRIV;
-               } else if ((val = str_has_pfx(s, TEST_TAG_RETVAL_PFX_UNPRIV))) {
+               } else if ((val = str_has_pfx(s, "test_retval_unpriv="))) {
                        err = parse_retval(val, &spec->unpriv.retval, "__retval_unpriv");
                        if (err)
                                goto cleanup;
                        spec->mode_mask |= UNPRIV;
                        spec->unpriv.execute = true;
                        has_unpriv_retval = true;
-               } else if ((val = str_has_pfx(s, TEST_TAG_LOG_LEVEL_PFX))) {
+               } else if ((val = str_has_pfx(s, "test_log_level="))) {
                        err = parse_int(val, &spec->log_level, "test log level");
                        if (err)
                                goto cleanup;
-               } else if ((val = str_has_pfx(s, TEST_TAG_PROG_FLAGS_PFX))) {
+               } else if ((val = str_has_pfx(s, "test_prog_flags="))) {
                        clear = val[0] == '!';
                        if (clear)
                                val++;
@@ -598,7 +570,7 @@ static int parse_test_spec(struct test_loader *tester,
                                        goto cleanup;
                                update_flags(&spec->prog_flags, flags, clear);
                        }
-               } else if ((val = str_has_pfx(s, TEST_TAG_ARCH))) {
+               } else if ((val = str_has_pfx(s, "test_arch="))) {
                        if (strcmp(val, "X86_64") == 0) {
                                arch = ARCH_X86_64;
                        } else if (strcmp(val, "ARM64") == 0) {
@@ -616,14 +588,14 @@ static int parse_test_spec(struct test_loader *tester,
                        collect_jit = get_current_arch() == arch;
                        unpriv_jit_on_next_line = true;
                        jit_on_next_line = true;
-               } else if ((val = str_has_pfx(s, TEST_BTF_PATH))) {
+               } else if ((val = str_has_pfx(s, "test_btf_path="))) {
                        spec->btf_custom_path = val;
-               } else if ((val = str_has_pfx(s, TEST_TAG_CAPS_UNPRIV))) {
+               } else if ((val = str_has_pfx(s, "test_caps_unpriv="))) {
                        err = parse_caps(val, &spec->unpriv.caps, "test caps");
                        if (err)
                                goto cleanup;
                        spec->mode_mask |= UNPRIV;
-               } else if ((val = str_has_pfx(s, TEST_TAG_LOAD_MODE_PFX))) {
+               } else if ((val = str_has_pfx(s, "load_mode="))) {
                        if (strcmp(val, "jited") == 0) {
                                load_mask = JITED;
                        } else if (strcmp(val, "no_jited") == 0) {
@@ -633,27 +605,27 @@ static int parse_test_spec(struct test_loader *tester,
                                err = -EINVAL;
                                goto cleanup;
                        }
-               } else if ((msg = str_has_pfx(s, TEST_TAG_EXPECT_STDERR_PFX))) {
+               } else if ((msg = str_has_pfx(s, "test_expect_stderr="))) {
                        err = push_disasm_msg(msg, &stderr_on_next_line,
                                              &spec->priv.stderr);
                        if (err)
                                goto cleanup;
-               } else if ((msg = str_has_pfx(s, TEST_TAG_EXPECT_STDERR_PFX_UNPRIV))) {
+               } else if ((msg = str_has_pfx(s, "test_expect_stderr_unpriv="))) {
                        err = push_disasm_msg(msg, &unpriv_stderr_on_next_line,
                                              &spec->unpriv.stderr);
                        if (err)
                                goto cleanup;
-               } else if ((msg = str_has_pfx(s, TEST_TAG_EXPECT_STDOUT_PFX))) {
+               } else if ((msg = str_has_pfx(s, "test_expect_stdout="))) {
                        err = push_disasm_msg(msg, &stdout_on_next_line,
                                              &spec->priv.stdout);
                        if (err)
                                goto cleanup;
-               } else if ((msg = str_has_pfx(s, TEST_TAG_EXPECT_STDOUT_PFX_UNPRIV))) {
+               } else if ((msg = str_has_pfx(s, "test_expect_stdout_unpriv="))) {
                        err = push_disasm_msg(msg, &unpriv_stdout_on_next_line,
                                              &spec->unpriv.stdout);
                        if (err)
                                goto cleanup;
-               } else if ((val = str_has_pfx(s, TEST_TAG_LINEAR_SIZE))) {
+               } else if ((val = str_has_pfx(s, "test_linear_size="))) {
                        switch (bpf_program__type(prog)) {
                        case BPF_PROG_TYPE_SCHED_ACT:
                        case BPF_PROG_TYPE_SCHED_CLS: