Bug 1486452 - mach static analysis autotest - display the error if we encounter clang-diagnostic-error. r=janx

Differential Revision: https://phabricator.services.mozilla.com/D4425

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andi-Bogdan Postelnicu 2018-08-29 12:11:07 +00:00
parent 7344cfce10
commit 1811c9a2df

View File

@ -1907,6 +1907,7 @@ class StaticAnalysis(MachCommandBase):
self.TOOLS_CHECKER_RESULT_FILE_NOT_FOUND = 5
self.TOOLS_CHECKER_DIFF_FAILED = 6
self.TOOLS_CHECKER_NOT_FOUND = 7
self.TOOLS_CHECKER_FAILED_FILE = 8
# Configure the tree or download clang-tidy package, depending on the option that we choose
if intree_tool:
@ -1989,12 +1990,21 @@ class StaticAnalysis(MachCommandBase):
continue
futures.append(executor.submit(self._verify_checker, item))
error_code = self.TOOLS_SUCCESS
for future in concurrent.futures.as_completed(futures):
# Wait for every task to finish
ret_val = future.result()
if ret_val != self.TOOLS_SUCCESS:
# Also delete the tmp folder
shutil.rmtree(self._compilation_commands_path)
return ret_val
# We are interested only in one error and we don't break
# the execution of for loop since we want to make sure that all
# tasks finished.
error_code = ret_val
if error_code != self.TOOLS_SUCCESS:
self.log(logging.INFO, 'static-analysis', {}, "FAIL: clang-tidy some tests failed.")
# Also delete the tmp folder
shutil.rmtree(self._compilation_commands_path)
return error_code
self.log(logging.INFO, 'static-analysis', {}, "SUCCESS: clang-tidy all tests passed.")
# Also delete the tmp folder
@ -2118,42 +2128,45 @@ class StaticAnalysis(MachCommandBase):
cmd = self._get_clang_tidy_command(
checks='-*,' + check, header_filter='', sources=[test_file_path_cpp], jobs=1, fix=False)
clang_output = subprocess.check_output(
cmd, stderr=subprocess.STDOUT).decode('utf-8')
issues = self._parse_issues(clang_output)
# Verify to see if we got any issues, if not raise exception
if not issues:
self.log(
logging.ERROR, 'static-analysis', {},
"ERROR: clang-tidy checker {0} did not find any issues in it\'s associated test suite.".
format(check))
return self.CHECKER_RETURNED_NO_ISSUES
if self._dump_results:
self._build_autotest_result(test_file_path_json, issues)
try:
clang_output = subprocess.check_output(
cmd, stderr=subprocess.STDOUT).decode('utf-8')
except subprocess.CalledProcessError as e:
print(e.output)
return self.TOOLS_CHECKER_FAILED_FILE
else:
if not os.path.exists(test_file_path_json):
# Result file for test not found maybe regenerate it?
self.log(
logging.ERROR, 'static-analysis', {},
"ERROR: clang-tidy result file not found for checker {0}".format(
check))
return self.TOOLS_CHECKER_RESULT_FILE_NOT_FOUND
# Read the pre-determined issues
baseline_issues = self._get_autotest_stored_issues(test_file_path_json)
issues = self._parse_issues(clang_output)
# Compare the two lists
if issues != baseline_issues:
print("Clang output: {}".format(clang_output))
# Verify to see if we got any issues, if not raise exception
if not issues:
self.log(
logging.ERROR, 'static-analysis', {},
"ERROR: clang-tidy auto-test failed for checker {0} Expected: {1} Got: {2}".
format(check, baseline_issues, issues))
return self.TOOLS_CHECKER_DIFF_FAILED
return self.TOOLS_SUCCESS
"ERROR: clang-tidy checker {0} did not find any issues in its associated test file.".
format(check))
return self.CHECKER_RETURNED_NO_ISSUES
if self._dump_results:
self._build_autotest_result(test_file_path_json, issues)
else:
if not os.path.exists(test_file_path_json):
# Result file for test not found maybe regenerate it?
self.log(
logging.ERROR, 'static-analysis', {},
"ERROR: clang-tidy result file not found for checker {0}".format(
check))
return self.TOOLS_CHECKER_RESULT_FILE_NOT_FOUND
# Read the pre-determined issues
baseline_issues = self._get_autotest_stored_issues(test_file_path_json)
# Compare the two lists
if issues != baseline_issues:
print("Clang output: {}".format(clang_output))
self.log(
logging.ERROR, 'static-analysis', {},
"ERROR: clang-tidy auto-test failed for checker {0} Expected: {1} Got: {2}".
format(check, baseline_issues, issues))
return self.TOOLS_CHECKER_DIFF_FAILED
return self.TOOLS_SUCCESS
def _build_autotest_result(self, file, issues):
with open(file, 'w') as f: