Debian Codegraph @

tests/Makefile

raw symbols SCIP
1 include ../Makefile.inc
2
3 # directory where to run the tests
4 TESTDIR := $(CURDIR)
5
6 CPPFLAGS += -I$(multipathdir) -I$(mpathutildir) -I$(mpathcmddir) -I$(daemondir) \
7 -DTESTCONFDIR=\"$(TESTDIR)/conf.d\"
8 CFLAGS += $(BIN_CFLAGS) -Wno-unused-parameter -Wno-unused-function $(W_MISSING_INITIALIZERS)
9 LIBDEPS += -L. -L $(mpathutildir) -L$(mpathcmddir) -lmultipath -lmpathutil -lmpathcmd -lcmocka
10
11 TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy \
12 alias directio valid devt mpathvalid strbuf sysfs features cli mapinfo
13 HELPERS := test-lib.o test-log.o
14
15 .PRECIOUS: $(TESTS:%=%-test)
16
17 all: $(TESTS:%=%.out)
18 progs: $(TESTS:%=%-test) lib/libchecktur.so
19 valgrind: $(TESTS:%=%.vgr)
20
21 # test-specific compiler flags
22 # XYZ-test_FLAGS: Additional compiler flags for this test
23
24 mpathvalid-test_FLAGS := -I$(mpathvaliddir)
25 features-test_FLAGS := -I$(multipathdir)/nvme
26
27 # test-specific linker flags
28 # XYZ-test_TESTDEPS: test libraries containing __wrap_xyz functions
29 # XYZ-test_OBJDEPS: object files from libraries to link in explicitly
30 # That may be necessary if functions called from the object file are wrapped
31 # (wrapping works only for symbols which are undefined after processing a
32 # linker input file).
33 # Some object files, e.g. "config.o", are compiled separately for the
34 # unit tests. Look for OBJS-U in libmultipath/Makefile. Make sure to use the
35 # unit test file, e.g. "config-test.o", in XYZ-test_OBJDEPS
36 # XYZ-test_LIBDEPS: Additional libs to link for this test
37
38 dmevents-test_OBJDEPS = $(multipathdir)/devmapper.o
39 dmevents-test_LIBDEPS = -lpthread -ldevmapper -lurcu
40 hwtable-test_TESTDEPS := test-lib.o
41 hwtable-test_OBJDEPS := $(multipathdir)/discovery.o $(multipathdir)/blacklist.o \
42 $(multipathdir)/structs_vec.o $(multipathdir)/structs.o $(multipathdir)/propsel.o \
43 $(mpathutildir)/mt-libudev.o
44 hwtable-test_LIBDEPS := -ludev -lpthread -ldl
45 blacklist-test_TESTDEPS := test-log.o
46 blacklist-test_OBJDEPS := $(mpathutildir)/mt-libudev.o
47 blacklist-test_LIBDEPS := -ludev -lpthread -ldl
48 vpd-test_OBJDEPS := $(multipathdir)/discovery.o $(mpathutildir)/mt-libudev.o
49 vpd-test_LIBDEPS := -ludev -lpthread -ldl
50 alias-test_TESTDEPS := test-log.o
51 alias-test_OBJDEPS := $(mpathutildir)/util.o $(mpathutildir)/mt-libudev.o
52 alias-test_LIBDEPS := -ludev -lpthread -ldl
53 valid-test_OBJDEPS := $(multipathdir)/valid.o $(multipathdir)/discovery.o $(mpathutildir)/mt-libudev.o
54 valid-test_LIBDEPS := -lmount -ludev -lpthread -ldl
55 devt-test_LIBDEPS := -ludev -lpthread -ldl
56 devt-test_OBJDEPS := $(mpathutildir)/mt-libudev.o
57 mpathvalid-test_LIBDEPS := -ludev -lpthread -ldl
58 mpathvalid-test_OBJDEPS := $(mpathvaliddir)/mpath_valid.o $(mpathutildir)/mt-libudev.o
59 directio-test_LIBDEPS := -laio
60 strbuf-test_OBJDEPS := $(mpathutildir)/strbuf.o
61 sysfs-test_TESTDEPS := test-log.o
62 sysfs-test_OBJDEPS := $(multipathdir)/sysfs.o $(mpathutildir)/util.o $(mpathutildir)/mt-libudev.o
63 sysfs-test_LIBDEPS := -ludev -lpthread -ldl
64 features-test_LIBDEPS := -ludev -lpthread
65 features-test_OBJDEPS := $(mpathutildir)/mt-libudev.o
66 cli-test_OBJDEPS := $(daemondir)/cli.o
67 mapinfo-test_LIBDEPS = -lpthread -ldevmapper
68
69 %.o: %.c
70 @echo building $@ because of $?
71 $(Q)$(CC) $(CPPFLAGS) $(CFLAGS) $($*-test_FLAGS) -c -o $@ $<
72
73 lib/libchecktur.so:
74 @mkdir -p lib
75 $(Q)cd lib && ln -s ../$(multipathdir)/*/*.so .
76
77 %.out: %-test lib/libchecktur.so
78 @echo == running $< ==
79 @LD_LIBRARY_PATH=.:$(mpathutildir):$(mpathcmddir) ./$< >$@ 2>&1 || { cat "$@"; false; }
80
81 %.vgr: %-test lib/libchecktur.so
82 @echo == running valgrind for $< ==
83 @LD_LIBRARY_PATH=.:$(mpathutildir):$(mpathcmddir) \
84 valgrind --leak-check=full --error-exitcode=128 ./$< >$@ 2>&1
85
86 OBJS = $(TESTS:%=%.o) $(HELPERS)
87
88 test_clean:
89 $(Q)$(RM) $(TESTS:%=%.out) $(TESTS:%=%.vgr) *.so*
90
91 valgrind_clean:
92 $(Q)$(RM) $(TESTS:%=%.vgr)
93
94 clean: test_clean valgrind_clean dep_clean
95 $(Q)$(RM) $(TESTS:%=%-test) $(OBJS) *.o.wrap
96 $(Q)$(RM) -rf lib conf.d
97
98 .SECONDARY: $(OBJS) $(foreach T,$(TESTS),$($T-test_OBJDEPS)) $(HELPERS:%=%.wrap)
99
100 include $(wildcard $(OBJS:.o=.d))
101
102 dep_clean:
103 $(Q)$(RM) $(OBJS:.o=.d)
104
105 # Parse the C code for __wrap_xyz() functions and generate linker options from them.
106 # See comment in wrap64.h
107 %.o.wrap: %.c
108 $(Q)$(CC) $(OPTFLAGS) $(CPPFLAGS) $($*-test_FLAGS) -E $< | \
109 sed -n 's/^.*__wrap_\([a-zA-Z0-9_]*\).*$$/-Wl,--wrap=\1/p' | \
110 sort -u | tr '\n' ' ' >$@
111
112 # Pass the original values of CFLAGS etc. to the sub-make, which will include
113 # Makefile.in again. Otherwise, the flags would be added twice.
114 libmultipath.so.0: $(multipathdir)/libmultipath.so.0
115 @CFLAGS="$(ORIG_CFLAGS)" CPPFLAGS="$(ORIG_CPPFLAGS)" LDFLAGS="$(ORIG_LDFLAGS)" \
116 $(MAKE) -C $(multipathdir) configdir=$(TESTDIR)/conf.d plugindir=$(TESTDIR)/lib test-lib
117
118 # COLON will get expanded during second expansion below
119 COLON:=:
120 .SECONDEXPANSION:
121 %-test: %.o %.o.wrap $$($$@_OBJDEPS) $$($$@_TESTDEPS) $$($$@_TESTDEPS$$(COLON).o=.o.wrap) \
122 libmultipath.so.0 $(mpathutildir)/libmpathutil.so.0 $(mpathcmddir)/libmpathcmd.so.0 Makefile
123 @echo building $@
124 $(Q)$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $< $($@_TESTDEPS) $($@_OBJDEPS) \
125 $(LIBDEPS) $($@_LIBDEPS) \
126 $(shell cat $<.wrap) $(foreach dep,$($@_TESTDEPS),$(shell cat $(dep).wrap))