Makefile revision 1.341 1 # $NetBSD: Makefile,v 1.341 2023/09/09 16:41:04 sjg Exp $
2 #
3 # Unit tests for make(1)
4 #
5 # The main targets are:
6 #
7 # all:
8 # run all the tests
9 # test:
10 # run 'all', and compare to expected results
11 # accept:
12 # move generated output to expected results
13 #
14 # Settable variables
15 #
16 # TEST_MAKE
17 # The make program to be tested.
18 #
19 #
20 # Adding a test case
21 #
22 # Each feature should get its own set of tests in its own suitably
23 # named makefile (*.mk), with its own set of expected results (*.exp),
24 # and it should be added to the TESTS list.
25 #
26 # Any added files must also be added to src/distrib/sets/lists/tests/mi.
27 # To do that, just run "make sync-mi" in this directory.
28 #
29
30 .MAIN: all
31
32 # we use these below but we might be an older make
33 .MAKE.OS?= ${uname -s:L:sh}
34 .MAKE.UID?= ${id -u:L:sh}
35
36 # for many tests we need a TMPDIR that will not collide
37 # with other users.
38 .if ${.OBJDIR} != ${.CURDIR}
39 # easy
40 TMPDIR:= ${.OBJDIR}/tmp
41 .elif defined(TMPDIR)
42 TMPDIR:= ${TMPDIR}/uid${.MAKE.UID}
43 .else
44 TMPDIR:= /tmp/uid${.MAKE.UID}
45 .endif
46 # make sure it exists
47 .if !exist(${TMPDIR})
48 _!= mkdir -p ${TMPDIR}
49 .endif
50
51 # Each test is in a sub-makefile.
52 # Keep the list sorted.
53 # Any test that is commented out must be ignored in
54 # src/tests/usr.bin/make/t_make.sh as well.
55 TESTS+= archive
56 TESTS+= archive-suffix
57 TESTS+= cmd-errors
58 TESTS+= cmd-errors-jobs
59 TESTS+= cmd-errors-lint
60 TESTS+= cmd-interrupt
61 TESTS+= cmdline
62 TESTS+= cmdline-redirect-stdin
63 TESTS+= cmdline-undefined
64 TESTS+= comment
65 TESTS+= compat-error
66 TESTS+= cond-cmp-numeric
67 TESTS+= cond-cmp-numeric-eq
68 TESTS+= cond-cmp-numeric-ge
69 TESTS+= cond-cmp-numeric-gt
70 TESTS+= cond-cmp-numeric-le
71 TESTS+= cond-cmp-numeric-lt
72 TESTS+= cond-cmp-numeric-ne
73 TESTS+= cond-cmp-string
74 TESTS+= cond-cmp-unary
75 TESTS+= cond-eof
76 TESTS+= cond-func
77 TESTS+= cond-func-commands
78 TESTS+= cond-func-defined
79 TESTS+= cond-func-empty
80 TESTS+= cond-func-exists
81 TESTS+= cond-func-make
82 TESTS+= cond-func-make-main
83 TESTS+= cond-func-target
84 TESTS+= cond-late
85 TESTS+= cond-op
86 TESTS+= cond-op-and
87 TESTS+= cond-op-and-lint
88 TESTS+= cond-op-not
89 TESTS+= cond-op-or
90 TESTS+= cond-op-or-lint
91 TESTS+= cond-op-parentheses
92 TESTS+= cond-short
93 TESTS+= cond-token-number
94 TESTS+= cond-token-plain
95 TESTS+= cond-token-string
96 TESTS+= cond-token-var
97 TESTS+= cond-undef-lint
98 TESTS+= counter
99 TESTS+= counter-append
100 TESTS+= dep
101 TESTS+= dep-colon
102 TESTS+= dep-colon-bug-cross-file
103 TESTS+= dep-double-colon
104 TESTS+= dep-double-colon-indep
105 TESTS+= dep-duplicate
106 TESTS+= dep-exclam
107 TESTS+= dep-none
108 TESTS+= dep-op-missing
109 TESTS+= dep-percent
110 TESTS+= dep-var
111 TESTS+= dep-wildcards
112 TESTS+= depsrc
113 TESTS+= depsrc-end
114 TESTS+= depsrc-exec
115 TESTS+= depsrc-ignore
116 TESTS+= depsrc-made
117 TESTS+= depsrc-make
118 TESTS+= depsrc-meta
119 TESTS+= depsrc-nometa
120 TESTS+= depsrc-nometa_cmp
121 TESTS+= depsrc-nopath
122 TESTS+= depsrc-notmain
123 TESTS+= depsrc-optional
124 TESTS+= depsrc-phony
125 TESTS+= depsrc-precious
126 TESTS+= depsrc-recursive
127 TESTS+= depsrc-silent
128 TESTS+= depsrc-use
129 TESTS+= depsrc-usebefore
130 TESTS+= depsrc-usebefore-double-colon
131 TESTS+= depsrc-wait
132 TESTS+= deptgt
133 TESTS+= deptgt-begin
134 TESTS+= deptgt-begin-fail
135 TESTS+= deptgt-begin-fail-indirect
136 TESTS+= deptgt-default
137 TESTS+= deptgt-delete_on_error
138 TESTS+= deptgt-end
139 TESTS+= deptgt-end-fail
140 TESTS+= deptgt-end-fail-all
141 TESTS+= deptgt-end-fail-indirect
142 TESTS+= deptgt-end-jobs
143 TESTS+= deptgt-error
144 TESTS+= deptgt-ignore
145 TESTS+= deptgt-interrupt
146 TESTS+= deptgt-main
147 TESTS+= deptgt-makeflags
148 TESTS+= deptgt-no_parallel
149 TESTS+= deptgt-nopath
150 TESTS+= deptgt-notparallel
151 TESTS+= deptgt-objdir
152 TESTS+= deptgt-order
153 TESTS+= deptgt-path
154 TESTS+= deptgt-path-suffix
155 TESTS+= deptgt-phony
156 TESTS+= deptgt-posix
157 TESTS+= deptgt-precious
158 TESTS+= deptgt-shell
159 TESTS+= deptgt-silent
160 TESTS+= deptgt-silent-jobs
161 TESTS+= deptgt-stale
162 TESTS+= deptgt-suffixes
163 TESTS+= dir
164 TESTS+= dir-expand-path
165 TESTS+= directive
166 TESTS+= directive-dinclude
167 TESTS+= directive-elif
168 TESTS+= directive-elifdef
169 TESTS+= directive-elifmake
170 TESTS+= directive-elifndef
171 TESTS+= directive-elifnmake
172 TESTS+= directive-else
173 TESTS+= directive-endfor
174 TESTS+= directive-endif
175 TESTS+= directive-error
176 TESTS+= directive-export
177 TESTS+= directive-export-env
178 TESTS+= directive-export-impl
179 TESTS+= directive-export-gmake
180 TESTS+= directive-export-literal
181 TESTS+= directive-for
182 TESTS+= directive-for-break
183 TESTS+= directive-for-empty
184 TESTS+= directive-for-errors
185 TESTS+= directive-for-escape
186 TESTS+= directive-for-generating-endif
187 TESTS+= directive-for-if
188 TESTS+= directive-for-lines
189 TESTS+= directive-for-null
190 TESTS+= directive-hyphen-include
191 TESTS+= directive-if
192 TESTS+= directive-if-nested
193 TESTS+= directive-ifdef
194 TESTS+= directive-ifmake
195 TESTS+= directive-ifndef
196 TESTS+= directive-ifnmake
197 TESTS+= directive-include
198 TESTS+= directive-include-fatal
199 TESTS+= directive-include-guard
200 TESTS+= directive-info
201 TESTS+= directive-misspellings
202 TESTS+= directive-sinclude
203 TESTS+= directive-undef
204 TESTS+= directive-unexport
205 TESTS+= directive-unexport-env
206 TESTS+= directive-warning
207 TESTS+= dollar
208 TESTS+= doterror
209 TESTS+= dotwait
210 TESTS+= error
211 TESTS+= # escape # broken by reverting POSIX changes
212 TESTS+= export
213 TESTS+= export-all
214 TESTS+= export-env
215 TESTS+= export-variants
216 TESTS+= gnode-submake
217 TESTS+= hanoi-include
218 TESTS+= impsrc
219 TESTS+= include-main
220 TESTS+= job-flags
221 TESTS+= job-output-long-lines
222 TESTS+= job-output-null
223 TESTS+= jobs-empty-commands
224 TESTS+= jobs-empty-commands-error
225 TESTS+= jobs-error-indirect
226 TESTS+= jobs-error-nested
227 TESTS+= jobs-error-nested-make
228 TESTS+= lint
229 TESTS+= make-exported
230 TESTS+= meta-cmd-cmp
231 TESTS+= moderrs
232 TESTS+= modmisc
233 .if ${.MAKE.UID} > 0
234 TESTS+= objdir-writable
235 .endif
236 TESTS+= opt
237 TESTS+= opt-backwards
238 TESTS+= opt-chdir
239 TESTS+= opt-debug
240 TESTS+= opt-debug-all
241 TESTS+= opt-debug-archive
242 TESTS+= opt-debug-curdir
243 TESTS+= opt-debug-cond
244 TESTS+= opt-debug-dir
245 TESTS+= opt-debug-errors
246 TESTS+= opt-debug-errors-jobs
247 TESTS+= opt-debug-file
248 TESTS+= opt-debug-for
249 TESTS+= opt-debug-graph1
250 TESTS+= opt-debug-graph2
251 TESTS+= opt-debug-graph3
252 TESTS+= opt-debug-hash
253 TESTS+= opt-debug-jobs
254 TESTS+= opt-debug-lint
255 TESTS+= opt-debug-loud
256 TESTS+= opt-debug-meta
257 TESTS+= opt-debug-making
258 TESTS+= opt-debug-no-rm
259 TESTS+= opt-debug-parse
260 TESTS+= opt-debug-suff
261 TESTS+= opt-debug-targets
262 TESTS+= opt-debug-varraw
263 TESTS+= opt-debug-var
264 TESTS+= opt-debug-x-trace
265 TESTS+= opt-define
266 TESTS+= opt-env
267 TESTS+= opt-file
268 TESTS+= opt-ignore
269 TESTS+= opt-include-dir
270 TESTS+= opt-jobs
271 TESTS+= opt-jobs-internal
272 TESTS+= opt-jobs-no-action
273 TESTS+= opt-keep-going
274 TESTS+= opt-keep-going-indirect
275 TESTS+= opt-keep-going-multiple
276 TESTS+= opt-m-include-dir
277 TESTS+= opt-no-action
278 TESTS+= opt-no-action-at-all
279 TESTS+= opt-no-action-runflags
280 TESTS+= opt-no-action-touch
281 TESTS+= opt-query
282 TESTS+= opt-raw
283 TESTS+= opt-silent
284 TESTS+= opt-touch
285 TESTS+= opt-touch-jobs
286 TESTS+= opt-tracefile
287 TESTS+= opt-var-expanded
288 TESTS+= opt-var-literal
289 TESTS+= opt-version
290 TESTS+= opt-warnings-as-errors
291 TESTS+= opt-where-am-i
292 TESTS+= opt-x-reduce-exported
293 TESTS+= order
294 TESTS+= parse
295 TESTS+= parse-var
296 TESTS+= phony-end
297 TESTS+= posix
298 TESTS+= # posix1 # broken by reverting POSIX changes
299 TESTS+= recursive
300 TESTS+= sh
301 TESTS+= sh-dots
302 TESTS+= sh-errctl
303 TESTS+= sh-flags
304 TESTS+= sh-jobs
305 TESTS+= sh-jobs-error
306 TESTS+= sh-leading-at
307 TESTS+= sh-leading-hyphen
308 TESTS+= sh-leading-plus
309 TESTS+= sh-meta-chars
310 TESTS+= sh-multi-line
311 TESTS+= sh-single-line
312 TESTS+= shell-csh
313 TESTS+= shell-custom
314 TESTS+= shell-ksh
315 TESTS+= shell-sh
316 TESTS+= suff-add-later
317 TESTS+= suff-clear-regular
318 TESTS+= suff-clear-single
319 TESTS+= suff-incomplete
320 TESTS+= suff-lookup
321 TESTS+= suff-main
322 TESTS+= suff-main-several
323 TESTS+= suff-phony
324 TESTS+= suff-rebuild
325 TESTS+= suff-self
326 TESTS+= suff-transform-debug
327 TESTS+= suff-transform-endless
328 TESTS+= suff-transform-expand
329 TESTS+= suff-transform-select
330 TESTS+= suff-use
331 TESTS+= sunshcmd
332 TESTS+= ternary
333 TESTS+= unexport
334 TESTS+= unexport-env
335 TESTS+= use-inference
336 TESTS+= var-readonly
337 TESTS+= var-scope
338 TESTS+= var-scope-cmdline
339 TESTS+= var-scope-env
340 TESTS+= var-scope-global
341 TESTS+= var-scope-local
342 TESTS+= var-scope-local-legacy
343 TESTS+= var-eval-short
344 TESTS+= var-op
345 TESTS+= var-op-append
346 TESTS+= var-op-assign
347 TESTS+= var-op-default
348 TESTS+= var-op-expand
349 TESTS+= var-op-shell
350 TESTS+= var-op-sunsh
351 TESTS+= var-recursive
352 TESTS+= varcmd
353 TESTS+= vardebug
354 TESTS+= varfind
355 TESTS+= varmisc
356 TESTS+= varmod
357 TESTS+= varmod-assign
358 TESTS+= varmod-assign-shell
359 TESTS+= varmod-defined
360 TESTS+= varmod-edge
361 TESTS+= varmod-exclam-shell
362 TESTS+= varmod-extension
363 TESTS+= varmod-gmtime
364 TESTS+= varmod-hash
365 TESTS+= varmod-head
366 TESTS+= varmod-ifelse
367 TESTS+= varmod-indirect
368 TESTS+= varmod-l-name-to-value
369 TESTS+= varmod-localtime
370 TESTS+= varmod-loop
371 TESTS+= varmod-loop-delete
372 TESTS+= varmod-loop-varname
373 TESTS+= varmod-match
374 TESTS+= varmod-match-escape
375 TESTS+= varmod-mtime
376 TESTS+= varmod-no-match
377 TESTS+= varmod-order
378 TESTS+= varmod-order-numeric
379 TESTS+= varmod-order-reverse
380 TESTS+= varmod-order-shuffle
381 TESTS+= varmod-order-string
382 TESTS+= varmod-path
383 TESTS+= varmod-quote
384 TESTS+= varmod-quote-dollar
385 TESTS+= varmod-range
386 TESTS+= varmod-remember
387 TESTS+= varmod-root
388 TESTS+= varmod-select-words
389 TESTS+= varmod-shell
390 TESTS+= varmod-subst
391 TESTS+= varmod-subst-regex
392 TESTS+= varmod-sun-shell
393 TESTS+= varmod-sysv
394 TESTS+= varmod-tail
395 TESTS+= varmod-to-abs
396 TESTS+= varmod-to-lower
397 TESTS+= varmod-to-many-words
398 TESTS+= varmod-to-one-word
399 TESTS+= varmod-to-separator
400 TESTS+= varmod-to-upper
401 TESTS+= varmod-undefined
402 TESTS+= varmod-unique
403 TESTS+= varname
404 TESTS+= varname-dollar
405 TESTS+= varname-dot-alltargets
406 TESTS+= varname-dot-curdir
407 TESTS+= varname-dot-includes
408 TESTS+= varname-dot-includedfromdir
409 TESTS+= varname-dot-includedfromfile
410 TESTS+= varname-dot-libs
411 TESTS+= varname-dot-make-dependfile
412 TESTS+= varname-dot-make-expand_variables
413 TESTS+= varname-dot-make-exported
414 TESTS+= varname-dot-make-jobs
415 TESTS+= varname-dot-make-jobs-prefix
416 TESTS+= varname-dot-make-level
417 TESTS+= varname-dot-make-makefile_preference
418 TESTS+= varname-dot-make-makefiles
419 TESTS+= varname-dot-make-meta-bailiwick
420 TESTS+= varname-dot-make-meta-created
421 TESTS+= varname-dot-make-meta-files
422 .if ${.MAKE.PATH_FILEMON:Uno:Nktrace:N/dev*} == "" && ${TMPDIR:N/tmp*:N/var/tmp*} != ""
423 # these tests will not work if TMPDIR is or is a subdir of
424 # /tmp or /var/tmp
425 TESTS+= varname-dot-make-meta-ignore_filter
426 TESTS+= varname-dot-make-meta-ignore_paths
427 TESTS+= varname-dot-make-meta-ignore_patterns
428 TESTS+= varname-dot-make-path_filemon
429 .endif
430 TESTS+= varname-dot-make-meta-prefix
431 TESTS+= varname-dot-make-mode
432 TESTS+= varname-dot-make-pid
433 TESTS+= varname-dot-make-ppid
434 TESTS+= varname-dot-make-save_dollars
435 TESTS+= varname-dot-makeflags
436 TESTS+= varname-dot-makeoverrides
437 TESTS+= varname-dot-newline
438 TESTS+= varname-dot-objdir
439 TESTS+= varname-dot-parsedir
440 TESTS+= varname-dot-parsefile
441 TESTS+= varname-dot-path
442 TESTS+= varname-dot-shell
443 TESTS+= varname-dot-suffixes
444 TESTS+= varname-dot-targets
445 TESTS+= varname-empty
446 TESTS+= varname-make
447 TESTS+= varname-make_print_var_on_error
448 TESTS+= varname-make_print_var_on_error-jobs
449 TESTS+= varname-makefile
450 TESTS+= varname-makeflags
451 TESTS+= varname-pwd
452 TESTS+= varname-vpath
453 TESTS+= varparse-dynamic
454 TESTS+= varparse-errors
455 TESTS+= varparse-mod
456 TESTS+= varparse-undef-partial
457
458 # Some tests just do not work on some platforms or environments
459 # so allow for some filtering.
460 .if !empty(BROKEN_TESTS)
461 TESTS:= ${TESTS:${BROKEN_TESTS:S,^,N,:ts:}}
462 .endif
463
464 # Ideas for more tests:
465 # char-0020-space.mk
466 # char-005C-backslash.mk
467 # escape-cond-str.mk
468 # escape-cond-func-arg.mk
469 # escape-varmod.mk
470 # escape-varmod-define.mk
471 # escape-varmod-match.mk
472 # escape-varname.mk
473 # escape-varassign-varname.mk
474 # escape-varassign-varname-cmdline.mk
475 # escape-varassign-value.mk
476 # escape-varassign-value-cmdline.mk
477 # escape-dependency-source.mk
478 # escape-dependency-target.mk
479 # escape-for-varname.mk
480 # escape-for-item.mk
481 # posix-*.mk (see posix.mk and posix1.mk)
482
483 # Additional environment variables for some of the tests.
484 # The base environment is -i PATH="$PATH".
485 ENV.depsrc-optional+= TZ=UTC
486 ENV.directive-undef= ENV_VAR=env-value
487 ENV.opt-env= FROM_ENV=value-from-env
488 ENV.opt-m-include-dir= ${MAKEOBJDIR:DMAKEOBJDIR=${MAKEOBJDIR}}
489 ENV.varmisc= FROM_ENV=env
490 ENV.varmisc+= FROM_ENV_BEFORE=env
491 ENV.varmisc+= FROM_ENV_AFTER=env
492 ENV.varmod-localtime+= TZ=Europe/Berlin
493 ENV.varname-vpath+= VPATH=varname-vpath.dir:varname-vpath.dir2
494
495 # Override make flags for some of the tests; default is -k.
496 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
497 # settings FLAGS.test=-dv here, since that is closer to the test code.
498 FLAGS.cond-func-make= via-cmdline
499 FLAGS.doterror= # none, especially not -k
500 FLAGS.jobs-error-indirect= # none, especially not -k
501 FLAGS.jobs-error-nested= # none, especially not -k
502 FLAGS.jobs-error-nested-make= # none, especially not -k
503 FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmdline-plain'
504
505 # Some tests need extra postprocessing.
506 SED_CMDS.deptgt-phony= ${STD_SED_CMDS.dd}
507 SED_CMDS.dir= ${STD_SED_CMDS.dd}
508 SED_CMDS.directive-include-guard= \
509 -e '/\.MAKEFLAGS/d' \
510 -e '/^Parsing line/d' \
511 -e '/^SetFilenameVars:/d' \
512 -e '/^ParseDependency/d' \
513 -e '/^ParseEOF:/d'
514 SED_CMDS.export= -e '/^[^=_A-Za-z0-9]*=/d'
515 SED_CMDS.export-all= ${SED_CMDS.export}
516 SED_CMDS.export-env= ${SED_CMDS.export}
517 SED_CMDS.job-output-long-lines= \
518 ${:D Job separators on their own line are ok. } \
519 -e '/^--- job-[ab] ---$$/d' \
520 ${:D Plain output lines are ok as well. } \
521 ${:D They may come in multiples of 1024 or as 10000. } \
522 -e '/^aa*$$/d' \
523 -e '/^bb*$$/d' \
524 ${:D The following lines should rather not occur since the job } \
525 ${:D marker should always be at the beginning of the line. } \
526 -e '/^aa*--- job-b ---$$/d' \
527 -e '/^bb*--- job-a ---$$/d'
528
529 # meta line numbers can vary based on filemon implementation
530 SED_CMDS.meta-ignore= -e 's,\(\.meta:\) [1-9][0-9]*:,\1 <line>:,'
531
532 SED_CMDS.opt-chdir= -e 's,\(nonexistent\).[1-9][0-9]*,\1,'
533 SED_CMDS.opt-debug-graph1= ${STD_SED_CMDS.dg1}
534 SED_CMDS.opt-debug-graph2= ${STD_SED_CMDS.dg2}
535 SED_CMDS.opt-debug-graph3= ${STD_SED_CMDS.dg3}
536 SED_CMDS.opt-debug-hash= -e 's,\(numEntries\)=[1-9][0-9],\1=<entries>,'
537 SED_CMDS.opt-debug-jobs= -e 's,([0-9][0-9]*),(<pid>),'
538 SED_CMDS.opt-debug-jobs+= -e 's,pid [0-9][0-9]*,pid <pid>,'
539 SED_CMDS.opt-debug-jobs+= -e 's,Process [0-9][0-9]*,Process <pid>,'
540 SED_CMDS.opt-debug-jobs+= -e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,'
541 SED_CMDS.opt-debug-jobs+= -e 's,Command: ${.SHELL:T},Command: <shell>,'
542 # The "-q" may be there or not, see jobs.c, variable shells.
543 SED_CMDS.opt-debug-jobs+= -e 's,^\(.Command: <shell>\) -q,\1,'
544 SED_CMDS.opt-debug-lint+= ${STD_SED_CMDS.regex}
545 SED_CMDS.opt-jobs-no-action= ${STD_SED_CMDS.hide-from-output}
546 SED_CMDS.opt-no-action-runflags= ${STD_SED_CMDS.hide-from-output}
547 SED_CMDS.opt-where-am-i= -e '/usr.obj/d'
548 # For Compat_RunCommand, useShell == false.
549 SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<not found: ...>,'
550 # For Compat_RunCommand, useShell == true.
551 SED_CMDS.sh-dots+= -e 's,^make: exec(\(.*\)) failed (.*)$$,<not found: \1>,'
552 SED_CMDS.sh-dots+= -e 's,^\(\*\*\* Error code \)[1-9][0-9]*,\1<nonzero>,'
553 SED_CMDS.sh-errctl= ${STD_SED_CMDS.dj}
554 SED_CMDS.sh-flags= ${STD_SED_CMDS.hide-from-output}
555 SED_CMDS.sh-leading-hyphen= ${STD_SED_CMDS.shell}
556 SED_CMDS.suff-main+= ${STD_SED_CMDS.dg1}
557 SED_CMDS.suff-main-several+= ${STD_SED_CMDS.dg1}
558 SED_CMDS.suff-transform-debug+= ${STD_SED_CMDS.dg1}
559 SED_CMDS.var-op-shell+= ${STD_SED_CMDS.shell}
560 SED_CMDS.var-op-shell+= -e '/command/s,No such.*,not found,'
561 SED_CMDS.vardebug+= -e 's,${.SHELL},</path/to/shell>,'
562 SED_CMDS.varmod-mtime+= -e "s,': .*,': <ENOENT>,"
563 SED_CMDS.varmod-subst-regex+= ${STD_SED_CMDS.regex}
564 SED_CMDS.varparse-errors+= ${STD_SED_CMDS.timestamp}
565 SED_CMDS.varname-dot-make-meta-ignore_filter+= ${SED_CMDS.meta-ignore}
566 SED_CMDS.varname-dot-make-meta-ignore_paths+= ${SED_CMDS.meta-ignore}
567 SED_CMDS.varname-dot-make-meta-ignore_patterns+= ${SED_CMDS.meta-ignore}
568 SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
569 SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
570 SED_CMDS.varname-dot-shell= -e 's, = /[^ ]*, = (details omitted),g'
571 SED_CMDS.varname-dot-shell+= -e 's,"/[^" ]*","(details omitted)",g'
572 SED_CMDS.varname-dot-shell+= -e 's,\[/[^] ]*\],[(details omitted)],g'
573 SED_CMDS.varname-empty= ${.OBJDIR .PARSEDIR .PATH .SHELL .SYSPATH:L:@v@-e '/\\$v/d'@}
574
575 # Some tests need an additional round of postprocessing.
576 POSTPROC.depsrc-wait= sed -e '/^---/d' -e 's,^\(: Making 3[abc]\)[123]$$,\1,'
577 POSTPROC.deptgt-suffixes= awk '/^\#\*\*\* Suffixes/,/^never-stop/'
578 POSTPROC.gnode-submake= awk '/Input graph/, /^$$/'
579 POSTPROC.varname-dot-make-mode= sed 's,^\(: Making [abc]\)[123]$$,\1,'
580
581 # Some tests reuse other tests, which makes them unnecessarily fragile.
582 export-all.rawout: export.mk
583 unexport.rawout: export.mk
584 unexport-env.rawout: export.mk
585
586 # End of the configuration section.
587
588 # Some standard sed commands, to be used in the SED_CMDS above.
589
590 # In tests that use the debugging option -dd, ignore debugging output that is
591 # only logged in -DCLEANUP mode.
592 STD_SED_CMDS.dd= -e '/^OpenDirs_Done:/d'
593 STD_SED_CMDS.dd+= -e '/^CachedDir /d'
594
595 # Omit details such as process IDs from the output of the -dg1 option.
596 STD_SED_CMDS.dg1= -e 's,${.CURDIR}$$,<curdir>,'
597 STD_SED_CMDS.dg1+= -e 's, ${DEFSYSPATH:U/usr/share/mk}$$, <defsyspath>,'
598 STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE *=\) .*,\1 <details omitted>,'
599 STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.[A-Z_]* *=\) .*,\1 <details omitted>,'
600 STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.JOBS\.C *=\) .*,\1 <details omitted>,'
601 STD_SED_CMDS.dg1+= -e 's,^\(MACHINE[_ARCH]* *=\) .*,\1 <details omitted>,'
602 STD_SED_CMDS.dg1+= -e 's,^\(MAKE *=\) .*,\1 <details omitted>,'
603 STD_SED_CMDS.dg1+= -e 's,^\(\.SHELL *=\) .*,\1 <details omitted>,'
604 STD_SED_CMDS.dg1+= -e '/\.SYSPATH/d'
605
606 STD_SED_CMDS.dg2= ${STD_SED_CMDS.dg1}
607 STD_SED_CMDS.dg2+= -e 's,\(last modified\) ..:..:.. ... ..\, ....,\1 <timestamp>,'
608 STD_SED_CMDS.dg3= ${STD_SED_CMDS.dg2}
609
610 # Omit details such as process IDs from the output of the -dj option.
611 STD_SED_CMDS.dj= \
612 -e '/Process/d;/JobFinish:/d' \
613 -e 's,^\(Job_TokenWithdraw\)([0-9]*),\1(<pid>),' \
614 -e 's,^([0-9][0-9]*) \(withdrew token\),(<pid>) \1,' \
615 -e 's, \(pid\) [0-9][0-9]*, \1 <pid>,' \
616 -e 's,^\( Command:\) .*,\1 <shell>,'
617
618 # Reduce the noise for tests running with the -n option, since there is no
619 # other way to suppress the echoing of the commands.
620 STD_SED_CMDS.hide-from-output= \
621 -e '/^echo hide-from-output/d' \
622 -e 's,hide-from-output ,,' \
623 -e 's,hide-from-output,,'
624
625 # Normalize the output for error messages from the shell.
626 #
627 # $shell -c '...'
628 # NetBSD sh ...: not found
629 # NetBSD ksh ksh: ...: not found
630 # bash 5.0.18 bash: ...: command not found
631 # bash 5.1.0 bash: line 1: ...: command not found
632 # dash dash: 1: ...: not found
633 #
634 # $shell -c '< /nonexistent'
635 # NetBSD sh sh: cannot open /nonexistent: no such file
636 # NetBSD ksh ksh: cannot open /nonexistent: No such file or directory
637 # bash 5.0.18 bash: /nonexistent: No such file or directory
638 # bash 5.1.0 bash: line 1: /nonexistent: No such file or directory
639 # dash dash: 1: cannot open /nonexistent: No such file
640 #
641 # echo '< /nonexistent' | $shell
642 # NetBSD sh sh: cannot open /nonexistent: no such file
643 # NetBSD ksh ksh: <stdin>[1]: cannot open /nonexistent: No such file or directory
644 # bash 5.0.18 bash: line 1: /nonexistent: No such file or directory
645 # bash 5.1.0 bash: line 1: /nonexistent: No such file or directory
646 # dash dash: 1: cannot open /nonexistent: No such file
647 #
648 STD_SED_CMDS.shell+= -e 's,^${.SHELL},${.SHELL:T},'
649 STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: line [0-9][0-9]*: ,,'
650 STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: [0-9][0-9]*: ,,'
651 STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: ,,'
652 STD_SED_CMDS.shell+= -e 's,: command not found,: not found,'
653
654 # The actual error messages for a failed regcomp or regexec differ between the
655 # implementations.
656 STD_SED_CMDS.regex= \
657 -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
658
659 # Normalize timestamps from ':gmtime' or ':localtime' to '<timestamp>'.
660 # See STD_SED_CMDS.dg2 for timestamps from the debug log.
661 STD_SED_CMDS.timestamp= \
662 -e 's,[A-Z][a-z][a-z] [A-Z][a-z][a-z] [ 0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [12][0-9][0-9][0-9],<timestamp>,'
663
664 # End of the configuration helpers section.
665
666 UNIT_TESTS:= ${.PARSEDIR}
667 .PATH: ${UNIT_TESTS}
668
669 .if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes
670 OUTFILES= ${TESTS:@test@${.CURDIR:tA}/${test}.out@}
671 .else
672 OUTFILES= ${TESTS:=.out}
673 .endif
674
675 all: ${OUTFILES}
676
677 CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp
678 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
679 CLEANFILES+= issue* .[ab]* # suffixes.mk
680 CLEANDIRS= dir dummy # posix1.mk
681
682 clean:
683 rm -f ${CLEANFILES}
684 rm -rf ${CLEANDIRS}
685
686 TEST_MAKE?= ${.MAKE}
687 TOOL_SED?= sed
688
689 # ensure consistent results from sort(1)
690 LC_ALL= C
691 LANG= C
692 .export LANG LC_ALL
693
694 # Some Linux systems such as Fedora have deprecated egrep in favor of grep -E.
695 .if ${.MAKE.OS:NLinux} == ""
696 EGREP= grep -E
697 .endif
698 # Keep the classical definition for all other systems. Just as the bmake code
699 # is kept compatible with C90, the tests are kept compatible with systems that
700 # are several decades old and don't follow modern POSIX standards.
701 EGREP?= egrep
702
703 MAKE_TEST_ENV= EGREP="${EGREP}"
704 MAKE_TEST_ENV+= MALLOC_OPTIONS="JA" # for jemalloc 100
705 MAKE_TEST_ENV+= MALLOC_CONF="junk:true" # for jemalloc 510
706 MAKE_TEST_ENV+= TMPDIR=${TMPDIR}
707
708 .if ${.MAKE.OS} == "NetBSD"
709 LIMIT_RESOURCES?= ulimit -v 300000
710 .endif
711 LIMIT_RESOURCES?= :
712
713 # Each test is run in a sub-make, to keep the tests from interfering with
714 # each other, and because they use different environment variables and
715 # command line options.
716 .SUFFIXES: .mk .rawout .out
717 .mk.rawout:
718 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX}
719 @set -eu; \
720 ${LIMIT_RESOURCES}; \
721 cd ${.OBJDIR}; \
722 env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \
723 ${TEST_MAKE} \
724 -r -C ${.CURDIR} -f ${.IMPSRC} \
725 ${FLAGS.${.PREFIX:T}:U-k} \
726 > ${.TARGET}.tmp 2>&1 \
727 && status=$$? || status=$$?; \
728 echo $$status > ${.TARGET:R}.status
729 @mv ${.TARGET}.tmp ${.TARGET}
730
731 # Postprocess the test output to make the output platform-independent.
732 #
733 # Replace anything after 'stopped in' with unit-tests
734 _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
735 # Allow the test files to be placed anywhere.
736 _SED_CMDS+= -e 's,\(\.PARSEDIR}\) = `'"/[^']*'"',\1 = <some-dir>,'
737 _SED_CMDS+= -e 's,\(\.INCLUDEDFROMDIR}\) = `'"/[^']*'"',\1 = <some-dir>,'
738 _SED_CMDS+= -e 's,${TMPDIR},<tmpdir>,g' -e 's,${TMPDIR:tA},<tmpdir>,g'
739 # canonicalize ${.OBJDIR} and ${.CURDIR}
740 _SED_CMDS+= -e 's,${.CURDIR},<curdir>,g'
741 .if ${.OBJDIR} != ${.CURDIR}
742 # yes this is inaccurate but none of the tests expect <objdir> anywhere
743 # which we get depending on how MAKEOBJDIR is set.
744 _SED_CMDS+= -e 's,${.OBJDIR},<curdir>,g' -e 's,${.OBJDIR:tA},<curdir>,g'
745 .endif
746 # always pretend .MAKE was called 'make'
747 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
748 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
749 _SED_CMDS+= -e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,'
750 _SED_CMDS+= -e 's,<curdir>/,,g'
751 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
752 _SED_CMDS+= -e '/MAKE_VERSION/d'
753 _SED_CMDS+= -e '/EGREP=/d'
754
755 .rawout.out:
756 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \
757 < ${.IMPSRC} > ${.TARGET}.tmp1
758 @${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
759 @rm ${.TARGET}.tmp1
760 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
761 @mv ${.TARGET}.tmp2 ${.TARGET}
762
763 # Compare all output files
764 test: ${OUTFILES} .PHONY
765 @failed= ; \
766 for test in ${TESTS}; do \
767 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
768 || failed="$${failed}$${failed:+ }$${test}" ; \
769 done ; \
770 if [ -n "$${failed}" ]; then \
771 echo "Failed tests: $${failed}" ; false ; \
772 else \
773 echo "All tests passed" ; \
774 fi
775
776 accept:
777 @for test in ${TESTS}; do \
778 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
779 || { echo "Replacing $${test}.exp" ; \
780 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
781 done
782
783 # Note: only works for adding tests.
784 # To remove a test, the $$mi file must be edited manually.
785 sync-mi:
786 @set -eu; \
787 cd "${MAKEFILE:tA:H}/../../.."; \
788 mi="distrib/sets/lists/tests/mi"; \
789 cvs update "$$mi"; \
790 testsdir="usr.bin/make/unit-tests"; \
791 fmt="./usr/tests/$$testsdir/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
792 cat "$$mi" > "$$mi.tmp"; \
793 (cd "$$testsdir" && egrep '\.(exp|mk)/' CVS/Entries | cut -d/ -f2) | \
794 xargs printf "$$fmt" >> "$$mi.tmp"; \
795 distrib/sets/fmt-list "$$mi.tmp"; \
796 mv "$$mi.tmp" "$$mi"; \
797 cvs diff "$$mi" || true
798
799 .if exists(${TEST_MAKE})
800 ${TESTS:=.rawout}: ${TEST_MAKE}
801 # in meta mode, we *know* if a target script is impacted
802 # by a makefile change.
803 .if ${.MAKE.MODE:Unormal:Mmeta} == ""
804 ${TESTS:=.rawout}: ${.PARSEDIR}/Makefile
805 .endif
806 .endif
807
808 .-include <bsd.obj.mk>
809