[dm-devel] [PATCH 1/7] multipath-tools: enable local configdir and plugindir for unit tests
mwilck at suse.com
mwilck at suse.com
Tue May 3 22:06:40 UTC 2022
From: Martin Wilck <mwilck at suse.com>
After the recent patches disabling the config_dir and multipath_dir
runtime options, we need to take special care while building the
unit tests. Create separate object files to link with the unit tests
(e.g. "config-test.o" instead of "config.o"), using overrides for
"configdir" and "plugindir".
Signed-off-by: Martin Wilck <mwilck at suse.com>
---
libmultipath/Makefile | 24 ++++++++++++++++++------
tests/Makefile | 9 ++++++---
tests/hwtable.c | 7 +++----
3 files changed, 27 insertions(+), 13 deletions(-)
diff --git a/libmultipath/Makefile b/libmultipath/Makefile
index b3a48c4..a56dd1e 100644
--- a/libmultipath/Makefile
+++ b/libmultipath/Makefile
@@ -49,17 +49,24 @@ ifneq ($(call check_var,ELS_DTAG_LNK_INTEGRITY,$(LINUX_HEADERS_INCDIR)/scsi/fc/f
CFLAGS += -DFPIN_EVENT_HANDLER
endif
+# object files referencing MULTIPATH_DIR or CONFIG_DIR
+# they need to be recompiled for unit tests
+OBJS-U := prio.o checkers.o foreign.o config.o
+OBJS-T := $(patsubst %.o,%-test.o,$(OBJS-U))
-OBJS = parser.o vector.o devmapper.o \
- hwtable.o blacklist.o util.o dmparser.o config.o \
+# other object files
+OBJS-O := parser.o vector.o devmapper.o \
+ hwtable.o blacklist.o util.o dmparser.o \
structs.o discovery.o propsel.o dict.o \
pgpolicies.o debug.o defaults.o uevent.o time-util.o \
switchgroup.o uxsock.o print.o alias.o log_pthread.o \
- log.o configure.o structs_vec.o sysfs.o prio.o checkers.o \
+ log.o configure.o structs_vec.o sysfs.o \
lock.o file.o wwids.o prioritizers/alua_rtpg.o prkey.o \
- io_err_stat.o dm-generic.o generic.o foreign.o nvme-lib.o \
+ io_err_stat.o dm-generic.o generic.o nvme-lib.o \
libsg.o valid.o strbuf.o
+OBJS := $(OBJS-O) $(OBJS-U)
+
all: $(DEVLIB)
nvme-lib.o: nvme-lib.c nvme-ioctl.c nvme-ioctl.h
@@ -97,11 +104,16 @@ $(LIBS:%.so.$(SONAME)=%-nv.so): $(OBJS) $(NV_VERSION_SCRIPT)
abi: $(LIBS:%.so.$(SONAME)=%-nv.abi)
-../tests/$(LIBS): $(OBJS) $(VERSION_SCRIPT)
+../tests/$(LIBS): $(OBJS-O) $(OBJS-T) $(VERSION_SCRIPT)
$(CC) $(LDFLAGS) $(SHARED_FLAGS) -Wl,-soname=`basename $@` \
- -o $@ $(OBJS) $(LIBDEPS)
+ -o $@ $(OBJS-O) $(OBJS-T) $(LIBDEPS)
$(LN) $@ ${@:.so.0=.so}
+# This rule is invoked from tests/Makefile, overriding configdir and plugindir
+%-test.o: %.c
+ @echo building $@ because of $?
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
+
test-lib: ../tests/$(LIBS)
install: all
diff --git a/tests/Makefile b/tests/Makefile
index 8cbc4b7..7341b7e 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -9,7 +9,7 @@ TEST_MISSING_INITIALIZERS = $(shell \
W_MISSING_INITIALIZERS := $(call TEST_MISSING_INITIALIZERS)
CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir) \
- -Wno-unused-parameter $(W_MISSING_INITIALIZERS)
+ -Wno-unused-parameter $(W_MISSING_INITIALIZERS) -DTESTCONFDIR=\"$(CURDIR)/conf.d\"
LIBDEPS += -L. -L$(mpathcmddir) -lmultipath -lmpathcmd -lcmocka
TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy \
@@ -40,6 +40,9 @@ mpathvalid-test_FLAGS := -I$(mpathvaliddir)
# That may be necessary if functions called from the object file are wrapped
# (wrapping works only for symbols which are undefined after processing a
# linker input file).
+# Some object files, e.g. "config.o", are compiled separately for the
+# unit tests. Look for OBJS-U in libmultipath/Makefile. Make sure to use the
+# unit test file, e.g. "config-test.o", in XYZ-test_OBJDEPS
# XYZ-test_LIBDEPS: Additional libs to link for this test
dmevents-test_OBJDEPS = ../libmultipath/devmapper.o
@@ -91,7 +94,7 @@ valgrind_clean:
clean: test_clean valgrind_clean dep_clean
$(RM) $(TESTS:%=%-test) $(OBJS) *.o.wrap
- $(RM) -rf lib
+ $(RM) -rf lib conf.d
.SECONDARY: $(OBJS)
@@ -105,7 +108,7 @@ dep_clean:
sort -u | tr '\n' ' ' >$@
libmultipath.so.0:
- $(MAKE) -C $(multipathdir) test-lib
+ make -C $(multipathdir) configdir=$(CURDIR)/conf.d plugindir=$(CURDIR)/lib test-lib
# COLON will get expanded during second expansion below
COLON:=:
diff --git a/tests/hwtable.c b/tests/hwtable.c
index 79bfa5f..400e114 100644
--- a/tests/hwtable.c
+++ b/tests/hwtable.c
@@ -143,12 +143,11 @@ static int setup(void **state)
}
hwt->tmpname = strdup(buf);
- snprintf(buf, sizeof(buf), "%s", tmplate);
- if (mkdtemp(buf) == NULL) {
- condlog(0, "mkdtemp (2): %s", strerror(errno));
+ hwt->dirname = strdup(TESTCONFDIR);
+ if (mkdir(hwt->dirname, 0744) != 0) {
+ condlog(0, "mkdir %s: %s", hwt->dirname, strerror(errno));
goto err;
}
- hwt->dirname = strdup(buf);
make_config_file_path(buf, sizeof(buf), hwt, -1);
hwt->config_file = fopen(buf, "w+");
--
2.36.0
More information about the dm-devel
mailing list