[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260109082631.246647-3-dongml2@chinatelecom.cn>
Date: Fri, 9 Jan 2026 16:26:30 +0800
From: Menglong Dong <menglong8.dong@...il.com>
To: ast@...nel.org,
eddyz87@...il.com
Cc: daniel@...earbox.net,
john.fastabend@...il.com,
andrii@...nel.org,
martin.lau@...ux.dev,
song@...nel.org,
yonghong.song@...ux.dev,
kpsingh@...nel.org,
sdf@...ichev.me,
haoluo@...gle.com,
jolsa@...nel.org,
bpf@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH bpf-next v3 2/3] selftests/bpf: add TEST_TAG_KCONFIG_CHECK to test_loader
Add the __kconfig_check() to specify the kernel config for the test case.
The test case will be skipped if the specified Kconfig option is not
matched.
Signed-off-by: Menglong Dong <dongml2@...natelecom.cn>
---
tools/testing/selftests/bpf/progs/bpf_misc.h | 3 ++
tools/testing/selftests/bpf/test_loader.c | 46 +++++++++++++++++++-
2 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/progs/bpf_misc.h b/tools/testing/selftests/bpf/progs/bpf_misc.h
index c9bfbe1bafc1..e230f135f580 100644
--- a/tools/testing/selftests/bpf/progs/bpf_misc.h
+++ b/tools/testing/selftests/bpf/progs/bpf_misc.h
@@ -129,6 +129,8 @@
*
* __linear_size Specify the size of the linear area of non-linear skbs, or
* 0 for linear skbs.
+ *
+ * __kconfig_check The test case is skipped if the specified Kconfig option is not set.
*/
#define __msg(msg) __attribute__((btf_decl_tag("comment:test_expect_msg=" XSTR(__COUNTER__) "=" msg)))
#define __not_msg(msg) __attribute__((btf_decl_tag("comment:test_expect_not_msg=" XSTR(__COUNTER__) "=" msg)))
@@ -163,6 +165,7 @@
#define __stdout(msg) __attribute__((btf_decl_tag("comment:test_expect_stdout=" XSTR(__COUNTER__) "=" msg)))
#define __stdout_unpriv(msg) __attribute__((btf_decl_tag("comment:test_expect_stdout_unpriv=" XSTR(__COUNTER__) "=" msg)))
#define __linear_size(sz) __attribute__((btf_decl_tag("comment:test_linear_size=" XSTR(sz))))
+#define __kconfig_check(config) __attribute__((btf_decl_tag("comment:test_kconfig=" config)))
/* Define common capabilities tested using __caps_unpriv */
#define CAP_NET_ADMIN 12
diff --git a/tools/testing/selftests/bpf/test_loader.c b/tools/testing/selftests/bpf/test_loader.c
index 338c035c3688..a5fbd70e37d6 100644
--- a/tools/testing/selftests/bpf/test_loader.c
+++ b/tools/testing/selftests/bpf/test_loader.c
@@ -4,6 +4,9 @@
#include <stdlib.h>
#include <test_progs.h>
#include <bpf/btf.h>
+#include <gelf.h>
+#include <zlib.h>
+#include <sys/utsname.h>
#include "autoconf_helper.h"
#include "disasm_helpers.h"
@@ -44,6 +47,7 @@
#define TEST_TAG_EXPECT_STDOUT_PFX "comment:test_expect_stdout="
#define TEST_TAG_EXPECT_STDOUT_PFX_UNPRIV "comment:test_expect_stdout_unpriv="
#define TEST_TAG_LINEAR_SIZE "comment:test_linear_size="
+#define TEST_TAG_KCONFIG_CHECK "comment:test_kconfig="
/* Warning: duplicated in bpf_misc.h */
#define POINTER_VALUE 0xbadcafe
@@ -93,6 +97,7 @@ struct test_spec {
int linear_sz;
bool auxiliary;
bool valid;
+ bool skip;
};
static int tester_init(struct test_loader *tester)
@@ -394,6 +399,41 @@ static int get_current_arch(void)
return ARCH_UNKNOWN;
}
+static int kconfig_check(const char *kconfig)
+{
+ int len, err = -ENOENT;
+ char buf[PATH_MAX];
+ struct utsname uts;
+ gzFile file;
+
+ uname(&uts);
+ len = snprintf(buf, PATH_MAX, "/boot/config-%s", uts.release);
+ if (len < 0)
+ return -EINVAL;
+ else if (len >= PATH_MAX)
+ return -ENAMETOOLONG;
+
+ /* gzopen also accepts uncompressed files. */
+ file = gzopen(buf, "re");
+ if (!file)
+ file = gzopen("/proc/config.gz", "re");
+
+ if (!file) {
+ fprintf(stderr, "failed to open system Kconfig\n");
+ return -ENOENT;
+ }
+
+ while (gzgets(file, buf, sizeof(buf))) {
+ if (strstr(buf, kconfig)) {
+ err = 0;
+ break;
+ }
+ }
+
+ gzclose(file);
+ return err;
+}
+
/* Uses btf_decl_tag attributes to describe the expected test
* behavior, see bpf_misc.h for detailed description of each attribute
* and attribute combinations.
@@ -650,6 +690,10 @@ static int parse_test_spec(struct test_loader *tester,
err = -EINVAL;
goto cleanup;
}
+ } else if (str_has_pfx(s, TEST_TAG_KCONFIG_CHECK)) {
+ val = s + sizeof(TEST_TAG_KCONFIG_CHECK) - 1;
+ if (kconfig_check(val))
+ spec->skip = true;
}
}
@@ -1151,7 +1195,7 @@ void run_subtest(struct test_loader *tester,
if (!test__start_subtest(subspec->name))
return;
- if ((get_current_arch() & spec->arch_mask) == 0) {
+ if ((get_current_arch() & spec->arch_mask) == 0 || spec->skip) {
test__skip();
return;
}
--
2.52.0
Powered by blists - more mailing lists