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