Imported Upstream version 0.8.4
[platform/upstream/multipath-tools.git] / tests / Makefile
1 include ../Makefile.inc
2
3 # Test special behavior of gcc 4.8 with nested initializers
4 # gcc 4.8 compiles blacklist.c only with -Wno-missing-field-initializers
5 TEST_MISSING_INITIALIZERS = $(shell \
6         echo 'struct A {int a, b;}; struct B {struct A a; int b;} b = {.a.a=1};' | \
7                 $(CC) -c -Werror -Wmissing-field-initializers -o /dev/null -xc - >/dev/null 2>&1 \
8         || echo -Wno-missing-field-initializers)
9 W_MISSING_INITIALIZERS := $(call TEST_MISSING_INITIALIZERS)
10
11 CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir) \
12         -Wno-unused-parameter $(W_MISSING_INITIALIZERS)
13 LIBDEPS += -L$(multipathdir) -lmultipath -lcmocka
14
15 TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy \
16          alias directio
17
18 .SILENT: $(TESTS:%=%.o)
19 .PRECIOUS: $(TESTS:%=%-test)
20
21 all:    $(TESTS:%=%.out)
22
23 # test-specific compiler flags
24 # XYZ-test_FLAGS: Additional compiler flags for this test
25
26 ifneq ($(wildcard directio_test_dev),)
27 DIO_TEST_DEV = $(shell sed -n -e 's/^[[:space:]]*DIO_TEST_DEV[[:space:]]*=[[:space:]]*\([^[:space:]\#]\+\).*/\1/p' < directio_test_dev)
28 endif
29 ifneq ($(DIO_TEST_DEV),)
30 directio-test_FLAGS := -DDIO_TEST_DEV=\"$(DIO_TEST_DEV)\"
31 endif
32
33 # test-specific linker flags
34 # XYZ-test_TESTDEPS: test libraries containing __wrap_xyz functions
35 # XYZ-test_OBJDEPS: object files from libraries to link in explicitly
36 #    That may be necessary if functions called from the object file are wrapped
37 #    (wrapping works only for symbols which are undefined after processing a
38 #    linker input file).
39 # XYZ-test_LIBDEPS: Additional libs to link for this test
40
41 dmevents-test_LIBDEPS = -lpthread -ldevmapper -lurcu
42 hwtable-test_TESTDEPS := test-lib.o
43 hwtable-test_OBJDEPS := ../libmultipath/discovery.o ../libmultipath/blacklist.o \
44         ../libmultipath/prio.o ../libmultipath/callout.o ../libmultipath/structs.o
45 hwtable-test_LIBDEPS := -ludev -lpthread -ldl
46 blacklist-test_TESTDEPS := test-log.o
47 blacklist-test_OBJDEPS := ../libmultipath/blacklist.o
48 blacklist-test_LIBDEPS := -ludev
49 vpd-test_OBJDEPS :=  ../libmultipath/discovery.o
50 vpd-test_LIBDEPS := -ludev -lpthread -ldl
51 alias-test_TESTDEPS := test-log.o
52 alias-test_LIBDEPS := -lpthread -ldl
53 ifneq ($(DIO_TEST_DEV),)
54 directio-test_LIBDEPS := -laio
55 endif
56
57 %.o: %.c
58         $(CC) $(CFLAGS) $($*-test_FLAGS) -c -o $@ $<
59
60 lib/libchecktur.so:
61         mkdir lib
62         ln -t lib ../libmultipath/{checkers,prioritizers,foreign}/*.so
63
64 %.out:  %-test lib/libchecktur.so
65         @echo == running $< ==
66         @LD_LIBRARY_PATH=$(multipathdir):$(mpathcmddir) ./$< >$@
67
68 OBJS = $(TESTS:%=%.o) test-lib.o
69
70 test_clean:
71         $(RM) $(TESTS:%=%.out)
72
73 clean: test_clean dep_clean
74         $(RM) $(TESTS:%=%-test) $(OBJS) *.o.wrap
75         $(RM) -rf lib
76
77 .SECONDARY: $(OBJS)
78
79 include $(wildcard $(OBJS:.o=.d))
80
81 dep_clean:
82         $(RM) $(OBJS:.o=.d)
83
84 %.o.wrap:       %.c
85         @sed -n 's/^.*__wrap_\([a-zA-Z0-9_]*\).*$$/-Wl,--wrap=\1/p' $< | \
86                 sort -u | tr '\n' ' ' >$@
87
88
89 # COLON will get expanded during second expansion below
90 COLON:=:
91 .SECONDEXPANSION:
92 %-test: %.o %.o.wrap $$($$@_OBJDEPS) $$($$@_TESTDEPS) $$($$@_TESTDEPS$$(COLON).o=.o.wrap) \
93                 $(multipathdir)/libmultipath.so Makefile
94         $(CC) $(CFLAGS) -o $@ $(LDFLAGS) $< $($@_TESTDEPS) $($@_OBJDEPS) \
95                 $(LIBDEPS) $($@_LIBDEPS) \
96                 $(shell cat $<.wrap) $(foreach dep,$($@_TESTDEPS),$(shell cat $(dep).wrap))