Makefile 1.89 KB
Newer Older
1
-include conf.mk
Natanael Copa's avatar
Natanael Copa committed
2 3 4 5 6 7 8 9

repos	:= repo1 repo2

tmproot := /tmp/apk-test
testroot = $(tmproot)/$(basename $@)

SUDO	:= sudo
APK	:= ../src/apk --keys-dir /etc/apk/keys
10

11
SYSREPO ?= http://nl.alpinelinux.org/alpine/edge/main
Natanael Copa's avatar
Natanael Copa committed
12

13 14 15 16 17 18
# Absolute path to QEMU user-mode emulation binary to be copied into every
# $testroot before running test. This is used when running root-tests in
# emulation using QEMU and binfmt (apk --root uses chroot to run pre/post
# install scripts).
QEMU_EMULATOR ?=

Natanael Copa's avatar
Natanael Copa committed
19 20 21
LD_LIBRARY_PATH = ../src
export LD_LIBRARY_PATH SYSREPO

22
all: tests
Natanael Copa's avatar
Natanael Copa committed
23 24 25 26 27

$(repos):
	@echo "Building $@"
	@rm -f repos.out
	@cd $@ &&\
28 29 30
		for i in */APKBUILD; do \
			( cd $${i%/*} && REPODEST="$$PWD/../.." abuild -R ) \
				>> ../repos.out 2>&1 || { cat ../repos.out >&2; exit 1; } \
Natanael Copa's avatar
Natanael Copa committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
		done


clean:
	$(SUDO) rm -rf $(addsuffix /*.apk,$(repos)) $(tmproot) *.ok *.out *.stamp


repos: repos.stamp
	
repos.stamp: $(repos)
	@touch $@
	

%.ok: %.sh
	@echo -n "$<"; \
		rm -rf "$(testroot)" ;\
		mkdir -p "$(testroot)"; \
48 49 50
		if [ -n "$(QEMU_EMULATOR)" ]; then \
			$(SUDO) install -Dm755 "$(QEMU_EMULATOR)" "$(testroot)$(QEMU_EMULATOR)"; \
		fi; \
51
		if ! APK="$(APK)" ROOT="$(testroot)" SYSREPO="$(SYSREPO)" sh -ex ./$< > $(basename $@).out 2>&1; then\
Natanael Copa's avatar
Natanael Copa committed
52
			echo " FAIL";\
53 54 55
			printf "------------- output -------------\n" >&2;\
			cat $(basename $@).out >&2;\
			printf "----------------------------------\n" >&2;\
Natanael Copa's avatar
Natanael Copa committed
56 57 58 59 60 61
			exit 1;\
		fi ;\
		echo " OK" ;\
		$(SUDO) rm -rf $(testroot); \
		touch $@

62 63
root-tests: repos.stamp
	@echo "== Testing `$(APK) --version` (tests that require root permission) =="
64
	@failed=0; for i in test*.sh; do \
Natanael Copa's avatar
Natanael Copa committed
65
		rm -f $${i%.sh}.ok ;\
66 67 68
		$(SUDO) $(MAKE) --no-print-directory $${i%.sh}.ok \
			SYSREPO=$(SYSREPO) \
			QEMU_EMULATOR=$(QEMU_EMULATOR) || failed=1; \
69 70
	done; \
	return $$failed
Natanael Copa's avatar
Natanael Copa committed
71

72 73 74 75 76 77 78
tests:
	@echo "== Testing `$(APK) --version` =="
	@for i in $(sort $(filter-out test%.sh,$(wildcard *.sh))); do \
		./$$i || exit 1 ; \
	done

.PHONY:	$(repos) tests