BPF Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/8] selftests/bpf: installation and out of tree build fixes
@ 2020-05-22  4:13 Yauheni Kaliuta
  2020-05-22  4:13 ` [PATCH 1/8] selftests/bpf: remove test_align from Makefile Yauheni Kaliuta
                   ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: Yauheni Kaliuta @ 2020-05-22  4:13 UTC (permalink / raw)
  To: bpf; +Cc: Jiri Benc, Jiri Olsa, Andrii Nakryiko, Daniel Borkmann

I had a look, here are some fixes.

Yauheni Kaliuta (8):
  selftests/bpf: remove test_align from Makefile
  selftests/bpf: build bench.o for any $(OUTPUT)
  selftests/bpf: install btf .c files
  selftests/bpf: fix object files installation
  selftests/bpf: add output dir to include list
  selftests/bpf: fix urandom_read installation
  selftests/bpf: fix test.h placing for out of tree build
  selftests/bpf: factor out MKDIR rule

 tools/testing/selftests/bpf/Makefile | 77 ++++++++++++++++++++--------
 1 file changed, 55 insertions(+), 22 deletions(-)

-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/8] selftests/bpf: remove test_align from Makefile
  2020-05-22  4:13 [PATCH 0/8] selftests/bpf: installation and out of tree build fixes Yauheni Kaliuta
@ 2020-05-22  4:13 ` Yauheni Kaliuta
  2020-05-22  4:13 ` [PATCH 2/8] selftests/bpf: build bench.o for any $(OUTPUT) Yauheni Kaliuta
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Yauheni Kaliuta @ 2020-05-22  4:13 UTC (permalink / raw)
  To: bpf; +Cc: Jiri Benc, Jiri Olsa, Andrii Nakryiko, Daniel Borkmann

test_align has been moved under test_progs.

Fixes: 3b09d27cc93d ("selftests/bpf: Move test_align under
test_progs")

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 tools/testing/selftests/bpf/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index e716e931d0c9..09700db35c2d 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -30,7 +30,7 @@ LDLIBS += -lcap -lelf -lz -lrt -lpthread
 
 # Order correspond to 'make run_tests' order
 TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
-	test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \
+	test_verifier_log test_dev_cgroup test_tcpbpf_user \
 	test_sock test_btf test_sockmap get_cgroup_id_user test_socket_cookie \
 	test_cgroup_storage \
 	test_netcnt test_tcpnotify_user test_sock_fields test_sysctl \
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 2/8] selftests/bpf: build bench.o for any $(OUTPUT)
  2020-05-22  4:13 [PATCH 0/8] selftests/bpf: installation and out of tree build fixes Yauheni Kaliuta
  2020-05-22  4:13 ` [PATCH 1/8] selftests/bpf: remove test_align from Makefile Yauheni Kaliuta
@ 2020-05-22  4:13 ` Yauheni Kaliuta
  2020-05-22  4:13 ` [PATCH 3/8] selftests/bpf: install btf .c files Yauheni Kaliuta
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Yauheni Kaliuta @ 2020-05-22  4:13 UTC (permalink / raw)
  To: bpf; +Cc: Jiri Benc, Jiri Olsa, Andrii Nakryiko, Daniel Borkmann

bench.o is produced by implicit rule only if it's built in the same
directory where bench.c is located. If OUTPUT points somewhere else,
build fails.

Make an explicit rule for it (factor out common part).
Add bench.c as a dependency to make it source for CC.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 tools/testing/selftests/bpf/Makefile | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 09700db35c2d..f0b7d41ed6dd 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -243,6 +243,11 @@ define GCC_BPF_BUILD_RULE
 	$(BPF_GCC) $3 $4 -O2 -c $1 -o $2
 endef
 
+define COMPILE_C_RULE
+	$(call msg,CC,,$@)
+	$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
+endef
+
 SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c
 
 # Set up extra TRUNNER_XXX "temporary" variables in the environment (relies on
