Name Date Size #Lines LOC

..--

android/H25-Apr-2025-766412

common/H25-Apr-2025-370210

cros_pkg/H25-Apr-2025-927591

full_bisect_test/H25-Apr-2025-864556

ndk/H25-Apr-2025-419199

sysroot_wrapper/H25-Apr-2025-633359

test/H25-Apr-2025-1,356943

.gitignoreH A D25-Apr-202599 86

MAINTENANCEH A D25-Apr-20255.9 KiB12398

README.bisect.mdH A D25-Apr-20258.7 KiB252189

README.pass_bisect.mdH A D25-Apr-20252.6 KiB8462

README.testing.mdH A D25-Apr-20252.3 KiB9569

__init__.pyH A D25-Apr-2025166 50

binary_search_perforce.pyH A D25-Apr-202518.6 KiB578474

binary_search_state.pyH A D25-Apr-202536.3 KiB1,021813

bisect_driver.pyH A D25-Apr-202514.4 KiB432302

common.pyH A D25-Apr-20259.2 KiB324258

compiler_wrapper.pyH A D25-Apr-20252.1 KiB6939

pass_mapping.pyH A D25-Apr-20251.1 KiB2713

run_bisect.pyH A D25-Apr-202514.8 KiB473393

run_bisect_tests.pyH A D25-Apr-20255.5 KiB199143

README.bisect.md

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

README.pass_bisect.md

1# Pass bisection
2
3This document describes a feature for the bisection tool, which provides
4pass and transformation level bisection for a bad object file.
5
6Before reading this document, please refer to README.bisect for general usage
7of the bisection tool.
8
9The benefit of using pass level bisection is:
10When building a bad object file, it can tell you which pass and transformation
11in the compiler caused the error.
12
13*Notice:* This tool will only work for LLVM/clang, since it is using options
14`-opt-bisect-limit` and `print-debug-counter` that only exist in LLVM.
15
16## Arguments
17
18All the required arguments in object-file-level bisection tool are still
19to be provided. In addition, you will need to add the following arguments:
20
211. `--pass_bisect`: enables pass level bisection
222. `--ir_diff`: enables output of IR differences
23
24Please refer to `--help` or the examples below for details about how to use
25them.
26
27## HOW TO USE: ChromeOS
28
29*TODO* - Future work: Currently this only works for Android.
30
31## HOW TO USE: Android
32
331.  Prerequisites: A general setup is still needed for Android, which means that
34    you need to populate good and bad set of objects with two versions of
35    compilers.
36
37    See the documentation in `README.bisect.md` for more detailed instructions.
38
391.  Pass/Transformation Bisection: If you do not wish to override the other
40    arguments, this command should be sufficient to do pass/transformation level
41    bisection:
42
43    ```
44    ./run_bisect.py android PATH_TO_ANDROID_HOME_DIR
45                --pass_bisect=’android/generate_cmd.sh46                --prune=False
47                --ir_diff
48                --verbose
49    ```
50
51    Where:
52
53    ```
54    --pass_bisect:
55        Enables pass/transformation level bisection and with default
56        script to generate the command as ‘android/generate_cmd.sh’.
57    --prune:
58        For now, prune must be set to False to return only the first
59        bad item.
60    --ir_diff:
61        Optional argument to print out IR differences.
62    --verbose:
63        To show IR diff, verbose needs to be on.
64    ```
65
66    Other default arguments:
67
68    ```
69    --get_initial_items='android/get_initial_items.sh'
70    --switch_to_good='android/switch_to_good.sh'
71    --switch_to_bad='android/switch_to_bad.sh'
72    --test_setup_script='android/test_setup.sh'
73    --test_script='android/interactive_test.sh'
74    --incremental
75    --prune
76    --file_args
77    ```
78
79    You can always override them if needed. See README.bisect for more
80    details.
81
821.  Other features: Features such as resuming, number of jobs, and device id
83    remain the same as before. See README.bisect for more details.
84

README.testing.md

1# Testing the binary search tool
2
3This file explains how to set up and run the various kinds of bisection tests.
4
5The bisection tool comes with several sets of tests which you should
6run after updating any of the bisection tool scripts OR after updating
7the Android compiler wrapper (to make sure the wrapper will still work
8correctly with bisection).
9
10## Before you start.
11
12Before you can run the tests, your PYTHONPATH environment variable
13must be correct.  This means that it must include both the
14toolchain-utils directory and the `binary_search_tool` directory.  The
15easiest way to set it is:
16
17```
18$ cd toolchain-utils
19$ export PYTHONPATH=`pwd`:${PYTHONPATH}
20$ cd binary_search_tool
21$ export PYTHONPATH=`pwd`:${PYTHONPATH}
22```
23
24
25## Running the unittests.
26
27To run the basic unit tests:
28
29```
30$ cd toolchain-utils/binary_search_tool/test
31$ ./binary_search_tool_test.py
32```
33
34# Running the bisection tests, testing the compiler wrapper.
35
36If you want to run the bisection tests, and test the compiler wrapper
37(to make sure the `POPULATE_GOOD` and `POPULATE_BAD` stages are still
38working properly) you can do the following.
39
40If you are testing with the ANDROID COMPILER WRAPPER, you need to to some
41preliminary setup:
42
43Set up the compiler wrapper to replace GCC:
44
45```
46$ cd <android-root/prebuilts/clang/host/linux-x86/clang-368880/bin
47$ cp clang gcc
48$ whereis gcc
49gcc: /usr/bin/gcc /usr/lib/gcc /usr/bin/X11/gcc /usr/share/man/man1/gcc.1.gz
50$ cd /usr/bin
51$ ls -l gcc
52lrwxrwxrwx 1 root root 7 Feb  3 17:00 gcc -> gcc-4.8*
53$ sudo mv gcc gcc.real
54$ sudo ln -s \
55    <android-root>/prebuilts/clang/host/linux-x86/clang-3688880/bin/gcc gcc
56```
57
58Move to the correct directory, then run the test script:
59
60```
61$ cd toolchain-utils/binary_search_tool
62$ ./run_bisect_tests.py
63```
64
65If you are testing with the CHROMEOS COMPILER WRAPPER, you MUST run the
66tests from INSIDE your CHROOT (but you don't need to do any special setup):
67
68```
69$ cd <path-to-chromeos-root>
70$ cros_sdk
71$ cd ~/trunk/src/third_party/toolchain-utils
72```
73
74Set up your `PYTHONPATH`:
75
76```
77$ export PYTHONPATH=`pwd`:${PYTHONPATH}
78$ cd binary_search_tool
79$ export PYTHONPATH=`pwd`:${PYTHONPATH}
80```
81
82Run the test script:
83
84```
85$ ./run_bisect_tests.py
86```
87
88
89## Running the bisection tests, without testing the compiler wrapper.
90
91```
92$ cd toolchain-utils/binary_search_tool
93$ ./full_bisect_test/run-test-nowrapper.sh
94```
95