1- kernel_patch_verify
2- ===================
1+ ` kernel_patch_verify `
2+ =====================
33
44Linux kernel patch static verification helper tool
55
66[ ![ Kernel Patch Verify Intro video] ( https://img.youtube.com/vi/HzW4DrDj32w/0.jpg )] ( https://www.youtube.com/watch?v=HzW4DrDj32w " Kernel Patch Verify Intro video ")
77
88Background and Motivation:
9- =========================
9+ ==========================
1010
1111This script came about as a result of various beatings I recieved and saw others
12- recieve in upstream kernel discussions over the last several years.
13- Did you run ' checkpatch.pl --strict' , did you run sparse, is your patch series
14- bisectable, or the newer ones - coccinelle, smatch. I mean, why debug or even
15- catch these in mailing lists, if you can programmatically try to catch them up
16- at developer's end?
12+ recieve in upstream kernel discussions over the last several years. Did you run
13+ ` checkpatch.pl --strict ` , did you run ` sparse ` , is your patch series bisectable,
14+ or the newer ones - ` coccinelle ` and ` smatch ` . I mean, why debug or even catch
15+ these in mailing lists, if you can programmatically try to catch them up at
16+ developer's end?
1717
1818Many of these were due to:
1919+ Too many tools constantly evolving in linux kernel - too many goodies, and
@@ -25,28 +25,29 @@ and almost everyone would like to have something quick and handy.. and if
2525possible, automated..
2626
2727As a result, while working on "evil vendor" Android kernel as a domain
28- maintainer, I had originally written a dumb application called Kmake
29- ( http://www.omappedia.com/wiki/Kmake ). This was my first attempt at automating
30- this entire process.. and was pretty crap code and was meant for me to test 1
31- single patch and was born out of pure desperation getting a hell lot of crap
28+ maintainer, I had originally written a dumb application called Kmake (unrelated
29+ to the current meta build systems ). This was my first attempt at automating this
30+ entire process... and was pretty crap code and was meant for me to test 1 single
31+ patch. It was born out of pure desperation from getting a hell lot of crap
3232patches from too many internal developers.
3333
3434As I shared around this original code over the years, I got feedback from
3535various folks on varied angles:
3636- Dan Murphy: why cant it report required applications for it to run?
3737- Tero Kristo: rewrote the entire script and got me thinking along the lines of a
3838'patch set that needs to be applied'
39- - And, others who suggested tiny little things..
39+ - And, others who suggested tiny little things...
4040
4141It was obvious, this original script needed a respin and update to newer kernel
4242world. So, here is another attempt with enough error handling that I could
43- reasonably think of in the few hours I spend rewriting.. And I do not think it
44- is good enough yet.. there are few things I dropped - storing dtbs+zImage per
43+ reasonably think of in the few hours I spend rewriting... And I do not think it
44+ is good enough yet... there are few things I dropped - storing dtbs+zImage per
4545patch to to allow for seperate verification by boot per patch and similar tiny
46- little thingies.. Maybe later.. I guess..
46+ little thingies... Maybe later... I guess. ..
4747
4848CONTRIBUTIONS:
49- =============
49+ ==============
50+
5051Just lets keep this on github and send pull requests to merge things up? As a
5152script developer, we all know that various developers have widely varying tastes.
5253if you feel an bug fixed or other improvements to share, send me a pull request
@@ -58,29 +59,32 @@ bash.
5859
5960INSTALL NOTES:
6061==============
62+
6163Almost nothing - I hope you are already using bash and building kernel -
6264The script should crib and provide recommendations for missing packages (or is
63- supposed to ;) )..
65+ supposed to ;) )
6466
65- For -C ' complete tests' , the following are needed:
67+ For ` -C ` or " complete tests" , the following are needed:
6668- smatch: (sudo apt-get install sqlite3 libsqlite3-dev llvm)
6769
68- http ://linuxplumbersconf.com /2011/ocw/ /system/presentations/165/original/transcript.txt
70+ https ://blog. linuxplumbersconf.org /2011/ocw/system/presentations/165/original/transcript.txt
6971
70- http ://smatch.sf .net
72+ https ://smatch.sourceforge .net/
7173
72- NOTE for older ubuntu installs, use: https://launchpad.net/ubuntu/+source/coccinelle
74+ NOTE for older Ubuntu installs, use: https://launchpad.net/ubuntu/+source/coccinelle
7375
7476- spatch: is provided by the coccinelle package in ubuntu
7577
76- :warning : ** If your changes include dtb changes, then please optimize your .config, since dtbscheck will take significant time!**
78+ :warning : ** If your changes include dtb changes, then please optimize your
79+ ` .config ` , since dtbscheck will take significant time!**
7780
7881```
79- for i in `cat arch/arm64/Kconfig.platforms |grep ARCH| grep "^config"|grep -v K3|cut -d ' ' -f2`; do echo "CONFIG_"$i"=n">> .config; done
82+ sed -n 's/^config \(ARCH.*\)/CONFIG_\1=n/p' arch/arm64/Kconfig.platforms | grep -v K3 >> .config
8083```
8184
8285Usage:
83- =====
86+ ======
87+
8488```
8589./kernel_patch_verify [-d] [-j CPUs] [-B build_target] [-T tmp_dir_base] [-l logfile] [-C] [-c defconfig_name] [-1]|[-p patch_dir]|[-b base_branch [-t head_branch]]
8690 -d: if not already defined, use CROSS_COMPILE=arm-linux-gnueabi-, ARCH=arm, and builds for ' zImage dtbs' build targets
@@ -99,97 +103,103 @@ Usage:
99103
100104NOTE:
101105* Only one of -1, -p or (-b,-t) should be used - but at least one of these should be used
102- * Cannot have a diff pending OR be on a dangling branch base_branch should exist as well
103- * The default tests are selected with view of as minimal time as possible, while the '-C' tests
106+ * Cannot have a diff pending OR be on a dangling branch ` base_branch ` should exist as well
107+ * The default tests are selected with view of as minimal time as possible, while the ` -C ` tests
104108are the comprehensive tests which are strongly recommended before showing your patches to any other
105109human being.
106110
107111Example usages:
108112===============
109113
110- * Verify last commmitted patch
114+ * Verify last commmitted patch:
111115
112- ```
113- ./kernel_patch_verify -1
114- ```
115- * Verify on top of current branch patches from location ~ /tmp/test-patches
116+ ```
117+ ./kernel_patch_verify -1
118+ ```
116119
117- ```
118- ./kernel_patch_verify -p ~/tmp/test-patches
119- ```
120- * Verify * from* branch 'base_branch' till current branch
120+ * Verify on top of current branch patches from location `~/tmp/test-patches`:
121121
122- ```
123- ./kernel_patch_verify -b base_branch
124- ```
125- * Verify from current branch, all patches * until* 'test_branch'
122+ ```
123+ ./kernel_patch_verify -p ~/tmp/test-patches
124+ ```
126125
127- ```
128- ./kernel_patch_verify -t test_branch
129- ```
130- * Verify, all patches from 'base_branch' until 'test_branch'
126+ * Verify *from* branch `base_branch` till current branch:
131127
132- ```
133- ./kernel_patch_verify -b base_branch -t test_branch
134- ```
135- * Verify with complete tests, all patches from 'base_branch' until 'test_branch'
128+ ```
129+ ./kernel_patch_verify -b base_branch
130+ ```
136131
137- ```
138- ./kernel_patch_verify -b base_branch -t test_branch -C
139- ```
132+ * Verify all patches *from* current branch *until* `test_branch`:
140133
141- * Verify last committed patch on a native x86 build using make, gcc and bzImage
134+ ```
135+ ./kernel_patch_verify -t test_branch
136+ ```
142137
143- ```
144- ./kernel_patch_verify -B bzImage -1
145- ```
138+ * Verify all patches *from* `base_branch` *until* `test_branch`:
146139
147- * Verify last committed patch on a cross_compiled ARM build using defaults
140+ ```
141+ ./kernel_patch_verify -b base_branch -t test_branch
142+ ```
148143
149- ```
150- ./kernel_patch_verify -d -1
151- ```
144+ * Verify, with complete tests, all patches *from* `base_branch` *until*
145+ `test_branch`:
146+
147+ ```
148+ ./kernel_patch_verify -b base_branch -t test_branch -C
149+ ```
150+
151+ * Verify last committed patch on a native x86 build using `make`, `gcc`, and the
152+ `bzImage` target:
153+
154+ ```
155+ ./kernel_patch_verify -B bzImage -1
156+ ```
157+
158+ * Verify last committed patch on a cross-compiled ARM build using defaults:
159+
160+ ```
161+ ./kernel_patch_verify -d -1
162+ ```
152163
153164Some script design stuff:
154- ========================
155- Alright, the shell script should be readable in it's own I hope.. anyways,
165+ =========================
166+
167+ Alright, the shell script should be readable in it's own I hope... anyways,
156168tests are organized as:
157- * ptest_xyz -> these tests take the patch as the argument
158- * ftest_xyz -> these tests take c file (impacted by the patch) as the argument
159- * btest_xyz -> there are of two types: the ones that take .o files as arguments
169+ * ` ptest_xyz` -> these tests take the patch as the argument
170+ * ` ftest_xyz` -> these tests take c file (impacted by the patch) as the argument
171+ * ` btest_xyz` -> there are of two types: the ones that take .o files as arguments
160172and those that build the entire kernel
161173
162174Tests are organized per patch OR overall (basically run before the patch series
163175and after the patch series). Reports are generated after all the tests are run,
164176I have not tried to standardize the reports in any way, except that if there is
165177a 'change' in log, for example:
166- * build warning was created with a patch.
167- * build warning was removed with a patch in the series.
178+ * A build warning was created with a patch.
179+ * A build warning was removed with a patch in the series.
168180
169181This will appear as a a diff (both build warning was removed or added is
170182considered similar) and that diff is provided in the report log. the final report
171183log is a consolidation of every single patch, over all results and also provides
172184information about the tools and versions used.
173185
174- '-C' tests are reserved for ones that take time. I would like to encourage
175- developers to constantly use the test script to keep their code clean,
176- so without the '-C', it tries to run tests that take a short amount of time.
177- For patches that take significant time, I'd list them under '-C'. I recommend
178- reading the code to see the list of tests executed - This will also be printed
179- as you execute the tests. just remember that false positives are irritable to
186+ Without the `-C` switch, only tests that take a short amount of time will be
187+ ran. Tests that take significant time should be listed under `-C`. I recommend
188+ reading the code to see the list of tests executed. This will also be printed as
189+ you execute the tests. Just remember that false positives are irritable to
180190developers, so be careful of the results.
181191
182192The generic strategy for the test is that everything in stderr is logged, a test
183193should never throw anything on stdout as it just craps up the developer's screen.
184194If a test provides result on stdout, redirect it to stderr. Pass/fail criteria is
185195as follows:
186- * for ftest_ , btest_ , the before and after logs should show 0 diff. if there are
187- it assumes new fail introduction
188- * for ptest, no output is a pass, any output tends to be a fail.
196+ * For ` ftest_`, ` btest_` , the before and after logs should show 0 diff. If there
197+ are, it assumes new fail introduction
198+ * For ` ptest` , no output is a pass, any output tends to be a fail.
189199
190200
191201Author and versioning highlights (chronological):
192- --------------------------------
202+ -------------------------------------------------
193203* Nishanth Menon Dec 2013, Dallas, TX, while lying in bed with a slight migraine
194- staring at a cloudy sky and spewing nonsense into vim.. and guessing that no one
195- might even care about this..
204+ staring at a cloudy sky and spewing nonsense into vim... and guessing that no one
205+ might even care about this...
0 commit comments