Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test case for suppress comments #819

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions tests/functional/suppress/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@ def setup_package():

os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

test_project = 'cpp'
test_project = 'suppress'

pg_db_config = env.get_postgresql_cfg()

test_config = {}

project_info = project.get_info(test_project)

test_proj_path = os.path.join(TEST_WORKSPACE, "test_proj")
shutil.copytree(project.path(test_project), test_proj_path)

project_info['project_path'] = test_proj_path

test_config['test_project'] = project_info

# Generate a suppress file for the tests.
Expand All @@ -49,16 +54,14 @@ def setup_package():
os.remove(suppress_file)
_generate_suppress_file(suppress_file)

skip_list_file = None

# Get port numbers for the tests.
host_port_cfg = env.get_host_port_cfg()

test_env = env.test_env()

codechecker_cfg = {
'suppress_file': None,
'skip_list_file': skip_list_file,
'skip_list_file': None,
'check_env': test_env,
'workspace': TEST_WORKSPACE,
'pg_db_config': pg_db_config,
Expand Down
7 changes: 0 additions & 7 deletions tests/functional/suppress/test_files/build.json

This file was deleted.

106 changes: 89 additions & 17 deletions tests/functional/suppress/test_suppress_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
Test source-code level suppression data writing to suppress file.
"""

from subprocess import CalledProcessError
import logging
import os
import shlex
import subprocess
import unittest

from libtest.thrift_client_to_db import get_all_run_results
from libtest import env
from libtest import codechecker
from subprocess import CalledProcessError

import shared


class TestSuppress(unittest.TestCase):
Expand All @@ -22,9 +27,27 @@ class TestSuppress(unittest.TestCase):
"""

def setUp(self):
self.test_workspace = os.environ['TEST_WORKSPACE']
self.test_dir = os.path.join(
os.path.dirname(__file__), "test_files")
self._test_workspace = os.environ['TEST_WORKSPACE']

self._testproject_data = env.setup_test_proj_cfg(self._test_workspace)
self.assertIsNotNone(self._testproject_data)

self._test_project_path = self._testproject_data['project_path']

self._cc_client = env.setup_viewer_client(self._test_workspace)
self.assertIsNotNone(self._cc_client)

# Get the run names which belong to this test
run_names = env.get_run_names(self._test_workspace)

runs = self._cc_client.getRunData(None)

test_runs = [run for run in runs if run.name in run_names]

self.assertEqual(len(test_runs), 1,
'There should be only one run for this test.')
self._runid = test_runs[0].runId
self._run_name = test_runs[0].name

def test_source_suppress_export(self):
"""
Expand All @@ -35,7 +58,7 @@ def __call(command):
try:
print(' '.join(command))
proc = subprocess.Popen(shlex.split(' '.join(command)),
cwd=self.test_dir,
cwd=self._test_project_path,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=env.test_env())
Expand All @@ -47,28 +70,77 @@ def __call(command):
print("Failed to call:\n" + ' '.join(cerr.cmd))
return cerr.returncode

analyze_cmd = ['CodeChecker', 'analyze',
os.path.join(self.test_dir, "build.json"),
"--output", os.path.join(self.test_workspace, "reports")
]
ret = __call(analyze_cmd)
self.assertEqual(ret, 0, "Couldn't create analysis of test project.")

generated_file = os.path.join(self.test_workspace,
generated_file = os.path.join(self._test_workspace,
"generated.suppress")

extract_cmd = ['CodeChecker', 'parse',
os.path.join(self.test_workspace, "reports"),
os.path.join(self._test_workspace, "reports"),
"--suppress", generated_file,
"--export-source-suppress"
]
__call(extract_cmd)
ret = __call(extract_cmd)
self.assertEqual(ret, 0, "Failed to generate suppress file.")

with open(generated_file, 'r') as generated:
with open(os.path.join(self.test_dir, "expected.suppress"),
'r') as expected:
with open(os.path.join(self._test_project_path,
"suppress.expected"), 'r') as expected:
self.assertEqual(generated.read().strip(),
expected.read().strip(),
"The generated suppress file does not "
"look like what was expected.")

def test_suppress_comment_in_db(self):
"""
Exported source suppress comment stored as a review status in the db.
"""
runid = self._runid
logging.debug('Get all run results from the db for runid: ' +
str(runid))

run_results = get_all_run_results(self._cc_client, runid)
self.assertIsNotNone(run_results)
self.assertNotEqual(len(run_results), 0)

bug = run_results[0]

report = self._cc_client.getReport(bug.reportId)

# Check the stored suppress comment
status = shared.ttypes.ReviewStatus.FALSE_POSITIVE
self.assertEqual(report.review.comment, 'deliberate segfault!')
self.assertEqual(report.review.status, status)

# Change review status to confirmed bug.
review_comment = 'This is really a bug'
status = shared.ttypes.ReviewStatus.CONFIRMED
success = self._cc_client.changeReviewStatus(
bug.reportId, status, review_comment)

self.assertTrue(success)
logging.debug('Bug review status changed successfully')

# Check the same project again.
codechecker_cfg = env.import_test_cfg(
self._test_workspace)['codechecker_cfg']

initial_test_project_name = self._run_name

ret = codechecker.check(codechecker_cfg,
initial_test_project_name,
self._test_project_path)
if ret:
sys.exit(1)

# Get the results to compare.
updated_results = get_all_run_results(self._cc_client, self._runid)
self.assertIsNotNone(updated_results)
self.assertNotEqual(len(updated_results), 0)

bug = updated_results[0]

report = self._cc_client.getReport(bug.reportId)

# The stored suppress comment for the same bughash is the same.
status = shared.ttypes.ReviewStatus.FALSE_POSITIVE
self.assertEqual(report.review.comment, 'deliberate segfault!')
self.assertEqual(report.review.status, status)
5 changes: 5 additions & 0 deletions tests/projects/suppress/project_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "suppress",
"clean_cmd": "rm a.out",
"build_cmd": "g++ suppress.cpp"
}