test: libcriu: use installed headers and library

Install libcriu into a local staging directory (.install/) using
'make install-lib' and reference only that directory during build
and test:

  CFLAGS  := -I$(INSTALL_DIR)/include/criu
  LDFLAGS := -L$(INSTALL_DIR)/lib -lcriu
  LD_LIBRARY_PATH=${MAIN_DIR}/.install/lib

Nothing from the non-test part of the repo is used at compile,
link, or run time.

The compile rule is also corrected to use $< instead of $^
for gcc -c.

Fixes: #2927

Signed-off-by: Ahmed Elaidy <elaidya225@gmail.com>
This commit is contained in:
Ahmed Elaidy 2026-03-03 21:00:22 +02:00 committed by Radostin Stoyanov
parent 3f3acc3200
commit 04f1b9fb62
2 changed files with 24 additions and 16 deletions

View file

@ -11,6 +11,16 @@ TESTS += test_pre_dump
TESTS += test_check
TESTS += test_feature_check
# Install libcriu (headers and library) into a local staging directory so
# that nothing from the non-test part of the repo is referenced directly
# during the build or at runtime.
INSTALL_DIR:= $(CURDIR)/.install
CRIU_INCLUDE:= $(INSTALL_DIR)/include/criu
CRIU_LIB:= $(INSTALL_DIR)/lib
CFLAGS:= -I$(CRIU_INCLUDE)
LDFLAGS:= -L$(CRIU_LIB) -lcriu
all: $(TESTS)
.PHONY: all
@ -18,24 +28,24 @@ run: all
./run.sh
.PHONY: run
$(CRIU_LIB)/libcriu.so:
$(MAKE) -C ../../../../criu install-lib \
DESTDIR=$(INSTALL_DIR) PREFIX=/ LIBDIR=/lib \
SKIP_PIP_INSTALL=1
$(CRIU_INCLUDE): $(CRIU_LIB)/libcriu.so
@:
define genb
$(1): $(1).o lib.o
gcc $$^ -L ../../../../criu/lib/c/ -L ../../../../criu/images/ -lcriu -o $$@
gcc $$^ $(LDFLAGS) -o $$@
endef
$(foreach t, $(TESTS), $(eval $(call genb, $(t))))
%.o: %.c
gcc -c $^ -iquote ../../../../criu/criu/include -I../../../../criu/lib/c/ -I../../../../criu/images/ -o $@ -Werror
%.o: %.c | $(CRIU_INCLUDE)
gcc -c $< $(CFLAGS) -o $@ -Werror
clean: libcriu_clean
rm -rf $(TESTS) $(TESTS:%=%.o) lib.o
clean:
rm -rf $(TESTS) $(TESTS:%=%.o) lib.o $(INSTALL_DIR)
.PHONY: clean
libcriu_clean:
rm -f libcriu.so.${CRIU_SO_VERSION_MAJOR}
.PHONY: libcriu_clean
libcriu:
ln -s ../../../../criu/lib/c/libcriu.so libcriu.so.${CRIU_SO_VERSION_MAJOR}
.PHONY: libcriu

View file

@ -14,12 +14,11 @@ source "${MAIN_DIR}/../env.sh" || exit 1
echo "== Clean"
make clean
make libcriu
rm -rf "${OUTPUT_DIR}"
echo "== Run tests"
export LD_LIBRARY_PATH=.
export LD_LIBRARY_PATH=${MAIN_DIR}/.install/lib
export PATH="${MAIN_DIR}/../../../criu:${PATH}"
RESULT=0
@ -76,6 +75,5 @@ fi
run_test test_feature_check
echo "== Tests done"
make libcriu_clean
[ "${RESULT}" -eq 0 ] && echo "Success" || echo "FAIL"
exit "${RESULT}"