This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Next revision Both sides next revision | ||
coccicheck [2015/10/22 13:46] Luis R. Rodriguez |
coccicheck [2016/06/22 00:04] Luis R. Rodriguez |
||
---|---|---|---|
Line 15: | Line 15: | ||
==== Modes ==== | ==== Modes ==== | ||
- | There are three different modes you can use to use the semantic patches: | + | There are four different modes you can use to use the semantic patches: |
- | * report - lets you generate a report - this is the '''default''' mode if one is not specified | ||
- | * org - xxx | ||
* patch - lets you fix the issues found | * patch - lets you fix the issues found | ||
+ | * report - lets you generate a report - this is the '''default''' mode if one is not specified | ||
+ | * context - highlights lines of interest and their context in a diff-like style.Lines of interest are indicated with '-'. | ||
+ | * org - generates a report in the Org mode format of Emacs | ||
- | You specify the mode want to operate | + | You specify the mode want to operate. Note that not all semantic patches implement all modes. For easy use |
+ | of Coccinelle, the default mode is "report". | ||
+ | |||
+ | Two other modes provide some common combinations of these modes. | ||
+ | |||
+ | * chain - tries the previous modes in the order above until one succeeds. | ||
+ | * rep+ctxt - runs successively the report mode and the context mode. It should be used with the C option (described later) which checks the code on a file basis. | ||
==== Run tests ==== | ==== Run tests ==== | ||
Line 30: | Line 37: | ||
make coccicheck MODE=report | make coccicheck MODE=report | ||
</code> | </code> | ||
+ | |||
+ | To produce patches for the entire kernel, run: | ||
+ | |||
+ | <code bash> | ||
+ | make coccicheck MODE=patch | ||
+ | </code> | ||
+ | |||
+ | For each semantic patch, a commit message is proposed. It gives a description of the problem being checked by the semantic patch, and includes a reference to Coccinelle. | ||
+ | |||
+ | As any static code analyzer, Coccinelle produces false positives. Thus, reports must be carefully checked, and patches reviewed. | ||
+ | |||
+ | ==== Maintainer work ==== | ||
If you are a maintainer you may want to use M=your/maintained-path/ to limit the scope to only the files you maintain. For instance the following will generate a report for all files in drivers/net/ only. | If you are a maintainer you may want to use M=your/maintained-path/ to limit the scope to only the files you maintain. For instance the following will generate a report for all files in drivers/net/ only. | ||
Line 42: | Line 61: | ||
<code bash> | <code bash> | ||
- | export COCCI=scripts/coccinelle/locks/double_lock.cocci | + | make coccicheck COCCI=scripts/coccinelle/locks/double_lock.cocci MODE=report |
- | make coccicheck MODE=report | + | |
</code> | </code> | ||
- | ===== Types of tests ==== | + | or |
+ | |||
+ | <code bash> | ||
+ | make coccicheck COCCI=scripts/coccinelle/locks/double_lock.cocci MODE=patch | ||
+ | </code> | ||
+ | |||
+ | ===== Controlling Which Files are Processed by Coccinelle ===== | ||
+ | |||
+ | By default the entire kernel source tree is checked. To apply Coccinelle to a specific directory, M= can be used. For example, to check drivers/net/wireless/ one may write: | ||
+ | |||
+ | <code bash> | ||
+ | make coccicheck MODE=report M=drivers/net/wireless/ | ||
+ | </code> | ||
+ | |||
+ | To apply Coccinelle on a file basis, instead of a directory basis, the following command may be used: | ||
+ | |||
+ | <code bash> | ||
+ | make C=1 CHECK="scripts/coccicheck" | ||
+ | </code> | ||
+ | |||
+ | To check only newly edited code, use the value 2 for the C flag, i.e. | ||
+ | |||
+ | <code bash> | ||
+ | make C=2 CHECK="scripts/coccicheck" | ||
+ | </code> | ||
+ | |||
+ | In these modes, which works on a file basis, there is no information about semantic patches displayed, and no commit message proposed. | ||
+ | |||
+ | This runs every semantic patch in scripts/coccinelle by default. The COCCI variable may additionally be used to only apply a single semantic patch as shown in the previous section. | ||
+ | |||
+ | The "report" mode is the default. You can select another one with the MODE variable explained above. | ||
+ | |||
+ | ===== Additional flags ===== | ||
+ | |||
+ | Additional flags can be passed to spatch through the SPFLAGS variable. | ||
+ | |||
+ | <code bash> | ||
+ | make SPFLAGS=--use-idutils coccicheck | ||
+ | </code> | ||
+ | |||
+ | See spatch --help to learn more about spatch options. | ||
+ | |||
+ | ===== Proposing new semantic patches ====== | ||
+ | |||
+ | New semantic patches can be proposed and submitted by kernel developers. For sake of clarity, they should be organized in the sub-directories of 'scripts/coccinelle/'. | ||
+ | |||
+ | ===== Types of tests ===== | ||
Below we document each type of test category which as been devised. | Below we document each type of test category which as been devised. |