Commit Graph

147 Commits

Author SHA1 Message Date
versat dc1cdd2b76 addons/test/test-*.py: Improve documentation about running the tests 2019-09-20 13:39:38 +02:00
Richard A. Smith 2b44fb57bc Loosen restrictions on MISRA rules text structure (#2157)
Version 1.88 changed the parsing of the MISRA rules file adding a
severity setting.  This caused a regression in rule parsing.

In particular the following format used to parse cleanly and produce
rule output that would show the severity as part of the rule text.

    Rule 1.2

    Advisory

    Rule text goes here.

    Rule 1.3

    Required

    More rule text goes here.

As of 1.88 a file structured like above would parse as having no rules.

The problem is the use of blank lines as a rule delimiter.   The
modified rule parser wants to see a rules formatted like below:

    Rule 3.1 Required
    R3.1 text.
    Rule 4.1 Required
    R4.1 text.

or:

    Rule 1.1
    Add this rule and parse to next, skipping empty lines.

    Rule 1.2
    Rule text.

Any rule text that did not fall into one of the above formats would
result in incomplete rule text parsing.

Change the parsing of the rule text file so that blank lines are ignored
instead of treating them as a delimiter between rules. Instead use the
start of the next rule as a delimiter for the end of the previous rule.
This allows both of the newer formats but also supports the behavior of
pre-1.88 versions.

Change units tests that were specifically forbidding the use of blank
lines to ones that allow blank lines.
2019-09-09 21:43:44 +02:00
Conrado Gouvea 3740c57160 misra: fix rule 5.4 false positive when macro is defined 'twice' inside #if/#else (#2125) 2019-08-31 07:53:16 +02:00
Daniel Marjamäki 2e9e3ed2f1 Fixed #8823 (false positive: MISRA rule 16.3) 2019-08-11 19:08:57 +02:00
Daniel Marjamäki 016340f77d Fixed #8657 (false postive: MISRA rule 15.7) 2019-08-11 17:54:02 +02:00
Daniel Marjamäki 43aabcd318 Fixed #8656 (false positive: MISRA rule 10.1) 2019-08-11 09:47:37 +02:00
Daniel Marjamäki 996000da52 Fixed #9208 (MISRA addon crashes on enum with constant expression) 2019-08-04 12:24:45 +02:00
Georgy Komarov fe2885e430 cert.py: Refactor arguments handling (#2044)
* cert.py: Add '--quiet' option and test

Main sentinel also was required.

* travis.yml: Install pytest with --user

To avoid possible conflicts with system packages later.

* Quickfix
2019-07-26 15:40:25 +02:00
Georgy Komarov fbd7b5180b Update addons structure. Make Y2038 addon works. (#2024)
* Update addons structure. Make Y2038 addon works.

All addons are now located in same directory, where cppcheck-gui is
looking for them.

Y2038 addon has been updated to latest cppcheck version. Output is same
as 303622f01c commit as it described in
README: 303622f01c/addons/y2038/README.

* Clean up .travis.yml

* Update travis.yml paths.

* misra.py: Bring back -P argument for backward compatibility

* Fix paths

* Normalize dumpfile paths tpo cppcheck format

* Fixup 3 test.

* Add arguments regression test.

* Fixing travis build
2019-07-26 06:38:03 +02:00
fuzzelhjb cc63728d6a add support for CERT-API01-C check (#1980)
* add support for CERT-API01-C check

* remove extra ident and simplify check
2019-07-24 10:39:31 +02:00
Georgy Komarov 6bd1c92c24 misra.py: Bring back -P argument for backward compatibility (#2030)
* misra.py: Bring back -P argument for backward compatibility

* Restore --file-prefix logic

* Add arguments regression test
2019-07-24 07:16:48 +02:00
Georgy Komarov 413a5a4865 MISRA: Fix rules suppression, add tests (#1996)
* MISRA: Fix suppressed rules line numbers

Line numbers represented as strings in lxml ETree, but we use it in
integer comparison later.

* MISRA: Use standard library function instead file_prefix.

* MISRA: Use pytest's capsys for capturing, add suppressions tests.

* travis.yml: Update pytest version
2019-07-16 22:32:41 +02:00
Daniel Marjamäki f524bf79ad Misra: Added 17.2 checker 2019-07-13 15:10:07 +02:00
Daniel Marjamäki 29f5f59242 Revert "Revert "Add MISRA 18.4 check (#1966)""
This reverts commit 9b674fa306.
2019-07-09 15:57:12 +02:00
Georgy Komarov 4eb362352d Fixup MISRA 5.1 (#1969) 2019-07-09 15:53:23 +02:00
Daniel Marjamäki 9b674fa306 Revert "Add MISRA 18.4 check (#1966)"
This reverts commit 3ff7ef0918.
2019-07-08 08:10:25 +02:00
Georgy Komarov 3ff7ef0918 Add MISRA 18.4 check (#1966)
* Add MISRA 18.4 check

* Fixup

* Quickfix
2019-07-07 21:54:08 +02:00
fuzzelhjb 999aa407f4 add CERT MSC24-C check (#1903)
* add CERT MSC24-C check

* make check a bit more robust

* fix cert tester

* finetune MSC24 check
2019-07-04 12:19:52 +02:00
fuzzelhjb 1887bd3cf0 add CERT STR11-C check (#1902)
* add CERT STR11-C check

* fix some logical checks

* fix merge issue

* update str11 check
2019-07-02 11:44:24 +02:00
Georgy Komarov f8c350fc70 misra.py: Add R18.7 check (#1934)
* misra.py: Add 18.7 check

* Simplify R18.7 check

* use token.link

* Remove isStruct method
2019-07-01 07:00:43 +02:00
Sebastian 2c71b47d4e
Addons scripts: Remove redundant code/characters, fix indentation. (#1926) 2019-06-27 06:59:47 +02:00
fuzzelhjb 9a7ecd622c add CERT exp15-c check (#1897)
* add CERT exp15-c check

* fix false positive

* remove useless check

* fine tune check and test
2019-06-26 18:49:47 +02:00
Georgy Komarov 5d58b14db8 misra.py: Update output according c97dc79 (#1917) 2019-06-25 00:42:13 +02:00
fuzzelhjb f36d671bc5 add CERT STR03-C check (#1898)
* add CERT STR03-C check

* fix cert test
2019-06-24 18:41:43 +02:00
Georgy Komarov 05bb4a0c8f misra.py: Fixup rules severity (#1911)
* misra.py: Fixup rules severity

* Divide cppcheck and MISRA severity.
2019-06-23 14:08:05 +02:00
fuzzelhjb 8fcfe0ceb0 add CERT STR07-C check 2019-06-23 13:59:24 +02:00
Georgy Komarov 02cc9ffcd8 misra.py: Add --verify-rule-texts option. (#1909)
* misra.py: Add verify-rule-texts option.

* Capture stdout output in travis.
2019-06-19 21:57:27 +02:00
Georgy Komarov e979b0652c misra.py: Fix up and improve load rules parser. (#1895)
* misra.py: Fixup load rules parser.

* misra.py: Report when rule text is missing in rule-texts file

* misra.py: Allow to skip misra checks not specified in rule-texts.

* misra.py: Remove top-level control flow.

Create separate class that stores settings, instead of global variables.

This is required to perform imports from misra.py for testing purposes.

* misra.py: Add simple pytest test for load rules.

* misra.py: Add document structure tests.

* misra.py: Exit after show rules table.

* misra.py: Add document structure tests.

* misra.py: Fixup import pitfall with python2

* misra.py: Minor fixes
2019-06-17 21:17:29 +02:00
fuzzelhjb 5e3da9e82a add CERT STR05-C check (#1899)
* add CERT STR05-C check

* update check
2019-06-17 20:42:23 +02:00
Daniel Marjamäki 7c6d15bb81 Fixed #8658 (false positive: MISRA rule 8.12) 2019-06-01 13:10:20 +02:00
Daniel Marjamäki d039c388ec Fixed #8582 (Regression MISRA Rule 5.1) 2019-05-26 18:46:35 +02:00
Daniel Marjamäki 54be0bc3cf Misra: Added checker for misra rule 17.7 2019-05-22 21:39:33 +02:00
Mathias Schmid 149c07f475 Fix misra addon rule 4 1 (#1846)
* Modifiy check for MISRA rule 4.1 to avoid skipping constant character literal enclosed by single quotes.
Add test for MISRA rule 4.1 which contains non-compliant cases defined by MISRA C 2012 document.

* Moved additional test cases for MISRA rule 4.1 to appropriate test case section.
2019-05-22 14:33:59 +02:00
Daniel Marjamäki 48dfba429a Fixed #8822 (false positive: MISRA rule 13.4) 2019-04-27 17:43:26 +02:00
Daniel Marjamäki a1c30b834c misra.py: Added rule 20.10 2019-04-11 10:50:07 +02:00
Daniel Marjamäki 3e3c805a66 misra.py: Add rule 20.7 2019-04-11 10:36:02 +02:00
eivindt ff1114e3c7 Misra explicitly allows spaces between # and the preprocessing tokens (#1781)
* Misra explicitly allows spaces between # and the preprocessing tokens

* Added tests illustrating need for changing preprocessor checking
2019-04-08 18:26:17 +02:00
Sebastian 4735b6ca1b
addons/naming.py: Fix crash on unnamed arguments, add regex validation. (#1762)
Crash has been reported in the forum:
https://sourceforge.net/p/cppcheck/discussion/development/thread/138788ac6b/
A small test has been added to avoid regression.
2019-03-26 18:54:09 +01:00
Sebastian c106dd2939
misra addon: Fix issue with unexpected encodings in loadRuleTexts() (trac 8946) (#1608)
https://trac.cppcheck.net/ticket/8946
Add tests to travis script for verifying rule text loading.
Add dummy rule text files.
misra.py: Try to find a suitable codec for rule texts file.
2019-01-18 21:30:08 +01:00
Thorsten Sick 43b6a391d8 Added a new naming check addon. Also verifies variable and function p… (#1456)
* Added a new naming check addon. Also verifies variable and function prefixes

* Verification added to code

* added naming checks ng selftest to travis file

* Ensure zero exit value for tests if tests succeed

* Expected values adjusted

* Fixed copy and paste error
2018-11-06 20:46:07 +01:00
Richard A. Smith f286325cec Fix per file excludes (#1437)
* MISRA: Allow printing of the suppressed rules to the console

--show-suppressed-rules will print rules in the suppression rule list to
the console sorted by rule number.

* MISRA: Correct rule suppression for entire file scope

The entire file scope suppression check was checking for the rule item
list to be None instead of looking for None as an entry into the list.

Correct this check and modify the documentation to explicitly state that
an entry of None in the rule item list will set the scope for that
suppression to be the entire file.

* MISRA: Tests for checking per-file rule suppressions

To run:

../../cppcheck --suppressions-list=suppressions.txt --dump misra-suppressions*-test.c
python ../misra.py misra-suppressions*-test.c.dump

There should be no violations reported

* MISRA: Allow ignoring a prefix from file paths when suppression matching

For environments that run cppcheck from the build system cppcheck may be
passed a filename that is a complete path.

Often this path will include a portion that is specific to the developer
or to the environment where the project is located.

The per-file suppression rules do filename matching based on the
filename passed to cppcheck. To match any path information also has to
be included into the suppressions file provided to cppcheck via the
--suppressions-list= option.

This limits the usefulness of the per-file based suppressions because
it requires the suppression to be customized on a per instance basis.

Add a option "--file-prefix" that allows a prefix to be excluded from
the file path when doing the suppression filename matching.

Example.

Given the following structure:

/test/path1/misra-suppressions1-test.c
/test/path1/misra-suppressions2-test.c

specifying --file-prefix /test/path1 will allow the use of
misra-suppressions1-test.c and misra-suppressions2-test.c as filenames
in the suppressions file without leading patch information but still
match the suppression rule.

* MISRA: Tests for --file-prefix option

To run:

../../cppcheck --suppressions-list=suppressions.txt \
    --dump misra-suppressions*-test.c \
           path1/misra-suppressions*-test.c

python ../misra.py misra-suppressions*-test.c.dump \
                   path1/misra-suppressions*-test.c

There should be no violations reported
2018-10-18 09:17:57 +02:00
Daniel Marjamäki d9e1cc957b Fixed #8704 (false postive: MISRA rule 5.2) 2018-10-07 17:19:40 +02:00
Daniel Marjamäki 90a2a46959 Fixed #8657 (false postive: MISRA rule 15.7) 2018-10-01 20:16:48 +02:00
Daniel Marjamäki 18eff25c98 misra: fix fp for rule 3.1 2018-09-08 17:23:24 +02:00
Daniel Marjamäki 8d88f75f03 Fixed #8567 (False positive: MISRA RULE 20.3) 2018-09-02 16:31:27 +02:00
Daniel Marjamäki 8f9fa2e6a7 Fixed #8562 (false positive: MISRA rule 20.13) 2018-09-02 16:05:37 +02:00
Sebastian dce3281766
addons/cert.py: Add MSC30-C: Do not use rand() (#1348)
Add function isStandardFunction() that checks if the given function is a standard function.
Only when this function returns true for the currently checked rand() tokens it is reported as a violation.
Tests added for C and C++.
2018-08-24 15:05:50 +02:00
Konrad Grochowski 3702c477c0 misra.py - rule 8.12 fixed for enums depending on other enums values (#1287) 2018-06-13 06:54:30 +02:00
Konrad Grochowski 8925a0fd81 misra.py - Rule 11.8 fixed in function arguments checks (#1288) 2018-06-13 06:51:24 +02:00
Konrad Grochowski 8290d84472 MISRA 10.4 - fixed ?: operator (#1281)
x ? a : b - only a and b has to be checked
2018-06-09 08:23:41 +02:00
Swasti Shrivastava bdb372f929 Modified rule 14.1 (#1267)
* Modified rule 14.1

* Made suggested changes

* Added findCounterTokens

* Removed hasFloatComparison

* Improved isFloatCounterInWhileLoop

* Made all required minor changes
2018-06-04 10:12:51 +02:00
Konrad Grochowski e1014253ef MISRA Rule 11.6 will no longer report violation on '(void)p;' (#1272) 2018-05-30 12:44:20 +02:00
Swasti Shrivastava a3b9745557 Modified Rule 10.8 (#1265)
* Modified Rule 10.8

* Made suggested changes to handle unary operators
2018-05-28 12:58:19 +02:00
Swasti Shrivastava 742d6513a1 Modified rule 10.6 (#1263)
* Modified rule 10.6

* Improved rule 10.6
2018-05-24 22:28:36 +02:00
Daniel Marjamäki 9f47d04af6 misra.py: add rule 10.1, partial checking 2018-05-23 16:26:00 +02:00
Swasti Shrivastava ea5417b8af Modified rule 11.9 (#1262) 2018-05-23 15:48:07 +02:00
Swasti Shrivastava 8daa8520ba Modified rule 11.6 (#1261) 2018-05-23 12:50:35 +02:00
Swasti Shrivastava 684c18f657 Modified rule 11.3 and 11.7 (#1260)
* Modified rule 11.3 and 11.7

* Changed if to elif
2018-05-23 10:14:17 +02:00
Swasti Shrivastava c73dc63537 Modified rule 11.5 (#1256) 2018-05-22 14:32:00 +02:00
Daniel Marjamäki dbe2a42e89 misra.py: Fixed 13.1 fp for struct initialization 2018-05-22 13:11:39 +02:00
Swasti Shrivastava c511b3de20 Modified rule 11.4 (#1252)
* Modified rule 11.4

* Made changes in isEnum()

* Made suggested changes in isEnum()
2018-05-22 09:07:48 +02:00
Swasti Shrivastava f78314b613 Updated rule 10 4 (#1251)
* Updated rule 10.4

* Updated rule 10.4

* updated rule 10.4 along with test suite
2018-05-21 12:04:20 +02:00
Swasti Shrivastava 00970274b2 Added rule 21.6 and 21.10 (#1243) 2018-05-20 14:44:12 +02:00
Swasti Shrivastava 248e2ef2f8 Modified rule 7.3 (#1232) 2018-05-16 12:04:02 +02:00
Swasti Shrivastava 92fd7d9343 Modified rule 5.1 along with test suite (#1231)
* Modified rule 5.1 along with test suite

* Modified variable name in misra-test.c

* Modified rule 5.1 along with test suite

* Changed variable name
2018-05-16 11:07:44 +02:00
Swasti Shrivastava bb7ffd123d Modified rule 8.12 (#1233) 2018-05-15 13:18:55 +02:00
Swasti Shrivastava 4b873ed573 Rule 5.3 modified along with test suite (#1227)
* Added rule 5.2

* updated 5.2

request-checks: true

* Added rule 5.3

* Changed rule 5.4, 5.5

* Updated test suite for Rule 5.2

* Changes in Rule 5.4 and 5.5

* Change in function name in test suite and removed type from class token in cppcheck

* Changed the name of function in misra-test.c

* Modified rule 5.3

* Modified misra-test.c for rule 5.3
2018-05-14 13:09:38 +02:00
swasti16 4956b89506 Changes in misra c rule 5.4 and 5.5 (#1219)
* Added rule 5.2

* updated 5.2

request-checks: true

* Added rule 5.3

* Changed rule 5.4, 5.5

* Updated test suite for Rule 5.2

* Changes in Rule 5.4 and 5.5

* Change in function name in test suite and removed type from class token in cppcheck

* Changed the name of function in misra-test.c
2018-05-11 14:57:08 +02:00
orbitcowboy c39e3467a4 misra.py: Rule 21.8, added missing exit() function. 2018-05-09 16:48:49 +02:00
swasti16 d934065d21 Added rule 5.2 (#1212)
* Added rule 5.2

* updated 5.2

request-checks: true

* Updated test suite for Rule 5.2
2018-05-08 20:41:45 +02:00
Daniel Marjamäki 286e300c6f misra: fix test assertion 2018-05-04 22:30:24 +02:00
Daniel Marjamäki 8b42706158 misra: Added check for rule 20.13 2018-05-03 22:53:06 +02:00
Daniel Marjamäki 493e243c0b misra: fix fp in 16.6 2018-05-03 10:59:09 +02:00
Daniel Marjamäki 2a9ee563c2 misra: avoid fp for essentially boolean conditions when bitfield member is used 2018-05-02 20:56:03 +02:00
Daniel Marjamäki 975be66c63 String concatenation in array: Improved handling of macros 2018-04-28 23:01:29 +02:00
Daniel Marjamäki 5e31911fcd misra.py: fix false positives in 16.3 for unconditional blocks of code 2018-04-24 09:28:24 +02:00
Daniel Marjamäki 86a9deffbf misc.py: removed bailouts 2018-04-20 08:18:49 +02:00
Daniel Marjamäki 3c48e08e6c misc.py: write debug message when valueType is None 2018-04-19 22:23:34 +02:00
Daniel Marjamäki fb89c987b0 misra.py: Improved 'isBoolExpression' 2018-04-18 16:20:54 +02:00
Daniel Marjamäki d181e98d02 misc.py: Added experimental ellipsisStructArg checker that warns when struct is passed to ellipsis function 2018-04-16 13:55:12 +02:00
Daniel Marjamäki 194b4096c2 renamed misc test file since it has c++ code 2018-04-16 13:17:47 +02:00
Daniel Marjamäki d65f00fe2e misc.py: Add check for implicitly virtual functions 2018-04-16 13:16:53 +02:00
Daniel Marjamäki 9579b12be9 misc.py: fixed FP 2018-04-16 12:55:27 +02:00
Daniel Marjamäki 19591298f1 misc.py: Fixed FP for string concatenation 2018-04-16 10:53:29 +02:00
Daniel Marjamäki 7031cc7e22 misc.py: Add addon for some misc checkers 2018-04-13 22:19:47 +02:00
Daniel Marjamäki 8f21ba91e3 cert.py: Fix FP 2018-04-12 20:23:50 +02:00
Daniel Marjamäki 97b17d50aa cert.py: fixed fp in exp05 for non-pointer casts 2018-04-03 15:12:01 +02:00
Daniel Marjamäki 2db7c6e1a3 cert.py: Add rule EXP-05: do not cast away const 2018-04-03 13:35:19 +02:00
Daniel Marjamäki ed8fda571b misra.py: Add rule 4.1 2018-03-31 12:17:55 +02:00
Daniel Marjamäki 480d84d69c Fixed #8441 (MISRA Addon: FP 12.3 issued for initializer lists) 2018-03-18 22:05:31 +01:00
Daniel Marjamäki 77318d0e14 misra.py: updated 16.3 code 2018-03-12 15:16:57 +01:00
Daniel Marjamäki f10d170ad3 misra addon: handle [[fallthrough]] attribute 2018-03-12 13:43:23 +01:00
Daniel Marjamäki 21bb973702 Removed code metrics addon 2018-02-18 11:17:54 +01:00
Daniel Marjamäki 5db9345a08 addons/metrics: Add simple script for generating some metrics 2018-02-17 14:59:40 +01:00
Daniel Marjamäki 6e8184f7cc cert.py: Added test for EXP46 2018-01-23 22:43:29 +01:00
Daniel Marjamäki 8eae9cdd60 cert.py: Added testcases for EXP42 and fixed the code a little 2018-01-23 17:18:47 +01:00
amai2012 fcbe88ad2f Move test files to subfolder 2018-01-23 11:33:13 +01:00