1#!/bin/sh
2
3test_description='test trace2 facility (perf target)'
4. ./test-lib.sh
5
6# Add t/helper directory to PATH so that we can use a relative
7# path to run nested instances of test-tool.exe (see 004child).
8# This helps with HEREDOC comparisons later.
9TTDIR="$GIT_BUILD_DIR/t/helper/" && export TTDIR
10PATH="$TTDIR:$PATH" && export PATH
11
12# Warning: use of 'test_cmp' may run test-tool.exe and/or git.exe
13# Warning: to do the actual diff/comparison, so the HEREDOCs here
14# Warning: only cover our actual calls to test-tool and/or git.
15# Warning: So you may see extra lines in artifact files when
16# Warning: interactively debugging.
17
18# Turn off any inherited trace2 settings for this test.
19unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT
20unset GIT_TR2_PERF_BRIEF
21unset GIT_TR2_CONFIG_PARAMS
22
23V=$(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#
30# Defer setting GIT_TR2_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.
33
34# Enable "brief" feature which turns off the prefix:
35# "<clock> <file>:<line> | <nr_parents> | "
36GIT_TR2_PERF_BRIEF=1 && export GIT_TR2_PERF_BRIEF
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
47test_expect_success 'perf stream, return code 0' '
48 test_when_finished "rm trace.perf actual expect" &&
49 GIT_TR2_PERF="$(pwd)/trace.perf" test-tool trace2 001return 0 &&
50 perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual &&
51 cat >expect <<-EOF &&
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
57 EOF
58 test_cmp expect actual
59'
60
61test_expect_success 'perf stream, return code 1' '
62 test_when_finished "rm trace.perf actual expect" &&
63 test_must_fail env GIT_TR2_PERF="$(pwd)/trace.perf" test-tool trace2 001return 1 &&
64 perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual &&
65 cat >expect <<-EOF &&
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
71 EOF
72 test_cmp expect actual
73'
74
75# Verb 003error
76#
77# To the above, add multiple 'error <msg>' events
78
79test_expect_success 'perf stream, error event' '
80 test_when_finished "rm trace.perf actual expect" &&
81 GIT_TR2_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 &&
83 cat >expect <<-EOF &&
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
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
125test_expect_success 'perf stream, child processes' '
126 test_when_finished "rm trace.perf actual expect" &&
127 GIT_TR2_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
149 EOF
150 test_cmp expect actual
151'
152
153test_done