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