Skip to content

Commit e8ddbfb

Browse files
fomichevborkmann
authored andcommitted
selftests/bpf: skip sockmap in test_maps if kernel doesn't have support
Use recently introduced bpf_probe_map_type() to skip test_sockmap() if map creation fails. The skipped test is indicated in the output. Example: test_sockmap SKIP (unsupported map type BPF_MAP_TYPE_SOCKMAP) Fork 1024 tasks to 'test_update_delete' ... test_sockmap SKIP (unsupported map type BPF_MAP_TYPE_SOCKMAP) Fork 1024 tasks to 'test_update_delete' ... test_maps: OK, 2 SKIPPED Signed-off-by: Stanislav Fomichev <sdf@google.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 630afc7 commit e8ddbfb

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tools/testing/selftests/bpf/test_maps.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#define ENOTSUPP 524
3333
#endif
3434

35+
static int skips;
36+
3537
static int map_flags;
3638

3739
#define CHECK(condition, tag, format...) ({ \
@@ -724,6 +726,15 @@ static void test_sockmap(int tasks, void *data)
724726
sizeof(key), sizeof(value),
725727
6, 0);
726728
if (fd < 0) {
729+
if (!bpf_probe_map_type(BPF_MAP_TYPE_SOCKMAP, 0)) {
730+
printf("%s SKIP (unsupported map type BPF_MAP_TYPE_SOCKMAP)\n",
731+
__func__);
732+
skips++;
733+
for (i = 0; i < 6; i++)
734+
close(sfd[i]);
735+
return;
736+
}
737+
727738
printf("Failed to create sockmap %i\n", fd);
728739
goto out_sockmap;
729740
}
@@ -1701,6 +1712,6 @@ int main(void)
17011712
map_flags = BPF_F_NO_PREALLOC;
17021713
run_all_tests();
17031714

1704-
printf("test_maps: OK\n");
1715+
printf("test_maps: OK, %d SKIPPED\n", skips);
17051716
return 0;
17061717
}

0 commit comments

Comments
 (0)