|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This is a script for running git-bisect on sycl, sycl-web, and sycl pulldown |
| 4 | +# branches. This is mostly a standard git-bisect, except that any upstream |
| 5 | +# commits that aren't sycl-based must be merged to a sycl-based branch before |
| 6 | +# being tested. When possible, this is done in a secondary worktree to avoid |
| 7 | +# clobbering files, which enables incremental builds and significantly improves |
| 8 | +# build times nearer to the end of the bisection. |
| 9 | + |
| 10 | +# Parse options. |
| 11 | +OPTS=$(getopt -n sycl-bisect-test-commit.bash -o 'ht:c:b' -l 'help,test:,command:,command-allow-bisect-codes' -- "$@") |
| 12 | +if [[ $? != 0 ]]; then |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | +eval set -- "$OPTS" |
| 16 | +unset OPTS TEST COMMAND COMMAND_ALLOW_BISECT_CODES |
| 17 | +while true; do |
| 18 | + case "$1" in |
| 19 | + '-h'|'--help') |
| 20 | + cat <<HELP |
| 21 | +Usage: |
| 22 | +
|
| 23 | +$0 [opts] <bad commit> <good commits...> |
| 24 | +
|
| 25 | + -h,--help Print this help message |
| 26 | + -t,--test <test> Test commits with LIT test <test>, a test file |
| 27 | + path relative to the current working directory |
| 28 | + -c,--command <command> Test commits with command <command>, which |
| 29 | + will be executed for each commit via bash -c |
| 30 | + in the current working directory |
| 31 | + -b,--command-allow-bisect-codes Pass 125 and >127 return codes to git-bisect |
| 32 | + directly when using --command to allow the |
| 33 | + command to skip commits or stop bisection. If |
| 34 | + this option is not present, any non-zero |
| 35 | + return value is interpreted as a bad commit. |
| 36 | +
|
| 37 | +Examples: |
| 38 | +
|
| 39 | +"Clang :: SemaSYCL/accessor_inheritance.cpp" started failing on sycl-web because |
| 40 | +of one of the commits merged by 96f730774ac4. To find which one of these 96 |
| 41 | +commits caused this test failure, sycl-bisect.bash can be run like this: |
| 42 | +
|
| 43 | +$ devops/scripts/sycl-bisect.bash 96f730774ac4 96f730774ac4^ --test clang/test/SemaSYCL/accessor_inheritance.cpp |
| 44 | +HELP |
| 45 | + exit 0 |
| 46 | + ;; |
| 47 | + '-t'|'--test') |
| 48 | + export TEST="$2" |
| 49 | + shift 2 |
| 50 | + ;; |
| 51 | + '-c'|'--command') |
| 52 | + export COMMAND="$2" |
| 53 | + shift 2 |
| 54 | + ;; |
| 55 | + '-b'|'--command-allow-bisect-codes') |
| 56 | + export COMMAND_ALLOW_BISECT_CODES=1 |
| 57 | + shift |
| 58 | + ;; |
| 59 | + '--') |
| 60 | + shift |
| 61 | + break |
| 62 | + ;; |
| 63 | + *) |
| 64 | + echo "Unexpected argument: $1" >&2 |
| 65 | + exit 1 |
| 66 | + ;; |
| 67 | + esac |
| 68 | +done |
| 69 | + |
| 70 | +# Validate options. |
| 71 | +if [[ "$1" == "" ]] || [[ "$2" == "" ]]; then |
| 72 | + echo "A bad rev and at least one good rev must be passed" >&2 |
| 73 | + exit 1 |
| 74 | +fi |
| 75 | +if [[ "$TEST" == "" ]] && [[ "$COMMAND" == "" ]]; then |
| 76 | + echo "--test <test> or --command <command> must be used to specify a test" >&2 |
| 77 | + exit 1 |
| 78 | +fi |
| 79 | +if [[ "$TEST" != "" ]] && [[ "$COMMAND" != "" ]]; then |
| 80 | + echo "Only one of --test <test> or --command <command> is allowed" >&2 |
| 81 | + exit 1 |
| 82 | +fi |
| 83 | +if [[ "$COMMAND_ALLOW_BISECT_CODES" != "" ]] && [[ "$COMMAND" == "" ]]; then |
| 84 | + echo "--command-allow-bisect-codes is only allowed with --command <command>" >&2 |
| 85 | + exit 1 |
| 86 | +fi |
| 87 | + |
| 88 | +# Save the current working directory before switching to the repository's |
| 89 | +# top-level directory. Tests will be run relative to the original working |
| 90 | +# directory. |
| 91 | +export TEST_WD="$PWD" |
| 92 | +TOPLEVEL="$(git rev-parse --show-toplevel)" |
| 93 | +if [[ "$TOPLEVEL" == "" ]]; then |
| 94 | + exit 1 |
| 95 | +fi |
| 96 | +cd "$TOPLEVEL" |
| 97 | + |
| 98 | +# A commit that should be on all sycl-based branches this script works with. |
| 99 | +# This is set to the initial sycl-specific commit. |
| 100 | +export SYCL_ANCESTOR=1e0b4966ba9a |
| 101 | + |
| 102 | +# This commit should be in the repository. |
| 103 | +if ! git rev-parse $SYCL_ANCESTOR &>/dev/null; then |
| 104 | + echo "Current repository is not sycl-based" >&2 |
| 105 | + exit 1 |
| 106 | +fi |
| 107 | + |
| 108 | +# Along with all the bad/good revs. |
| 109 | +for REV in "$@"; do |
| 110 | + if ! git rev-parse --verify "$REV" &>/dev/null; then |
| 111 | + echo "'$REV' is not a valid revision" >&2 |
| 112 | + exit 1 |
| 113 | + fi |
| 114 | +done |
| 115 | + |
| 116 | +# Make sure the build directory is set up; if not, tell the user to run |
| 117 | +# the configure step. |
| 118 | +if [[ ! -f build/CMakeCache.txt ]]; then |
| 119 | + echo "The build directory doesn't seem to be configured yet." >&2 |
| 120 | + echo "Please run the configure step as documented in sycl/doc/GetStartedGuide.md:" >&2 |
| 121 | + echo " https://intel.github.io/llvm-docs/GetStartedGuide.html#build-dpc-toolchain" >&2 |
| 122 | + exit 1 |
| 123 | +fi |
| 124 | + |
| 125 | +# If this is a LIT test, make sure FileCheck and other testing utilities are |
| 126 | +# built. |
| 127 | +if [[ ! -f build/bin/FileCheck ]]; then |
| 128 | + echo "FileCheck not found; building test-depends" |
| 129 | + cmake --build build -- test-depends -j $(nproc) |
| 130 | +fi |
| 131 | + |
| 132 | +# Determines if the passed commit is sycl-based or not. |
| 133 | +function is_sycl_based_commit { |
| 134 | + git merge-base --is-ancestor $SYCL_ANCESTOR "$1" 2>/dev/null |
| 135 | +} |
| 136 | + |
| 137 | +# Checks if this commit/branch is a candidate for SYCL_DESCENDANT. For that to |
| 138 | +# be the case, it needs to be sycl-based and a descendant of the bad and good |
| 139 | +# commits. |
| 140 | +readonly -a REQUIRED_ANCESTORS=($SYCL_ANCESTOR "$@") |
| 141 | +function check_sycl_descendant { |
| 142 | + local ancestor |
| 143 | + for ancestor in "${REQUIRED_ANCESTORS[@]}"; do |
| 144 | + git merge-base --is-ancestor "$ancestor" "$1" &>/dev/null || return 1 |
| 145 | + done |
| 146 | + export SYCL_DESCENDANT="$1" |
| 147 | + return 0 |
| 148 | +} |
| 149 | + |
| 150 | +# If SYCL_DESCENDANT isn't specified, poke around until a suitable commit/branch |
| 151 | +# is found. |
| 152 | +function find_sycl_descendant { |
| 153 | + [[ "$SYCL_DESCENDANT" != "" ]] && return |
| 154 | + |
| 155 | + # Try the bad rev first. |
| 156 | + check_sycl_descendant "${REQUIRED_ANCESTORS[1]}" && return |
| 157 | + |
| 158 | + # Try "sycl" and "sycl-web", both locally and in all the remotes. |
| 159 | + check_sycl_descendant "sycl" && return |
| 160 | + check_sycl_descendant "sycl-web" && return |
| 161 | + local remote |
| 162 | + for remote in $(git remote); do |
| 163 | + check_sycl_descendant "$remote/sycl" && return |
| 164 | + check_sycl_descendant "$remote/sycl-web" && return |
| 165 | + done |
| 166 | + |
| 167 | + # Try all of the local branches. |
| 168 | + local branch |
| 169 | + for branch in $(git branch); do |
| 170 | + check_sycl_descendant "$branch" && return |
| 171 | + done |
| 172 | + |
| 173 | + # Give up and ask the user to pick one. |
| 174 | + echo "Unable to find a sycl-based branch containing all bad/good commits" >&2 |
| 175 | + echo "Please specify one with SYCL_DESCENDANT" >&2 |
| 176 | + exit 1 |
| 177 | +} |
| 178 | +find_sycl_descendant |
| 179 | + |
| 180 | +# Try creating a worktree for out-of-tree merges. If this is successful, set a |
| 181 | +# trap to clean it up when bisection is complete. |
| 182 | +echo "Attempting to set up sycl-bisect-merge worktree..." |
| 183 | +git worktree add sycl-bisect-merge \ |
| 184 | + && trap "git worktree remove sycl-bisect-merge" EXIT |
| 185 | + |
| 186 | +# Save test-commit-sycl-bisect.bash to a temporary file to use during the |
| 187 | +# bisection. Otherwise, git-bisect might check out a commit with a substantially |
| 188 | +# different version than sycl-bisect.bash expects, or it might check out a |
| 189 | +# commit where test-commit-sycl-bisect.bash doesn't exist at all. |
| 190 | +SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" |
| 191 | +TEST_COMMIT="$(mktemp --tmpdir test-commit-XXX.bash)" |
| 192 | +if [[ -f "$TEST_COMMIT" ]]; then |
| 193 | + if [[ "$(trap -p EXIT)" != "" ]]; then |
| 194 | + trap "git worktree remove sycl-bisect-merge ; rm $TEST_COMMIT" EXIT |
| 195 | + else |
| 196 | + trap "rm $TEST_COMMIT" EXIT |
| 197 | + fi |
| 198 | + cp "$SCRIPT_DIR/test-commit-sycl-bisect.bash" "$TEST_COMMIT" |
| 199 | +else |
| 200 | + TEST_COMMIT="$SCRIPT_DIR/test-commit-sycl-bisect.bash" |
| 201 | +fi |
| 202 | + |
| 203 | +# Do the bisection. |
| 204 | +git bisect start --no-checkout "$@" || exit |
| 205 | +git bisect run bash "$TEST_COMMIT" |
| 206 | +git bisect reset |
0 commit comments