3 test_description
='test trace2 facility'
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_BARE
11 sane_unset GIT_TRACE2_CONFIG_PARAMS
13 perl
-MJSON::PP
-e 0 >/dev
/null
2>&1 && test_set_prereq JSON_PP
15 # Add t/helper directory to PATH so that we can use a relative
16 # path to run nested instances of test-tool.exe (see 004child).
17 # This helps with HEREDOC comparisons later.
18 TTDIR
="$GIT_BUILD_DIR/t/helper/" && export TTDIR
19 PATH
="$TTDIR:$PATH" && export PATH
21 # Warning: use of 'test_cmp' may run test-tool.exe and/or git.exe
22 # Warning: to do the actual diff/comparison, so the HEREDOCs here
23 # Warning: only cover our actual calls to test-tool and/or git.
24 # Warning: So you may see extra lines in artifact files when
25 # Warning: interactively debugging.
27 V
=$
(git version |
sed -e 's/^git version //') && export V
29 # There are multiple trace2 targets: normal, perf, and event.
30 # Trace2 events will/can be written to each active target (subject
31 # to whatever filtering that target decides to do).
32 # Test each target independently.
34 # Defer setting GIT_TRACE2_PERF until the actual command we want to
35 # test because hidden git and test-tool commands in the test
36 # harness can contaminate our output.
38 # We don't bother repeating the 001return and 002exit tests, since they
39 # have coverage in the normal and perf targets.
43 # To the above, add multiple 'error <msg>' events
45 test_expect_success JSON_PP
'event stream, error event' '
46 test_when_finished "rm trace.event actual expect" &&
47 GIT_TRACE2_EVENT="$(pwd)/trace.event" test-tool trace2 003error "hello world" "this is a test" &&
48 perl "$TEST_DIRECTORY/t0212/parse_events.perl" <trace.event >actual &&
49 sed -e "s/^|//" >expect <<-EOF &&
64 | "hierarchy":"trace2",
70 test_cmp expect actual
75 # Test nested spawning of child processes.
77 # Conceptually, this looks like:
78 # P1: TT trace2 004child
79 # P2: |--- TT trace2 004child
80 # P3: |--- TT trace2 001return 0
82 test_expect_success JSON_PP
'event stream, return code 0' '
83 test_when_finished "rm trace.event actual expect" &&
84 GIT_TRACE2_EVENT="$(pwd)/trace.event" test-tool trace2 004child test-tool trace2 004child test-tool trace2 001return 0 &&
85 perl "$TEST_DIRECTORY/t0212/parse_events.perl" <trace.event >actual &&
86 sed -e "s/^|//" >expect <<-EOF &&
118 | "hierarchy":"trace2",
146 | "hierarchy":"trace2/trace2",
150 | "_SID0_/_SID1_/_SID2_":{
158 | "hierarchy":"trace2/trace2/trace2",
164 test_cmp expect actual
167 # Test listing of all "interesting" config settings.
169 test_expect_success JSON_PP
'event stream, list config' '
170 test_when_finished "rm trace.event actual expect" &&
171 git config --local t0212.abc 1 &&
172 git config --local t0212.def "hello world" &&
173 GIT_TRACE2_EVENT="$(pwd)/trace.event" GIT_TRACE2_CONFIG_PARAMS="t0212.*" test-tool trace2 001return 0 &&
174 perl "$TEST_DIRECTORY/t0212/parse_events.perl" <trace.event >actual &&
175 sed -e "s/^|//" >expect <<-EOF &&
185 | "hierarchy":"trace2",
189 | "param":"t0212.abc",
193 | "param":"t0212.def",
194 | "value":"hello world"
201 test_cmp expect actual
204 # Test listing of all "interesting" environment variables.
206 test_expect_success JSON_PP
'event stream, list env vars' '
207 test_when_finished "rm trace.event actual expect" &&
208 GIT_TRACE2_EVENT="$(pwd)/trace.event" \
209 GIT_TRACE2_ENV_VARS="A_VAR,OTHER_VAR,MISSING" \
210 A_VAR=1 OTHER_VAR="hello world" test-tool trace2 001return 0 &&
211 perl "$TEST_DIRECTORY/t0212/parse_events.perl" <trace.event >actual &&
212 sed -e "s/^|//" >expect <<-EOF &&
222 | "hierarchy":"trace2",
230 | "param":"OTHER_VAR",
231 | "value":"hello world"
238 test_cmp expect actual
241 test_expect_success JSON_PP
'basic trace2_data' '
242 test_when_finished "rm trace.event actual expect" &&
243 GIT_TRACE2_EVENT="$(pwd)/trace.event" test-tool trace2 006data test_category k1 v1 test_category k2 v2 &&
244 perl "$TEST_DIRECTORY/t0212/parse_events.perl" <trace.event >actual &&
245 sed -e "s/^|//" >expect <<-EOF &&
266 | "hierarchy":"trace2",
272 test_cmp expect actual
275 # Now test without environment variables and get all Trace2 settings
276 # from the global config.
278 test_expect_success JSON_PP
'using global config, event stream, error event' '
279 test_when_finished "rm trace.event actual expect" &&
280 test_config_global trace2.eventTarget "$(pwd)/trace.event" &&
281 test-tool trace2 003error "hello world" "this is a test" &&
282 perl "$TEST_DIRECTORY/t0212/parse_events.perl" <trace.event >actual &&
283 sed -e "s/^|//" >expect <<-EOF &&
298 | "hierarchy":"trace2",
304 test_cmp expect actual
307 test_expect_success
'discard traces when there are too many files' '
308 mkdir trace_target_dir &&
309 test_when_finished "rm -r trace_target_dir" &&
311 GIT_TRACE2_MAX_FILES=5 &&
312 export GIT_TRACE2_MAX_FILES &&
313 cd trace_target_dir &&
314 test_seq $GIT_TRACE2_MAX_FILES >../expected_filenames.txt &&
315 xargs touch <../expected_filenames.txt &&
317 GIT_TRACE2_EVENT="$(pwd)/trace_target_dir" test-tool trace2 001return 0
319 echo git-trace2-discard >>expected_filenames.txt &&
320 ls trace_target_dir >ls_output.txt &&
321 test_cmp expected_filenames.txt ls_output.txt &&
322 head -n1 trace_target_dir/git-trace2-discard | grep \"event\":\"version\" &&
323 head -n2 trace_target_dir/git-trace2-discard | tail -n1 | grep \"event\":\"too_many_files\"