#!/bin/bash set -ef -o pipefail scripts=$(dirname $0) . $scripts/jenkins-helpers.sh artifacts=$(pwd)/artifacts fresh_dir $artifacts "$artifacts/manifests/*" "$artifacts/jenkins/*" # Process bisect-only args convert_args_to_variables "$@" shift "$SHIFT_CONVERTED_ARGS" bad_rev="${bad_rev:-default}" baseline_rev="${baseline_rev:-baseline}" BUILD_URL="${BUILD_URL:-$(pwd)}" reproduce_bisect="${reproduce_bisect:-false}" # Process build args and record them in build-parameters.sh convert_args_to_variables ^^ $reproduce_bisect %% $artifacts/manifests/build-parameters.sh "$@" $reproduce_bisect || manifest_pop obligatory_variables current_project toolchain linux_config="${linux_config:-defconfig}" target="${target:-native}" verbose="${verbose:-true}" set -u if $verbose; then set -x; fi trap "eval \"echo ERROR at \${FUNCNAME[0]}:\${BASH_LINENO[0]}\" > $artifacts/failures" EXIT if [ x"$bad_rev" = x"default" ]; then echo "ERROR: Need explicit --bad_rev" exit 1 else bad_rev=$(git -C $current_project rev-parse "$bad_rev") fi # Build baseline that we are going to re-use to speed-up bisection. # (This also confirms that infrastructure is OK.) echo "Testing baseline_rev $baseline_rev (should be success)" $scripts/tcwg_kernel-build.sh \ ^^ $reproduce_bisect \ %% $artifacts/manifests/build-baseline.sh \ @@ $artifacts/manifests/build-parameters.sh \ --mode "baseline" \ --current_rev "$baseline_rev" \ --reset_baseline true \ --top_artifacts "$artifacts/build-baseline" \ --verbose "$verbose" assert ! [ -f $artifacts/failures ] cd $current_project # Remember $good_rev from the baseline build above. good_rev=$(git rev-parse HEAD) baseline_rev="$good_rev" ln -f -s "build-baseline" "$artifacts/build-$baseline_rev" ln -f -s "build-baseline.sh" "$artifacts/manifests/build-$baseline_rev.sh" echo "$baseline_rev" >> $artifacts/good_revs cat < $artifacts/test.sh <> $artifacts/bad_revs exit 1 elif [ x"\$res" != x"0" ]; then echo "\$rev" >> $artifacts/skipped_revs exit 125 else echo "\$rev" >> $artifacts/good_revs exit 0 fi EOF chmod +x $artifacts/test.sh # Workaround linux-next/master rebasing on top of linux-next/stable. # Try to find $good_rev that is "good" compared to baseline # and that is an ancesstor of both $baseline_rev and $bad_rev. merge_base=$(git merge-base $bad_rev HEAD) origin=$(git remote get-url origin) origin=$(basename "$origin") if [ x"$merge_base" != x"$good_rev" -a x"$origin" = x"linux-next.git" ]; then echo "Testing merge_base $merge_base (hoping for success)" git checkout --detach "$merge_base" $artifacts/test.sh & res=0 && wait $! || res=$? if [ x"$res" != x"0" ]; then # Check if we can use linux-next/stable as our pre-last resort. linux_next_stable="${linux_next_stable-$(git rev-parse refs/remotes/origin/stable)}" cat < /dev/null 2>&1 || true git remote set-url mainline "$url" clone_or_update_repo . refs/remotes/mainline/master "$url" merge_base=$(git merge-base $bad_rev HEAD) mainline_master="${mainline_master-$merge_base}" cat < $artifacts/trigger-2-build-master <&1 | tee $artifacts/bisect.log # "git bisect run" can fail (exit with non-zero) in a number of cases: # - on trivial bisects (e.g., between HEAD^ and HEAD), # - when merge-base between baseline and bad is worse than baseline, # - something else? # In all these cases we want to reset baseline to HEAD, so that we catch # most of the commits that introduced change in the result metric. git bisect run $artifacts/test.sh 2>&1 | tee -a $artifacts/bisect.log & res=0 && wait $! || res=$? if [ x"$res" = x"0" ]; then first_bad=$(cat .git/BISECT_RUN | head -n 1 | grep "is the first bad commit" | cut -d" " -f 1) assert [ x"$first_bad" != x"" ] echo $first_bad > $artifacts/first-bad else first_bad=$(git rev-parse HEAD) if ! [ -f .git/BISECT_LOG ]; then # It seems this was a trivial bisect with $bad_rev^ == $good_rev. first_bad=$bad_rev echo $first_bad > $artifacts/first-bad fi fi cd .. # Save BISECT_* logs mkdir $artifacts/git-logs find "$current_project" -path "$current_project/.git/BISECT_*" -print0 | xargs -0 -I@ mv @ $artifacts/git-logs/ # Reset baseline to the regressed commit so that we will catch subsequent # regressions (worse than $bad_rev). cat > $artifacts/trigger-1-reset-baseline < $artifacts/trigger-2-build-master <> $artifacts/jenkins/mail-body.txt < $(git -C $current_project log -n 1 $first_bad) EOF else good_name="good_rev" good_sha1="$good_rev" bad_name="bad" bad_sha1="$bad_rev" cat >> $artifacts/jenkins/mail-body.txt <> $artifacts/jenkins/mail-body.txt < $(cat $artifacts/build-$good_sha1/results) to (for $bad_name == $bad_sha1) $(cat $artifacts/build-$bad_sha1/results) Artifacts of $good_name build: ${BUILD_URL}artifact/artifacts/build-$good_sha1/ Artifacts of $bad_name build: ${BUILD_URL}artifact/artifacts/build-$bad_sha1/ Reproduce builds: mkdir investigate-$current_project-$bad_sha1 cd investigate-$current_project-$bad_sha1 git clone https://git.linaro.org/toolchain/jenkins-scripts mkdir reproduce-$good_name cd reproduce-$good_name wget ${BUILD_URL}artifact/artifacts/manifests/build-$good_sha1.sh ../jenkins-scripts/tcwg_kernel-build.sh @@ build-$good_sha1.sh cd .. mkdir reproduce-$bad_name cd reproduce-$bad_name wget ${BUILD_URL}artifact/artifacts/manifests/build-$bad_sha1.sh ../jenkins-scripts/tcwg_kernel-build.sh @@ build-$bad_sha1.sh cd .. History of pending regressions and results: https://git.linaro.org/toolchain/ci/base-artifacts.git/log/?h=linaro-local/ci/tcwg_kernel/$toolchain-${rr[${toolchain}_version]}-$target-${rr[linux_version]}-$linux_config Bisect log: ${BUILD_URL}artifact/artifacts/bisect.log/*view*/ Artifacts: ${BUILD_URL}artifact/artifacts/ Build URL: $BUILD_URL Build log: ${BUILD_URL}consoleText EOF if [ -f $artifacts/first-bad ]; then cat >> $artifacts/jenkins/mail-body.txt < $(git -C $current_project show $first_bad) EOF fi # Set mail recipients last to preserve catch-error value from tcwg_kernel.yaml. # Email developers. CI_MAIL_RECIPIENTS="tcwg-validation@linaro.org" case "$toolchain:$current_project" in gnu:*) CI_MAIL_RECIPIENTS="$CI_MAIL_RECIPIENTS, christophe.lyon@linaro.org, maxim.kuvyrkov@linaro.org" ;; llvm:linux) CI_MAIL_RECIPIENTS="$CI_MAIL_RECIPIENTS, arnd@linaro.org, mark.brown@linaro.org, ndesaulniers@google.com, trong@google.com" ;; llvm:llvm) CI_MAIL_RECIPIENTS="$CI_MAIL_RECIPIENTS, adhemerval.zanella@linaro.org, maxim.kuvyrkov@linaro.org, ndesaulniers@google.com, trong@google.com, yvan.roux@linaro.org" ;; esac cat > $artifacts/jenkins/mail-recipients.txt <