This changes Python API tests to use a single build shared across all test functions, instead of the previous default behavior of a separate build dir for each test function. This build behavior opt-out, tests can use the previous behavior of one individual (unshared) build directory per test function, by setting `SHARED_BUILD_TESTCASE` to False (in the test class). The motivation is to make the test suite more efficient, by not repeatedly building the same test source. When running tests on my macOS machine, this reduces the time of `ninja check-lldb-api` by almost 60% (sample numbers: from ~492s down to ~207s = 58%). Almost 5min time saved. Each test function still calls `self.build()`, but only the first call will do a build, in the subsequent tests `make` will be a no-op because the sources won't have changed.
37 lines
1003 B
Python
37 lines
1003 B
Python
"""
|
|
Test TestBase test functions.
|
|
"""
|
|
|
|
import io
|
|
|
|
from lldbsuite.test.lldbtest import *
|
|
from lldbsuite.test_event import build_exception
|
|
|
|
|
|
class TestBuildMethod(Base):
|
|
SHARED_BUILD_TESTCASE = False
|
|
|
|
def setUp(self):
|
|
super().setUp()
|
|
self._traces = []
|
|
self.traceAlways = True
|
|
|
|
# override the parent trace method
|
|
def trace(self, *args, **kwargs):
|
|
buf = io.StringIO()
|
|
print(*args, file=buf, **kwargs)
|
|
self._traces.append(buf.getvalue())
|
|
|
|
def test_build_fails_helpfully(self):
|
|
try:
|
|
self.build(dictionary={"CXX_SOURCES": "nonexisting-file.cpp"})
|
|
except build_exception.BuildError as e:
|
|
self.assertIn("nonexisting-file.cpp", str(e))
|
|
else:
|
|
self.fail("BuildError not raised!")
|
|
|
|
def test_build_logs_traces(self):
|
|
self.build(dictionary={"CXX_SOURCES": "return0.cpp"})
|
|
self.assertIn("CXX_SOURCES", self._traces[0])
|
|
self.assertIn("return0.o", self._traces[1])
|