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'.

v2 changes:
* add SKIP indication on the stdout

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

diff --git a/tools/testing/selftests/bpf/test_maps.c 
b/tools/testing/selftests/bpf/test_maps.c
index 9c79ee017df3..4b2cd6300153 100644
--- a/tools/testing/selftests/bpf/test_maps.c
+++ b/tools/testing/selftests/bpf/test_maps.c
@@ -21,6 +21,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <linux/bpf.h>
+#include <tools/config.h>
 
 #include <bpf/bpf.h>
 #include <bpf/libbpf.h>
@@ -32,7 +33,15 @@
 #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;
+static int skips = 0;
 
 #define CHECK(condition, tag, format...) ({                            \
        int __ret = !!(condition);                                      \
@@ -43,6 +52,16 @@ static int map_flags;
        }                                                               \
 })
 
+#define CHECK_CONFIG(opt) ({                                           \
+       if (!IS_BUILTIN(opt)) {                                         \
+               printf("%s SKIP "                                       \
+                      "(missing required config)\n",                   \
+                      __func__);                                       \
+               skips++;                                                \
+               return;                                                 \
+       }                                                               \
+})
+
 static void test_hashmap(int task, void *data)
 {
        long long key, next_key, first_key, value;
@@ -657,6 +676,8 @@ static void test_sockmap(int tasks, void *data)
        pid_t pid[tasks];
        fd_set w;
 
+       CHECK_CONFIG(CONFIG_BPF_STREAM_PARSER);
+
        /* Create some sockets to use with sockmap */
        for (i = 0; i < 2; i++) {
                sfd[i] = socket(AF_INET, SOCK_STREAM, 0);
@@ -1702,6 +1723,6 @@ int main(void)
        map_flags = BPF_F_NO_PREALLOC;
        run_all_tests();
 
-       printf("test_maps: OK\n");
+       printf("test_maps: OK, %d SKIPPED\n", skips);
        return 0;
 }
-- 
2.20.0.rc2.403.gdbc3b29805-goog

Reply via email to