This is an archive of the discontinued LLVM Phabricator instance.

[lldb] [test] Add unittest for DynamicRegisterInfo::Finalize()
ClosedPublic

Authored by mgorny on Sep 16 2021, 11:53 AM.

Diff Detail

Event Timeline

mgorny requested review of this revision.Sep 16 2021, 11:53 AM
mgorny created this revision.
mgorny updated this revision to Diff 373410.Sep 18 2021, 5:49 AM

Add a helper function. Test the weird invalidate_regs expansion logic.

mgorny updated this revision to Diff 373411.Sep 18 2021, 5:53 AM

Eliminate unused vars.

labath accepted this revision.Sep 20 2021, 12:01 AM
labath added inline comments.
lldb/unittests/Process/Utility/DynamicRegisterInfoTest.cpp
24

It would be better to create a fixture class, and make this a member variable of that class. If this ends up used from two tests, it will begin returning different values depending on the order of tests, whether they are run standalone, etc.

This revision is now accepted and ready to land.Sep 20 2021, 12:01 AM
mgorny marked an inline comment as done.Sep 20 2021, 12:46 AM

Made fixture class. Now you made me think of adding a helper method to test register properties too.

mgorny updated this revision to Diff 373506.Sep 20 2021, 1:23 AM

Create a helper class and move adding regs there. Add a helper function to assert on registers.

mgorny updated this revision to Diff 373509.Sep 20 2021, 1:27 AM

Test for register name too.

In general, I'd prefer to avoid adding new methods to the class under test, and save subclassing for the cases where it's impossible to do things otherwise (abstract class, visibility restrictions (although that often means you're not testing what you should be)). These things could live inside an gtest fixture (subclass of testing::Test), which could have a DynamicRegisterInfo member if needed.

lldb/unittests/Process/Utility/DynamicRegisterInfoTest.cpp
52–53

Maybe use SCOPED_TRACE instead?

62–94

I'd probably write a helper function to convert the register lists to a vector, and then have gtest compare the vectors:

std::vector<uint32_t> to_vector(uint32_t *regs) {
  std::vector<uint32_t> result;
  if (regs) {
    while(*regs != LLDB_INVALID_REGNUM)
      result.push_back(*regs++);
  }
  return result;
}
...
ASSERT_THAT(to_vector(info->value_regs), value_regs);
mgorny updated this revision to Diff 373524.Sep 20 2021, 2:19 AM
mgorny marked 2 inline comments as done.

Implemented all the suggested improvements.

labath accepted this revision.Sep 20 2021, 5:11 AM
This revision was landed with ongoing or failed builds.Sep 20 2021, 6:03 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 20 2021, 6:03 AM