Skip to content

Commit

Permalink
[test] Environment variable on forcing ctu related tests
Browse files Browse the repository at this point in the history
CTU related tests should be forced in an environment which contains
an underlying Clang that supports this feature. Automatic detection
is not enough because there may be a bug in the automatic
detection itself.
  • Loading branch information
csordasmarton committed Apr 7, 2022
1 parent 999ffda commit 1f6546e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
7 changes: 4 additions & 3 deletions analyzer/tests/functional/ctu/test_ctu.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from typing import IO

from libtest import env
from libtest.codechecker import call_command
from libtest.codechecker import call_command, is_ctu_capable, \
is_ctu_on_demand_capable
from libtest.ctu_decorators import makeSkipUnlessCTUCapable, \
makeSkipUnlessCTUOnDemandCapable

Expand Down Expand Up @@ -53,11 +54,11 @@ def setUp(self):
cmd = [self._codechecker_cmd, 'analyze', '-h']
output, _, result = call_command(cmd, cwd=self.test_dir, env=self.env)
self.assertEqual(result, 0, "Analyzing failed.")
setattr(self, CTU_ATTR, '--ctu-' in output)
setattr(self, CTU_ATTR, is_ctu_capable(output))
print("'analyze' reported CTU-compatibility? " +
str(getattr(self, CTU_ATTR)))

setattr(self, ON_DEMAND_ATTR, '--ctu-ast-mode' in output)
setattr(self, ON_DEMAND_ATTR, is_ctu_on_demand_capable(output))
print("'analyze' reported CTU-on-demand-compatibility? " +
str(getattr(self, ON_DEMAND_ATTR)))

Expand Down
13 changes: 6 additions & 7 deletions analyzer/tests/functional/ctu_failure/test_ctu_failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
import unittest
import zipfile

from codechecker_analyzer import host_check

from libtest import env
from libtest import project
from libtest.codechecker import call_command
from libtest.codechecker import call_command, is_ctu_capable, \
is_ctu_on_demand_capable, is_ctu_display_progress_capable
from libtest.ctu_decorators import makeSkipUnlessCTUCapable, \
makeSkipUnlessCTUOnDemandCapable, makeSkipUnlessCTUDisplayCapable

Expand Down Expand Up @@ -57,17 +56,17 @@ def setUp(self):
output, _, result = call_command(cmd, cwd=self.test_workspace,
env=self.env)
self.assertEqual(result, 0, "Analyzing failed.")
setattr(self, CTU_ATTR, '--ctu-' in output)
setattr(self, CTU_ATTR, is_ctu_capable(output))
print("'analyze' reported CTU compatibility? " +
str(getattr(self, CTU_ATTR)))

setattr(self, ON_DEMAND_ATTR, '--ctu-ast-mode' in output)
setattr(self, ON_DEMAND_ATTR, is_ctu_on_demand_capable(output))
print("'analyze' reported CTU-on-demand-compatibility? " +
str(getattr(self, ON_DEMAND_ATTR)))

setattr(self, DISPLAY_PROGRESS_ATTR,
host_check.has_analyzer_config_option(
self.__getClangSaPath(), 'display-ctu-progress', self.env))
is_ctu_display_progress_capable(
self.__getClangSaPath(), self.env))

print("Has display-ctu-progress=true? " +
str(getattr(self, DISPLAY_PROGRESS_ATTR)))
Expand Down
50 changes: 50 additions & 0 deletions analyzer/tests/libtest/codechecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
import shlex
import subprocess

from distutils import util
from typing import Dict

from codechecker_analyzer import host_check

from . import project


Expand Down Expand Up @@ -120,3 +125,48 @@ def log_and_analyze(codechecker_cfg, test_project_path, clean_project=True):
except subprocess.CalledProcessError as cerr:
print("Failed to call:\n" + ' '.join(cerr.cmd))
return cerr.returncode


def check_force_ctu_capable(is_capable):
"""
Returns True if the given parameter is True of if CTU is force enabled by
the 'CC_TEST_FORCE_CTU_CAPABLE' environment variable.
"""
if not is_capable:
try:
return bool(util.strtobool(
os.environ['CC_TEST_FORCE_CTU_CAPABLE']))
except (ValueError, KeyError):
pass

return is_capable


def is_ctu_capable(output: str) -> bool:
"""
Returns True if the used clang is CTU capable or if it's force enabled by
environment variable.
"""
return check_force_ctu_capable('--ctu' in output)


def is_ctu_on_demand_capable(output: str) -> bool:
"""
Returns True if the used clang is CTU on demand capable or if it's force
enabled by environment variable.
"""
return check_force_ctu_capable('--ctu-ast-mode' in output)


def is_ctu_display_progress_capable(
clangsa_path: str,
env: Dict
) -> bool:
"""
Returns True if the used clang is CTU display progress capable or if it's
force enabled by environment variable.
"""
ctu_display_progress_capable = host_check.has_analyzer_config_option(
clangsa_path, 'display-ctu-progress', env)

return check_force_ctu_capable(ctu_display_progress_capable)

0 comments on commit 1f6546e

Please sign in to comment.