From 2bce8b9d1ba519bcd7f25aab22de8dbfacc384e4 Mon Sep 17 00:00:00 2001 From: Bastien Abadie Date: Mon, 20 May 2019 09:11:07 +0200 Subject: [PATCH 1/3] staticanalysis/bot: Add an option to disable zero coverage analyzer, fixes #2109. --- src/staticanalysis/bot/static_analysis_bot/cli.py | 3 ++- src/staticanalysis/bot/static_analysis_bot/workflow.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/staticanalysis/bot/static_analysis_bot/cli.py b/src/staticanalysis/bot/static_analysis_bot/cli.py index fd5c92d65d..e0351f10e3 100644 --- a/src/staticanalysis/bot/static_analysis_bot/cli.py +++ b/src/staticanalysis/bot/static_analysis_bot/cli.py @@ -43,6 +43,7 @@ def main(taskcluster_secret, 'APP_CHANNEL': 'development', 'REPORTERS': [], 'PUBLICATION': 'IN_PATCH', + 'ZERO_COVERAGE_ENABLED': True, 'ALLOWED_PATHS': ['*', ], }, taskcluster_client_id=taskcluster_client_id, @@ -106,7 +107,7 @@ def main(taskcluster_secret, ) # Run workflow according to source - w = Workflow(reporters, index_service, queue_service, phabricator_api) + w = Workflow(reporters, index_service, queue_service, phabricator_api, secrets['ZERO_COVERAGE_ENABLED']) try: w.run(revision) except Exception as e: diff --git a/src/staticanalysis/bot/static_analysis_bot/workflow.py b/src/staticanalysis/bot/static_analysis_bot/workflow.py index b6880b58ea..f6eb385666 100644 --- a/src/staticanalysis/bot/static_analysis_bot/workflow.py +++ b/src/staticanalysis/bot/static_analysis_bot/workflow.py @@ -35,11 +35,12 @@ class Workflow(object): - find issues from remote tasks - publish issues ''' - def __init__(self, reporters, index_service, queue_service, phabricator_api): + def __init__(self, reporters, index_service, queue_service, phabricator_api, zero_coverage_enabled=True): assert settings.try_task_id is not None, \ 'Cannot run without Try task id' assert settings.try_group_id is not None, \ 'Cannot run without Try task id' + self.zero_coverage_enabled = zero_coverage_enabled # Use share phabricator API client assert isinstance(phabricator_api, PhabricatorAPI) @@ -213,7 +214,8 @@ def _in_group(dep_id): return [] # Add zero-coverage task - dependencies.append(ZeroCoverageTask) + if self.zero_coverage_enabled: + dependencies.append(ZeroCoverageTask) # Find issues and patches in dependencies issues = [] From 2034242f944f0f1f4c71d4397fd2295d0d9872ca Mon Sep 17 00:00:00 2001 From: Bastien Abadie Date: Mon, 20 May 2019 09:17:12 +0200 Subject: [PATCH 2/3] staticanalysis/bot: Add unit tests --- src/staticanalysis/bot/tests/conftest.py | 1 + src/staticanalysis/bot/tests/test_remote.py | 45 +++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/staticanalysis/bot/tests/conftest.py b/src/staticanalysis/bot/tests/conftest.py index 4a33adb556..1d4e0f0413 100644 --- a/src/staticanalysis/bot/tests/conftest.py +++ b/src/staticanalysis/bot/tests/conftest.py @@ -277,6 +277,7 @@ def __init__(self): self.phabricator_api = None self.index_service = MockIndex() self.queue_service = MockQueue() + self.zero_coverage_enabled = True def setup_mock_tasks(self, tasks): ''' diff --git a/src/staticanalysis/bot/tests/test_remote.py b/src/staticanalysis/bot/tests/test_remote.py index 7655e78b48..8c50df8c5e 100644 --- a/src/staticanalysis/bot/tests/test_remote.py +++ b/src/staticanalysis/bot/tests/test_remote.py @@ -677,3 +677,48 @@ def test_no_tasks(mock_config, mock_revision, mock_workflow): }) issues = mock_workflow.run(mock_revision) assert len(issues) == 0 + + +def test_zero_coverage_option(mock_config, mock_revision, mock_workflow): + ''' + Test a normal remote workflow (aka Try mode) + - current task with analyzer deps + - an analyzer in failed status + - with some issues in its log + ''' + from static_analysis_bot.tasks.coverage import CoverageIssue + + mock_workflow.setup_mock_tasks({ + 'decision': { + 'image': 'taskcluster/decision:XXX', + 'env': { + 'GECKO_HEAD_REPOSITORY': 'https://hg.mozilla.org/try', + 'GECKO_HEAD_REV': 'deadbeef1234', + } + }, + 'remoteTryTask': { + 'dependencies': ['xxx'] + }, + 'zero-cov': { + 'route': 'project.releng.services.project.production.code_coverage_bot.latest', + 'artifacts': { + 'public/zero_coverage_report.json': { + 'files': [ + { + 'uncovered': True, + 'name': 'test.cpp', + } + ], + }, + } + }, + }) + + mock_workflow.zero_coverage_enabled = False + issues = mock_workflow.run(mock_revision) + assert len(issues) == 0 + + mock_workflow.zero_coverage_enabled = True + issues = mock_workflow.run(mock_revision) + assert len(issues) == 1 + assert isinstance(issues[0], CoverageIssue) From 991959022f3bd14c9a97434d22142e562f23a980 Mon Sep 17 00:00:00 2001 From: Bastien Abadie Date: Mon, 20 May 2019 09:20:06 +0200 Subject: [PATCH 3/3] Update comment --- src/staticanalysis/bot/tests/test_remote.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/staticanalysis/bot/tests/test_remote.py b/src/staticanalysis/bot/tests/test_remote.py index 8c50df8c5e..9cd66fc69e 100644 --- a/src/staticanalysis/bot/tests/test_remote.py +++ b/src/staticanalysis/bot/tests/test_remote.py @@ -681,10 +681,7 @@ def test_no_tasks(mock_config, mock_revision, mock_workflow): def test_zero_coverage_option(mock_config, mock_revision, mock_workflow): ''' - Test a normal remote workflow (aka Try mode) - - current task with analyzer deps - - an analyzer in failed status - - with some issues in its log + Test the zero coverage trigger on the workflow ''' from static_analysis_bot.tasks.coverage import CoverageIssue