Android Kernel Bisection Attempts - liuyq/android-issues GitHub Wiki

plan:

  1. use git log to get the commits to bisect, only first parent commits this needs to be done manually on local side as input, as it's not easy to get for the bisecting script
  2. decide how many commits to bisect this should be done by the
  3. check the results manually and bisect for the second iteration manually check $ ./bisecting-script -i commits-list.txt -O jobs-list-submitted.log, -t job-template.yaml
# git log --oneline --first-parent --no-abbrev-commit --no-decorate
# depth: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# less than or equal to 10 commits: submit jobs for all commits
# more than 10 commits, use depth 3 to bisect, at least 9 jobs submitted with the first and last commits
# the first and the last are not counted.
#   1 => 1 submitted, 1 in total
#   2 => 2 more, 3 in total
#   3 => 4 more, 7 in total <======== 9 in total if the first and the last counted
#   4 => 8 more, 15 in total

One script

#!/bin/bash -ex

commits="${commits} 5d96c24be923"
commits="${commits} 75aa4c087eab"
commits="${commits} f162762e3abc"
commits="${commits} 25f2c8b4c791"
commits="${commits} d0822a3f9ba9"
commits="${commits} 37d8fe8dc330"
function build(){
    for commit in ${commits}; do
        export SRCREV_kernel=${commit}
        cd common && git checkout ${commit} && cd -
        ./test.sh

        mv out/lkft-db845c-android13-android13-5.15-gki/ out/lkft-db845c-android13-android13-5.15-gki-$(date +%Y-%m-%d-%H-%M)-${commit}

    done
}

function boottime_test(){
    for commit in ${commits}; do
        local dir_output="out/lkft-db845c-android13-android13-5.15-gki-$(date +%Y-%m-%d-%H-%M)-${commit}"


    done
}

another script

#!/bin/bash -e

dir_kernel_src="/home/liuyq/data/android/lkft/kernel/common/mainline"
dir_kernel_src="/home/liuyq/data/android/lkft/common"
kernel_branch="android-mainline"
kernel_branch_current_backup="current_backup"
commit_good="4429151d285e"
commit_bad="0f3be1b18ead"
f_git_log_oneline="${dir_kernel_src}/git-log-oneline.log"
f_bisect="${dir_kernel_src}/git-log-oneline-bisect.log"
number_logs=500

# git log --first-parent -100 --oneline --no-decorate
# git rev-parse b38e72d30c99
##############
cd "${dir_kernel_src}"
res=$(git branch --list ${kernel_branch_current_backup})
[ -n "${res}" ] && git branch -D "${kernel_branch_current_backup}"
git branch "${kernel_branch_current_backup}"
git checkout "${kernel_branch}"
git log --oneline -n${number_logs} > "${f_git_log_oneline}"
cd -

if ! grep -q "^${commit_bad} " "${f_git_log_oneline}"; then
    echo "Note: The bad commit of ${commit_bad} was not found with the \"git log --oneline -n${number_logs}\" "
    echo "Note: Please try with larger log numbers"
    exit 1
fi
if ! grep -q  "^${commit_good} " "${f_git_log_oneline}"; then
    echo "Note: The good commit of ${commit_good} was not found with the \"git log --oneline -n${number_logs}\" "
    echo "Note: Please try with larger log numbers"
    exit 1
fi
found_good=false
found_bad=false
rm -fr "${f_bisect}"
while read line; do
    if ! ${found_bad} && echo "${line}" | grep -q "^${commit_bad} "; then
        found_bad=true
        echo "${line}" >> "${f_bisect}"
    elif echo "${line}" | grep -q "^${commit_good} "; then
        echo "${line}" >> "${f_bisect}"
        found_good=true
        break
    elif ${found_bad} && ! ${found_good}; then
        echo "${line}" >> "${f_bisect}"
        continue
    fi
done < "${f_git_log_oneline}"

number_commits=$(wc -l ${f_bisect}|awk '{print $1-2}')
if [ ${number_commits} -eq 0 ]; then
    echo "There is no commit between the good(${commit_good}) and bad(${commit_bad})"
    echo "Please check the difference between them: git diff ${commit_good} ${commit_bad}"
else
    echo "There are ${number_commits} commits between the good(${commit_good}) and bad(${commit_bad})"
    target_number=$(echo "${number_commits}"|awk '{print $1/2 + 2}')
    target_commit=$(cat -n "${f_bisect}" |egrep "^\s+${target_number}\s+" |awk '{print $2}')

    SRCREV_kernel=${target_commit} ./test.sh
    echo "The images were generated based on commit ${target_commit}"
    grep "^${target_commit} " "${f_bisect}"
    echo "Please deploy and check if that works."
fi

Script to apply commits

#!/bin/bash -e

git diff --staged >changes-before-patches-$(date +%Y-%m-%d-%H-%M).patch
f_commits="/tmp/x15-commits-old-first.txt"
f_merged="/tmp/x15-commits-merged.txt"
number_commits=$(wc -l "${f_commits}"|awk '{print $1}')
index=0
while read line; do
    if [ -z "${line}" ]; then
        break
    fi  
    commit=$(echo "${line}"|awk '{print $1}')
    word_2nd=$(echo "${line}"|awk '{print $2}')
    if [ "X${word_2nd}" = "XMerge" ]; then
        continue
    fi  
    index=$((index + 1))
    f_patch=$(git format-patch -n1 "${commit}")
    echo "Try to apply ${index}/${number_commits}: ${line}"
    patch -p1 -i "${f_patch}"
    echo "${line}" >> ${f_merged}
    rm -fr "${f_patch}"