@@ -409,11 +414,11 @@ $(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ)
 
 # Benchmark runner
 $(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h
-	$(call msg,CC,,$@)
-	$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
+	$(COMPILE_C_RULE)
 $(OUTPUT)/bench_rename.o: $(OUTPUT)/test_overhead.skel.h
 $(OUTPUT)/bench_trigger.o: $(OUTPUT)/trigger_bench.skel.h
-$(OUTPUT)/bench.o: bench.h testing_helpers.h
+$(OUTPUT)/bench.o: bench.c bench.h testing_helpers.h
+	$(COMPILE_C_RULE)
 $(OUTPUT)/bench: LDLIBS += -lm
 $(OUTPUT)/bench: $(OUTPUT)/bench.o $(OUTPUT)/testing_helpers.o \
 		 $(OUTPUT)/bench_count.o \
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 3/8] selftests/bpf: install btf .c files
  2020-05-22  4:13 [PATCH 0/8] selftests/bpf: installation and out of tree build fixes Yauheni Kaliuta
  2020-05-22  4:13 ` [PATCH 1/8] selftests/bpf: remove test_align from Makefile Yauheni Kaliuta
  2020-05-22  4:13 ` [PATCH 2/8] selftests/bpf: build bench.o for any $(OUTPUT) Yauheni Kaliuta
@ 2020-05-22  4:13 ` Yauheni Kaliuta
  2020-05-22  4:13 ` [PATCH 4/8] selftests/bpf: fix object files installation Yauheni Kaliuta
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Yauheni Kaliuta @ 2020-05-22  4:13 UTC (permalink / raw)
  To: bpf; +Cc: Jiri Benc, Jiri Olsa, Andrii Nakryiko, Daniel Borkmann

Some .c files used by test_progs to check btf and they are missing
from installation after commit 74b5a5968fe8 ("selftests/bpf: Replace
test_progs and test_maps w/ general rule").

Take them back.

Reuse BTF_C_FILES for TRUNNER_EXTRA_FILES.

Fixes: 74b5a5968fe8 ("selftests/bpf: Replace test_progs and
test_maps w/ general rule")

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
---
 tools/testing/selftests/bpf/Makefile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index f0b7d41ed6dd..19091dbc8ca4 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -46,6 +46,9 @@ TEST_GEN_FILES =
 TEST_FILES = test_lwt_ip_encap.o \
 	test_tc_edt.o
 
+BTF_C_FILES = $(wildcard progs/btf_dump_test_case_*.c)
+TEST_FILES += $(BTF_C_FILES)
+
 # Order correspond to 'make run_tests' order
 TEST_PROGS := test_kmod.sh \
 	test_xdp_redirect.sh \
@@ -362,8 +365,7 @@ TRUNNER_BPF_PROGS_DIR := progs
 TRUNNER_EXTRA_SOURCES := test_progs.c cgroup_helpers.c trace_helpers.c	\
 			 network_helpers.c testing_helpers.c		\
 			 flow_dissector_load.h
-TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read				\
-		       $(wildcard progs/btf_dump_test_case_*.c)
+TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(BTF_C_FILES)
 TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
 TRUNNER_BPF_LDFLAGS := -mattr=+alu32
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 4/8] selftests/bpf: fix object files installation
  2020-05-22  4:13 [PATCH 0/8] selftests/bpf: installation and out of tree build fixes Yauheni Kaliuta
                   ` (2 preceding siblings ...)
  2020-05-22  4:13 ` [PATCH 3/8] selftests/bpf: install btf .c files Yauheni Kaliuta
@ 2020-05-22  4:13 ` Yauheni Kaliuta
  2020-05-22  4:13 ` [PATCH 5/8] selftests/bpf: add output dir to include list Yauheni Kaliuta
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Yauheni Kaliuta @ 2020-05-22  4:13 UTC (permalink / raw)
  To: bpf; +Cc: Jiri Benc, Jiri Olsa, Andrii Nakryiko, Daniel Borkmann

There are problems with bpf test programs object files:

1) some of them are build for flavored test runner and should be
installed in the subdirectory;
2) it's possible that the same file mentioned several times (added
for every different unflavored test runner);
3) some generated files are not treated properly.

Fix 1) by adding subdirectory to the list. rsync -a in the install
target will handle it.

Fix 2) by filtering the list. Performance should not matter for such
amount of files.

Fix 3) by use proper (TEST_GEN_FILES) variable for the list.

