3 test_description='test trace2 facility (perf target)'
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_PERF_BRIEF
9 sane_unset GIT_TRACE2_CONFIG_PARAMS
11 # Add t/helper directory to PATH so that we can use a relative
12 # path to run nested instances of test-tool.exe (see 004child).
13 # This helps with HEREDOC comparisons later.
14 TTDIR="$GIT_BUILD_DIR/t/helper/" && export TTDIR
15 PATH="$TTDIR:$PATH" && export PATH
17 # Warning: use of 'test_cmp' may run test-tool.exe and/or git.exe
18 # Warning: to do the actual diff/comparison, so the HEREDOCs here
19 # Warning: only cover our actual calls to test-tool and/or git.
20 # Warning: So you may see extra lines in artifact files when
21 # Warning: interactively debugging.
23 V=$(git version | sed -e 's/^git version //') && export V
25 # There are multiple trace2 targets: normal, perf, and event.
26 # Trace2 events will/can be written to each active target (subject
27 # to whatever filtering that target decides to do).
28 # Test each target independently.
30 # Defer setting GIT_TRACE2_PERF until the actual command we want to
31 # test because hidden git and test-tool commands in the test
32 # harness can contaminate our output.
34 # Enable "brief" feature which turns off the prefix:
35 # "<clock> <file>:<line> | <nr_parents> | "
36 GIT_TRACE2_PERF_BRIEF=1 && export GIT_TRACE2_PERF_BRIEF
38 # Repeat some of the t0210 tests using the perf target stream instead of
41 # Tokens here of the form _FIELD_ have been replaced in the observed output.
45 # Implicit return from cmd_<verb> function propagates <code>.
47 test_expect_success 'perf stream, return code 0' '
48 test_when_finished "rm trace.perf actual expect" &&
49 GIT_TRACE2_PERF="$(pwd)/trace.perf" test-tool trace2 001return 0 &&
50 perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual &&
52 d0|main|version|||||$V
53 d0|main|start||_T_ABS_|||_EXE_ trace2 001return 0
54 d0|main|cmd_name|||||trace2 (trace2)
55 d0|main|exit||_T_ABS_|||code:0
56 d0|main|atexit||_T_ABS_|||code:0
58 test_cmp expect actual
61 test_expect_success 'perf stream, return code 1' '
62 test_when_finished "rm trace.perf actual expect" &&
63 test_must_fail env GIT_TRACE2_PERF="$(pwd)/trace.perf" test-tool trace2 001return 1 &&
64 perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual &&
66 d0|main|version|||||$V
67 d0|main|start||_T_ABS_|||_EXE_ trace2 001return 1
68 d0|main|cmd_name|||||trace2 (trace2)
69 d0|main|exit||_T_ABS_|||code:1
70 d0|main|atexit||_T_ABS_|||code:1
72 test_cmp expect actual
77 # To the above, add multiple 'error <msg>' events
79 test_expect_success 'perf stream, error event' '
80 test_when_finished "rm trace.perf actual expect" &&
81 GIT_TRACE2_PERF="$(pwd)/trace.perf" test-tool trace2 003error "hello world" "this is a test" &&
82 perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual &&
84 d0|main|version|||||$V
85 d0|main|start||_T_ABS_|||_EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\''
86 d0|main|cmd_name|||||trace2 (trace2)
87 d0|main|error|||||hello world
88 d0|main|error|||||this is a test
89 d0|main|exit||_T_ABS_|||code:0
90 d0|main|atexit||_T_ABS_|||code:0
92 test_cmp expect actual
97 # Test nested spawning of child processes.
99 # Conceptually, this looks like:
100 # P1: TT trace2 004child
101 # P2: |--- TT trace2 004child
102 # P3: |--- TT trace2 001return 0
104 # Which should generate events:
125 test_expect_success 'perf stream, child processes' '
126 test_when_finished "rm trace.perf actual expect" &&
127 GIT_TRACE2_PERF="$(pwd)/trace.perf" test-tool trace2 004child test-tool trace2 004child test-tool trace2 001return 0 &&
128 perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual &&
129 cat >expect <<-EOF &&
130 d0|main|version|||||$V
131 d0|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0
132 d0|main|cmd_name|||||trace2 (trace2)
133 d0|main|child_start||_T_ABS_|||[ch0] class:? argv:[test-tool trace2 004child test-tool trace2 001return 0]
134 d1|main|version|||||$V
135 d1|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 001return 0
136 d1|main|cmd_name|||||trace2 (trace2/trace2)
137 d1|main|child_start||_T_ABS_|||[ch0] class:? argv:[test-tool trace2 001return 0]
138 d2|main|version|||||$V
139 d2|main|start||_T_ABS_|||_EXE_ trace2 001return 0
140 d2|main|cmd_name|||||trace2 (trace2/trace2/trace2)
141 d2|main|exit||_T_ABS_|||code:0
142 d2|main|atexit||_T_ABS_|||code:0
143 d1|main|child_exit||_T_ABS_|_T_REL_||[ch0] pid:_PID_ code:0
144 d1|main|exit||_T_ABS_|||code:0
145 d1|main|atexit||_T_ABS_|||code:0
146 d0|main|child_exit||_T_ABS_|_T_REL_||[ch0] pid:_PID_ code:0
147 d0|main|exit||_T_ABS_|||code:0
148 d0|main|atexit||_T_ABS_|||code:0
150 test_cmp expect actual
153 sane_unset GIT_TRACE2_PERF_BRIEF
155 # Now test without environment variables and get all Trace2 settings
156 # from the global config.
158 test_expect_success 'using global config, perf stream, return code 0' '
159 test_when_finished "rm trace.perf actual expect" &&
160 test_config_global trace2.perfBrief 1 &&
161 test_config_global trace2.perfTarget "$(pwd)/trace.perf" &&
162 test-tool trace2 001return 0 &&
163 perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual &&
164 cat >expect <<-EOF &&
165 d0|main|version|||||$V
166 d0|main|start||_T_ABS_|||_EXE_ trace2 001return 0
167 d0|main|cmd_name|||||trace2 (trace2)
168 d0|main|exit||_T_ABS_|||code:0
169 d0|main|atexit||_T_ABS_|||code:0
171 test_cmp expect actual