done <${f_commits}

Script to find possible commits:

#!/bin/bash -ex

sha_ok="080d4caf553c"
sha_ng="c7cdbb44e3a4"

f_ng_work=$(mktemp -t bisect-XXX)
f_diff_list=$(mktemp -t files-XXX)
f_commits_list=$(mktemp -t commits-XXX)
git diff ${sha_ng} ${sha_ok} > "${f_ng_work}"
grep 'diff --git' ${f_ng_work} |awk '{print $3}'|sed 's|a/||' > ${f_diff_list}

rm -fr "${f_commits_list}"
while read -r f; do
    echo "$f" >> ${f_commits_list}
    git log --oneline ${sha_ok}..${sha_ng} ${f} |sed 's|^|\t|' >> ${f_commits_list}
done < "${f_diff_list}"

echo "Please check the file of ${f_commits_list}"

LAVA Job Template:

timeouts:
  job:
    minutes: 110
  connection:
    minutes: 2
  actions:
    finalize:
      seconds: 60
context:
  test_character_delay: 10
reboot_to_fastboot: false
device_type: dragonboard-845c
job_name: lkft-android-android-mainline-796141055-boot-{{COMMIT_SHA}}
priority: 60
visibility: personal
tags:
- lcg

actions:
- deploy:
    timeout:
      minutes: 65
    to: downloads
    images:
      partition:0:
        url: https://images.validation.linaro.org/snapshots.linaro.org/96boards/dragonboard845c/linaro/rescue/101/dragonboard-845c-bootloader-ufs-aosp-101/gpt_both0.bin
    os: android
    postprocess:
      docker:
        image: linaro/lava-android-postprocess:latest
        steps:
        - pip3 install --force-reinstall tuxsuite
        - TUXSUITE_TOKEN={{TUXSUITE_TOKEN}} SRCREV_kernel={{COMMIT_SHA}} /usr/bin/linaro-lkft-android.sh -g -c lkft-db845c-aosp-master-mainline-gki
- deploy:
    timeout:
      minutes: 10
    to: fastboot
    docker:
      image: linaro/lava-android-test:latest
    images:
      partition:0:
        url: downloads://gpt_both0.bin
      boot:
        url: downloads://boot.img
      super:
        url: downloads://super.img
      vendor_boot:
        url: downloads://vendor_boot.img
      userdata:
        url: downloads://userdata.img
- test:
    docker:
      image: linaro/lava-android-test:latest
    timeout:
      minutes: 5
    definitions:
    - from: inline
      path: format-metatdata.yaml
      name: format-metatdata
      repository:
        metadata:
          format: Lava-Test Test Definition 1.0
          name: format-metatdata
          description: format-metatdata
        run:
          steps:
          - lava-test-case "format-metadata" --shell fastboot format:ext4 metadata
- test:
    docker:
      image: linaro/lava-android-test:latest
    timeout:
      minutes: 5
    definitions:
    - from: inline
      path: select-display-panel.yaml
      name: select-display-panel
      repository:
        metadata:
          format: Lava-Test Test Definition 1.0
          name: select-display-panel
          description: select-display-panel
        run:
          steps:
          - lava-test-case "select-display-panel-1" --shell fastboot oem select-display-panel
            hdmi
          - lava-test-case "reboot-bootloader-1" --shell fastboot reboot bootloader
          - lava-test-case "select-display-panel-2" --shell fastboot oem select-display-panel
            hdmi
          - lava-test-case "reboot-bootloader-2" --shell fastboot reboot bootloader
          - lava-test-case "select-display-panel-3" --shell fastboot oem select-display-panel
            hdmi
          - lava-test-case "reboot" --shell fastboot reboot
- boot:
    docker:
      image: linaro/lava-android-test:latest
    prompts:
    - console:/
    - root@(.*):[/~]#
    timeout:
      minutes: 15
    method: fastboot
- test:
    timeout:
      minutes: 5
    interactive:
    - name: sleep-before-adb-available
      prompts:
      - console:/
      - root@(.*):[/~]#
      script:
      - command: echo ===========================
      - command: while ! getprop sys.boot_completed|grep 1; do echo sleep 10s for
          sys.boot_completed; sleep 10; done
      - command: echo ===========================
      - command: while ! getprop init.svc.adbd|grep running; do echo sleep 10s for
          init.svc.adbd; sleep 10; done
      - command: echo ===========================
      - command: getprop | grep adb
      - command: echo ===========================
- test:
    docker:
      image: linaro/lava-android-test:latest
    timeout:
      minutes: 10
    definitions:
    - from: inline
      path: android-boot.yaml
      name: android-boot
      repository:
        metadata:
          format: Lava-Test Test Definition 1.0
          name: android-boot
          description: android-boot
        run:
          steps:
          - lava-test-case "android-boot-wait-for-device" --shell adb wait-for-device
          - lava-test-case "android-boot-boot-completed" --shell "while ! adb shell
            getprop sys.boot_completed|grep 1; do sleep 2; done"
          - lava-test-case "android-boot-set-power-stayon" --shell adb shell su 0
            svc power stayon true
          - lava-test-case "android-boot-screencap" --shell adb shell screencap -p
            /data/local/tmp/screencap.png
- test:
    docker:
      image: linaro/lava-android-test:latest
    timeout:
      minutes: 30
    definitions:
    - repository: https://github.com/Linaro/test-definitions.git
      from: git
      path: automated/android/boottime/boottime.yaml
      name: boot-test