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