]>
Commit | Line | Data |
---|---|---|
a15860dc JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='test trace2 facility (perf target)' | |
4 | . ./test-lib.sh | |
5 | ||
bce9db6d | 6 | # Turn off any inherited trace2 settings for this test. |
e4b75d6a SG |
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 | |
bce9db6d | 10 | |
a15860dc JH |
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 | |
16 | ||
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. | |
22 | ||
a15860dc JH |
23 | V=$(git version | sed -e 's/^git version //') && export V |
24 | ||
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. | |
29 | # | |
e4b75d6a | 30 | # Defer setting GIT_TRACE2_PERF until the actual command we want to |
a15860dc JH |
31 | # test because hidden git and test-tool commands in the test |
32 | # harness can contaminate our output. | |
33 | ||
34 | # Enable "brief" feature which turns off the prefix: | |
35 | # "<clock> <file>:<line> | <nr_parents> | " | |
e4b75d6a | 36 | GIT_TRACE2_PERF_BRIEF=1 && export GIT_TRACE2_PERF_BRIEF |
a15860dc JH |
37 | |
38 | # Repeat some of the t0210 tests using the perf target stream instead of | |
39 | # the normal stream. | |
40 | # | |
41 | # Tokens here of the form _FIELD_ have been replaced in the observed output. | |
42 | ||
43 | # Verb 001return | |
44 | # | |
45 | # Implicit return from cmd_<verb> function propagates <code>. | |
46 | ||
47 | test_expect_success 'perf stream, return code 0' ' | |
48 | test_when_finished "rm trace.perf actual expect" && | |
e4b75d6a | 49 | GIT_TRACE2_PERF="$(pwd)/trace.perf" test-tool trace2 001return 0 && |
a15860dc JH |
50 | perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && |
51 | cat >expect <<-EOF && | |
52 | d0|main|version|||||$V | |
39f43177 | 53 | d0|main|start||_T_ABS_|||_EXE_ trace2 001return 0 |
a15860dc JH |
54 | d0|main|cmd_name|||||trace2 (trace2) |
55 | d0|main|exit||_T_ABS_|||code:0 | |
56 | d0|main|atexit||_T_ABS_|||code:0 | |
57 | EOF | |
58 | test_cmp expect actual | |
59 | ' | |
60 | ||
61 | test_expect_success 'perf stream, return code 1' ' | |
62 | test_when_finished "rm trace.perf actual expect" && | |
e4b75d6a | 63 | test_must_fail env GIT_TRACE2_PERF="$(pwd)/trace.perf" test-tool trace2 001return 1 && |
a15860dc JH |
64 | perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && |
65 | cat >expect <<-EOF && | |
66 | d0|main|version|||||$V | |
39f43177 | 67 | d0|main|start||_T_ABS_|||_EXE_ trace2 001return 1 |
a15860dc JH |
68 | d0|main|cmd_name|||||trace2 (trace2) |
69 | d0|main|exit||_T_ABS_|||code:1 | |
70 | d0|main|atexit||_T_ABS_|||code:1 | |
71 | EOF | |
72 | test_cmp expect actual | |
73 | ' | |
74 | ||
75 | # Verb 003error | |
76 | # | |
77 | # To the above, add multiple 'error <msg>' events | |
78 | ||
79 | test_expect_success 'perf stream, error event' ' | |
80 | test_when_finished "rm trace.perf actual expect" && | |
e4b75d6a | 81 | GIT_TRACE2_PERF="$(pwd)/trace.perf" test-tool trace2 003error "hello world" "this is a test" && |
a15860dc JH |
82 | perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && |
83 | cat >expect <<-EOF && | |
84 | d0|main|version|||||$V | |
39f43177 | 85 | d0|main|start||_T_ABS_|||_EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\'' |
a15860dc JH |
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 | |
91 | EOF | |
92 | test_cmp expect actual | |
93 | ' | |
94 | ||
95 | # Verb 004child | |
96 | # | |
97 | # Test nested spawning of child processes. | |
98 | # | |
99 | # Conceptually, this looks like: | |
100 | # P1: TT trace2 004child | |
101 | # P2: |--- TT trace2 004child | |
102 | # P3: |--- TT trace2 001return 0 | |
103 | # | |
104 | # Which should generate events: | |
105 | # P1: version | |
106 | # P1: start | |
107 | # P1: cmd_name | |
108 | # P1: child_start | |
109 | # P2: version | |
110 | # P2: start | |
111 | # P2: cmd_name | |
112 | # P2: child_start | |
113 | # P3: version | |
114 | # P3: start | |
115 | # P3: cmd_name | |
116 | # P3: exit | |
117 | # P3: atexit | |
118 | # P2: child_exit | |
119 | # P2: exit | |
120 | # P2: atexit | |
121 | # P1: child_exit | |
122 | # P1: exit | |
123 | # P1: atexit | |
124 | ||
125 | test_expect_success 'perf stream, child processes' ' | |
126 | test_when_finished "rm trace.perf actual expect" && | |
e4b75d6a | 127 | GIT_TRACE2_PERF="$(pwd)/trace.perf" test-tool trace2 004child test-tool trace2 004child test-tool trace2 001return 0 && |
a15860dc JH |
128 | perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && |
129 | cat >expect <<-EOF && | |
130 | d0|main|version|||||$V | |
39f43177 | 131 | d0|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0 |
a15860dc | 132 | d0|main|cmd_name|||||trace2 (trace2) |
742ed633 | 133 | d0|main|child_start||_T_ABS_|||[ch0] class:? argv:[test-tool trace2 004child test-tool trace2 001return 0] |
a15860dc | 134 | d1|main|version|||||$V |
39f43177 | 135 | d1|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 001return 0 |
a15860dc | 136 | d1|main|cmd_name|||||trace2 (trace2/trace2) |
742ed633 | 137 | d1|main|child_start||_T_ABS_|||[ch0] class:? argv:[test-tool trace2 001return 0] |
a15860dc | 138 | d2|main|version|||||$V |
39f43177 | 139 | d2|main|start||_T_ABS_|||_EXE_ trace2 001return 0 |
a15860dc JH |
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 | |
149 | EOF | |
150 | test_cmp expect actual | |
151 | ' | |
152 | ||
e4b75d6a | 153 | sane_unset GIT_TRACE2_PERF_BRIEF |
bce9db6d JH |
154 | |
155 | # Now test without environment variables and get all Trace2 settings | |
156 | # from the global config. | |
157 | ||
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 | |
170 | EOF | |
171 | test_cmp expect actual | |
172 | ' | |
173 | ||
a15860dc | 174 | test_done |