test-variants.mk revision 1.6 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
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 # Use emalloc for memory allocation.
31 TESTS+= emalloc
32 ENV.emalloc= TOOLDIR=""
33
34 # NetBSD 10 fails with:
35 # filemon_dev.c:93:19: error: 'FILEMON_SET_FD' undeclared
36 TESTS+= filemon-dev
37 ENV.filemon-dev= USE_FILEMON="dev"
38 SKIP.filemon-dev= yes
39
40 TESTS+= filemon-ktrace
41 ENV.filemon-ktrace= USE_FILEMON="ktrace"
42
43 TESTS+= filemon-none
44 ENV.filemon-none= USE_FILEMON="no"
45 # The following tests only fail due to the extra variable in the debug log.
46 SKIP_TESTS.filemon-none= \
47 opt-debug-graph1 \
48 opt-debug-graph2 \
49 opt-debug-graph3 \
50 suff-main-several \
51 suff-transform-debug
52
53 TESTS+= no-meta
54 ENV.no-meta= USE_META="no"
55 SKIP_TESTS.no-meta= depsrc-meta meta-cmd-cmp
56
57 TESTS+= cleanup
58 CPPFLAGS.cleanup= -DCLEANUP
59
60 TESTS+= debug-refcnt
61 CPPFLAGS.debug-refcnt= -DDEBUG_REFCNT
62
63 TESTS+= debug-hash
64 CPPFLAGS.debug-hash= -DDEBUG_HASH_LOOKUP
65 SKIP_TESTS.debug-hash= opt-debug-hash # mixes regular and debug output
66
67 TESTS+= debug-meta
68 CPPFLAGS.debug-meta= -DDEBUG_META_MODE
69 SKIP_TESTS.debug-meta= depsrc-meta meta-cmd-cmp # generate extra debug output
70
71 # Produces lots of debugging output.
72 #
73 TESTS+= debug-src
74 CPPFLAGS.debug-src= -DDEBUG_SRC
75 SKIP.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]
80 TESTS+= maxpathlen
81 CPPFLAGS.maxpathlen= -DMAXPATHLEN=20
82 SKIP.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]
88 TESTS+= path_max
89 CPPFLAGS.path_max= -DPATH_MAX=20
90 SKIP.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 #
95 TESTS+= opt-3
96 CFLAGS.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.
100 TESTS+= opt-size
101 CFLAGS.opt-size= -Os
102
103 TESTS+= opt-none
104 CFLAGS.opt-none= -O0 -ggdb
105
106 # Ensure that every inline function is declared as MAKE_ATTR_UNUSED.
107 TESTS+= no-inline
108 CPPFLAGS.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.
114 TESTS+= c90-plain
115 ENV.c90-plain= USE_FILEMON=no # filemon uses designated initializers
116 CFLAGS.c90-plain= -std=c90 -ansi -pedantic -Wno-system-headers
117 SKIP.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.
123 TESTS+= c90-stdbool
124 ENV.c90-stdbool= USE_FILEMON=no # filemon uses designated initializers
125 CFLAGS.c90-stdbool= -std=c90 -ansi -pedantic -Wno-system-headers
126 CPPFLAGS.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 #
131 TESTS+= no-assert
132 CPPFLAGS.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.
138 TESTS+= non-native
139 CPPFLAGS.non-native= -UMAKE_NATIVE
140 CPPFLAGS.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 #
152 TESTS+= coverage
153 ENV.coverage= USE_COVERAGE="yes"
154 CFLAGS.coverage= -O0 -ggdb
155
156 TESTS+= fort
157 ENV.fort= USE_FORT="yes"
158
159 # Ensure that the tests can be specified either as relative filenames or
160 # as absolute filenames.
161 TESTS+= abs
162 ENV.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 #
167 TESTS+= gcc-warn
168 CFLAGS.gcc-warn= -Wmisleading-indentation
169 CFLAGS.gcc-warn+= -Wmissing-attributes
170 CFLAGS.gcc-warn+= -Wmissing-braces
171 CFLAGS.gcc-warn+= -Wextra
172 CFLAGS.gcc-warn+= -Wnonnull
173 CFLAGS.gcc-warn+= -Wnonnull-compare
174 CFLAGS.gcc-warn+= -Wnull-dereference
175 CFLAGS.gcc-warn+= -Wimplicit
176 CFLAGS.gcc-warn+= -Wimplicit-fallthrough=4
177 CFLAGS.gcc-warn+= -Wignored-qualifiers
178 CFLAGS.gcc-warn+= -Wunused
179 CFLAGS.gcc-warn+= -Wunused-but-set-variable
180 CFLAGS.gcc-warn+= -Wunused-parameter
181 CFLAGS.gcc-warn+= -Wduplicated-branches
182 CFLAGS.gcc-warn+= -Wduplicated-cond
183 CFLAGS.gcc-warn+= -Wunused-macros
184 CFLAGS.gcc-warn+= -Wcast-function-type
185 CFLAGS.gcc-warn+= -Wconversion
186 CFLAGS.gcc-warn+= -Wenum-compare
187 CFLAGS.gcc-warn+= -Wmissing-field-initializers
188 CFLAGS.gcc-warn+= -Wredundant-decls
189 CFLAGS.gcc-warn+= -Wno-error=conversion
190 CFLAGS.gcc-warn+= -Wno-error=sign-conversion
191 CFLAGS.gcc-warn+= -Wno-error=unused-macros
192 CFLAGS.gcc-warn+= -Wno-error=unused-parameter
193 CFLAGS.gcc-warn+= -Wno-error=duplicated-branches
194
195 .for shell in /usr/pkg/bin/bash /usr/pkg/bin/dash
196 . if exists(${shell})
197 TESTS+= ${shell:T}
198 CPPFLAGS.${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
208 all: ${TESTS:${TESTS:@t@${SKIP.$t:Myes:%=N$t}@:ts:}}
209
210 SLOW_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
228 run-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
239 list:
240 @printf '%s%s\n' ${TESTS:O:@t@$t '${SKIP.$t:Myes:%= (skipped)}'@}
241