3 test_description
='test trace2 facility (normal target)'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 # Turn off any inherited trace2 settings for this test.
9 sane_unset GIT_TRACE2 GIT_TRACE2_PERF GIT_TRACE2_EVENT
10 sane_unset GIT_TRACE2_BRIEF
11 sane_unset GIT_TRACE2_CONFIG_PARAMS
13 # Add t/helper directory to PATH so that we can use a relative
14 # path to run nested instances of test-tool.exe (see 004child).
15 # This helps with HEREDOC comparisons later.
16 TTDIR
="$GIT_BUILD_DIR/t/helper/" && export TTDIR
17 PATH
="$TTDIR:$PATH" && export PATH
19 # Warning: use of 'test_cmp' may run test-tool.exe and/or git.exe
20 # Warning: to do the actual diff/comparison, so the HEREDOCs here
21 # Warning: only cover our actual calls to test-tool and/or git.
22 # Warning: So you may see extra lines in artifact files when
23 # Warning: interactively debugging.
25 V
=$
(git version |
sed -e 's/^git version //') && export V
27 # There are multiple trace2 targets: normal, perf, and event.
28 # Trace2 events will/can be written to each active target (subject
29 # to whatever filtering that target decides to do).
30 # This script tests the normal target in isolation.
32 # Defer setting GIT_TRACE2 until the actual command line we want to test
33 # because hidden git and test-tool commands run by the test harness
34 # can contaminate our output.
36 # Enable "brief" feature which turns off "<clock> <file>:<line> " prefix.
37 GIT_TRACE2_BRIEF
=1 && export GIT_TRACE2_BRIEF
39 # Basic tests of the trace2 normal stream. Since this stream is used
40 # primarily with printf-style debugging/tracing, we do limited testing
43 # We do confirm the following API features:
44 # [] the 'version <v>' event
45 # [] the 'start <argv>' event
46 # [] the 'cmd_name <name>' event
47 # [] the 'exit <time> code:<code>' event
48 # [] the 'atexit <time> code:<code>' event
50 # Fields of the form _FIELD_ are tokens that have been replaced (such
51 # as the elapsed time).
55 # Implicit return from cmd_<verb> function propagates <code>.
57 test_expect_success
'normal stream, return code 0' '
58 test_when_finished "rm trace.normal actual expect" &&
59 GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 001return 0 &&
60 perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
63 start _EXE_ trace2 001return 0
64 cmd_name trace2 (trace2)
65 exit elapsed:_TIME_ code:0
66 atexit elapsed:_TIME_ code:0
68 test_cmp expect actual
71 test_expect_success
'normal stream, return code 1' '
72 test_when_finished "rm trace.normal actual expect" &&
73 test_must_fail env GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 001return 1 &&
74 perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
77 start _EXE_ trace2 001return 1
78 cmd_name trace2 (trace2)
79 exit elapsed:_TIME_ code:1
80 atexit elapsed:_TIME_ code:1
82 test_cmp expect actual
85 test_expect_success
'automatic filename' '
86 test_when_finished "rm -r traces actual expect" &&
88 GIT_TRACE2="$(pwd)/traces" test-tool trace2 001return 0 &&
89 perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <"$(ls traces/*)" >actual &&
92 start _EXE_ trace2 001return 0
93 cmd_name trace2 (trace2)
94 exit elapsed:_TIME_ code:0
95 atexit elapsed:_TIME_ code:0
97 test_cmp expect actual
102 # Explicit exit(code) from within cmd_<verb> propagates <code>.
104 test_expect_success
'normal stream, exit code 0' '
105 test_when_finished "rm trace.normal actual expect" &&
106 GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 002exit 0 &&
107 perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
108 cat >expect <<-EOF &&
110 start _EXE_ trace2 002exit 0
111 cmd_name trace2 (trace2)
112 exit elapsed:_TIME_ code:0
113 atexit elapsed:_TIME_ code:0
115 test_cmp expect actual
118 test_expect_success
'normal stream, exit code 1' '
119 test_when_finished "rm trace.normal actual expect" &&
120 test_must_fail env GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 002exit 1 &&
121 perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
122 cat >expect <<-EOF &&
124 start _EXE_ trace2 002exit 1
125 cmd_name trace2 (trace2)
126 exit elapsed:_TIME_ code:1
127 atexit elapsed:_TIME_ code:1
129 test_cmp expect actual
134 # To the above, add multiple 'error <msg>' events
136 test_expect_success
'normal stream, error event' '
137 test_when_finished "rm trace.normal actual expect" &&
138 GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 003error "hello world" "this is a test" &&
139 perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
140 cat >expect <<-EOF &&
142 start _EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\''
143 cmd_name trace2 (trace2)
146 exit elapsed:_TIME_ code:0
147 atexit elapsed:_TIME_ code:0
149 test_cmp expect actual
154 # Check that BUG writes to trace2
156 test_expect_success
'BUG messages are written to trace2' '
157 test_when_finished "rm trace.normal actual expect" &&
158 test_must_fail env GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 007bug &&
159 perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
160 cat >expect <<-EOF &&
162 start _EXE_ trace2 007bug
163 cmd_name trace2 (trace2)
164 error the bug message
165 exit elapsed:_TIME_ code:99
166 atexit elapsed:_TIME_ code:99
168 test_cmp expect actual
171 sane_unset GIT_TRACE2_BRIEF
173 # Now test without environment variables and get all Trace2 settings
174 # from the global config.
176 test_expect_success
'using global config, normal stream, return code 0' '
177 test_when_finished "rm trace.normal actual expect" &&
178 test_config_global trace2.normalBrief 1 &&
179 test_config_global trace2.normalTarget "$(pwd)/trace.normal" &&
180 test-tool trace2 001return 0 &&
181 perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
182 cat >expect <<-EOF &&
184 start _EXE_ trace2 001return 0
185 cmd_name trace2 (trace2)
186 exit elapsed:_TIME_ code:0
187 atexit elapsed:_TIME_ code:0
189 test_cmp expect actual
192 test_expect_success
'using global config with include' '
193 test_when_finished "rm trace.normal actual expect real.gitconfig" &&
194 test_config_global trace2.normalBrief 1 &&
195 test_config_global trace2.normalTarget "$(pwd)/trace.normal" &&
196 mv "$(pwd)/.gitconfig" "$(pwd)/real.gitconfig" &&
197 test_config_global include.path "$(pwd)/real.gitconfig" &&
198 test-tool trace2 001return 0 &&
199 perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
200 cat >expect <<-EOF &&
202 start _EXE_ trace2 001return 0
203 cmd_name trace2 (trace2)
204 exit elapsed:_TIME_ code:0
205 atexit elapsed:_TIME_ code:0
207 test_cmp expect actual