Fixes: 309b81f0fdc4 ("selftests/bpf: Install generated test progs")
Fixes: e47a179997ce ("bpf, testing: Add missing object file to
TEST_FILES")

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 tools/testing/selftests/bpf/Makefile | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 19091dbc8ca4..1ba3d72c3261 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -42,8 +42,7 @@ ifneq ($(BPF_GCC),)
 TEST_GEN_PROGS += test_progs-bpf_gcc
 endif
 
-TEST_GEN_FILES =
-TEST_FILES = test_lwt_ip_encap.o \
+TEST_GEN_FILES = test_lwt_ip_encap.o \
 	test_tc_edt.o
 
 BTF_C_FILES = $(wildcard progs/btf_dump_test_case_*.c)
@@ -273,7 +272,11 @@ TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, $$(TRUNNER_BPF_SRCS)
 TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.skel.h,	\
 				 $$(filter-out $(SKEL_BLACKLIST),	\
 					       $$(TRUNNER_BPF_SRCS)))
-TEST_GEN_FILES += $$(TRUNNER_BPF_OBJS)
+
+TO_ADD := $(if $2,$$(TRUNNER_OUTPUT),$$(TRUNNER_BPF_OBJS))
+$$(foreach i,$$(TO_ADD),\
+	$$(eval \
+		TEST_GEN_FILES += $$(if $$(filter $$i,$$(TEST_GEN_FILES)),,$$i)))
 
 # Evaluate rules now with extra TRUNNER_XXX variables above already defined
 $$(eval $$(call DEFINE_TEST_RUNNER_RULES,$1,$2))
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 5/8] selftests/bpf: add output dir to include list
  2020-05-22  4:13 [PATCH 0/8] selftests/bpf: installation and out of tree build fixes Yauheni Kaliuta
                   ` (3 preceding siblings ...)
  2020-05-22  4:13 ` [PATCH 4/8] selftests/bpf: fix object files installation Yauheni Kaliuta
@ 2020-05-22  4:13 ` Yauheni Kaliuta
  2020-05-22  4:13 ` [PATCH 6/8] selftests/bpf: fix urandom_read installation Yauheni Kaliuta
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Yauheni Kaliuta @ 2020-05-22  4:13 UTC (permalink / raw)
  To: bpf; +Cc: Jiri Benc, Jiri Olsa, Andrii Nakryiko, Daniel Borkmann

Some headers (skel) are generated in the output directory and used
for build (test_cpp.cpp), so add it to the list (as well as
CURDIR) otherwise out of tree build is broken.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 tools/testing/selftests/bpf/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 1ba3d72c3261..efab82151ce2 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -22,7 +22,8 @@ LLVM_OBJCOPY	?= llvm-objcopy
 BPF_GCC		?= $(shell command -v bpf-gcc;)
 SAN_CFLAGS	?=
 CFLAGS += -g -rdynamic -Wall -O2 $(GENFLAGS) $(SAN_CFLAGS)		\
-	  -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR)		\
+	  -I$(CURDIR) -I$(abspath $(OUTPUT)) 				\
+	  -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR)			\
 	  -I$(TOOLSINCDIR) -I$(APIDIR)					\
 	  -Dbpf_prog_load=bpf_prog_test_load				\
 	  -Dbpf_load_program=bpf_test_load_program
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 6/8] selftests/bpf: fix urandom_read installation
  2020-05-22  4:13 [PATCH 0/8] selftests/bpf: installation and out of tree build fixes Yauheni Kaliuta
                   ` (4 preceding siblings ...)
  2020-05-22  4:13 ` [PATCH 5/8] selftests/bpf: add output dir to include list Yauheni Kaliuta
@ 2020-05-22  4:13 ` Yauheni Kaliuta
  2020-05-22  4:13 ` [PATCH 7/8] selftests/bpf: fix test.h placing for out of tree build Yauheni Kaliuta
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Yauheni Kaliuta @ 2020-05-22  4:13 UTC (permalink / raw)
  To: bpf; +Cc: Jiri Benc, Jiri Olsa, Andrii Nakryiko, Daniel Borkmann

