User Tools

Site Tools


coccicheck

This is an old revision of the document!


Go back –> Main Linux bot tests page

coccicheck

'coccicheck' is one of the targets of the Linux kernel, this page documents how you can use it, what it provides and how to help extend it. 'coccicheck' provides a series of semantic patches written in Semantic Patch Language (SmPL) and make use of the Coccinelle engine to interpret and complete these tests. These tests can help you vet for correctness and avoid certain bugs which have been able to be expressed semantically.

If you're a developer you are encouraged to vet for your patch using cocciecheck to ensure you are not introducing issues which are known semantically. If you're a maintainer you are encouraged to be using coccicheck with M=your/maintained-code-path so you can make use of the learned SmPL patches to avoid bugs in your maintained code. How maintainers can use this is explained below. Automatic code bot setups which test patches for inlusion upstream are encouraged to consider using 'make coccicheck' as well.

SmPL patches exist for a few different types of categories, documented below.

Confidence

Eeach SmPL patch has a 'confidence' tag associated with it, to help highlight how confident the devlelopers of the SmPL patch are that the reports / fixes generated by the SmPL patch will be accurate or relevant. If an SmPL patch has a 'High' confidence annotated on it, it means that if you use coccicheck with it and it generates a report for a file there is a high degree of confidence that the report should be valid. Likewise if the confidence annotated is 'Low' you should take good care to review the report/patch generated and vet for the validity of it before sending it to maintainers.

Modes

There are three 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

You specify the mode want to operate

Run tests

By default all SmPL files will be used to run tests using the 'report' mode. To run all tests you can run:

make coccicheck MODE=report

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.

make coccicheck MODE=report M=drivers/net/

Run specific tests

To only run a specific cocci test or a set of tests set the COCCI environment variable with the list of tests you want to run. For instance to only run the scripts/coccinelle/locks/double_lock.cocci you would use:

export COCCI=scripts/coccinelle/locks/double_lock.cocci
make coccicheck MODE=report

Types of tests

Below we document each type of test category which as been devised.

api

Help vet for correctness when using certain APIs. The following tests exist:

alloc_cast.cocci

scripts/coccinelle/api/alloc/alloc_cast.cocci

Remove casting the values returned by memory allocation functions like kmalloc, kzalloc, kmem_cache_alloc, kmem_cache_zalloc etc. This makes an effort to find cases of casting of values returned by kmalloc, kzalloc, kcalloc, kmem_cache_alloc, kmem_cache_zalloc, kmem_cache_alloc_node, kmalloc_node and kzalloc_node and removes the casting as it is not required. The result in the patch case may need some reformatting.

kzalloc-simple.cocci

scripts/coccinelle/api/alloc/kzalloc-simple.cocci

Use kzalloc rather than kmalloc followed by memset with 0. This considers some simple cases that are common and easy to validate. Note in particular that there are no …s in the rule, so all of the matched code has to be contiguous.

free

Avoid freeing bugs

iterator

Help vet for correctness when using kernel iterators

locks

Vet for correct locking behaviour and avoid bugs

misc

Things not covered in any of the other categories.

null

Avoid null bugs

tests

Certain tests which are known to help with consistent kernel use.

Who runs these tests

Linux kernel maintainers are encouraged to make use of the cocciecheck to vet for issues on their tree. This can be used to help review quality of patches before they get merged into your tree as well.

These days coccicheck is run every now and then by Julia Lawall, false possitives are reviewed (in particular cocci files where confidence is annotated as low), and then once issues are confirmed patches typically are sent to maintainers.

Average developers can and should use coccicheck as well but care should be taken to ensure the 'Confidence' tag is reviewed and proper dilligence is done before sending any reports / fixes to kernel maintainers.

It seems the zero day bot test infrastructure also makes use of 'make coccicheck' — this section needs to be extended to document in what capacity this is done, how often, etc.

How often are these tests run

The point of merging these SmPL patches upstream was to enable develoeprs and maintainers vet for code themselves. Ideally developers would run 'make coccicheck M=path/to-their-code/' prior to submitting a patch upstream, and maintainers would use it regularly, perhaps after applying new patches, to avoid introducing new issues.

Time permitting Julia will also run these tests on her own when possible as linux-next moves on. There is no specific regular interval in which these tests are run. The zero day bot tests infrasctructure also seems to use 'make coccicheck' – but this section should be extended to document this.

coccicheck.1445521570.txt.gz · Last modified: 2015/10/22 13:46 by Luis R. Rodriguez