3 test_description='test trace2 facility'
6 perl -MJSON::PP -e 0 >/dev/null 2>&1 && test_set_prereq JSON_PP
8 # Add t/helper directory to PATH so that we can use a relative
9 # path to run nested instances of test-tool.exe (see 004child).
10 # This helps with HEREDOC comparisons later.
11 TTDIR="$GIT_BUILD_DIR/t/helper/" && export TTDIR
12 PATH="$TTDIR:$PATH" && export PATH
14 # Warning: use of 'test_cmp' may run test-tool.exe and/or git.exe
15 # Warning: to do the actual diff/comparison, so the HEREDOCs here
16 # Warning: only cover our actual calls to test-tool and/or git.
17 # Warning: So you may see extra lines in artifact files when
18 # Warning: interactively debugging.
20 # Turn off any inherited trace2 settings for this test.
21 unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT
23 unset GIT_TR2_CONFIG_PARAMS
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_TR2_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_TR2_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_TR2_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_TR2_EVENT="$(pwd)/trace.event" GIT_TR2_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_TR2_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