selftests/lib.mk does not prepend TEST_CUSTOM_PROGS with OUTPUT (vs
TEST_GEN_PROGS, TEST_GEN_PROGS_EXTENDED, TEST_GEN_FILES). So do it
in the bpf Makefile. Otherwise make install fails to install it on
out of tree build.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 tools/testing/selftests/bpf/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index efab82151ce2..31598ca2d396 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -82,7 +82,7 @@ TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \
 	flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \
 	test_lirc_mode2_user xdping test_cpp runqslower bench
 
-TEST_CUSTOM_PROGS = urandom_read
+TEST_CUSTOM_PROGS = $(OUTPUT)/urandom_read
 
 # Emit succinct information message describing current building step
 # $1 - generic step name (e.g., CC, LINK, etc);
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 7/8] selftests/bpf: fix test.h placing for out of tree build
  2020-05-22  4:13 [PATCH 0/8] selftests/bpf: installation and out of tree build fixes Yauheni Kaliuta
                   ` (5 preceding siblings ...)
  2020-05-22  4:13 ` [PATCH 6/8] selftests/bpf: fix urandom_read installation Yauheni Kaliuta
@ 2020-05-22  4:13 ` Yauheni Kaliuta
  2020-05-22  4:13 ` [PATCH 8/8] selftests/bpf: factor out MKDIR rule Yauheni Kaliuta
  2020-05-22  6:40 ` [PATCH 0/8] selftests/bpf: installation and out of tree build fixes Yauheni Kaliuta
  8 siblings, 0 replies; 11+ messages in thread
From: Yauheni Kaliuta @ 2020-05-22  4:13 UTC (permalink / raw)
  To: bpf; +Cc: Jiri Benc, Jiri Olsa, Andrii Nakryiko, Daniel Borkmann

Flavors of test.h are generated in tree even for out of tree
build. Use OUTPUT directory for that.

It requires rules to make sure the directories exist.

Split EXTRA_CLEAN generation since existance of test.h files depends
of dynamic makefile generation.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 tools/testing/selftests/bpf/Makefile | 38 +++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 31598ca2d396..bade24e29a1a 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -83,6 +83,7 @@ TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \
 	test_lirc_mode2_user xdping test_cpp runqslower bench
 
 TEST_CUSTOM_PROGS = $(OUTPUT)/urandom_read
+EXTRA_CLEAN += $(TEST_CUSTOM_PROGS)
 
 # Emit succinct information message describing current building step
 # $1 - generic step name (e.g., CC, LINK, etc);
@@ -267,7 +268,7 @@ TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o,	\
 TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o,		\
 				 $$(filter %.c,$(TRUNNER_EXTRA_SOURCES)))
 TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES))
-TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h
+TRUNNER_TESTS_HDR := $(OUTPUT)/$(TRUNNER_TESTS_DIR)/tests.h
 TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c))
 TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, $$(TRUNNER_BPF_SRCS))
 TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.skel.h,	\
@@ -295,6 +296,11 @@ $(TRUNNER_OUTPUT)-dir := y
 $(TRUNNER_OUTPUT):
 	$$(call msg,MKDIR,,$$@)
 	mkdir -p $$@
+
+ifneq ($2,)
+EXTRA_CLEAN +=$(TRUNNER_OUTPUT)
+endif
+
 endif
 
 # ensure we set up BPF objects generation rule just once for a given
@@ -320,13 +326,19 @@ endif
 # ensure we set up tests.h header generation rule just once
 ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),)
 $(TRUNNER_TESTS_DIR)-tests-hdr := y
-$(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c
+$(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c | $(dir $(TRUNNER_TESTS_HDR))
 	$$(call msg,TEST-HDR,$(TRUNNER_BINARY),$$@)
 	$$(shell ( cd $(TRUNNER_TESTS_DIR);				\
 		  echo '/* Generated header, do not edit */';		\
 		  ls *.c 2> /dev/null |					\
 			sed -e 's@\([^\.]*\)\.c@DEFINE_TEST(\1)@';	\
 		 ) > $$@)
+
+EXTRA_CLEAN += $(TRUNNER_TESTS_HDR)
+
+$(dir $(TRUNNER_TESTS_HDR)):
+	$$(call msg,MKDIR,,$$@)
+	mkdir -p $$@
 endif
 
 # compile individual test files
@@ -402,14 +414,23 @@ $(eval $(call DEFINE_TEST_RUNNER,test_maps))
 # It is much simpler than test_maps/test_progs and sufficiently different from
 # them (e.g., test.h is using completely pattern), that it's worth just
 # explicitly defining all the rules explicitly.
-verifier/tests.h: verifier/*.c
+$(OUTPUT)/verifier/tests.h: verifier/*.c | $(OUTPUT)/verifier
 	$(shell ( cd verifier/; \
 		  echo '/* Generated header, do not edit */'; \
 		  echo '#ifdef FILL_ARRAY'; \
 		  ls *.c 2> /dev/null | sed -e 's@\(.*\)@#include \"\1\"@'; \
 		  echo '#endif' \
-		) > verifier/tests.h)
-$(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT)
+		) > $@)
+
+EXTRA_CLEAN += $(OUTPUT)/verifier/tests.h
+
+$(OUTPUT)/verifier:
+	$(call msg,MKDIR,,$@)
+	mkdir -p $@
+
+$(OUTPUT)/test_verifier: CFLAGS += -I$(abspath verifier)
+$(OUTPUT)/test_verifier: test_verifier.c $(OUTPUT)/verifier/tests.h $(BPFOBJ) \
+			| $(OUTPUT)
 	$(call msg,BINARY,,$@)
 	$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
 
@@ -433,7 +454,6 @@ $(OUTPUT)/bench: $(OUTPUT)/bench.o $(OUTPUT)/testing_helpers.o \
 	$(call msg,BINARY,,$@)
 	$(CC) $(LDFLAGS) -o $@ $(filter %.a %.o,$^) $(LDLIBS)
 
-EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR)			\
-	prog_tests/tests.h map_tests/tests.h verifier/tests.h		\
-	feature								\
-	$(addprefix $(OUTPUT)/,*.o *.skel.h no_alu32 bpf_gcc)
+EXTRA_CLEAN += $(SCRATCH_DIR)			\
+	feature					\
+	$(addprefix $(OUTPUT)/,*.o *.skel.h)
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 8/8] selftests/bpf: factor out MKDIR rule
  2020-05-22  4:13 [PATCH 0/8] selftests/bpf: installation and out of tree build fixes Yauheni Kaliuta
                   ` (6 preceding siblings ...)
  2020-05-22  4:13 ` [PATCH 7/8] selftests/bpf: fix test.h placing for out of tree build Yauheni Kaliuta
@ 2020-05-22  4:13 ` Yauheni Kaliuta
  2020-05-22  6:40 ` [PATCH 0/8] selftests/bpf: installation and out of tree build fixes Yauheni Kaliuta
  8 siblings, 0 replies; 11+ messages in thread
From: Yauheni Kaliuta @ 2020-05-22  4:13 UTC (permalink / raw)
  To: bpf; +Cc: Jiri Benc, Jiri Olsa, Andrii Nakryiko, Daniel Borkmann

Do not repeat youself, move common mkdir code (message and action)
to a variable.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 tools/testing/selftests/bpf/Makefile | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index bade24e29a1a..26497d8869ea 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -252,6 +252,11 @@ define COMPILE_C_RULE
 	$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
 endef
 
+define MKDIR_RULE
+	$(call msg,MKDIR,,$@)
+	mkdir -p $@
+endef
+
 SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c
 
 # Set up extra TRUNNER_XXX "temporary" variables in the environment (relies on
@@ -294,8 +299,7 @@ define DEFINE_TEST_RUNNER_RULES
 ifeq ($($(TRUNNER_OUTPUT)-dir),)
 $(TRUNNER_OUTPUT)-dir := y
 $(TRUNNER_OUTPUT):
-	$$(call msg,MKDIR,,$$@)
-	mkdir -p $$@
+	$$(MKDIR_RULE)
 
 ifneq ($2,)
 EXTRA_CLEAN +=$(TRUNNER_OUTPUT)
@@ -337,8 +341,7 @@ $(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c | $(dir $(TRUNNER_TESTS_HDR))
 EXTRA_CLEAN += $(TRUNNER_TESTS_HDR)
 
 $(dir $(TRUNNER_TESTS_HDR)):
-	$$(call msg,MKDIR,,$$@)
-	mkdir -p $$@
+	$$(MKDIR_RULE)
 endif
 
 # compile individual test files
@@ -425,8 +428,7 @@ $(OUTPUT)/verifier/tests.h: verifier/*.c | $(OUTPUT)/verifier
 EXTRA_CLEAN += $(OUTPUT)/verifier/tests.h
 
 $(OUTPUT)/verifier:
-	$(call msg,MKDIR,,$@)
-	mkdir -p $@
+	$(MKDIR_RULE)
 
 $(OUTPUT)/test_verifier: CFLAGS += -I$(abspath verifier)
 $(OUTPUT)/test_verifier: test_verifier.c $(OUTPUT)/verifier/tests.h $(BPFOBJ) \
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/8] selftests/bpf: installation and out of tree build fixes
  2020-05-22  4:13 [PATCH 0/8] selftests/bpf: installation and out of tree build fixes Yauheni Kaliuta
                   ` (7 preceding siblings ...)
  2020-05-22  4:13 ` [PATCH 8/8] selftests/bpf: factor out MKDIR rule Yauheni Kaliuta
@ 2020-05-22  6:40 ` Yauheni Kaliuta
  2020-05-22  8:19   ` [PATCH] selftests/bpf: split -extras target to -static and -gen Yauheni Kaliuta
  8 siblings, 1 reply; 11+ messages in thread
From: Yauheni Kaliuta @ 2020-05-22  6:40 UTC (permalink / raw)
  To: bpf; +Cc: Jiri Benc, Jiri Olsa, Andrii Nakryiko, Daniel Borkmann


Actually, a bit more needed :)

>>>>> On Fri, 22 May 2020 07:13:02 +0300, Yauheni Kaliuta  wrote:

 > I had a look, here are some fixes.
 > Yauheni Kaliuta (8):
 >   selftests/bpf: remove test_align from Makefile
 >   selftests/bpf: build bench.o for any $(OUTPUT)
 >   selftests/bpf: install btf .c files
 >   selftests/bpf: fix object files installation
 >   selftests/bpf: add output dir to include list
 >   selftests/bpf: fix urandom_read installation
 >   selftests/bpf: fix test.h placing for out of tree build
 >   selftests/bpf: factor out MKDIR rule

 >  tools/testing/selftests/bpf/Makefile | 77 ++++++++++++++++++++--------
 >  1 file changed, 55 insertions(+), 22 deletions(-)

 > -- 
 > 2.26.2


-- 
WBR,
Yauheni Kaliuta


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] selftests/bpf: split -extras target to -static and -gen
  2020-05-22  6:40 ` [PATCH 0/8] selftests/bpf: installation and out of tree build fixes Yauheni Kaliuta
