Files
clang-p2996/lldb/test/API/android/platform/TestDefaultCacheLineSize.py
Raphael Isemann 54c2687292 [lldb] Introduce createTestTarget for creating a valid target in API tests
At the moment nearly every test calls something similar to
`self.dbg.CreateTarget(self.getBuildArtifact("a.out"))` and them sometimes
checks if the created target is actually valid with something like
`self.assertTrue(target.IsValid(), "some useless text")`.

Beside being really verbose the error messages generated by this pattern are
always just indicating that the target failed to be created but now why.

This patch introduces a helper function `createTestTarget` to our Test class
that creates the target with the much more verbose `CreateTarget` overload that
gives us back an SBError (with a fancy error). If the target couldn't be created
the function prints out the SBError that LLDB returned and asserts for us. It
also defaults to the "a.out" build artifact path that nearly all tests are using
to avoid to hardcode "a.out" in every test.

I converted a bunch of tests to the new function but I'll do the rest of the
test suite as follow ups.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D102771
2021-05-24 16:18:44 +02:00

45 lines
1.3 KiB
Python

"""
Verify the default cache line size for android targets
"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class DefaultCacheLineSizeTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
@skipUnlessTargetAndroid
def test_cache_line_size(self):
self.build(dictionary=self.getBuildFlags())
target = self.createTestTarget()
self.assertTrue(target and target.IsValid(), "Target is valid")
breakpoint = target.BreakpointCreateByName("main")
self.assertTrue(
breakpoint and breakpoint.IsValid(),
"Breakpoint is valid")
# Run the program.
process = target.LaunchSimple(
None, None, self.get_process_working_directory())
self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID)
self.assertEqual(
process.GetState(),
lldb.eStateStopped,
PROCESS_STOPPED)
# check the setting value
self.expect(
"settings show target.process.memory-cache-line-size",
patterns=[" = 2048"])
# Run to completion.
process.Continue()
self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)