xref: /netbsd-src/usr.bin/make/test-variants.mk (revision 345cf9fb81bd0411c53e25d62cd93bdcaa865312)
1# $NetBSD: test-variants.mk,v 1.6 2024/03/01 17:47:05 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# NetBSD 8.0 x86_64 says:
85# In file included from /usr/include/sys/param.h:115:0,
86#                 from arch.c:135:
87# /usr/include/sys/syslimits.h:60:0: error: "PATH_MAX" redefined [-Werror]
88TESTS+=			path_max
89CPPFLAGS.path_max=	-DPATH_MAX=20
90SKIP.path_max=		yes
91
92# This higher optimization level may trigger additional "may be used
93# uninitialized" errors. Could be combined with other compilers as well.
94#
95TESTS+=			opt-3
96CFLAGS.opt-3=		-O3
97
98# When optimizing for small code size, GCC gets confused by the initialization
99# status of local variables in some cases.
100TESTS+=			opt-size
101CFLAGS.opt-size=	-Os
102
103TESTS+=			opt-none
104CFLAGS.opt-none=	-O0 -ggdb
105
106# Ensure that every inline function is declared as MAKE_ATTR_UNUSED.
107TESTS+=			no-inline
108CPPFLAGS.no-inline=	-Dinline=
109
110# Is expected to fail with "<stdbool.h> is included in pre-C99 mode" since
111# main.c includes <sys/sysctl.h>, which includes <stdbool.h> even in pre-C99
112# mode.  This would lead to inconsistent definitions of bool and thus
113# differently sized struct CmdOpts and others.
114TESTS+=			c90-plain
115ENV.c90-plain=		USE_FILEMON=no	# filemon uses designated initializers
116CFLAGS.c90-plain=	-std=c90 -ansi -pedantic -Wno-system-headers
117SKIP.c90-plain=		yes
118
119# The make source code is _intended_ to be compatible with C90, it uses some
120# C99 features though (snprintf).  The workaround with USE_C99_BOOLEAN is
121# necessary on NetBSD 9.99 since main.c includes <sys/sysctl.h>, which
122# includes <stdbool.h> even in pre-C99 mode.
123TESTS+=			c90-stdbool
124ENV.c90-stdbool=	USE_FILEMON=no	# filemon uses designated initializers
125CFLAGS.c90-stdbool=	-std=c90 -ansi -pedantic -Wno-system-headers
126CPPFLAGS.c90-stdbool=	-DUSE_C99_BOOLEAN
127
128# Ensure that there are only side-effect-free conditions in the assert
129# macro, or at least none that affect the outcome of the tests.
130#
131TESTS+=			no-assert
132CPPFLAGS.no-assert=	-DNDEBUG
133
134# Only in native mode, make dares to use a shortcut in Compat_RunCommand
135# that circumvents the shell and instead calls execvp directly.
136# Another effect is that the shell is run with -q, which prevents the
137# -x and -v flags from echoing the commands from profile files.
138TESTS+=			non-native
139CPPFLAGS.non-native=	-UMAKE_NATIVE
140CPPFLAGS.non-native+=	-DHAVE_STRERROR -DHAVE_SETENV -DHAVE_VSNPRINTF
141
142# Running the code coverage using gcov took a long time on NetBSD < 10, due to
143# https://gnats.netbsd.org/55808.
144#
145# Combining USE_COVERAGE with HAVE_LLVM does not work since ld fails to link
146# with the coverage library.
147#
148# Turning the optimization off is required because gcov does not work on the
149# source code level but on the intermediate code after optimization:
150# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96622
151#
152TESTS+=			coverage
153ENV.coverage=		USE_COVERAGE="yes"
154CFLAGS.coverage=	-O0 -ggdb
155
156TESTS+=			fort
157ENV.fort=		USE_FORT="yes"
158
159# Ensure that the tests can be specified either as relative filenames or
160# as absolute filenames.
161TESTS+=			abs
162ENV.abs=		USE_ABSOLUTE_TESTNAMES="yes"
163
164# This test is the result of reading through the GCC 10 "Warning Options"
165# documentation, noting down everything that sounded interesting.
166#
167TESTS+=			gcc-warn
168CFLAGS.gcc-warn=	-Wmisleading-indentation
169CFLAGS.gcc-warn+=	-Wmissing-attributes
170CFLAGS.gcc-warn+=	-Wmissing-braces
171CFLAGS.gcc-warn+=	-Wextra
172CFLAGS.gcc-warn+=	-Wnonnull
173CFLAGS.gcc-warn+=	-Wnonnull-compare
174CFLAGS.gcc-warn+=	-Wnull-dereference
175CFLAGS.gcc-warn+=	-Wimplicit
176CFLAGS.gcc-warn+=	-Wimplicit-fallthrough=4
177CFLAGS.gcc-warn+=	-Wignored-qualifiers
178CFLAGS.gcc-warn+=	-Wunused
179CFLAGS.gcc-warn+=	-Wunused-but-set-variable
180CFLAGS.gcc-warn+=	-Wunused-parameter
181CFLAGS.gcc-warn+=	-Wduplicated-branches
182CFLAGS.gcc-warn+=	-Wduplicated-cond
183CFLAGS.gcc-warn+=	-Wunused-macros
184CFLAGS.gcc-warn+=	-Wcast-function-type
185CFLAGS.gcc-warn+=	-Wconversion
186CFLAGS.gcc-warn+=	-Wenum-compare
187CFLAGS.gcc-warn+=	-Wmissing-field-initializers
188CFLAGS.gcc-warn+=	-Wredundant-decls
189CFLAGS.gcc-warn+=	-Wno-error=conversion
190CFLAGS.gcc-warn+=	-Wno-error=sign-conversion
191CFLAGS.gcc-warn+=	-Wno-error=unused-macros
192CFLAGS.gcc-warn+=	-Wno-error=unused-parameter
193CFLAGS.gcc-warn+=	-Wno-error=duplicated-branches
194
195.for shell in /usr/pkg/bin/bash /usr/pkg/bin/dash
196.  if exists(${shell})
197TESTS+=		${shell:T}
198CPPFLAGS.${shell:T}=	-DDEFSHELL_CUSTOM="\"${shell}\""
199.  endif
200.endfor
201
202
203.MAKEFLAGS: -k
204.MAKE.DEPENDFILE=	nonexistent
205
206.PHONY: usage list all ${TESTS}
207
208all: ${TESTS:${TESTS:@t@${SKIP.$t:Myes:%=N$t}@:ts:}}
209
210SLOW_TESTS=	dotwait sh-flags
211
212.for test in ${TESTS}
213_ENV.${test}=	PATH="$$PATH"
214_ENV.${test}+=	USETOOLS="no"
215_ENV.${test}+=	MALLOC_OPTIONS="JA"		# for jemalloc 1.0.0
216_ENV.${test}+=	MALLOC_CONF="junk:true"		# for jemalloc 5.1.0
217_ENV.${test}+=	_MKMSG_COMPILE=":"
218_ENV.${test}+=	_MKMSG_CREATE=":"
219_ENV.${test}+=	_MKMSG_FORMAT=":"
220_ENV.${test}+=	_MKMSG_TEST=":"
221_ENV.${test}+=	${ENV.${test}}
222_ENV.${test}+=	USER_CPPFLAGS=${CPPFLAGS.${.TARGET}:Q}
223_ENV.${test}+=	USER_CFLAGS=${CFLAGS.${.TARGET}:Q}
224_ENV.${test}+=	BROKEN_TESTS=${${SLOW_TESTS} ${SKIP_TESTS.${.TARGET}}:L:Q}
225.endfor
226
227${TESTS}: run-test
228run-test: .USE
229	@echo "===> Running ${.TARGET}"
230	@echo "env: "${ENV.${.TARGET}:U"(none)"}
231	@echo "cflags: "${CFLAGS.${.TARGET}:U(none):Q}
232	@echo "cppflags: "${CPPFLAGS.${.TARGET}:U(none):Q}
233
234	@env -i ${_ENV.${.TARGET}} sh -ce "ma""ke -s cleandir"
235	@env -i ${_ENV.${.TARGET}} sh -ce "ma""ke -ks -j6 dependall"
236	@size *.o make
237	@env -i ${_ENV.${.TARGET}} sh -ce "ma""ke -s test"
238
239list:
240	@printf '%s%s\n' ${TESTS:O:@t@$t '${SKIP.$t:Myes:%= (skipped)}'@}
241