Skip to content

Commit 017602a

Browse files
yonghong-songNobody
authored andcommitted
selftests/bpf: skip btf_tag test if btf_tag attribute not supported
Commit c240ba2 ("selftests/bpf: Add a test with a bpf program with btf_tag attributes") added btf_tag selftest to test BTF_KIND_TAG generation from C source code, and to test kernel validation of generated BTF types. But if an old clang (clang 13 or earlier) is used, the following compiler warning may be seen: progs/tag.c:23:20: warning: unknown attribute 'btf_tag' ignored and the test itself is marked OK. The compiler warning is bad and the test itself shouldn't be marked OK. This patch added the check for btf_tag attribute support. If btf_tag is not supported by the clang, the attribute will not be used in the code and the test will be marked as skipped. For example, with clang 13: ./test_progs -t btf_tag #21 btf_tag:SKIP Summary: 1/0 PASSED, 1 SKIPPED, 0 FAILED The selftests/README.rst is updated to clarify when the btf_tag test may be skipped. Signed-off-by: Yonghong Song <[email protected]>
1 parent bd975ca commit 017602a

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

tools/testing/selftests/bpf/README.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,20 @@ Without it, the error from compiling bpf selftests looks like:
201201
202202
__ https://reviews.llvm.org/D93563
203203

204+
btf_tag test and Clang version
205+
==============================
206+
207+
The btf_tag selftest require LLVM support to recognize the btf_tag attribute.
208+
It was introduced in `Clang 14`__.
209+
210+
Without it, the btf_tag selftest will be skipped and you will observe:
211+
212+
.. code-block:: console
213+
214+
#<test_num> btf_tag:SKIP
215+
216+
__ https://reviews.llvm.org/D106614
217+
204218
Clang dependencies for static linking tests
205219
===========================================
206220

tools/testing/selftests/bpf/prog_tests/btf_tag.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@ void test_btf_tag(void)
1010
skel = tag__open_and_load();
1111
if (!ASSERT_OK_PTR(skel, "btf_tag"))
1212
return;
13+
14+
if (skel->rodata->skip_tests) {
15+
printf("%s:SKIP: btf_tag attribute not supported", __func__);
16+
test__skip();
17+
}
18+
1319
tag__destroy(skel);
1420
}

tools/testing/selftests/bpf/progs/tag.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@
44
#include <bpf/bpf_helpers.h>
55
#include <bpf/bpf_tracing.h>
66

7+
#ifndef __has_attribute
8+
#define __has_attribute(x) 0
9+
#endif
10+
11+
#if __has_attribute(btf_tag)
712
#define __tag1 __attribute__((btf_tag("tag1")))
813
#define __tag2 __attribute__((btf_tag("tag2")))
14+
volatile const bool skip_tests __tag1 __tag2 = false;
15+
#else
16+
#define __tag1
17+
#define __tag2
18+
volatile const bool skip_tests = true;
19+
#endif
920

1021
struct key_t {
1122
int a;
@@ -20,7 +31,6 @@ struct {
2031
__type(value, __u64);
2132
} hashmap1 SEC(".maps");
2233

23-
__u32 total __tag1 __tag2 = 0;
2434

2535
static __noinline int foo(int x __tag1 __tag2) __tag1 __tag2
2636
{

0 commit comments

Comments
 (0)