[bpf] selftests/bpf: skip sockmap tests on kernels without support

Message ID f215ba8356288b442e18f01050e0599886dad3e5.1544153769.git.sdf@google.com
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series
  • [bpf] selftests/bpf: skip sockmap tests on kernels without support
Related show

Commit Message

Stanislav Fomichev Dec. 7, 2018, 3:39 a.m.
Include "autoconf.h" header in the test_maps.c and selectively
disable test_sockmap if CONFIG_BPF_STREAM_PARSER is not specified
in the kernel config.
When building out of tree/without autoconf.h, fall back to 'enabled'.

Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
 tools/testing/selftests/bpf/test_maps.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Jakub Kicinski Dec. 10, 2018, 12:35 a.m. | #1
On Thu,  6 Dec 2018 19:39:06 -0800, Stanislav Fomichev wrote:
> Include "autoconf.h" header in the test_maps.c and selectively
> disable test_sockmap if CONFIG_BPF_STREAM_PARSER is not specified
> in the kernel config.
> When building out of tree/without autoconf.h, fall back to 'enabled'.
> 
> Signed-off-by: Stanislav Fomichev <sdf@google.com>

No opinion on the merits, but if we are to skip tests I think its
better to use SKIP result.  IMHO its better for person running the test
to know they are not running all the tests than have them silently
disappear.

If we were to conditionally skip tests should we also tackle the
test_verifier cases which require sockmap?

#274/p prevent map lookup in sockmap Failed to create hash map 'Invalid argument'!
FAIL
Unexpected error message!
	EXP: cannot pass map_type 15 into func bpf_map_lookup_elem
	RES: fd -1 is not pointing to valid bpf_map

fd -1 is not pointing to valid bpf_map
#275/p prevent map lookup in sockhash Failed to create hash map 'Invalid argument'!
FAIL
Unexpected error message!
	EXP: cannot pass map_type 18 into func bpf_map_lookup_elem
	RES: fd -1 is not pointing to valid bpf_map

fd -1 is not pointing to valid bpf_map
David Miller Dec. 10, 2018, 12:53 a.m. | #2
From: Jakub Kicinski <jakub.kicinski@netronome.com>
Date: Sun, 9 Dec 2018 16:35:16 -0800

> IMHO its better for person running the test to know they are not
> running all the tests than have them silently disappear.

Agreed.
Stanislav Fomichev Dec. 10, 2018, 7:22 p.m. | #3
On 12/09, Jakub Kicinski wrote:
> On Thu,  6 Dec 2018 19:39:06 -0800, Stanislav Fomichev wrote:
> > Include "autoconf.h" header in the test_maps.c and selectively
> > disable test_sockmap if CONFIG_BPF_STREAM_PARSER is not specified
> > in the kernel config.
> > When building out of tree/without autoconf.h, fall back to 'enabled'.
> > 
> > Signed-off-by: Stanislav Fomichev <sdf@google.com>
> 
> No opinion on the merits, but if we are to skip tests I think its
> better to use SKIP result.  IMHO its better for person running the test
> to know they are not running all the tests than have them silently
> disappear.
SGTM, I'll add some indication that there were X tests skipped.

> If we were to conditionally skip tests should we also tackle the
> test_verifier cases which require sockmap?
Yes, I was going to follow up on that, I just wanted to get some
initial response on the idea of skipping the tests based on .config

> #274/p prevent map lookup in sockmap Failed to create hash map 'Invalid argument'!
> FAIL
> Unexpected error message!
> 	EXP: cannot pass map_type 15 into func bpf_map_lookup_elem
> 	RES: fd -1 is not pointing to valid bpf_map
> 
> fd -1 is not pointing to valid bpf_map
> #275/p prevent map lookup in sockhash Failed to create hash map 'Invalid argument'!
> FAIL
> Unexpected error message!
> 	EXP: cannot pass map_type 18 into func bpf_map_lookup_elem
> 	RES: fd -1 is not pointing to valid bpf_map
> 
> fd -1 is not pointing to valid bpf_map

Patch

diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c
index 4db2116e52be..3548de8a78ac 100644
--- a/tools/testing/selftests/bpf/test_maps.c
+++ b/tools/testing/selftests/bpf/test_maps.c
@@ -32,6 +32,13 @@ 
 #define ENOTSUPP 524
 #endif
 
+#ifdef HAVE_GENHDR
+# include "autoconf.h"
+#else
+/* fallback to all features enabled */
+# define CONFIG_BPF_STREAM_PARSER 1
+#endif
+
 static int map_flags;
 
 #define CHECK(condition, tag, format...) ({				\
@@ -588,6 +595,7 @@  static void test_stackmap(int task, void *data)
 	close(fd);
 }
 
+#ifdef CONFIG_BPF_STREAM_PARSER
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <arpa/inet.h>
@@ -1079,6 +1087,7 @@  static void test_sockmap(int tasks, void *data)
 	close(fd);
 	exit(1);
 }
+#endif
 
 #define MAP_SIZE (32 * 1024)
 
@@ -1541,7 +1550,9 @@  static void run_all_tests(void)
 	test_arraymap_percpu_many_keys();
 
 	test_devmap(0, NULL);
+#ifdef CONFIG_BPF_STREAM_PARSER
 	test_sockmap(0, NULL);
+#endif
 
 	test_map_large();
 	test_map_parallel();