diff --git a/tests/test_coverity.py b/tests/test_coverity.py index f43c4af3..5d84ee28 100644 --- a/tests/test_coverity.py +++ b/tests/test_coverity.py @@ -19,8 +19,11 @@ def ordered(obj): else: return obj - -@mock.patch.dict(os.environ, {"MIN_COV_WARNINGS": "1", "MAX_COV_WARNINGS": "2"}) +@mock.patch.dict(os.environ, { + "MIN_UNCLASSIFIED": "8", "MAX_UNCLASSIFIED": "8", + "MIN_INTENTIONAL": "1", "MAX_INTENTIONAL": "1", + "MIN_FALSE_POSITIVE": "2", "MAX_FALSE_POSITIVE": "2", +}) class TestCoverityWarnings(TestCase): def setUp(self): Finding.fingerprints = {} @@ -76,14 +79,30 @@ def test_code_quality_without_config(self): self.assertEqual(8, retval) self.assertTrue(filecmp.cmp(out_file, ref_file)) - def test_code_quality_with_config(self): + def test_code_quality_with_config_pass(self): filename = 'coverity_cq.json' out_file = str(TEST_OUT_DIR / filename) ref_file = str(TEST_IN_DIR / filename) retval = warnings_wrapper([ '--code-quality', out_file, '--config', str(TEST_IN_DIR / 'config_example_coverity.yml'), - str(TEST_IN_DIR / 'defects.txt'), + str(TEST_IN_DIR / 'coverity_full.txt'), + ]) + self.assertEqual(0, retval) + self.assertTrue(filecmp.cmp(out_file, ref_file)) + + @mock.patch.dict(os.environ, { + "MIN_UNCLASSIFIED": "11", "MAX_UNCLASSIFIED": "-1", + "MIN_FALSE_POSITIVE": "0", "MAX_FALSE_POSITIVE": "1", + }) + def test_code_quality_with_config_fail(self): + filename = 'coverity_cq.json' + out_file = str(TEST_OUT_DIR / filename) + ref_file = str(TEST_IN_DIR / filename) + retval = warnings_wrapper([ + '--code-quality', out_file, + '--config', str(TEST_IN_DIR / 'config_example_coverity.yml'), + str(TEST_IN_DIR / 'coverity_full.txt'), ]) - self.assertEqual(3, retval) + self.assertEqual(10, retval) # 8 + 2 not within range 6 and 7 self.assertTrue(filecmp.cmp(out_file, ref_file)) diff --git a/tests/test_in/config_example_coverity.yml b/tests/test_in/config_example_coverity.yml index da3b4f0d..a53cef2f 100644 --- a/tests/test_in/config_example_coverity.yml +++ b/tests/test_in/config_example_coverity.yml @@ -1,11 +1,11 @@ coverity: enabled: true unclassified: - min: $MIN_COV_WARNINGS - max: '$MAX_COV_WARNINGS' + min: $MIN_UNCLASSIFIED + max: '$MAX_UNCLASSIFIED' intentional: - min: 0 - max: -1 + min: $MIN_INTENTIONAL + max: $MAX_INTENTIONAL bug: min: 0 max: 0 @@ -13,8 +13,8 @@ coverity: min: 0 max: 0 false_positive: - min: 0 - max: -1 + min: $MIN_FALSE_POSITIVE + max: $MAX_FALSE_POSITIVE sphinx: enabled: false doxygen: diff --git a/tests/test_in/coverity_cq.json b/tests/test_in/coverity_cq.json index 77095db5..6329e0fc 100644 --- a/tests/test_in/coverity_cq.json +++ b/tests/test_in/coverity_cq.json @@ -1,73 +1,115 @@ [ { "severity": "major", - "description": "Coverity: CID 431350: MISRA C-2012 Declarations and Definitions (MISRA C-2012 Rule 8.5, Required)", + "description": "Coverity: CID 446411: Infinite loop (INFINITE_LOOP)", "location": { - "path": "some/path/dummy_uncl.h", + "path": "some/path/boot.c", "positions": { "begin": { - "line": 194, - "column": 14 + "line": 32, + "column": 5 } } }, - "fingerprint": "0feb782a7b77d9d45307dc0e1d37cabc" + "fingerprint": "61cc73ec6e5801eabd5b14dee4eddc09" }, { "severity": "major", - "description": "Coverity: CID 431349: MISRA C-2012 Declarations and Definitions (MISRA C-2012 Rule 8.6, Required)", + "description": "Coverity: CID 446410: MISRA C-2012 The Essential Type Model (MISRA C-2012 Rule 10.3, Required)", "location": { - "path": "some/path/dummy_uncl.c", + "path": "some/path/boot.c", "positions": { "begin": { - "line": 1404, - "column": 14 + "line": 55, + "column": 12 } } }, - "fingerprint": "1b9bc9863b1d43eaa17d6bd5672e3b9d" + "fingerprint": "ee2a9b741d33d5085807562a66c7ef21" }, { "severity": "major", - "description": "Coverity: CID 431348: MISRA C-2012 Identifiers (MISRA C-2012 Rule 5.8, Required)", + "description": "Coverity: CID 446409: MISRA C-2012 Control Flow Expressions (MISRA C-2012 Rule 14.3, Required)", "location": { - "path": "some/path/dummy_uncl.c", + "path": "some/path/boot.c", "positions": { "begin": { - "line": 923, + "line": 37, "column": 13 } } }, - "fingerprint": "c83e3d6a9d30ddc3ccc8e6c3b3e0a34a" + "fingerprint": "0a8e4e7431af33984280c95a3289f307" }, { - "severity": "info", - "description": "Coverity: CID 417642: MISRA C-2012 Standard C Environment (MISRA C-2012 Rule 1.2, Advisory)", + "severity": "major", + "description": "Coverity: CID 446408: Logically dead code (DEADCODE)", "location": { - "path": "some/path/dummy_int.h", + "path": "some/path/boot.c", "positions": { "begin": { - "line": 150, - "column": 16 + "line": 37, + "column": 13 } } }, - "fingerprint": "281a13b77a22e0b91b4b1de826e83a54" + "fingerprint": "2817d729a41e3c9af04ea9711305dd6c" }, { - "severity": "info", - "description": "Coverity: CID 417639: MISRA C-2012 Standard C Environment (MISRA C-2012 Rule 1.2, Advisory)", + "severity": "major", + "description": "Coverity: CID 446407: MISRA C-2012 The Essential Type Model (MISRA C-2012 Rule 10.4, Required)", "location": { - "path": "some/path/dummy_int.h", + "path": "some/path/boot.c", + "positions": { + "begin": { + "line": 36, + "column": 13 + } + } + }, + "fingerprint": "8c2bcaf164d9104351c066775b8ce7d1" + }, + { + "severity": "major", + "description": "Coverity: CID 446406: MISRA C-2012 Control Flow Expressions (MISRA C-2012 Rule 14.3, Required)", + "location": { + "path": "some/path/boot.c", "positions": { "begin": { - "line": 164, - "column": 16 + "line": 32, + "column": 5 } } }, - "fingerprint": "6875f7de0399adaba119ad4945514a76" + "fingerprint": "98fda4d0677b7c979affa2769fc21c9f" + }, + { + "severity": "major", + "description": "Coverity: CID 446405: MISRA C-2012 Unused Code (MISRA C-2012 Rule 2.2, Required)", + "location": { + "path": "some/path/boot.c", + "positions": { + "begin": { + "line": 37, + "column": 31 + } + } + }, + "fingerprint": "1cbe936313d71154034d7728387409bf" + }, + { + "severity": "major", + "description": "Coverity: CID 431350: MISRA C-2012 Declarations and Definitions (MISRA C-2012 Rule 8.5, Required)", + "location": { + "path": "some/path/dummy_uncl.h", + "positions": { + "begin": { + "line": 194, + "column": 14 + } + } + }, + "fingerprint": "0feb782a7b77d9d45307dc0e1d37cabc" }, { "severity": "info",