mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Menglong Dong <menglong8.dong@gmail.com>
To: ast@kernel.org, eddyz87@gmail.com
Cc: daniel@iogearbox.net, john.fastabend@gmail.com,
	andrii@kernel.org, martin.lau@linux.dev, song@kernel.org,
	yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me,
	haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH bpf-next v3 2/3] selftests/bpf: add TEST_TAG_KCONFIG_CHECK to test_loader
Date: Fri,  9 Jan 2026 16:26:30 +0800	[thread overview]
Message-ID: <20260109082631.246647-3-dongml2@chinatelecom.cn> (raw)
In-Reply-To: <20260109082631.246647-1-dongml2@chinatelecom.cn>

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@chinatelecom.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


  parent reply	other threads:[~2026-01-09  8:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-09  8:26 [PATCH bpf-next v3 0/3] bpf, x86: inline bpf_get_current_task() for x86_64 Menglong Dong
2026-01-09  8:26 ` [PATCH bpf-next v3 1/3] " Menglong Dong
2026-01-09  8:42   ` Menglong Dong
2026-01-10  3:43   ` Menglong Dong
2026-01-09  8:26 ` Menglong Dong [this message]
2026-01-09  8:26 ` [PATCH bpf-next v3 3/3] selftests/bpf: test the jited inline of bpf_get_current_task Menglong Dong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260109082631.246647-3-dongml2@chinatelecom.cn \
    --to=menglong8.dong@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®