File: bisect.sh

package info (click to toggle)
cppcheck 2.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,132 kB
  • sloc: cpp: 268,935; python: 20,890; ansic: 8,090; sh: 1,045; makefile: 1,008; xml: 1,005; cs: 291
file content (99 lines) | stat: -rw-r--r-- 2,444 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh

# TODO: set -e
set -x

# TODO: check parameters
hash_good=$1
hash_bad=$2
options=$3
expected=$4

# TODO: verify "good" commit happened before "bad" commit

# 0 - regular result based bisect
# 1 - find commit which started hang
# 2 - find commit which resolved hang
hang=0

script_dir="$(dirname "$(realpath "$0")")"

# TODO: make configurable
bisect_dir=~/.bisect

mkdir -p "$bisect_dir" || exit 1

cd "$bisect_dir" || exit 1

if [ ! -d 'cppcheck' ]; then
  git clone https://github.com/danmar/cppcheck.git || exit 1
fi

bisect_repo_dir="$bisect_dir/cppcheck"

cd $bisect_repo_dir || exit 1

git fetch --all --tags || exit 1

# clean up in case we previously exited prematurely
git restore . || exit 1
git clean -df || exit 1

# reset potentially unfinished bisect - also reverts to 'main' branch
git bisect reset || exit 1

# update `main` branch
git pull || exit 1

# TODO: filter addons, cfg and platforms based on the options
# limit to paths which actually affect the analysis
git bisect start -- Makefile 'addons/*.py' 'cfg/*.cfg' 'cli/*.cpp' 'cli/*.h' 'externals/**/*.cpp' 'externals/**/*.h' 'lib/*.cpp' 'lib/*.h' platforms tools/matchcompiler.py || exit 1

git checkout "$hash_good" || exit 1

if [ $hang -ne 0 ]; then
  # TODO: exitcode overflow on 255
  # get expected time from good commit
  python3 "$script_dir/bisect_hang.py" "$bisect_dir" "$options"
  elapsed_time=$?
else
  # verify the given commit is actually "good"
  python3 "$script_dir/bisect_res.py" "$bisect_dir" "$options" "$expected"
  # shellcheck disable=SC2181
  if [ $? -ne 0 ]; then
    echo "given good commit is not actually good"
    exit 1
  fi
fi

# mark commit as "good"
git bisect good || exit 1

git checkout "$hash_bad" || exit 1

# verify the given commit is actually "bad"
if [ $hang -ne 0 ]; then
  python3 "$script_dir/bisect_hang.py" "$bisect_dir" "$options" $elapsed_time $hang
else
  python3 "$script_dir/bisect_res.py" "$bisect_dir" "$options" "$expected"
fi

if [ $? -ne 1 ]; then
  echo "given bad commit is not actually bad"
  exit 1
fi

# mark commit as "bad"
git bisect bad || exit 1

# perform the actual bisect
if [ $hang -ne 0 ]; then
  git bisect run python3 "$script_dir/bisect_hang.py" "$bisect_dir" "$options" $elapsed_time $hang || exit 1
else
  git bisect run python3 "$script_dir/bisect_res.py" "$bisect_dir" "$options" "$expected" || exit 1
fi

# show the bisect log
git bisect log || exit 1

git bisect reset || exit 1