3 test_description
='test trace2 facility'
6 # Turn off any inherited trace2 settings for this test.
7 sane_unset GIT_TRACE2 GIT_TRACE2_PERF GIT_TRACE2_EVENT
8 sane_unset GIT_TRACE2_BARE
9 sane_unset GIT_TRACE2_CONFIG_PARAMS
11 perl
-MJSON::PP
-e 0 >/dev
/null
2>&1 && test_set_prereq JSON_PP
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 # Test each target independently.
32 # Defer setting GIT_TRACE2_PERF until the actual command we want to
33 # test because hidden git and test-tool commands in the test
34 # harness can contaminate our output.
36 # We don't bother repeating the 001return and 002exit tests, since they
37 # have coverage in the normal and perf targets.
41 # To the above, add multiple 'error <msg>' events
43 test_expect_success JSON_PP
'event stream, error event' '
44 test_when_finished "rm trace.event actual expect" &&
45 GIT_TRACE2_EVENT="$(pwd)/trace.event" test-tool trace2 003error "hello world" "this is a test" &&
46 perl "$TEST_DIRECTORY/t0212/parse_events.perl" <trace.event >actual &&
47 sed -e "s/^|//" >expect <<-EOF &&
62 | "hierarchy":"trace2",
68 test_cmp expect actual
73 # Test nested spawning of child processes.
75 # Conceptually, this looks like:
76 # P1: TT trace2 004child
77 # P2: |--- TT trace2 004child
78 # P3: |--- TT trace2 001return 0
80 test_expect_success JSON_PP
'event stream, return code 0' '
81 test_when_finished "rm trace.event actual expect" &&
82 GIT_TRACE2_EVENT="$(pwd)/trace.event" test-tool trace2 004child test-tool trace2 004child test-tool trace2 001return 0 &&
83 perl "$TEST_DIRECTORY/t0212/parse_events.perl" <trace.event >actual &&
84 sed -e "s/^|//" >expect <<-EOF &&
116 | "hierarchy":"trace2",
144 | "hierarchy":"trace2/trace2",
148 | "_SID0_/_SID1_/_SID2_":{
156 | "hierarchy":"trace2/trace2/trace2",
162 test_cmp expect actual
165 # Test listing of all "interesting" config settings.
167 test_expect_success JSON_PP
'event stream, list config' '
168 test_when_finished "rm trace.event actual expect" &&
169 git config --local t0212.abc 1 &&
170 git config --local t0212.def "hello world" &&
171 GIT_TRACE2_EVENT="$(pwd)/trace.event" GIT_TRACE2_CONFIG_PARAMS="t0212.*" test-tool trace2 001return 0 &&
172 perl "$TEST_DIRECTORY/t0212/parse_events.perl" <trace.event >actual &&
173 sed -e "s/^|//" >expect <<-EOF &&
183 | "hierarchy":"trace2",
187 | "param":"t0212.abc",
191 | "param":"t0212.def",
192 | "value":"hello world"
199 test_cmp expect actual
202 test_expect_success JSON_PP
'basic trace2_data' '
203 test_when_finished "rm trace.event actual expect" &&
204 GIT_TRACE2_EVENT="$(pwd)/trace.event" test-tool trace2 006data test_category k1 v1 test_category k2 v2 &&
205 perl "$TEST_DIRECTORY/t0212/parse_events.perl" <trace.event >actual &&
206 sed -e "s/^|//" >expect <<-EOF &&
227 | "hierarchy":"trace2",
233 test_cmp expect actual
236 # Now test without environment variables and get all Trace2 settings
237 # from the global config.
239 test_expect_success JSON_PP
'using global config, event stream, error event' '
240 test_when_finished "rm trace.event actual expect" &&
241 test_config_global trace2.eventTarget "$(pwd)/trace.event" &&
242 test-tool trace2 003error "hello world" "this is a test" &&
243 perl "$TEST_DIRECTORY/t0212/parse_events.perl" <trace.event >actual &&
244 sed -e "s/^|//" >expect <<-EOF &&
259 | "hierarchy":"trace2",
265 test_cmp expect actual