-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The introduced new plist xml parsing method with lxml was not introduced for the use cases where a skip file was used. In case of a skip file the report plist files can be rewritten (the reports based on the skip file content) are removed. Previous tests did not fail because a second skip is done at the server side during storage and the server skip tests worked on the stored reports.
- Loading branch information
Gyorgy Orban
committed
Jul 3, 2019
1 parent
bc6a5e6
commit ccf4e61
Showing
14 changed files
with
252 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# coding=utf-8 | ||
# ----------------------------------------------------------------------------- | ||
# The CodeChecker Infrastructure | ||
# This file is distributed under the University of Illinois Open Source | ||
# License. See LICENSE.TXT for details. | ||
# ----------------------------------------------------------------------------- | ||
|
||
"""Setup for the skip test for the analyze command. | ||
""" | ||
from __future__ import print_function | ||
from __future__ import division | ||
from __future__ import absolute_import | ||
|
||
import os | ||
import shutil | ||
|
||
from libtest import env | ||
|
||
|
||
# Test workspace should be initialized in this module. | ||
TEST_WORKSPACE = None | ||
|
||
|
||
def setup_package(): | ||
"""Setup the environment for the tests.""" | ||
|
||
global TEST_WORKSPACE | ||
TEST_WORKSPACE = env.get_workspace('skip') | ||
|
||
report_dir = os.path.join(TEST_WORKSPACE, 'reports') | ||
os.makedirs(report_dir) | ||
|
||
os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE | ||
|
||
|
||
def teardown_package(): | ||
"""Delete the workspace associated with this test""" | ||
|
||
# TODO: If environment variable is set keep the workspace | ||
# and print out the path. | ||
global TEST_WORKSPACE | ||
|
||
print("Removing: " + TEST_WORKSPACE) | ||
shutil.rmtree(TEST_WORKSPACE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
OBJS = $(SRCS:.cpp=.o) | ||
|
||
CXXFLAGS = -Wno-all -Wno-extra -Wno-division-by-zero | ||
|
||
SRCS = skip_header.cpp \ | ||
file_to_be_skipped.cpp | ||
|
||
.cpp.o: | ||
$(CXX) $(CXXFLAGS) -c $< -o $@ | ||
|
||
all: $(OBJS) | ||
|
||
clean: | ||
rm -rf *.o |
12 changes: 12 additions & 0 deletions
12
analyzer/tests/functional/skip/test_files/file_to_be_skipped.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// ----------------------------------------------------------------------------- | ||
// The CodeChecker Infrastructure | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// ----------------------------------------------------------------------------- | ||
|
||
// This file is to be included in a skip list file. | ||
|
||
void skipped_test(int z) { | ||
if (z == 0) | ||
int x = 1 / z; // warn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// ----------------------------------------------------------------------------- | ||
// The CodeChecker Infrastructure | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// ----------------------------------------------------------------------------- | ||
|
||
int null_div(int z) { | ||
int x = z / 0; // warn | ||
return x; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// ----------------------------------------------------------------------------- | ||
// The CodeChecker Infrastructure | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// ----------------------------------------------------------------------------- | ||
|
||
#include "skip.h" | ||
|
||
int test() { | ||
int x = null_div(42); | ||
return x; | ||
} | ||
|
||
int test1(int i) { | ||
int y = i / 0; // warn | ||
return y; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-*file_to_be_skipped.cpp | ||
-*skip.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# | ||
# ----------------------------------------------------------------------------- | ||
# The CodeChecker Infrastructure | ||
# This file is distributed under the University of Illinois Open Source | ||
# License. See LICENSE.TXT for details. | ||
# ----------------------------------------------------------------------------- | ||
|
||
""" | ||
Test skipping the analysis of a file and the removal | ||
of skipped reports from the report files. | ||
""" | ||
from __future__ import print_function | ||
from __future__ import division | ||
from __future__ import absolute_import | ||
|
||
import os | ||
import plistlib | ||
import subprocess | ||
import unittest | ||
import shutil | ||
|
||
from libtest import env | ||
|
||
|
||
class TestSkip(unittest.TestCase): | ||
_ccClient = None | ||
|
||
def setUp(self): | ||
|
||
# TEST_WORKSPACE is automatically set by test package __init__.py . | ||
self.test_workspace = os.environ['TEST_WORKSPACE'] | ||
|
||
test_class = self.__class__.__name__ | ||
print('Running ' + test_class + ' tests in ' + self.test_workspace) | ||
|
||
# Get the CodeChecker cmd if needed for the tests. | ||
self._codechecker_cmd = env.codechecker_cmd() | ||
self.report_dir = os.path.join(self.test_workspace, "reports") | ||
self.test_dir = os.path.join(os.path.dirname(__file__), 'test_files') | ||
# Change working dir to testfile dir so CodeChecker can be run easily. | ||
self.__old_pwd = os.getcwd() | ||
os.chdir(self.test_dir) | ||
|
||
def tearDown(self): | ||
"""Restore environment after tests have ran.""" | ||
os.chdir(self.__old_pwd) | ||
if os.path.isdir(self.report_dir): | ||
shutil.rmtree(self.report_dir) | ||
|
||
def test_skip(self): | ||
""" | ||
""" | ||
build_json = os.path.join(self.test_workspace, "build.json") | ||
|
||
clean_cmd = ["make", "clean"] | ||
out = subprocess.check_output(clean_cmd) | ||
print(out) | ||
|
||
# Create and run log command. | ||
log_cmd = [self._codechecker_cmd, "log", "-b", "make", | ||
"-o", build_json] | ||
out = subprocess.check_output(log_cmd) | ||
print(out) | ||
# Create and run analyze command. | ||
analyze_cmd = [self._codechecker_cmd, "analyze", build_json, | ||
"--analyzers", "clangsa", "--verbose", "debug", | ||
"--ignore", "skipfile", "-o", self.report_dir] | ||
|
||
process = subprocess.Popen( | ||
analyze_cmd, stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, cwd=self.test_dir) | ||
out, err = process.communicate() | ||
|
||
print(out) | ||
print(err) | ||
errcode = process.returncode | ||
self.assertEquals(errcode, 0) | ||
|
||
# Check if file is skipped. | ||
report_dir_files = os.listdir(self.report_dir) | ||
for f in report_dir_files: | ||
self.assertFalse("file_to_be_skipped.cpp" in f) | ||
|
||
# Check if report from the report file is removed. | ||
report_dir_files = os.listdir(self.report_dir) | ||
report_file_to_check = None | ||
for f in report_dir_files: | ||
if "skip_header.cpp" in f: | ||
report_file_to_check = os.path.join(self.report_dir, f) | ||
break | ||
|
||
self.assertIsNotNone(report_file_to_check, | ||
"Report file should be generated.") | ||
report_data = plistlib.readPlist(report_file_to_check) | ||
files = report_data['files'] | ||
|
||
skiped_file_index = None | ||
for i, f in enumerate(files): | ||
if "skip.h" in f: | ||
skiped_file_index = i | ||
break | ||
|
||
for diag in report_data['diagnostics']: | ||
self.assertNotEqual(diag['location']['file'], | ||
skiped_file_index, | ||
"Found a location which points to " | ||
"skiped file, this report should " | ||
"have been removed.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.