From d452561dcf7425e746f5ad8eb0b37d49b8e33910 Mon Sep 17 00:00:00 2001 From: Gabor Marton Date: Wed, 17 Jan 2018 11:28:49 +0100 Subject: [PATCH] Add better diagnostics for ctu tests in case of failure --- .../ctu/ctu_failure/test_ctu_failure.py | 7 ++----- tests/functional/ctu/test_ctu.py | 21 +++++++------------ tests/libtest/codechecker.py | 2 +- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/tests/functional/ctu/ctu_failure/test_ctu_failure.py b/tests/functional/ctu/ctu_failure/test_ctu_failure.py index 4412df7193..d2c33d4e93 100644 --- a/tests/functional/ctu/ctu_failure/test_ctu_failure.py +++ b/tests/functional/ctu/ctu_failure/test_ctu_failure.py @@ -9,7 +9,6 @@ import json import os import shutil -import subprocess import unittest import zipfile @@ -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)) @@ -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"] diff --git a/tests/functional/ctu/test_ctu.py b/tests/functional/ctu/test_ctu.py index ad38289961..dbd1bf8830 100644 --- a/tests/functional/ctu/test_ctu.py +++ b/tests/functional/ctu/test_ctu.py @@ -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" @@ -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)) @@ -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. """ @@ -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. """ @@ -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. """ @@ -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) diff --git a/tests/libtest/codechecker.py b/tests/libtest/codechecker.py index 90d273fbbf..44622cbd24 100644 --- a/tests/libtest/codechecker.py +++ b/tests/libtest/codechecker.py @@ -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,