aboutsummaryrefslogtreecommitdiff
path: root/lldb/packages/Python/lldbsuite/test/lldbtest.py
diff options
context:
space:
mode:
authorJordan Rupprecht <rupprecht@google.com>2023-11-15 17:51:25 -0800
committerGitHub <noreply@github.com>2023-11-15 17:51:25 -0800
commit212a60ec37322f853e91e171b305479b1abff2f2 (patch)
tree95010c665b5e0bcb290de5c58448c6da48f7154f /lldb/packages/Python/lldbsuite/test/lldbtest.py
parent71a7108ee91a522251ff37638e26158570c1e2a5 (diff)
downloadllvm-212a60ec37322f853e91e171b305479b1abff2f2.zip
llvm-212a60ec37322f853e91e171b305479b1abff2f2.tar.gz
llvm-212a60ec37322f853e91e171b305479b1abff2f2.tar.bz2
[lldb][test] Remove `self` references from decorators (#72416)
This is partial step toward removing the vendored `unittest2` dep in favor of the `unittest` library in standard python. One of the large differences is when xfail decorators are evaluated. With the `unittest2` vendored dep, this can happen at the moment of calling the test case, and with LLDB's decorator wrappers, we are passed the test class in the decorator arg. With the `unittest` framework, this is determined much earlier; we cannot decide when the test is about to start that we need to xfail. Fortunately, almost none of these checks require any state that can't be determined statically. For this patch, I moved the impl for all the checks to `lldbplatformutil` and pointed the decorators to that, removing as many `self` (i.e. test class object) references as possible. I left wrappers within `TestBase` that forward to `lldbplatformutil` for convenience, but we should probably remove those later. The remaining check that can't be moved statically is the check for the debug info type (e.g. to xfail only for dwarf). Fixing that requires a different approach, so I will postpone that to the next patch.
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/lldbtest.py')
-rw-r--r--lldb/packages/Python/lldbsuite/test/lldbtest.py103
1 files changed, 9 insertions, 94 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 19ba0e8..dc4e322 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -29,7 +29,6 @@ $
# System modules
import abc
-from distutils.version import LooseVersion
from functools import wraps
import gc
import glob
@@ -58,7 +57,6 @@ from . import test_categories
from lldbsuite.support import encoded_file
from lldbsuite.support import funcutils
from lldbsuite.support import seven
-from lldbsuite.test.builders import get_builder
from lldbsuite.test_event import build_exception
# See also dotest.parseOptionsAndInitTestdirs(), where the environment variables
@@ -516,7 +514,7 @@ def getsource_if_available(obj):
def builder_module():
- return get_builder(sys.platform)
+ return lldbplatformutil.builder_module()
class Base(unittest2.TestCase):
@@ -1310,82 +1308,29 @@ class Base(unittest2.TestCase):
def getArchitecture(self):
"""Returns the architecture in effect the test suite is running with."""
- module = builder_module()
- arch = module.getArchitecture()
- if arch == "amd64":
- arch = "x86_64"
- if arch in ["armv7l", "armv8l"]:
- arch = "arm"
- return arch
+ return lldbplatformutil.getArchitecture()
def getLldbArchitecture(self):
"""Returns the architecture of the lldb binary."""
- if not hasattr(self, "lldbArchitecture"):
- # These two target settings prevent lldb from doing setup that does
- # nothing but slow down the end goal of printing the architecture.
- command = [
- lldbtest_config.lldbExec,
- "-x",
- "-b",
- "-o",
- "settings set target.preload-symbols false",
- "-o",
- "settings set target.load-script-from-symbol-file false",
- "-o",
- "file " + lldbtest_config.lldbExec,
- ]
-
- output = check_output(command)
- str = output.decode()
-
- for line in str.splitlines():
- m = re.search(r"Current executable set to '.*' \((.*)\)\.", line)
- if m:
- self.lldbArchitecture = m.group(1)
- break
-
- return self.lldbArchitecture
+ return lldbplatformutil.getLLDBArchitecture()
def getCompiler(self):
"""Returns the compiler in effect the test suite is running with."""
- module = builder_module()
- return module.getCompiler()
+ return lldbplatformutil.getCompiler()
def getCompilerBinary(self):
"""Returns the compiler binary the test suite is running with."""
- return self.getCompiler().split()[0]
+ return lldbplatformutil.getCompilerBinary()
def getCompilerVersion(self):
"""Returns a string that represents the compiler version.
Supports: llvm, clang.
"""
- compiler = self.getCompilerBinary()
- version_output = check_output([compiler, "--version"], errors="replace")
- m = re.search("version ([0-9.]+)", version_output)
- if m:
- return m.group(1)
- return "unknown"
+ return lldbplatformutil.getCompilerVersion()
def getDwarfVersion(self):
"""Returns the dwarf version generated by clang or '0'."""
- if configuration.dwarf_version:
- return str(configuration.dwarf_version)
- if "clang" in self.getCompiler():
- try:
- triple = builder_module().getTriple(self.getArchitecture())
- target = ["-target", triple] if triple else []
- driver_output = check_output(
- [self.getCompiler()] + target + "-g -c -x c - -o - -###".split(),
- stderr=STDOUT,
- )
- driver_output = driver_output.decode("utf-8")
- for line in driver_output.split(os.linesep):
- m = re.search("dwarf-version=([0-9])", line)
- if m:
- return m.group(1)
- except CalledProcessError:
- pass
- return "0"
+ return lldbplatformutil.getDwarfVersion()
def platformIsDarwin(self):
"""Returns true if the OS triple for the selected platform is any valid apple OS"""
@@ -1412,41 +1357,11 @@ class Base(unittest2.TestCase):
of trunk, so any less-than or equal-to comparisons will return False, and any
greater-than or not-equal-to comparisons will return True.
"""
- if compiler_version is None:
- return True
- operator = str(compiler_version[0])
- version = compiler_version[1]
-
- if version is None:
- return True
-
- test_compiler_version = self.getCompilerVersion()
- if test_compiler_version == "unknown":
- # Assume the compiler version is at or near the top of trunk.
- return operator in [">", ">=", "!", "!=", "not"]
-
- if operator == ">":
- return LooseVersion(test_compiler_version) > LooseVersion(version)
- if operator == ">=" or operator == "=>":
- return LooseVersion(test_compiler_version) >= LooseVersion(version)
- if operator == "<":
- return LooseVersion(test_compiler_version) < LooseVersion(version)
- if operator == "<=" or operator == "=<":
- return LooseVersion(test_compiler_version) <= LooseVersion(version)
- if operator == "!=" or operator == "!" or operator == "not":
- return str(version) not in str(test_compiler_version)
- return str(version) in str(test_compiler_version)
+ return lldbplatformutil.expectedCompilerVersion(compiler_version)
def expectedCompiler(self, compilers):
"""Returns True iff any element of compilers is a sub-string of the current compiler."""
- if compilers is None:
- return True
-
- for compiler in compilers:
- if compiler in self.getCompiler():
- return True
-
- return False
+ return lldbplatformutil.expectedCompiler(compilers)
def expectedArch(self, archs):
"""Returns True iff any element of archs is a sub-string of the current architecture."""