From 5b1e31892230933c6cb23048d9e995d1a81d86fd Mon Sep 17 00:00:00 2001 From: bruntib Date: Fri, 6 May 2022 16:50:05 +0200 Subject: [PATCH] [cmd] Get failed files with "CodeChecker cmd runs" CodeChecker cmd runs is added `--details` flag which extends JSON output with the list of files that are failed to analyze. --- docs/web/user_guide.md | 3 +++ web/client/codechecker_client/cmd/cmd.py | 8 ++++++ .../codechecker_client/cmd_line_client.py | 3 +++ .../codechecker_client/helpers/results.py | 4 +++ .../codechecker_server/api/report_server.py | 2 +- web/tests/functional/cmdline/test_cmdline.py | 27 +++++++++++++++++++ 6 files changed, 46 insertions(+), 1 deletion(-) diff --git a/docs/web/user_guide.md b/docs/web/user_guide.md index 277c43cb75..b52dcb04fa 100644 --- a/docs/web/user_guide.md +++ b/docs/web/user_guide.md @@ -912,6 +912,9 @@ optional arguments: you have run_1_a_name, run_2_b_name, run_2_c_name, run_3_d_name then "run_2* run_3_d_name" shows the last three runs. + --details Adds extra details to the run information in JSON + format, such as the list of files that are failed to + analyze. --all-before-run RUN_NAME Get all runs that were stored to the server BEFORE the specified one. diff --git a/web/client/codechecker_client/cmd/cmd.py b/web/client/codechecker_client/cmd/cmd.py index 86967cc603..cea7d1a305 100644 --- a/web/client/codechecker_client/cmd/cmd.py +++ b/web/client/codechecker_client/cmd/cmd.py @@ -1085,6 +1085,14 @@ def __register_runs(parser): "run_2_c_name, run_3_d_name then \"run_2* " "run_3_d_name\" shows the last three runs.") + group.add_argument('--details', + default=argparse.SUPPRESS, + action='store_true', + required=False, + help="Adds extra details to the run information in " + "JSON format, such as the list of files that are " + "failed to analyze.") + group.add_argument('--all-before-run', type=str, dest="all_before_run", diff --git a/web/client/codechecker_client/cmd_line_client.py b/web/client/codechecker_client/cmd_line_client.py index 769a579477..b153c54dae 100644 --- a/web/client/codechecker_client/cmd_line_client.py +++ b/web/client/codechecker_client/cmd_line_client.py @@ -628,6 +628,9 @@ def handle_list_runs(args): # to a json format. results = [] for run in runs: + if 'details' in args and args.details: + run.analyzerStatistics = \ + client.getAnalysisStatistics(run.runId, None) results.append({run.name: run}) print(CmdLineOutputEncoder().encode(results)) diff --git a/web/client/codechecker_client/helpers/results.py b/web/client/codechecker_client/helpers/results.py index f33f855a0a..a659482fa9 100644 --- a/web/client/codechecker_client/helpers/results.py +++ b/web/client/codechecker_client/helpers/results.py @@ -178,6 +178,10 @@ def allowsStoringAnalysisStatistics(self): def getAnalysisStatisticsLimits(self): pass + @ThriftClientCall + def getAnalysisStatistics(self, run_id, run_history_id): + pass + @ThriftClientCall def storeAnalysisStatistics(self, run_name, zip_file): pass diff --git a/web/server/codechecker_server/api/report_server.py b/web/server/codechecker_server/api/report_server.py index ae71e22ba8..ba0cd26180 100644 --- a/web/server/codechecker_server/api/report_server.py +++ b/web/server/codechecker_server/api/report_server.py @@ -3107,7 +3107,7 @@ def getAnalysisStatistics(self, run_id, run_history_id): for stat, run_id in query: failed_files = zlib.decompress(stat.failed_files).decode( - 'utf-8').split('\n') if stat.failed_files else None + 'utf-8').split('\n') if stat.failed_files else [] analyzer_version = zlib.decompress( stat.version).decode('utf-8') if stat.version else None diff --git a/web/tests/functional/cmdline/test_cmdline.py b/web/tests/functional/cmdline/test_cmdline.py index 96c38f1c20..9d64c1afe9 100644 --- a/web/tests/functional/cmdline/test_cmdline.py +++ b/web/tests/functional/cmdline/test_cmdline.py @@ -123,6 +123,33 @@ def test_runs_filter(self): self.assertEqual(0, ret) self.assertEqual(1, len(json.loads(res))) + def test_runs_analysis_statistics(self): + """ Test analysis statistics in detailed mode. """ + + env = self._test_config['codechecker_cfg']['check_env'] + + res_cmd = [self._codechecker_cmd, 'cmd', 'runs', + '-o', 'json', '--url', str(self.server_url)] + ret, res, _ = run_cmd(res_cmd, env=env) + + self.assertEqual(0, ret) + for run in json.loads(res): + for data in run.values(): + self.assertIsNone( + data['analyzerStatistics']['clangsa']['failedFilePaths']) + + res_cmd = [self._codechecker_cmd, 'cmd', 'runs', + '-o', 'json', '--url', str(self.server_url), + '--details'] + ret, res, _ = run_cmd(res_cmd, env=env) + + self.assertEqual(0, ret) + for run in json.loads(res): + for data in run.values(): + self.assertEqual( + data['analyzerStatistics']['clangsa']['failedFilePaths'], + []) + def test_proxy_settings(self): """ Test proxy settings validation. """ server_url = f"{self.codechecker_cfg['viewer_host']}:" \