summaryrefslogtreecommitdiffstats
path: root/tests/Test.mk
blob: 3c020af2c1b4cc91e07eb218e53dede78cd1b0e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#
# Dpkg functional testsuite (kind of)
#
# Copyright © 2008-2012 Guillem Jover <guillem@debian.org>
#

-include ../.pkg-tests.conf

## Feature checks setup ##

include ../Feature.mk

## Test case support ##

ifneq (,$(filter debug,$(DPKG_TESTSUITE_OPTIONS)))
DPKG_MAINTSCRIPT_DEBUG = DPKG_DEBUG=1
endif

DPKG_PATH := $(PATH):/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ifdef DPKG_BUILDTREE
DPKG_PATH := $(DPKG_BUILDTREE)/src:$(DPKG_BUILDTREE)/utils:$(DPKG_BUILDTREE)/scripts:$(DPKG_PATH)
endif

DPKG_ENV = \
  PATH=$(DPKG_PATH) \
  $(DPKG_MAINTSCRIPT_DEBUG)

# eatmydata confuses ASAN link order check.
export ASAN_OPTIONS = verify_asan_link_order=0

ifdef DPKG_BUILDTREE
export DPKG_DATADIR := $(DPKG_BUILDTREE)/src
DPKG_ENV += \
  DPKG_DATADIR="$(DPKG_DATADIR)"
endif

export PATH
PATH = $(DPKG_PATH)

DPKG_OPTIONS =
DPKG_DIVERT_OPTIONS =

ifdef DPKG_AS_ROOT
DPKG_INSTDIR = /
ifeq ($(shell id -u),0)
BEROOT := env $(DPKG_ENV)
else
DPKG_ENV += \
  LD_PRELOAD="$(LD_PRELOAD)" \
  LD_LIBRARY_PATH="$(LD_LIBRARY_PATH)"
BEROOT := sudo -E env $(DPKG_ENV)
endif
else
DPKG_INSTDIR = $(CURDIR)/../dpkginst
DPKG_OPTIONS += \
 --force-script-chrootless \
 --force-not-root \
 # EOL
BEROOT := env $(DPKG_ENV)

DPKG_DIVERT_OPTIONS += \
  --instdir="$(DPKG_INSTDIR)" \
  # EOL
endif

DPKG_OPTIONS += \
  --force-unsafe-io \
  --instdir="$(DPKG_INSTDIR)" \
  --no-debsig --log=/dev/null \
  # EOL

ifneq (,$(filter debug,$(DPKG_TESTSUITE_OPTIONS)))
DPKG_OPTIONS += -D77777
endif

# Always use a local db.
DPKG_ADMINDIR = $(CURDIR)/../dpkgdb
DPKG_COMMON_OPTIONS = --admindir="$(DPKG_ADMINDIR)"

DPKG = dpkg $(DPKG_COMMON_OPTIONS) $(DPKG_OPTIONS)
DPKG_INSTALL = $(BEROOT) $(DPKG) -i
DPKG_UNPACK = $(BEROOT) $(DPKG) --unpack
DPKG_CONFIGURE = $(BEROOT) $(DPKG) --configure
DPKG_REMOVE = $(BEROOT) $(DPKG) -r
DPKG_PURGE = $(BEROOT) $(DPKG) -P
DPKG_VERIFY = $(DPKG) -V
DPKG_DEB = dpkg-deb $(DPKG_DEB_OPTIONS)
DPKG_DIVERT = dpkg-divert $(DPKG_COMMON_OPTIONS) $(DPKG_DIVERT_OPTIONS)
DPKG_DIVERT_ADD = $(BEROOT) $(DPKG_DIVERT) --add
DPKG_DIVERT_DEL = $(BEROOT) $(DPKG_DIVERT) --remove
DPKG_SPLIT = dpkg-split $(DPKG_SPLIT_OPTIONS)
DPKG_BUILD_DEB = $(DPKG_DEB) -b
DPKG_QUERY = dpkg-query $(DPKG_COMMON_OPTIONS) $(DPKG_QUERY_OPTIONS)
DPKG_TRIGGER = dpkg-trigger $(DPKG_COMMON_OPTIONS) $(DPKG_TRIGGER_OPTIONS)

PKG_STATUS = $(DPKG_QUERY) -f '$${Status}' -W

DEB = $(addsuffix .deb,$(TESTS_DEB))

# Common test patterns to use with $(call foo,args...)
stdout_is = test "`$(1)`" = "$(2)"
stdout_has = $(1) | grep -qE "$(2)"
stderr_is = test "`$(1) 2>&1 1>/dev/null`" = "$(2)"
stderr_has = $(1) 2>&1 1>/dev/null | grep -qE "$(2)"
pkg_is_installed = $(call stdout_is,$(PKG_STATUS) $(1),install ok installed)
pkg_is_not_installed = $(call stdout_has,$(PKG_STATUS) $(1) 2>/dev/null, ok not-installed) || ! $(PKG_STATUS) $(1) >/dev/null 2>&1
pkg_status_is = $(call stdout_is,$(PKG_STATUS) $(1),$(2))
pkg_field_is = $(call stdout_is,$(DPKG_QUERY) -f '$${$(2)}' -W $(1),$(3))

%.deb: %
	$(DPKG_BUILD_DEB) $< $@

TEST_CASES :=

build: build-hook $(DEB)

test: build test-case test-clean

clean: clean-hook
	$(RM) $(DEB)

.PHONY: build-hook build test test-case test-clean clean-hook clean

# Most of the tests are serial in nature, as they perform package database
# changes, and the Makefile are written with that in mind. Avoid any
# surprises by explicitly disallowing parallel executions.
.NOTPARALLEL: