This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Introduce createTestTarget for creating a valid target in API tests
ClosedPublic

Authored by teemperor on May 19 2021, 6:45 AM.

Details

Summary

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.

Diff Detail

Event Timeline

teemperor requested review of this revision.May 19 2021, 6:45 AM
teemperor created this revision.
teemperor updated this revision to Diff 346444.May 19 2021, 6:47 AM
  • Made test stricter.

(This isn't really NFC as this now tests that we always return an SBError when we fail to create a target).

Good idea! I had a test failing to create a target just this morning.

AssertionError: <lldb.SBTarget; proxy of <Swig Object of type 'lldb::SBTarget *' at 0x7f98113702a0> > is not True : Got a valid target

Bit of a head scratcher with the inverted assert message. This will be a lot more helpful.

lldb/test/API/assert_messages_test/TestAssertMessages.py
31

You can ommit the + here.

JDevlieghere accepted this revision.May 19 2021, 9:32 AM

Great improvement. Could you add this to the TestSampleTest.py as well? I think it's used a lot as a starting point and thus would help with discoverability.

This revision is now accepted and ready to land.May 19 2021, 9:32 AM
This revision was landed with ongoing or failed builds.May 24 2021, 7:19 AM
This revision was automatically updated to reflect the committed changes.