Skip to content

Commit

Permalink
[cmd] Parse command exits with error in case of duplicated suppress c…
Browse files Browse the repository at this point in the history
…omments
  • Loading branch information
zomen2 committed May 4, 2021
1 parent 3f66012 commit 25e09a1
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 45 deletions.
25 changes: 12 additions & 13 deletions analyzer/tests/functional/suppress/test_suppress.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from libtest import env


def call_cmd(command, cwd, env):
def _call_cmd(command, cwd, env):
try:
print(' '.join(command))
proc = subprocess.Popen(
Expand Down Expand Up @@ -61,15 +61,15 @@ def test_source_suppress_export(self):
"generated.suppress")
skip_file = os.path.join(self._test_directory, "suppress_export.skip")

extract_cmd = ['CodeChecker', 'parse',
extract_cmd = [env.codechecker_cmd(), 'parse',
os.path.join(self._test_workspace, "reports"),
"--suppress", generated_file,
"--export-source-suppress", "--ignore", skip_file,
"--verbose", "debug"]

ret = call_cmd(extract_cmd,
self._test_project_path,
env.test_env(self._test_directory))
ret = _call_cmd(extract_cmd,
self._test_project_path,
env.test_env(self._test_directory))
self.assertEqual(ret, 2, "Failed to generate suppress file.")

with open(generated_file, 'r',
Expand Down Expand Up @@ -101,13 +101,13 @@ def test_doubled_suppress(self):

skip_file = os.path.join(self._test_directory, "doubled_suppress.skip")

extract_cmd = ['CodeChecker', 'parse',
extract_cmd = [env.codechecker_cmd(), 'parse',
os.path.join(self._test_workspace, "reports"),
"--ignore", skip_file, "--verbose", "debug"]

ret = call_cmd(extract_cmd,
self._test_project_path,
env.test_env(self._test_workspace))
ret = _call_cmd(extract_cmd,
self._test_project_path,
env.test_env(self._test_workspace))
self.assertEqual(ret, 1, "Repeated suppress comment not recognized.")

def test_doubled_suppress_by_all(self):
Expand All @@ -118,12 +118,11 @@ def test_doubled_suppress_by_all(self):

skip_file = os.path.join(self._test_directory, "suppress_by_all.skip")

extract_cmd = ['CodeChecker', 'parse',
extract_cmd = [env.codechecker_cmd(), 'parse',
os.path.join(self._test_workspace, "reports"),
"--ignore", skip_file, "--verbose", "debug"]

ret = call_cmd(extract_cmd,
self._test_project_path,
env.test_env(self._test_workspace))
ret = _call_cmd(extract_cmd, self._test_project_path,
env.test_env(self._test_workspace))
self.assertEqual(ret, 1, "Already covered suppress comment not "
"recognized.")
1 change: 0 additions & 1 deletion web/tests/functional/store/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"""Setup for the package tests."""


import multiprocessing
import os
import shutil

Expand Down
7 changes: 5 additions & 2 deletions web/tests/functional/store/test_proj/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
# for the store update tests.

build:
$(CXX) -c divide_zero.cpp -o /dev/null
$(CXX) -c divide_zero.cpp -o divide_zero.o
$(CXX) -c double_suppress.cpp -o double_suppress.o

clean:
rm -rf divide_zero
rm -rf divide_zero.o double_suppress.o

# Using relative path to the source files
# it is easier to prefix them with the temporary
# directory during test preparation.
analyze:
clang --analyze -I. divide_zero.cpp --analyzer-output plist-multi-file \
-o divide_zero.plist
clang --analyze double_suppress.cpp --analyzer-output plist-multi-file \
-o double_suppress.plist
6 changes: 6 additions & 0 deletions web/tests/functional/store/test_proj/double_suppress.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
void foo()
{
// codechecker_suppress [deadcode.DeadStores] Same suppress comment twice.
// codechecker_suppress [deadcode.DeadStores] Same suppress comment twice.
int *p = new int;
}
190 changes: 190 additions & 0 deletions web/tests/functional/store/test_proj/double_suppress.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>clang_version</key>
<string>Ubuntu clang version 11.0.0-2~ubuntu20.04.1</string>
<key>diagnostics</key>
<array>
<dict>
<key>path</key>
<array>
<dict>
<key>kind</key><string>event</string>
<key>location</key>
<dict>
<key>line</key><integer>5</integer>
<key>col</key><integer>10</integer>
<key>file</key><integer>0</integer>
</dict>
<key>ranges</key>
<array>
<array>
<dict>
<key>line</key><integer>5</integer>
<key>col</key><integer>10</integer>
<key>file</key><integer>0</integer>
</dict>
<dict>
<key>line</key><integer>5</integer>
<key>col</key><integer>10</integer>
<key>file</key><integer>0</integer>
</dict>
</array>
<array>
<dict>
<key>line</key><integer>5</integer>
<key>col</key><integer>14</integer>
<key>file</key><integer>0</integer>
</dict>
<dict>
<key>line</key><integer>5</integer>
<key>col</key><integer>20</integer>
<key>file</key><integer>0</integer>
</dict>
</array>
</array>
<key>depth</key><integer>0</integer>
<key>extended_message</key>
<string>Value stored to &apos;p&apos; during its initialization is never read</string>
<key>message</key>
<string>Value stored to &apos;p&apos; during its initialization is never read</string>
</dict>
</array>
<key>description</key><string>Value stored to &apos;p&apos; during its initialization is never read</string>
<key>category</key><string>Dead store</string>
<key>type</key><string>Dead initialization</string>
<key>check_name</key><string>deadcode.DeadStores</string>
<!-- This hash is experimental and going to change! -->
<key>issue_hash_content_of_line_in_context</key><string>5ccff44aa49130936add404dab9e1a6c</string>
<key>issue_context_kind</key><string>function</string>
<key>issue_context</key><string>foo</string>
<key>issue_hash_function_offset</key><string>3</string>
<key>location</key>
<dict>
<key>line</key><integer>5</integer>
<key>col</key><integer>10</integer>
<key>file</key><integer>0</integer>
</dict>
<key>ExecutedLines</key>
<dict>
<key>0</key>
<array>
<integer>5</integer>
</array>
</dict>
</dict>
<dict>
<key>path</key>
<array>
<dict>
<key>kind</key><string>event</string>
<key>location</key>
<dict>
<key>line</key><integer>5</integer>
<key>col</key><integer>14</integer>
<key>file</key><integer>0</integer>
</dict>
<key>ranges</key>
<array>
<array>
<dict>
<key>line</key><integer>5</integer>
<key>col</key><integer>14</integer>
<key>file</key><integer>0</integer>
</dict>
<dict>
<key>line</key><integer>5</integer>
<key>col</key><integer>20</integer>
<key>file</key><integer>0</integer>
</dict>
</array>
</array>
<key>depth</key><integer>0</integer>
<key>extended_message</key>
<string>Memory is allocated</string>
<key>message</key>
<string>Memory is allocated</string>
</dict>
<dict>
<key>kind</key><string>control</string>
<key>edges</key>
<array>
<dict>
<key>start</key>
<array>
<dict>
<key>line</key><integer>5</integer>
<key>col</key><integer>5</integer>
<key>file</key><integer>0</integer>
</dict>
<dict>
<key>line</key><integer>5</integer>
<key>col</key><integer>7</integer>
<key>file</key><integer>0</integer>
</dict>
</array>
<key>end</key>
<array>
<dict>
<key>line</key><integer>6</integer>
<key>col</key><integer>1</integer>
<key>file</key><integer>0</integer>
</dict>
<dict>
<key>line</key><integer>6</integer>
<key>col</key><integer>1</integer>
<key>file</key><integer>0</integer>
</dict>
</array>
</dict>
</array>
</dict>
<dict>
<key>kind</key><string>event</string>
<key>location</key>
<dict>
<key>line</key><integer>6</integer>
<key>col</key><integer>1</integer>
<key>file</key><integer>0</integer>
</dict>
<key>depth</key><integer>0</integer>
<key>extended_message</key>
<string>Potential leak of memory pointed to by &apos;p&apos;</string>
<key>message</key>
<string>Potential leak of memory pointed to by &apos;p&apos;</string>
</dict>
</array>
<key>description</key><string>Potential leak of memory pointed to by &apos;p&apos;</string>
<key>category</key><string>Memory error</string>
<key>type</key><string>Memory leak</string>
<key>check_name</key><string>cplusplus.NewDeleteLeaks</string>
<!-- This hash is experimental and going to change! -->
<key>issue_hash_content_of_line_in_context</key><string>1a6ea464fbd26b31573aab0d8a784d6a</string>
<key>issue_context_kind</key><string>function</string>
<key>issue_context</key><string>foo</string>
<key>issue_hash_function_offset</key><string>3</string>
<key>location</key>
<dict>
<key>line</key><integer>6</integer>
<key>col</key><integer>1</integer>
<key>file</key><integer>0</integer>
</dict>
<key>ExecutedLines</key>
<dict>
<key>0</key>
<array>
<integer>1</integer>
<integer>2</integer>
<integer>5</integer>
<integer>6</integer>
</array>
</dict>
</dict>
</array>
<key>files</key>
<array>
<string>double_suppress.cpp</string>
</array>
</dict>
</plist>
Loading

0 comments on commit 25e09a1

Please sign in to comment.