Message ID | b38450e4a57c49afc57d0a5876857cf219847f42.1544474487.git.sdf@google.com |
---|---|
State | Accepted, archived |
Delegated to: | BPF Maintainers |
Headers | show |
Series | [bpf-next,v2,1/2] selftests/bpf: skip maps sockmap tests on kernels without support | expand |
On 12/10/2018 09:43 PM, 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'. > > v2 changes: > * add SKIP indication on the stdout > > Signed-off-by: Stanislav Fomichev <sdf@google.com> The kconfig selection for skipping features feels slightly random ;), but the infrastructure seems useful in general and we might extend it to other cases in future, thus applied to bpf-next, thanks!
On 12/12, Daniel Borkmann wrote: > On 12/10/2018 09:43 PM, 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'. > > > > v2 changes: > > * add SKIP indication on the stdout > > > > Signed-off-by: Stanislav Fomichev <sdf@google.com> > > The kconfig selection for skipping features feels slightly random ;), Yeah, I fixed the obvious issues with my current setup :-) > but the infrastructure seems useful in general and we might extend > it to other cases in future, thus applied to bpf-next, thanks! I'll try to follow up with more cases in the future, thanks for taking this!
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; }
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 <sdf@google.com> --- tools/testing/selftests/bpf/test_maps.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)