Skip to content

Commit

Permalink
Merge pull request #1298 from martong/better_ctu_test_output
Browse files Browse the repository at this point in the history
Add better diagnostics for ctu tests in case of failure
  • Loading branch information
gyorb authored Jan 17, 2018
2 parents d8a03a7 + d452561 commit 5b742a0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
7 changes: 2 additions & 5 deletions tests/functional/ctu/ctu_failure/test_ctu_failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import json
import os
import shutil
import subprocess
import unittest
import zipfile

Expand Down Expand Up @@ -46,8 +45,7 @@ def __set_up_test_dir(self, project_path):

# Get if clang is CTU-capable or not.
cmd = [self._codechecker_cmd, 'analyze', '-h']
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT,
cwd=self.test_dir, env=self.env)
output, _ = call_command(cmd, cwd=self.test_dir, env=self.env)
self.ctu_capable = '--ctu-' in output
print("'analyze' reported CTU-compatibility? " + str(self.ctu_capable))

Expand Down Expand Up @@ -211,8 +209,7 @@ def __do_ctu_all(self, reparse, extra_args=None):

def __getClangSaPath(self):
cmd = [self._codechecker_cmd, 'analyzers', '--details', '-o', 'json']
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT,
cwd=self.test_dir, env=self.env)
output, _ = call_command(cmd, cwd=self.test_dir, env=self.env)
json_data = json.loads(output)
if json_data[0]["name"] == "clangsa":
return json_data[0]["path"]
Expand Down
21 changes: 8 additions & 13 deletions tests/functional/ctu/test_ctu.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import json
import os
import shutil
import subprocess
import unittest

from libtest import env
from libtest.codechecker import call_command

NO_CTU_MESSAGE = "CTU is not supported"

Expand All @@ -39,8 +39,7 @@ def setUp(self):

# Get if clang is CTU-capable or not.
cmd = [self._codechecker_cmd, 'analyze', '-h']
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT,
cwd=self.test_dir, env=self.env)
output, _ = call_command(cmd, cwd=self.test_dir, env=self.env)
self.ctu_capable = '--ctu-' in output
print("'analyze' reported CTU-compatibility? " + str(self.ctu_capable))

Expand Down Expand Up @@ -125,9 +124,8 @@ def __do_ctu_all(self, reparse):
if reparse:
cmd.append('--ctu-on-the-fly')
cmd.append(self.buildlog)
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT,
cwd=self.test_dir, env=self.env)
return output
out, _ = call_command(cmd, cwd=self.test_dir, env=self.env)
return out

def __do_ctu_collect(self, reparse):
""" Execute CTU collect phase. """
Expand All @@ -137,8 +135,7 @@ def __do_ctu_collect(self, reparse):
if reparse:
cmd.append('--ctu-on-the-fly')
cmd.append(self.buildlog)
subprocess.check_output(cmd, stderr=subprocess.STDOUT,
cwd=self.test_dir, env=self.env)
call_command(cmd, cwd=self.test_dir, env=self.env)

def __check_ctu_collect(self, reparse):
""" Check artifacts of CTU collect phase. """
Expand All @@ -160,9 +157,8 @@ def __do_ctu_analyze(self, reparse):
if reparse:
cmd.append('--ctu-on-the-fly')
cmd.append(self.buildlog)
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT,
cwd=self.test_dir, env=self.env)
return output
out, _ = call_command(cmd, cwd=self.test_dir, env=self.env)
return out

def __check_ctu_analyze(self, output):
""" Check artifacts of CTU analyze phase. """
Expand All @@ -172,8 +168,7 @@ def __check_ctu_analyze(self, output):
self.assertIn("analyzed main.c successfully", output)

cmd = [self._codechecker_cmd, 'parse', self.report_dir]
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT,
cwd=self.test_dir, env=self.env)
output, _ = call_command(cmd, cwd=self.test_dir, env=self.env)
self.assertIn("no defects while analyzing lib.c", output)
self.assertIn("defect(s) while analyzing main.c", output)
self.assertIn("lib.c:3:", output)
Expand Down
2 changes: 1 addition & 1 deletion tests/libtest/codechecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def show(out, err):
print("\nTEST execute stdout:\n")
print(out.decode("utf-8"))
print("\nTEST execute stderr:\n")
print(out.decode("utf-8"))
print(err.decode("utf-8"))
try:
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
Expand Down

0 comments on commit 5b742a0

Please sign in to comment.