1*760c253cSXin Li# `run_bisect.py` 2*760c253cSXin Li 3*760c253cSXin Li`run_bisect.py` is a wrapper around the general purpose 4*760c253cSXin Li`binary_search_state.py`. It provides a user friendly interface for 5*760c253cSXin Libisecting various compilation errors. The 2 currently provided 6*760c253cSXin Limethods of bisecting are ChromeOS package and object bisection. Each 7*760c253cSXin Limethod defines a default set of options to pass to 8*760c253cSXin Li`binary_search_state.py` and allow the user to override these defaults 9*760c253cSXin Li(see the "Overriding" section). 10*760c253cSXin Li 11*760c253cSXin LiPlease note that all commands, examples, scripts, etc. are to be run from your 12*760c253cSXin Lichroot unless stated otherwise. 13*760c253cSXin Li 14*760c253cSXin Li## Bisection Methods 15*760c253cSXin Li 16*760c253cSXin Li### ChromeOS Package 17*760c253cSXin Li 18*760c253cSXin LiThis method will bisect across all packages in a ChromeOS repository and find 19*760c253cSXin Lithe offending packages (according to your test script). This method takes the 20*760c253cSXin Lifollowing arguments: 21*760c253cSXin Li 22*760c253cSXin Li* board: The board to bisect on. For example: daisy, falco, etc. 23*760c253cSXin Li* remote: The IP address of the physical machine you're using to test with. 24*760c253cSXin Li 25*760c253cSXin LiBy default the ChromeOS package method will do a simple interactive test that 26*760c253cSXin Lipings the machine and prompts the user if the machine is good. 27*760c253cSXin Li 28*760c253cSXin Li1. Setup: The ChromeOS package method requires that you have three build trees: 29*760c253cSXin Li 30*760c253cSXin Li ``` 31*760c253cSXin Li /build/${board}.bad - The build tree for your "bad" build 32*760c253cSXin Li /build/${board}.good - The build tree for your "good" build 33*760c253cSXin Li /build/${board}.work - A full copy of /build/${board}.bad 34*760c253cSXin Li ``` 35*760c253cSXin Li 36*760c253cSXin Li1. Cleanup: run_bisect.py does most cleanup for you, the only thing required by 37*760c253cSXin Li the user is to cleanup all built images and the three build trees made in 38*760c253cSXin Li `/build/` 39*760c253cSXin Li 40*760c253cSXin Li1. Default Arguments: 41*760c253cSXin Li 42*760c253cSXin Li ``` 43*760c253cSXin Li --get_initial_items='cros_pkg/get_initial_items.sh' 44*760c253cSXin Li --switch_to_good='cros_pkg/switch_to_good.sh' 45*760c253cSXin Li --switch_to_bad='cros_pkg/switch_to_bad.sh' 46*760c253cSXin Li --test_setup_script='cros_pkg/test_setup.sh' 47*760c253cSXin Li --test_script='cros_pkg/interactive_test.sh' 48*760c253cSXin Li --incremental 49*760c253cSXin Li --prune 50*760c253cSXin Li --file_args 51*760c253cSXin Li ``` 52*760c253cSXin Li 53*760c253cSXin Li1. Additional Documentation: See `./cros_pkg/README.cros_pkg_triage` for full 54*760c253cSXin Li documentation of ChromeOS package bisection. 55*760c253cSXin Li 56*760c253cSXin Li1. Examples: 57*760c253cSXin Li 58*760c253cSXin Li 1. Basic interactive test package bisection, on daisy board: 59*760c253cSXin Li 60*760c253cSXin Li ``` 61*760c253cSXin Li ./run_bisect.py package daisy 172.17.211.184 62*760c253cSXin Li ``` 63*760c253cSXin Li 64*760c253cSXin Li 2. Basic boot test package bisection, on daisy board: 65*760c253cSXin Li 66*760c253cSXin Li ``` 67*760c253cSXin Li ./run_bisect.py package daisy 172.17.211.184 -t cros_pkg/boot_test.sh 68*760c253cSXin Li ``` 69*760c253cSXin Li 70*760c253cSXin Li### ChromeOS Object 71*760c253cSXin Li 72*760c253cSXin LiThis method will bisect across all objects in a ChromeOS package and find 73*760c253cSXin Lithe offending objects (according to your test script). This method takes the 74*760c253cSXin Lifollowing arguments: 75*760c253cSXin Li 76*760c253cSXin Li* board: The board to bisect on. For example: daisy, falco, etc. 77*760c253cSXin Li* remote: The IP address of the physical machine you're using to test with. 78*760c253cSXin Li* package: The package to bisect with. For example: chromeos-chrome. 79*760c253cSXin Li* use_flags: (Optional) Use flags for emerge. For example: "-thinlto -cfi". 80*760c253cSXin Li* noreboot: (Optional) Do not reboot after updating the package. 81*760c253cSXin Li* dir: (Optional) the directory for your good/bad build trees. Defaults to 82*760c253cSXin Li $BISECT_DIR or /tmp/sysroot_bisect. This value will set $BISECT_DIR 83*760c253cSXin Li for all bisecting scripts. 84*760c253cSXin Li 85*760c253cSXin LiBy default the ChromeOS object method will do a simple interactive test that 86*760c253cSXin Lipings the machine and prompts the user if the machine is good. 87*760c253cSXin Li 88*760c253cSXin Li1. Setup: The ChromeOS package method requires that you populate your good and 89*760c253cSXin Li bad set of objects. `sysroot_wrapper` will automatically detect the 90*760c253cSXin Li `BISECT_STAGE` variable and use this to populate emerged objects. Here is an 91*760c253cSXin Li example: 92*760c253cSXin Li 93*760c253cSXin Li ``` 94*760c253cSXin Li # Defaults to /tmp/sysroot_bisect 95*760c253cSXin Li export BISECT_DIR="/path/to/where/you/want/to/store/builds/" 96*760c253cSXin Li 97*760c253cSXin Li export BISECT_STAGE="POPULATE_GOOD" 98*760c253cSXin Li ./switch_to_good_compiler.sh 99*760c253cSXin Li emerge-${board} -C ${package_to_bisect} 100*760c253cSXin Li emerge-${board} ${package_to_bisect} 101*760c253cSXin Li 102*760c253cSXin Li export BISECT_STAGE="POPULATE_BAD" 103*760c253cSXin Li ./switch_to_bad_compiler.sh 104*760c253cSXin Li emerge-${board} -C {package_to_bisect} 105*760c253cSXin Li emerge-${board} ${package_to_bisect} 106*760c253cSXin Li ``` 107*760c253cSXin Li 108*760c253cSXin Li1. Cleanup: The user must clean up all built images and the populated object 109*760c253cSXin Li files. 110*760c253cSXin Li 111*760c253cSXin Li1. Default Arguments: 112*760c253cSXin Li 113*760c253cSXin Li ``` 114*760c253cSXin Li --get_initial_items='sysroot_wrapper/get_initial_items.sh' 115*760c253cSXin Li --switch_to_good='sysroot_wrapper/switch_to_good.sh' 116*760c253cSXin Li --switch_to_bad='sysroot_wrapper/switch_to_bad.sh' 117*760c253cSXin Li --test_setup_script='sysroot_wrapper/test_setup.sh' 118*760c253cSXin Li --test_script='sysroot_wrapper/interactive_test.sh' 119*760c253cSXin Li --noincremental 120*760c253cSXin Li --prune 121*760c253cSXin Li --file_args 122*760c253cSXin Li ``` 123*760c253cSXin Li 124*760c253cSXin Li1. Additional Documentation: See `./sysroot_wrapper/README` for full 125*760c253cSXin Li documentation of ChromeOS object file bisecting. 126*760c253cSXin Li 127*760c253cSXin Li1. Examples: 128*760c253cSXin Li 129*760c253cSXin Li 1. Basic interactive test object bisection, on daisy board for cryptohome 130*760c253cSXin Li package: `./run_bisect.py object daisy 172.17.211.184 cryptohome` 131*760c253cSXin Li 132*760c253cSXin Li 2. Basic boot test package bisection, on daisy board for cryptohome 133*760c253cSXin Li package: `./run_bisect.py object daisy 172.17.211.184 cryptohome 134*760c253cSXin Li --test_script=sysroot_wrapper/boot_test.sh` 135*760c253cSXin Li 136*760c253cSXin Li### Android object 137*760c253cSXin Li 138*760c253cSXin LiNOTE: Because this isn't a ChromeOS bisection tool, the concept of a 139*760c253cSXin Li chroot doesn't exist. Just run this tool from a normal shell. 140*760c253cSXin Li 141*760c253cSXin LiThis method will bisect across all objects in the Android source tree and 142*760c253cSXin Lifind the offending objects (according to your test script). This method takes 143*760c253cSXin Lithe following arguments: 144*760c253cSXin Li 145*760c253cSXin Li* `android_src`: The location of your android source tree 146*760c253cSXin Li 147*760c253cSXin Li* `num_jobs`: (Optional) The number of jobs to pass to make. This is dependent 148*760c253cSXin Li on how many cores your machine has. A good number is probably somewhere 149*760c253cSXin Li around 5 to 10. 150*760c253cSXin Li 151*760c253cSXin Li* `device_id`: (Optional) The serial code for the device you are testing on. 152*760c253cSXin Li This is used to determine which device should be used in case multiple 153*760c253cSXin Li devices are plugged into your computer. You can get serial code for your 154*760c253cSXin Li device by running "adb devices". 155*760c253cSXin Li 156*760c253cSXin Li* `dir`: (Optional) the directory for your good/bad build trees. Defaults to 157*760c253cSXin Li `$BISECT_DIR` or `~/ANDROID_BISECT/`. This value will set `$BISECT_DIR` for 158*760c253cSXin Li all bisecting scripts. 159*760c253cSXin Li 160*760c253cSXin Li By default the Android object method will do a simple interactive test that 161*760c253cSXin Li pings the machine and prompts the user if the machine is good. 162*760c253cSXin Li 163*760c253cSXin Li1. Setup: The Android object method requires that you populate your good and 164*760c253cSXin Li bad set of objects. The Android compiler wrapper will automatically detect 165*760c253cSXin Li the `BISECT_STAGE` variable and use this to populate emerged objects. Here 166*760c253cSXin Li is an example: 167*760c253cSXin Li 168*760c253cSXin Li ``` 169*760c253cSXin Li # Defaults to ~/ANDROID_BISECT/ 170*760c253cSXin Li export BISECT_DIR="/path/to/where/you/want/to/store/builds/" 171*760c253cSXin Li 172*760c253cSXin Li export BISECT_STAGE="POPULATE_GOOD" 173*760c253cSXin Li # Install the "good" compiler 174*760c253cSXin Li ./switch_to_good_compiler.sh 175*760c253cSXin Li make clean 176*760c253cSXin Li make -j <your_preferred_number_of_jobs> 177*760c253cSXin Li 178*760c253cSXin Li export BISECT_STAGE="POPULATE_BAD" 179*760c253cSXin Li # Install the "bad" compiler 180*760c253cSXin Li ./switch_to_bad_compiler.sh 181*760c253cSXin Li make clean 182*760c253cSXin Li make -j <your_preferred_number_of_jobs> 183*760c253cSXin Li ``` 184*760c253cSXin Li 185*760c253cSXin Li1. Cleanup: The user must clean up all built images and the populated object 186*760c253cSXin Li files. 187*760c253cSXin Li 188*760c253cSXin Li1. Default Arguments: 189*760c253cSXin Li 190*760c253cSXin Li ``` 191*760c253cSXin Li --get_initial_items='android/get_initial_items.sh' 192*760c253cSXin Li --switch_to_good='android/switch_to_good.sh' 193*760c253cSXin Li --switch_to_bad='android/switch_to_bad.sh' 194*760c253cSXin Li --test_setup_script='android/test_setup.sh' 195*760c253cSXin Li --test_script='android/interactive_test.sh' 196*760c253cSXin Li --incremental 197*760c253cSXin Li --prune 198*760c253cSXin Li --file_args 199*760c253cSXin Li ``` 200*760c253cSXin Li 201*760c253cSXin Li1. Additional Documentation: See `./android/README.android` for full 202*760c253cSXin Li documentation of Android object file bisecting. 203*760c253cSXin Li 204*760c253cSXin Li1. Examples: 205*760c253cSXin Li 206*760c253cSXin Li 1. Basic interactive test android bisection, where the android source is at 207*760c253cSXin Li ~/android_src: `./run_bisect.py android ~/android_src` 208*760c253cSXin Li 209*760c253cSXin Li 2. Basic boot test android bisection, where the android source is at 210*760c253cSXin Li `~/android_src`, and 10 jobs will be used to build android: 211*760c253cSXin Li `./run_bisect.py 212*760c253cSXin Li android ~/android_src --num_jobs=10 213*760c253cSXin Li --test_script=sysroot_wrapper/boot_test.sh` 214*760c253cSXin Li 215*760c253cSXin Li### Resuming 216*760c253cSXin Li 217*760c253cSXin Li`run_bisect.py` and `binary_search_state.py` offer the 218*760c253cSXin Liability to resume a bisection in case it was interrupted by a 219*760c253cSXin LiSIGINT, power failure, etc. Every time the tool completes a 220*760c253cSXin Libisection iteration its state is saved to disk (usually to the file 221*760c253cSXin Li`./bisect_driver.py.state`). If passed the --resume option, the tool 222*760c253cSXin Liit will automatically detect the state file and resume from the last 223*760c253cSXin Licompleted iteration. 224*760c253cSXin Li 225*760c253cSXin Li### Overriding 226*760c253cSXin Li 227*760c253cSXin LiYou can run `./run_bisect.py --help` or `./binary_search_state.py 228*760c253cSXin Li--help` for a full list of arguments that can be overriden. Here are 229*760c253cSXin Lia couple of examples: 230*760c253cSXin Li 231*760c253cSXin LiExample 1 (do boot test instead of interactive test): 232*760c253cSXin Li 233*760c253cSXin Li``` 234*760c253cSXin Li./run_bisect.py package daisy 172.17.211.182 --test_script=cros_pkg/boot_test.sh 235*760c253cSXin Li``` 236*760c253cSXin Li 237*760c253cSXin LiExample 2 (do package bisector system test instead of interactive test, this 238*760c253cSXin Li is used to test the bisecting tool itself -- see comments in 239*760c253cSXin Li hash_test.sh for more details): 240*760c253cSXin Li 241*760c253cSXin Li``` 242*760c253cSXin Li./run_bisect.py package daisy 172.17.211.182 \ 243*760c253cSXin Li --test_script=common/hash_test.sh --test_setup_script="" 244*760c253cSXin Li``` 245*760c253cSXin Li 246*760c253cSXin LiExample 3 (enable verbose mode, disable pruning, and disable verification): 247*760c253cSXin Li 248*760c253cSXin Li``` 249*760c253cSXin Li./run_bisect.py package daisy 172.17.211.182 250*760c253cSXin Li --verbose --prune=False --verify=False 251*760c253cSXin Li``` 252