Simon J. Gerraty b897d72a5a Import bmake-20200517
Changes since 20181221 are mostly portability related
hence the large gap in versions imported.

There are however some bug fixes, and a rework of filemon handling.
In NetBSD make/filemon/filemon_ktrace.c allows use of fktrace
and elimination of filemon(4) which has not had the TLC it needs.

FreeBSD filemon(4) is in much better shape, so bmake/filemon/filemon_dev.c
allows use of that, with a bit less overhead than the ktrace model.

Summary of changes from ChangeLog

	o str.c: empty string does not match % pattern
	  plus unit-test changes
	o var.c: import handling of old sysV style modifier using '%'
	o str.c: refactor brk_string
	o meta.c: meta_oodate, CHECK_VALID_META is too aggressive for CMD
	  a blank command is perfectly valid.
	o meta.c: meta_oodate, check for corrupted meta file
	  earlier and more often.
	* meta.c: meta_compat_parent check for USE_FILEMON
	  patch from Soeren Tempel
	o meta.c: fix compat mode, need to call meta_job_output()
	o job.c: extra fds for meta mode not needed if using filemon_dev
	o meta.c: avoid passing NULL to filemon_*() when meta_needed()
	  returns FALSE.
	o filemon/filemon_{dev,ktrace}.c: allow selection of
	  filemon implementation.  filemon_dev.c uses the kernel module
	  while filemon_ktrace.c leverages the fktrace api available in
	  NetBSD.  filemon_ktrace.c can hopefully form the basis for
	  adding support for other tracing mechanisms such as strace on
	  Linux.
	o meta.c: when target is out-of-date per normal make rules
	  record value of .OODATE in meta file.
	o parse.c: don't pass NULL to realpath(3)
	  some versions cannot handle it.
	o parse.c: ParseDoDependency: free paths rather than assert

plus more unit-tests
2020-05-20 19:34:48 +00:00

156 lines
3.4 KiB
Makefile

# $Id: Makefile,v 1.54 2020/05/17 17:26:14 sjg Exp $
#
# $NetBSD: Makefile,v 1.58 2020/05/17 12:36:26 rillig Exp $
#
# Unit tests for make(1)
# The main targets are:
#
# all: run all the tests
# test: run 'all', and compare to expected results
# accept: move generated output to expected results
#
# Adding a test case.
# Each feature should get its own set of tests in its own suitably
# named makefile (*.mk), with its own set of expected results (*.exp),
# and it should be added to the TESTNAMES list.
#
.MAIN: all
.-include "Makefile.config"
UNIT_TESTS:= ${.PARSEDIR}
.PATH: ${UNIT_TESTS}
# Each test is in a sub-makefile.
# Keep the list sorted.
TESTNAMES= \
comment \
cond-late \
cond1 \
cond2 \
dollar \
doterror \
dotwait \
error \
export \
export-all \
export-env \
forloop \
forsubst \
hash \
include-main \
misc \
moderrs \
modmatch \
modmisc \
modorder \
modts \
modword \
order \
posix \
qequals \
sunshcmd \
sysv \
ternary \
unexport \
unexport-env \
varcmd \
varmisc \
varmod-edge \
varquote \
varshell
# these tests were broken by referting POSIX chanegs
STRICT_POSIX_TESTS = \
escape \
impsrc \
phony-end \
posix1 \
suffixes
# Override make flags for certain tests
flags.doterror=
flags.order=-j1
OUTFILES= ${TESTNAMES:S/$/.out/}
all: ${OUTFILES}
CLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp
CLEANFILES += obj*.[och] lib*.a # posix1.mk
CLEANFILES += issue* .[ab]* # suffixes.mk
CLEANRECURSIVE += dir dummy # posix1.mk
clean:
rm -f ${CLEANFILES}
.if !empty(CLEANRECURSIVE)
rm -rf ${CLEANRECURSIVE}
.endif
TEST_MAKE?= ${.MAKE}
TOOL_SED?= sed
TOOL_TR?= tr
TOOL_DIFF?= diff
.if defined(.PARSEDIR)
# ensure consistent results from sort(1)
LC_ALL= C
LANG= C
.export LANG LC_ALL
.endif
# some tests need extra post-processing
SED_CMDS.varshell = -e 's,^[a-z]*sh: ,,' \
-e '/command/s,No such.*,not found,'
# the tests are actually done with sub-makes.
.SUFFIXES: .mk .rawout .out
.mk.rawout:
@echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC}
-@cd ${.OBJDIR} && \
{ ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \
2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
@mv ${.TARGET}.tmp ${.TARGET}
# We always pretend .MAKE was called 'make'
# and strip ${.CURDIR}/ from the output
# and replace anything after 'stopped in' with unit-tests
# so the results can be compared.
.rawout.out:
@echo postprocess ${.TARGET}
@${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \
-e 's,${TEST_MAKE:C/\./\\\./g},make,' \
-e '/stopped/s, /.*, unit-tests,' \
-e 's,${.CURDIR:C/\./\\\./g}/,,g' \
-e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' ${SED_CMDS.${.TARGET:T:R}} \
< ${.IMPSRC} > ${.TARGET}.tmp
@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
@mv ${.TARGET}.tmp ${.TARGET}
# Compare all output files
test: ${OUTFILES} .PHONY
@failed= ; \
for test in ${TESTNAMES}; do \
${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/$${test}.exp $${test}.out \
|| failed="$${failed}$${failed:+ }$${test}" ; \
done ; \
if [ -n "$${failed}" ]; then \
echo "Failed tests: $${failed}" ; false ; \
else \
echo "All tests passed" ; \
fi
accept:
@for test in ${TESTNAMES}; do \
cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
|| { echo "Replacing $${test}.exp" ; \
cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
done
.if exists(${TEST_MAKE})
${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE}
.endif
.-include <obj.mk>