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