Jeff Hostetler | a15860d | 2019-02-22 14:25:10 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test trace2 facility (normal target)' |
| 4 | . ./test-lib.sh |
| 5 | |
Jeff Hostetler | bce9db6 | 2019-04-15 13:39:47 -0700 | [diff] [blame] | 6 | # Turn off any inherited trace2 settings for this test. |
SZEDER Gábor | e4b75d6 | 2019-05-19 16:43:08 +0200 | [diff] [blame] | 7 | sane_unset GIT_TRACE2 GIT_TRACE2_PERF GIT_TRACE2_EVENT |
| 8 | sane_unset GIT_TRACE2_BRIEF |
| 9 | sane_unset GIT_TRACE2_CONFIG_PARAMS |
Jeff Hostetler | bce9db6 | 2019-04-15 13:39:47 -0700 | [diff] [blame] | 10 | |
Jeff Hostetler | a15860d | 2019-02-22 14:25:10 -0800 | [diff] [blame] | 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 | |
Jeff Hostetler | a15860d | 2019-02-22 14:25:10 -0800 | [diff] [blame] | 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 | # This script tests the normal target in isolation. |
| 29 | # |
SZEDER Gábor | e4b75d6 | 2019-05-19 16:43:08 +0200 | [diff] [blame] | 30 | # Defer setting GIT_TRACE2 until the actual command line we want to test |
Jeff Hostetler | a15860d | 2019-02-22 14:25:10 -0800 | [diff] [blame] | 31 | # because hidden git and test-tool commands run by the test harness |
| 32 | # can contaminate our output. |
| 33 | |
| 34 | # Enable "brief" feature which turns off "<clock> <file>:<line> " prefix. |
SZEDER Gábor | e4b75d6 | 2019-05-19 16:43:08 +0200 | [diff] [blame] | 35 | GIT_TRACE2_BRIEF=1 && export GIT_TRACE2_BRIEF |
Jeff Hostetler | a15860d | 2019-02-22 14:25:10 -0800 | [diff] [blame] | 36 | |
| 37 | # Basic tests of the trace2 normal stream. Since this stream is used |
| 38 | # primarily with printf-style debugging/tracing, we do limited testing |
| 39 | # here. |
| 40 | # |
| 41 | # We do confirm the following API features: |
| 42 | # [] the 'version <v>' event |
| 43 | # [] the 'start <argv>' event |
| 44 | # [] the 'cmd_name <name>' event |
| 45 | # [] the 'exit <time> code:<code>' event |
| 46 | # [] the 'atexit <time> code:<code>' event |
| 47 | # |
| 48 | # Fields of the form _FIELD_ are tokens that have been replaced (such |
| 49 | # as the elapsed time). |
| 50 | |
| 51 | # Verb 001return |
| 52 | # |
| 53 | # Implicit return from cmd_<verb> function propagates <code>. |
| 54 | |
| 55 | test_expect_success 'normal stream, return code 0' ' |
| 56 | test_when_finished "rm trace.normal actual expect" && |
SZEDER Gábor | e4b75d6 | 2019-05-19 16:43:08 +0200 | [diff] [blame] | 57 | GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 001return 0 && |
Jeff Hostetler | a15860d | 2019-02-22 14:25:10 -0800 | [diff] [blame] | 58 | perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && |
| 59 | cat >expect <<-EOF && |
| 60 | version $V |
| 61 | start _EXE_ trace2 001return 0 |
| 62 | cmd_name trace2 (trace2) |
| 63 | exit elapsed:_TIME_ code:0 |
| 64 | atexit elapsed:_TIME_ code:0 |
| 65 | EOF |
| 66 | test_cmp expect actual |
| 67 | ' |
| 68 | |
| 69 | test_expect_success 'normal stream, return code 1' ' |
| 70 | test_when_finished "rm trace.normal actual expect" && |
SZEDER Gábor | e4b75d6 | 2019-05-19 16:43:08 +0200 | [diff] [blame] | 71 | test_must_fail env GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 001return 1 && |
Jeff Hostetler | a15860d | 2019-02-22 14:25:10 -0800 | [diff] [blame] | 72 | perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && |
| 73 | cat >expect <<-EOF && |
| 74 | version $V |
| 75 | start _EXE_ trace2 001return 1 |
| 76 | cmd_name trace2 (trace2) |
| 77 | exit elapsed:_TIME_ code:1 |
| 78 | atexit elapsed:_TIME_ code:1 |
| 79 | EOF |
| 80 | test_cmp expect actual |
| 81 | ' |
| 82 | |
Josh Steadmon | a4d3a28 | 2019-03-21 14:09:51 -0700 | [diff] [blame] | 83 | test_expect_success 'automatic filename' ' |
| 84 | test_when_finished "rm -r traces actual expect" && |
| 85 | mkdir traces && |
SZEDER Gábor | e4b75d6 | 2019-05-19 16:43:08 +0200 | [diff] [blame] | 86 | GIT_TRACE2="$(pwd)/traces" test-tool trace2 001return 0 && |
Josh Steadmon | a4d3a28 | 2019-03-21 14:09:51 -0700 | [diff] [blame] | 87 | perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <"$(ls traces/*)" >actual && |
| 88 | cat >expect <<-EOF && |
| 89 | version $V |
| 90 | start _EXE_ trace2 001return 0 |
| 91 | cmd_name trace2 (trace2) |
| 92 | exit elapsed:_TIME_ code:0 |
| 93 | atexit elapsed:_TIME_ code:0 |
| 94 | EOF |
| 95 | test_cmp expect actual |
| 96 | ' |
| 97 | |
Jeff Hostetler | a15860d | 2019-02-22 14:25:10 -0800 | [diff] [blame] | 98 | # Verb 002exit |
| 99 | # |
| 100 | # Explicit exit(code) from within cmd_<verb> propagates <code>. |
| 101 | |
| 102 | test_expect_success 'normal stream, exit code 0' ' |
| 103 | test_when_finished "rm trace.normal actual expect" && |
SZEDER Gábor | e4b75d6 | 2019-05-19 16:43:08 +0200 | [diff] [blame] | 104 | GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 002exit 0 && |
Jeff Hostetler | a15860d | 2019-02-22 14:25:10 -0800 | [diff] [blame] | 105 | perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && |
| 106 | cat >expect <<-EOF && |
| 107 | version $V |
| 108 | start _EXE_ trace2 002exit 0 |
| 109 | cmd_name trace2 (trace2) |
| 110 | exit elapsed:_TIME_ code:0 |
| 111 | atexit elapsed:_TIME_ code:0 |
| 112 | EOF |
| 113 | test_cmp expect actual |
| 114 | ' |
| 115 | |
| 116 | test_expect_success 'normal stream, exit code 1' ' |
| 117 | test_when_finished "rm trace.normal actual expect" && |
SZEDER Gábor | e4b75d6 | 2019-05-19 16:43:08 +0200 | [diff] [blame] | 118 | test_must_fail env GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 002exit 1 && |
Jeff Hostetler | a15860d | 2019-02-22 14:25:10 -0800 | [diff] [blame] | 119 | perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && |
| 120 | cat >expect <<-EOF && |
| 121 | version $V |
| 122 | start _EXE_ trace2 002exit 1 |
| 123 | cmd_name trace2 (trace2) |
| 124 | exit elapsed:_TIME_ code:1 |
| 125 | atexit elapsed:_TIME_ code:1 |
| 126 | EOF |
| 127 | test_cmp expect actual |
| 128 | ' |
| 129 | |
| 130 | # Verb 003error |
| 131 | # |
| 132 | # To the above, add multiple 'error <msg>' events |
| 133 | |
| 134 | test_expect_success 'normal stream, error event' ' |
| 135 | test_when_finished "rm trace.normal actual expect" && |
SZEDER Gábor | e4b75d6 | 2019-05-19 16:43:08 +0200 | [diff] [blame] | 136 | GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 003error "hello world" "this is a test" && |
Jeff Hostetler | a15860d | 2019-02-22 14:25:10 -0800 | [diff] [blame] | 137 | perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && |
| 138 | cat >expect <<-EOF && |
| 139 | version $V |
| 140 | start _EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\'' |
| 141 | cmd_name trace2 (trace2) |
| 142 | error hello world |
| 143 | error this is a test |
| 144 | exit elapsed:_TIME_ code:0 |
| 145 | atexit elapsed:_TIME_ code:0 |
| 146 | EOF |
| 147 | test_cmp expect actual |
| 148 | ' |
| 149 | |
Jonathan Tan | 0a9dde4 | 2021-02-05 12:09:08 -0800 | [diff] [blame] | 150 | # Verb 007bug |
| 151 | # |
| 152 | # Check that BUG writes to trace2 |
| 153 | |
| 154 | test_expect_success 'BUG messages are written to trace2' ' |
| 155 | test_when_finished "rm trace.normal actual expect" && |
| 156 | test_must_fail env GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 007bug && |
| 157 | perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && |
| 158 | cat >expect <<-EOF && |
| 159 | version $V |
| 160 | start _EXE_ trace2 007bug |
| 161 | cmd_name trace2 (trace2) |
| 162 | error the bug message |
| 163 | exit elapsed:_TIME_ code:99 |
| 164 | atexit elapsed:_TIME_ code:99 |
| 165 | EOF |
| 166 | test_cmp expect actual |
| 167 | ' |
| 168 | |
SZEDER Gábor | e4b75d6 | 2019-05-19 16:43:08 +0200 | [diff] [blame] | 169 | sane_unset GIT_TRACE2_BRIEF |
Jeff Hostetler | bce9db6 | 2019-04-15 13:39:47 -0700 | [diff] [blame] | 170 | |
| 171 | # Now test without environment variables and get all Trace2 settings |
| 172 | # from the global config. |
| 173 | |
| 174 | test_expect_success 'using global config, normal stream, return code 0' ' |
| 175 | test_when_finished "rm trace.normal actual expect" && |
| 176 | test_config_global trace2.normalBrief 1 && |
| 177 | test_config_global trace2.normalTarget "$(pwd)/trace.normal" && |
| 178 | test-tool trace2 001return 0 && |
| 179 | perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && |
| 180 | cat >expect <<-EOF && |
| 181 | version $V |
| 182 | start _EXE_ trace2 001return 0 |
| 183 | cmd_name trace2 (trace2) |
| 184 | exit elapsed:_TIME_ code:0 |
| 185 | atexit elapsed:_TIME_ code:0 |
| 186 | EOF |
| 187 | test_cmp expect actual |
| 188 | ' |
| 189 | |
| 190 | test_expect_success 'using global config with include' ' |
| 191 | test_when_finished "rm trace.normal actual expect real.gitconfig" && |
| 192 | test_config_global trace2.normalBrief 1 && |
| 193 | test_config_global trace2.normalTarget "$(pwd)/trace.normal" && |
| 194 | mv "$(pwd)/.gitconfig" "$(pwd)/real.gitconfig" && |
| 195 | test_config_global include.path "$(pwd)/real.gitconfig" && |
| 196 | test-tool trace2 001return 0 && |
| 197 | perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && |
| 198 | cat >expect <<-EOF && |
| 199 | version $V |
| 200 | start _EXE_ trace2 001return 0 |
| 201 | cmd_name trace2 (trace2) |
| 202 | exit elapsed:_TIME_ code:0 |
| 203 | atexit elapsed:_TIME_ code:0 |
| 204 | EOF |
| 205 | test_cmp expect actual |
| 206 | ' |
| 207 | |
Jeff Hostetler | a15860d | 2019-02-22 14:25:10 -0800 | [diff] [blame] | 208 | test_done |