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