xref: /freebsd/contrib/bmake/unit-tests/job-output-null.mk (revision 4fde40d9b540ea1a544cb4378a14f2f6da85ca6d)
1*4fde40d9SSimon J. Gerraty# $NetBSD: job-output-null.mk,v 1.4 2022/09/03 08:03:27 rillig Exp $
2b0c40a00SSimon J. Gerraty#
3b0c40a00SSimon J. Gerraty# Test how null bytes in the output of a command are handled.  Make processes
4b0c40a00SSimon J. Gerraty# them using null-terminated strings, which may cut off some of the output.
5b0c40a00SSimon J. Gerraty#
6*4fde40d9SSimon J. Gerraty# Before job.c 1.454 from 2022-09-03, make handled null bytes in the output
7*4fde40d9SSimon J. Gerraty# from the child process inconsistently.  It's an edge case though since
8*4fde40d9SSimon J. Gerraty# typically the child processes output text.
9b0c40a00SSimon J. Gerraty
1012904384SSimon J. Gerraty# Note: The printf commands used in this test must only use a single format
1112904384SSimon J. Gerraty# string, without parameters.  This is because it is implementation-dependent
1212904384SSimon J. Gerraty# how many times the command 'printf "fmt%s" "" "" ""' calls write(2).
1312904384SSimon J. Gerraty#
1412904384SSimon J. Gerraty#	NetBSD /bin/sh		1 x write("fmtfmtfmt")
1512904384SSimon J. Gerraty#	Dash			1 x write("fmtfmtfmt")
1612904384SSimon J. Gerraty#	NetBSD /bin/ksh		3 x write("fmt") (via /bin/printf)
1712904384SSimon J. Gerraty#	Bash 5			3 x write("fmt")
1812904384SSimon J. Gerraty#
19*4fde40d9SSimon J. Gerraty# In the latter case the output may arrive in 1 to 3 parts, depending on the
20*4fde40d9SSimon J. Gerraty# exact timing, which in this test makes a crucial difference since before
21*4fde40d9SSimon J. Gerraty# job.c 1.454 from 2022-09-03, the outcome of the test depended on whether
22*4fde40d9SSimon J. Gerraty# there was a '\n' in each of the blocks from the output.  Depending on the
23*4fde40d9SSimon J. Gerraty# exact timing, the output of that test varied, its possible values were '2a',
24*4fde40d9SSimon J. Gerraty# '2a 2b', '2a 2c', '2a 2b 2c'.
2512904384SSimon J. Gerraty
26b0c40a00SSimon J. Gerraty.MAKEFLAGS: -j1		# force jobs mode
27b0c40a00SSimon J. Gerraty
28b0c40a00SSimon J. Gerratyall: .PHONY
29*4fde40d9SSimon J. Gerraty	# The null byte from the command output is replaced with a single
30*4fde40d9SSimon J. Gerraty	# space by CollectOutput.
3112904384SSimon J. Gerraty	@printf '1\0trailing\n'
32*4fde40d9SSimon J. Gerraty	# expect: 1 trailing
33b0c40a00SSimon J. Gerraty
34b0c40a00SSimon J. Gerraty	# Give the parent process a chance to see the above output, but not
35b0c40a00SSimon J. Gerraty	# yet the output from the next printf command.
36b0c40a00SSimon J. Gerraty	@sleep 1
37b0c40a00SSimon J. Gerraty
38*4fde40d9SSimon J. Gerraty	# Each null byte from the command output is replaced with a single
39*4fde40d9SSimon J. Gerraty	# space.
4012904384SSimon J. Gerraty	@printf '2a\0trailing\n''2b\0trailing\n''2c\0trailing\n'
41*4fde40d9SSimon J. Gerraty	# expect: 2a trailing
42*4fde40d9SSimon J. Gerraty	# expect: 2b trailing
43*4fde40d9SSimon J. Gerraty	# expect: 2c trailing
44b0c40a00SSimon J. Gerraty
45b0c40a00SSimon J. Gerraty	@sleep 1
46b0c40a00SSimon J. Gerraty
47*4fde40d9SSimon J. Gerraty	# Each null byte from the command output is replaced with a single
48*4fde40d9SSimon J. Gerraty	# space.  Because there is no trailing newline in the output, these
49*4fde40d9SSimon J. Gerraty	# null bytes were replaced with spaces even before job.c 1.454 from
50*4fde40d9SSimon J. Gerraty	# 2022-09-03, unlike in the cases above.
51b0c40a00SSimon J. Gerraty	#
52b0c40a00SSimon J. Gerraty	# The three null bytes in a row test whether this output is
53b0c40a00SSimon J. Gerraty	# compressed to a single space like in DebugFailedTarget.  It isn't.
5412904384SSimon J. Gerraty	@printf '3a\0without\0\0\0newline, 3b\0without\0\0\0newline.'
55*4fde40d9SSimon J. Gerraty	# expect: 3a without   newline, 3b without   newline.
56