xref: /netbsd-src/usr.bin/make/test-variants.mk (revision d16b7486a53dcb8072b60ec6fcb4373a2d0c27b7)
1# $NetBSD: test-variants.mk,v 1.5 2023/01/19 19:55:27 rillig Exp $
2#
3# Build several variants of make and run the tests on them.
4#
5# The output of this test suite must be inspected manually to see the
6# interesting details.  The main purpose is to list the available build
7# options.
8
9.MAIN: usage
10usage:
11	@echo 'usage: ${MAKE} -f ${MAKEFILE} list'
12	@echo '       ${MAKE} -f ${MAKEFILE} all'
13	@echo '       ${MAKE} -f ${MAKEFILE} <test>...'
14
15
16TESTS+=			default
17#ENV.default=		VAR=value...
18#CPPFLAGS.default=	-DMACRO -I...
19#CFLAGS.default=	-O1
20#SKIP.default=		yes
21#SKIP_TESTS.default=	varmod-subst
22
23# Try a different compiler, with slightly different warnings and error
24# messages.  Clang has a few stricter checks than GCC, concerning enums
25# and non-literal format strings.
26#
27TESTS+=			llvm
28ENV.llvm=		HAVE_LLVM="yes"
29
30# Use emalloc for memory allocation.
31TESTS+=			emalloc
32ENV.emalloc=		TOOLDIR=""
33
34# NetBSD 10 fails with:
35# filemon_dev.c:93:19: error: 'FILEMON_SET_FD' undeclared
36TESTS+=			filemon-dev
37ENV.filemon-dev=	USE_FILEMON="dev"
38SKIP.filemon-dev=	yes
39
40TESTS+=			filemon-ktrace
41ENV.filemon-ktrace=	USE_FILEMON="ktrace"
42
43TESTS+=			filemon-none
44ENV.filemon-none=	USE_FILEMON="no"
45# The following tests only fail due to the extra variable in the debug log.
46SKIP_TESTS.filemon-none= \
47			opt-debug-graph1 \
48			opt-debug-graph2 \
49			opt-debug-graph3 \
50			suff-main-several \
51			suff-transform-debug
52
53TESTS+=			no-meta
54ENV.no-meta=		USE_META="no"
55SKIP_TESTS.no-meta=	depsrc-meta meta-cmd-cmp
56
57TESTS+=			cleanup
58CPPFLAGS.cleanup=	-DCLEANUP
59
60TESTS+=			debug-refcnt
61CPPFLAGS.debug-refcnt=	-DDEBUG_REFCNT
62
63TESTS+=			debug-hash
64CPPFLAGS.debug-hash=	-DDEBUG_HASH_LOOKUP
65SKIP_TESTS.debug-hash=	opt-debug-hash	# mixes regular and debug output
66
67TESTS+=			debug-meta
68CPPFLAGS.debug-meta=	-DDEBUG_META_MODE
69SKIP_TESTS.debug-meta=	depsrc-meta meta-cmd-cmp # generate extra debug output
70
71# Produces lots of debugging output.
72#
73TESTS+=			debug-src
74CPPFLAGS.debug-src=	-DDEBUG_SRC
75SKIP.debug-src=		yes
76
77# NetBSD 8.0 x86_64
78# In file included from arch.c:135:0:
79# /usr/include/sys/param.h:357:0: error: "MAXPATHLEN" redefined [-Werror]
80TESTS+=			maxpathlen
81CPPFLAGS.maxpathlen=	-DMAXPATHLEN=20
82SKIP.maxpathlen=	yes
83
84# In this variant, the unit tests using the modifier ':C' fail, as expected.
85#
86TESTS+=			no-regex
87CPPFLAGS.no-regex=	-DNO_REGEX
88SKIP_TESTS.no-regex=	archive cond-short deptgt-makeflags dollar export-all
89SKIP_TESTS.no-regex+=	moderrs modmatch modmisc var-eval-short
90SKIP_TESTS.no-regex+=	varmod-select-words varmod-subst varmod-subst-regex
91SKIP_TESTS.no-regex+=	varname-dot-make-pid varname-dot-make-ppid
92
93# NetBSD 8.0 x86_64 says:
94# In file included from /usr/include/sys/param.h:115:0,
95#                 from arch.c:135:
96# /usr/include/sys/syslimits.h:60:0: error: "PATH_MAX" redefined [-Werror]
97TESTS+=			path_max
98CPPFLAGS.path_max=	-DPATH_MAX=20
99SKIP.path_max=		yes
100
101# This higher optimization level may trigger additional "may be used
102# uninitialized" errors. Could be combined with other compilers as well.
103#
104TESTS+=			opt-3
105CFLAGS.opt-3=		-O3
106
107# When optimizing for small code size, GCC gets confused by the initialization
108# status of local variables in some cases.
109TESTS+=			opt-size
110CFLAGS.opt-size=	-Os
111
112TESTS+=			opt-none
113CFLAGS.opt-none=	-O0 -ggdb
114
115# Ensure that every inline function is declared as MAKE_ATTR_UNUSED.
116TESTS+=			no-inline
117CPPFLAGS.no-inline=	-Dinline=
118
119# Is expected to fail with "<stdbool.h> is included in pre-C99 mode" since
120# main.c includes <sys/sysctl.h>, which includes <stdbool.h> even in pre-C99
121# mode.  This would lead to inconsistent definitions of bool and thus
122# differently sized struct CmdOpts and others.
123TESTS+=			c90-plain
124ENV.c90-plain=		USE_FILEMON=no	# filemon uses designated initializers
125CFLAGS.c90-plain=	-std=c90 -ansi -pedantic -Wno-system-headers
126SKIP.c90-plain=		yes
127
128# The make source code is _intended_ to be compatible with C90, it uses some
129# C99 features though (snprintf).  The workaround with USE_C99_BOOLEAN is
130# necessary on NetBSD 9.99 since main.c includes <sys/sysctl.h>, which
131# includes <stdbool.h> even in pre-C99 mode.
132TESTS+=			c90-stdbool
133ENV.c90-stdbool=	USE_FILEMON=no	# filemon uses designated initializers
134CFLAGS.c90-stdbool=	-std=c90 -ansi -pedantic -Wno-system-headers
135CPPFLAGS.c90-stdbool=	-DUSE_C99_BOOLEAN
136
137# Ensure that there are only side-effect-free conditions in the assert
138# macro, or at least none that affect the outcome of the tests.
139#
140TESTS+=			no-assert
141CPPFLAGS.no-assert=	-DNDEBUG
142
143# Only in native mode, make dares to use a shortcut in Compat_RunCommand
144# that circumvents the shell and instead calls execvp directly.
145# Another effect is that the shell is run with -q, which prevents the
146# -x and -v flags from echoing the commands from profile files.
147TESTS+=			non-native
148CPPFLAGS.non-native=	-UMAKE_NATIVE
149CPPFLAGS.non-native+=	-DHAVE_STRERROR -DHAVE_SETENV -DHAVE_VSNPRINTF
150
151# Running the code coverage using gcov took a long time on NetBSD < 10, due to
152# https://gnats.netbsd.org/55808.
153#
154# Combining USE_COVERAGE with HAVE_LLVM does not work since ld fails to link
155# with the coverage library.
156#
157# Turning the optimization off is required because gcov does not work on the
158# source code level but on the intermediate code after optimization:
159# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96622
160#
161TESTS+=			coverage
162ENV.coverage=		USE_COVERAGE="yes"
163CFLAGS.coverage=	-O0 -ggdb
164
165TESTS+=			fort
166ENV.fort=		USE_FORT="yes"
167
168# Ensure that the tests can be specified either as relative filenames or
169# as absolute filenames.
170TESTS+=			abs
171ENV.abs=		USE_ABSOLUTE_TESTNAMES="yes"
172
173# This test is the result of reading through the GCC 10 "Warning Options"
174# documentation, noting down everything that sounded interesting.
175#
176TESTS+=			gcc-warn
177CFLAGS.gcc-warn=	-Wmisleading-indentation
178CFLAGS.gcc-warn+=	-Wmissing-attributes
179CFLAGS.gcc-warn+=	-Wmissing-braces
180CFLAGS.gcc-warn+=	-Wextra
181CFLAGS.gcc-warn+=	-Wnonnull
182CFLAGS.gcc-warn+=	-Wnonnull-compare
183CFLAGS.gcc-warn+=	-Wnull-dereference
184CFLAGS.gcc-warn+=	-Wimplicit
185CFLAGS.gcc-warn+=	-Wimplicit-fallthrough=4
186CFLAGS.gcc-warn+=	-Wignored-qualifiers
187CFLAGS.gcc-warn+=	-Wunused
188CFLAGS.gcc-warn+=	-Wunused-but-set-variable
189CFLAGS.gcc-warn+=	-Wunused-parameter
190CFLAGS.gcc-warn+=	-Wduplicated-branches
191CFLAGS.gcc-warn+=	-Wduplicated-cond
192CFLAGS.gcc-warn+=	-Wunused-macros
193CFLAGS.gcc-warn+=	-Wcast-function-type
194CFLAGS.gcc-warn+=	-Wconversion
195CFLAGS.gcc-warn+=	-Wenum-compare
196CFLAGS.gcc-warn+=	-Wmissing-field-initializers
197CFLAGS.gcc-warn+=	-Wredundant-decls
198CFLAGS.gcc-warn+=	-Wno-error=conversion
199CFLAGS.gcc-warn+=	-Wno-error=sign-conversion
200CFLAGS.gcc-warn+=	-Wno-error=unused-macros
201CFLAGS.gcc-warn+=	-Wno-error=unused-parameter
202CFLAGS.gcc-warn+=	-Wno-error=duplicated-branches
203
204.for shell in /usr/pkg/bin/bash /usr/pkg/bin/dash
205.  if exists(${shell})
206TESTS+=		${shell:T}
207CPPFLAGS.${shell:T}=	-DDEFSHELL_CUSTOM="\"${shell}\""
208.  endif
209.endfor
210
211
212.MAKEFLAGS: -k
213.MAKE.DEPENDFILE=	nonexistent
214
215.PHONY: usage list all ${TESTS}
216
217all: ${TESTS:${TESTS:@t@${SKIP.$t:Myes:%=N$t}@:ts:}}
218
219SLOW_TESTS=	dotwait sh-flags
220
221.for test in ${TESTS}
222_ENV.${test}=	PATH="$$PATH"
223_ENV.${test}+=	USETOOLS="no"
224_ENV.${test}+=	MALLOC_OPTIONS="JA"		# for jemalloc 1.0.0
225_ENV.${test}+=	MALLOC_CONF="junk:true"		# for jemalloc 5.1.0
226_ENV.${test}+=	_MKMSG_COMPILE=":"
227_ENV.${test}+=	_MKMSG_CREATE=":"
228_ENV.${test}+=	_MKMSG_FORMAT=":"
229_ENV.${test}+=	_MKMSG_TEST=":"
230_ENV.${test}+=	${ENV.${test}}
231_ENV.${test}+=	USER_CPPFLAGS=${CPPFLAGS.${.TARGET}:Q}
232_ENV.${test}+=	USER_CFLAGS=${CFLAGS.${.TARGET}:Q}
233_ENV.${test}+=	BROKEN_TESTS=${${SLOW_TESTS} ${SKIP_TESTS.${.TARGET}}:L:Q}
234.endfor
235
236${TESTS}: run-test
237run-test: .USE
238	@echo "===> Running ${.TARGET}"
239	@echo "env: "${ENV.${.TARGET}:U"(none)"}
240	@echo "cflags: "${CFLAGS.${.TARGET}:U(none):Q}
241	@echo "cppflags: "${CPPFLAGS.${.TARGET}:U(none):Q}
242
243	@env -i ${_ENV.${.TARGET}} sh -ce "ma""ke -s cleandir"
244	@env -i ${_ENV.${.TARGET}} sh -ce "ma""ke -ks -j6 dependall"
245	@size *.o make
246	@env -i ${_ENV.${.TARGET}} sh -ce "ma""ke -s test"
247
248list:
249	@printf '%s%s\n' ${TESTS:O:@t@$t '${SKIP.$t:Myes:%= (skipped)}'@}
250