@ 2020-05-22  8:19   ` Yauheni Kaliuta
  0 siblings, 0 replies; 11+ messages in thread
From: Yauheni Kaliuta @ 2020-05-22  8:19 UTC (permalink / raw)
  To: bpf; +Cc: Jiri Benc, Jiri Olsa, Andrii Nakryiko, Daniel Borkmann

There is difference in depoying static and generated extra resource
files between in/out of tree build and flavors:

- in case of unflavored out-of-tree build static files are not
available and must be copied as well as both static and generated
files for flavored build.

So split the rules and variables. The name TRUNNER_EXTRA_GEN_FILES
is chosen in analogy to TEST_GEN_* variants.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 tools/testing/selftests/bpf/Makefile | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 26497d8869ea..c80c06272759 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -363,12 +363,28 @@ $(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o:				\
 	$$(call msg,EXT-OBJ,$(TRUNNER_BINARY),$$@)
 	$$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@
 
-# only copy extra resources if in flavored build
-$(TRUNNER_BINARY)-extras: $(TRUNNER_EXTRA_FILES) | $(TRUNNER_OUTPUT)
-ifneq ($2,)
+# copy extra resources when needed.
+# Static files for both out of tree and flavored (so, not current dir).
+# Generated files for flavored only.
+$(TRUNNER_BINARY)-extras: $(TRUNNER_BINARY)-extras-static \
+			  $(TRUNNER_BINARY)-extras-gen
+
+$(TRUNNER_BINARY)-extras-static: $(TRUNNER_EXTRA_FILES) | $(TRUNNER_OUTPUT)
+ifneq ($(CURDIR)),$(realpath $(TRUNNER_OUTPUT)))
 	$$(call msg,EXT-COPY,$(TRUNNER_BINARY),$(TRUNNER_EXTRA_FILES))
+ifneq ($(TRUNNER_EXTRA_FILES),)
 	cp -a $$^ $(TRUNNER_OUTPUT)/
 endif
+endif
+
+$(TRUNNER_BINARY)-extras-gen: $(addprefix $(OUTPUT)/,$(TRUNNER_EXTRA_GEN_FILES)) \
+			    | $(TRUNNER_OUTPUT)
+ifneq ($2,)
+	$$(call msg,EXT-COPY,$(TRUNNER_BINARY),$(TRUNNER_EXTRA_GEN_FILES))
+ifneq ($(TRUNNER_EXTRA_GEN_FILES),)
+	cp -a $$^ $(TRUNNER_OUTPUT)/
+endif
+endif
 
 $(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS)			\
 			     $(TRUNNER_EXTRA_OBJS) $$(BPFOBJ)		\
@@ -384,7 +400,8 @@ TRUNNER_BPF_PROGS_DIR := progs
 TRUNNER_EXTRA_SOURCES := test_progs.c cgroup_helpers.c trace_helpers.c	\
 			 network_helpers.c testing_helpers.c		\
 			 flow_dissector_load.h
-TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(BTF_C_FILES)
+TRUNNER_EXTRA_FILES := $(BTF_C_FILES)
+TRUNNER_EXTRA_GEN_FILES := urandom_read
 TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
 TRUNNER_BPF_LDFLAGS := -mattr=+alu32
@@ -408,6 +425,7 @@ TRUNNER_TESTS_DIR := map_tests
 TRUNNER_BPF_PROGS_DIR := progs
 TRUNNER_EXTRA_SOURCES := test_maps.c
 TRUNNER_EXTRA_FILES :=
+TRUNNER_EXTRA_GEN_FILES :=
 TRUNNER_BPF_BUILD_RULE := $$(error no BPF objects should be built)
 TRUNNER_BPF_CFLAGS :=
 TRUNNER_BPF_LDFLAGS :=
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, back to index

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-22  4:13 [PATCH 0/8] selftests/bpf: installation and out of tree build fixes Yauheni Kaliuta
2020-05-22  4:13 ` [PATCH 1/8] selftests/bpf: remove test_align from Makefile Yauheni Kaliuta
2020-05-22  4:13 ` [PATCH 2/8] selftests/bpf: build bench.o for any $(OUTPUT) Yauheni Kaliuta
2020-05-22  4:13 ` [PATCH 3/8] selftests/bpf: install btf .c files Yauheni Kaliuta
2020-05-22  4:13 ` [PATCH 4/8] selftests/bpf: fix object files installation Yauheni Kaliuta
2020-05-22  4:13 ` [PATCH 5/8] selftests/bpf: add output dir to include list Yauheni Kaliuta
2020-05-22  4:13 ` [PATCH 6/8] selftests/bpf: fix urandom_read installation Yauheni Kaliuta
2020-05-22  4:13 ` [PATCH 7/8] selftests/bpf: fix test.h placing for out of tree build Yauheni Kaliuta
2020-05-22  4:13 ` [PATCH 8/8] selftests/bpf: factor out MKDIR rule Yauheni Kaliuta
2020-05-22  6:40 ` [PATCH 0/8] selftests/bpf: installation and out of tree build fixes Yauheni Kaliuta
2020-05-22  8:19   ` [PATCH] selftests/bpf: split -extras target to -static and -gen Yauheni Kaliuta

BPF Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/bpf/0 bpf/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 bpf bpf/ https://lore.kernel.org/bpf \
		bpf@vger.kernel.org
	public-inbox-index bpf

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.bpf


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git