Lines Matching +full:test +full:- +full:docs

1 # SPDX-License-Identifier: GPL-2.0
22 PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
25 GENFLAGS := -DHAVE_GENHDR
28 BPF_GCC ?= $(shell command -v bpf-gcc;)
32 OPT_FLAGS ?= $(if $(RELEASE),-O2,-O0)
34 LIBELF_CFLAGS := $(shell $(PKG_CONFIG) libelf --cflags 2>/dev/null)
35 LIBELF_LIBS := $(shell $(PKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
47 CFLAGS += -g $(OPT_FLAGS) -rdynamic -std=gnu11 \
48 -Wall -Werror -fno-omit-frame-pointer \
50 -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \
51 -I$(TOOLSINCDIR) -I$(TOOLSARCHINCDIR) -I$(APIDIR) -I$(OUTPUT)
53 LDLIBS += $(LIBELF_LIBS) -lz -lrt -lpthread
55 PCAP_CFLAGS := $(shell $(PKG_CONFIG) --cflags libpcap 2>/dev/null && echo "-DTRAFFIC_MONITOR=1")
56 PCAP_LIBS := $(shell $(PKG_CONFIG) --libs libpcap 2>/dev/null)
61 jit_disasm_helpers.c-CFLAGS = $(LLVM_CFLAGS)
65 CFLAGS += -Wno-unused-command-line-argument
69 ifneq ($(shell $(CLANG) --target=bpf -mcpu=help 2>&1 | grep 'v4'),)
77 test_progs-no_alu32
80 # Also test bpf-gcc, if present
82 TEST_GEN_PROGS += test_progs-bpf_gcc
88 progs/btf_dump_test_case_bitfields.c-bpf_gcc-CFLAGS := -Wno-error
89 progs/btf_dump_test_case_namespacing.c-bpf_gcc-CFLAGS := -Wno-error
90 progs/btf_dump_test_case_packing.c-bpf_gcc-CFLAGS := -Wno-error
91 progs/btf_dump_test_case_padding.c-bpf_gcc-CFLAGS := -Wno-error
92 progs/btf_dump_test_case_syntax.c-bpf_gcc-CFLAGS := -Wno-error
97 TEST_GEN_PROGS += test_progs-cpuv4
140 TEST_GEN_FILES += $(TEST_KMODS) liburandom_read.so urandom_read sign-file uprobe_multi
150 $(Q)$(RM) -r $(TEST_GEN_PROGS)
151 $(Q)$(RM) -r $(TEST_GEN_PROGS_EXTENDED)
152 $(Q)$(RM) -r $(TEST_GEN_FILES)
153 $(Q)$(RM) -r $(TEST_KMODS)
154 $(Q)$(RM) -r $(EXTRA_CLEAN)
155 $(Q)$(MAKE) -C test_kmods clean
156 $(Q)$(MAKE) docs-clean
161 NON_CHECK_FEAT_TARGETS := clean docs-clean
162 CHECK_FEAT := $(filter-out $(NON_CHECK_FEAT_TARGETS),$(or $(MAKECMDGOALS), "none"))
180 ifeq ($(feature-llvm),1)
181 LLVM_CFLAGS += -DHAVE_LLVM_SUPPORT
182 LLVM_CONFIG_LIB_COMPONENTS := mcdisassembler all-targets
183 # both llvm-config and lib.mk add -D_GNU_SOURCE, which ends up as conflict
184 LLVM_CFLAGS += $(filter-out -D_GNU_SOURCE,$(shell $(LLVM_CONFIG) --cflags))
186 ifeq ($(shell $(LLVM_CONFIG) --link-static --libs >/dev/null 2>&1 && echo static),static)
187 LLVM_LDLIBS += $(shell $(LLVM_CONFIG) --link-static --libs $(LLVM_CONFIG_LIB_COMPONENTS))
188 LLVM_LDLIBS += $(filter-out -lxml2,$(shell $(LLVM_CONFIG) --link-static --system-libs $(LLVM_CONFIG_LIB_COMPONENTS)))
189 LLVM_LDLIBS += -lstdc++
191 LLVM_LDLIBS += $(shell $(LLVM_CONFIG) --link-shared --libs $(LLVM_CONFIG_LIB_COMPONENTS))
193 LLVM_LDFLAGS += $(shell $(LLVM_CONFIG) --ldflags)
203 HOST_SCRATCH_DIR := $(OUTPUT)/host-tools
218 /boot/vmlinux-$(shell uname -r)
231 # sort removes libbpf duplicates when not cross-building
238 $(Q)mkdir -p $@
242 $(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
246 $(Q)$(LINK.c) $^ $(LDLIBS) -o $@
252 LLD := $(shell command -v $(LD))
255 # Filter out -static for liburandom_read.so and its dependent targets so that static builds
256 # do not fail. Static builds leave urandom_read relying on system-wide shared libraries.
260 $(filter-out -static,$(CFLAGS) $(LDFLAGS)) \
261 $(filter %.c,$^) $(filter-out -static,$(LDLIBS)) \
262 -Wno-unused-command-line-argument \
263 -fuse-ld=$(LLD) -Wl,-znoseparate-code -Wl,--build-id=sha1 \
264 -Wl,--version-script=liburandom_read.map \
265 -fPIC -shared -o $@
270 $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $(filter %.c,$^) \
271 -Wno-unused-command-line-argument \
272 -lurandom_read $(filter-out -static,$(LDLIBS)) -L$(OUTPUT) \
273 -fuse-ld=$(LLD) -Wl,-znoseparate-code -Wl,--build-id=sha1 \
274 -Wl,-rpath=. -o $@
276 $(OUTPUT)/sign-file: ../../../../scripts/sign-file.c
277 $(call msg,SIGN-FILE,,$@)
278 $(Q)$(CC) $(shell $(PKG_CONFIG) --cflags libcrypto 2> /dev/null) \
279 $< -o $@ \
280 $(shell $(PKG_CONFIG) --libs libcrypto 2> /dev/null || echo -lcrypto)
287 $(Q)$(RM) test_kmods/*.ko test_kmods/*.mod.o # force re-compilation
288 $(Q)$(MAKE) $(submake_extras) -C test_kmods \
308 $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/runqslower \
314 EXTRA_CFLAGS='-g $(OPT_FLAGS) $(SAN_CFLAGS) $(EXTRA_CFLAGS)' \
344 $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \
346 EXTRA_CFLAGS='-g $(OPT_FLAGS) $(EXTRA_CFLAGS)' \
351 prefix= DESTDIR=$(HOST_SCRATCH_DIR)/ install-bin
356 $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \
358 EXTRA_CFLAGS='-g $(OPT_FLAGS) $(EXTRA_CFLAGS)' \
363 prefix= DESTDIR=$(SCRATCH_DIR)/ install-bin
367 all: docs
370 docs:
371 $(Q)RST2MAN_OPTS="--exit-status=1" $(MAKE) $(submake_extras) \
372 -f Makefile.docs \
375 docs-clean:
377 -f Makefile.docs \
383 $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \
384 EXTRA_CFLAGS='-g $(OPT_FLAGS) $(SAN_CFLAGS) $(EXTRA_CFLAGS)' \
392 $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) \
394 EXTRA_CFLAGS='-g $(OPT_FLAGS) $(EXTRA_CFLAGS)' \
402 # the previous version. This helps to avoid unnecessary re-builds of
408 $(Q)cmp -s $(INCLUDE_DIR)/.vmlinux.h.tmp $@ || mv $(INCLUDE_DIR)/.vmlinux.h.tmp $@
421 $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/resolve_btfids \
427 # '--target=bpf'. This fixes "missing" files on some architectures/distros,
430 # Use '-idirafter': Don't interfere with include mechanics except where the
433 $(shell $(1) $(2) -v -E - </dev/null 2>&1 \
434 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
435 $(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') \
436 $(shell $(1) $(2) -dM -E - </dev/null | grep '__loongarch_grlen ' | awk '{printf("-D__BITS_PER_LONG=%d", $$3)}') \
437 $(shell $(1) $(2) -dM -E - </dev/null | grep -E 'MIPS(EL|EB)|_MIPS_SZ(PTR|LONG) |_MIPS_SIM |_ABI(O32|N32|64) ' | awk '{printf("-D%s=%s ", $$2, $$3)}')
441 IS_LITTLE_ENDIAN := $(shell $(CC) -dM -E - </dev/null | \
443 MENDIAN:=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian)
444 BPF_TARGET_ENDIAN:=$(if $(IS_LITTLE_ENDIAN),--target=bpfel,--target=bpfeb)
447 CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%))
451 BPF_CFLAGS = -g -Wall -Werror -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \
452 -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \
453 -I$(abspath $(OUTPUT)/../usr/include) \
454 -std=gnu11 \
455 -fno-strict-aliasing \
456 -Wno-compare-distinct-pointer-types
457 # TODO: enable me -Wsign-compare
461 $(OUTPUT)/test_l4lb_noinline.o: BPF_CFLAGS += -fno-inline
462 $(OUTPUT)/test_xdp_noinline.o: BPF_CFLAGS += -fno-inline
468 # $1 - input .c file
469 # $2 - output .o file
470 # $3 - CFLAGS
471 # $4 - binary name
473 $(call msg,CLNG-BPF,$4,$2)
474 $(Q)$(CLANG) $3 -O2 $(BPF_TARGET_ENDIAN) -c $1 -mcpu=v3 -o $2
478 $(call msg,CLNG-BPF,$4,$2)
479 $(Q)$(CLANG) $3 -O2 $(BPF_TARGET_ENDIAN) -c $1 -mcpu=v2 -o $2
481 # Similar to CLANG_BPF_BUILD_RULE, but with cpu-v4
483 $(call msg,CLNG-BPF,$4,$2)
484 $(Q)$(CLANG) $3 -O2 $(BPF_TARGET_ENDIAN) -c $1 -mcpu=v4 -o $2
488 $(call msg,GCC-BPF,$4,$2)
489 $(Q)$(BPF_GCC) $3 -DBPF_NO_PRESERVE_ACCESS_INDEX -Wno-attributes -O2 -c $1 -o $2
510 test_static_linked.skel.h-deps := test_static_linked1.bpf.o test_static_linked2.bpf.o
511 linked_funcs.skel.h-deps := linked_funcs1.bpf.o linked_funcs2.bpf.o
512 linked_vars.skel.h-deps := linked_vars1.bpf.o linked_vars2.bpf.o
513 linked_maps.skel.h-deps := linked_maps1.bpf.o linked_maps2.bpf.o
515 # but that's created as a side-effect of the skel.h generation.
516 test_subskeleton.skel.h-deps := test_subskeleton_lib2.bpf.o test_subskeleton_lib.bpf.o test_subskeleton.bpf.o
517 test_subskeleton_lib.skel.h-deps := test_subskeleton_lib2.bpf.o test_subskeleton_lib.bpf.o
518 test_usdt.skel.h-deps := test_usdt.bpf.o test_usdt_multispec.bpf.o
519 xsk_xdp_progs.skel.h-deps := xsk_xdp_progs.bpf.o
520 xdp_hw_metadata.skel.h-deps := xdp_hw_metadata.bpf.o
521 xdp_features.skel.h-deps := xdp_features.bpf.o
523 LINKED_BPF_OBJS := $(foreach skel,$(LINKED_SKELS),$($(skel)-deps))
535 # $1 - test runner base binary name (e.g., test_progs)
536 # $2 - test runner extra "flavor" (e.g., no_alu32, cpuv4, bpf_gcc, etc)
539 LSKEL_SIGN := -S -k $(PRIVATE_KEY) -i $(VERIFICATION_CERT)
541 TRUNNER_BINARY := $1$(if $2,-)$2
542 TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o, \
551 $$(filter-out $(SKEL_BLACKLIST) $(LINKED_BPF_SRCS),\
564 # set up by DEFINE_TEST_RUNNER itself, create test runner build rules with:
565 # $1 - test runner base binary name (e.g., test_progs)
566 # $2 - test runner extra "flavor" (e.g., no_alu32, cpuv4, bpf_gcc, etc)
569 ifeq ($($(TRUNNER_OUTPUT)-dir),)
570 $(TRUNNER_OUTPUT)-dir := y
573 $(Q)mkdir -p $$@
578 ifeq ($($(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs),)
579 $(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs := y
588 $$($$<-CFLAGS) \
589 $$($$<-$2-CFLAGS),$(TRUNNER_BINARY))
592 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@)
599 $(Q)rm -f $$(<:.o=.linked1.o) $$(<:.o=.linked2.o) $$(<:.o=.linked3.o)
602 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@)
607 $(Q)$$(BPFTOOL) gen skeleton -L $$(<:.o=.llinked3.o) name $$(notdir $$(<:.bpf.o=_lskel)) > $$@
608 $(Q)rm -f $$(<:.o=.llinked1.o) $$(<:.o=.llinked2.o) $$(<:.o=.llinked3.o)
611 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY) (signed),$$@)
617 $(Q)rm -f $$(<:.o=.llinked1.o) $$(<:.o=.llinked2.o) $$(<:.o=.llinked3.o)
621 # .SECONDEXPANSION here allows to correctly expand %-deps variables as prerequisites
623 $(TRUNNER_BPF_SKELS_LINKED): $(TRUNNER_OUTPUT)/%: $$$$(%-deps) $(BPFTOOL) | $(TRUNNER_OUTPUT)
624 $$(call msg,LINK-BPF,$(TRUNNER_BINARY),$$(@:.skel.h=.bpf.o))
625 $(Q)$$(BPFTOOL) gen object $$(@:.skel.h=.linked1.o) $$(addprefix $(TRUNNER_OUTPUT)/,$$($$(@F)-deps))
629 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@)
632 $(Q)rm -f $$(@:.skel.h=.linked1.o) $$(@:.skel.h=.linked2.o) $$(@:.skel.h=.linked3.o)
645 ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),)
646 $(TRUNNER_TESTS_DIR)-tests-hdr := y
648 $$(call msg,TEST-HDR,$(TRUNNER_BINARY),$$@)
650 sed -n -E 's/^void (serial_)?test_([a-zA-Z0-9_]+)\((void)?\).*/DEFINE_TEST(\2)/p' \
655 # compile individual test files
657 $(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \
659 | $(TRUNNER_OUTPUT)/%.test.d
660 $$(call msg,TEST-OBJ,$(TRUNNER_BINARY),$$@)
661 $(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) -MMD -MT $$@ -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F)
663 $(TRUNNER_TEST_OBJS:.o=.d): $(TRUNNER_OUTPUT)/%.test.d: \
672 ifeq ($(filter clean docs-clean,$(MAKECMDGOALS)),)
678 $(eval $(TRUNNER_OUTPUT)/$(N).o: CFLAGS += $($(N).c-CFLAGS)))
686 $$(call msg,EXT-OBJ,$(TRUNNER_BINARY),$$@)
687 $(Q)$$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@
689 # non-flavored in-srctree builds receive special treatment, in particular, we
691 $(TRUNNER_BINARY)-extras: $(TRUNNER_EXTRA_FILES) | $(TRUNNER_OUTPUT)
693 $$(call msg,EXT-COPY,$(TRUNNER_BINARY),$(TRUNNER_EXTRA_FILES))
694 $(Q)rsync -aq $$^ $(TRUNNER_OUTPUT)/
697 # some X.test.o files have runtime dependencies on Y.bpf.o files
705 | $(TRUNNER_BINARY)-extras
707 $(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) $$(LLVM_LDLIBS) $$(LDFLAGS) $$(LLVM_LDFLAGS) -o $$@
708 $(Q)$(RESOLVE_BTFIDS) --btf $(TRUNNER_OUTPUT)/btf_data.bpf.o $$@
709 $(Q)ln -sf $(if $2,..,.)/tools/build/bpftool/$(USE_BOOTSTRAP)bpftool \
720 $(Q)mkdir -p $(BUILD_DIR)
724 $(Q)xxd -i -n test_progs_verification_cert $< > $@
726 # Define test_progs test runner.
751 $(OUTPUT)/sign-file \
759 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) -DENABLE_ATOMICS_TESTS
762 # Define test_progs-no_alu32 test runner.
767 # Define test_progs-cpuv4 test runner.
770 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) -DENABLE_ATOMICS_TESTS
774 # Define test_progs BPF-GCC-flavored test runner.
781 # Define test_maps test runner.
790 # Define test_verifier test runner.
792 # them (e.g., test.h is using completely pattern), that it's worth just
798 ls *.c 2> /dev/null | sed -e 's@\(.*\)@#include \"\1\"@'; \
803 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
809 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
813 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
817 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
821 CXXFLAGS := $(subst -D_GNU_SOURCE=,,$(CXXFLAGS))
822 CXXFLAGS := $(subst -std=gnu11,-std=gnu++11,$(CXXFLAGS))
825 $(Q)$(CXX) $(CXXFLAGS) $(filter %.a %.o %.cpp,$^) $(LDLIBS) -o $@
830 $(Q)$(CC) $(CFLAGS) -O2 -c $(filter %.c,$^) $(LDLIBS) -o $@
848 $(OUTPUT)/bench: LDLIBS += -lm
871 $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@
876 # snprintf(a, "%s/foo", b); // triggers -Wformat-truncation
877 $(OUTPUT)/veristat.o: CFLAGS += -Wno-format-truncation
881 $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@
884 $(OUTPUT)/uprobe_multi: CFLAGS += $(if $(filter mips, $(ARCH)),-mxgot)
887 $(Q)$(CC) $(CFLAGS) -Wl,-T,uprobe_multi.ld -O0 $(LDFLAGS) \
888 $(filter-out %.ld,$^) $(LDLIBS) -o $@
896 $(OUTPUT)/FEATURE-DUMP.selftests
898 .PHONY: docs docs-clean
907 mkdir -p $(INSTALL_PATH)/$$DIR; \
908 rsync -a $(OUTPUT)/$$DIR/*.bpf.o $(INSTALL_PATH)/$$DIR;\