[lldb/Test] Rewrite ReproducerInstrumentationTest
The instrumentation unit tests' current implementation uses global
variables to track constructor calls for the instrumented classes during
replay. This is suboptimal because it indirectly relies on how the
reproducer instrumentation is implemented. I found out when adding
support for passive replay and the test broke because we made an extra
(temporary) copy of the instrumented objects.
Additionally, the old approach wasn't very self-explanatory. It took me
a bit of time to understand why we were expecting the number of objects
in the test.
This patch rewrites the test and uses the index-to-object-mapping to
verify the objects created during replay. You can now specify the
expected objects, in order, and whether they should be valid or not. I
find that it makes the tests much easier to understand. More
importantly, this approach is resilient to implementation detail changes
in the instrumentation.
diff --git a/lldb/include/lldb/Utility/ReproducerInstrumentation.h b/lldb/include/lldb/Utility/ReproducerInstrumentation.h
index 2246267..1eae930 100644
--- a/lldb/include/lldb/Utility/ReproducerInstrumentation.h
+++ b/lldb/include/lldb/Utility/ReproducerInstrumentation.h
@@ -255,6 +255,9 @@
const_cast<typename std::remove_const<T>::type *>(&object)));
}
+ /// Get all objects sorted by their index.
+ std::vector<void *> GetAllObjects() const;
+
private:
/// Helper method that does the actual lookup. The void* result is later cast
/// by the caller.
@@ -345,6 +348,10 @@
(void)result;
}
+ std::vector<void *> GetAllObjects() const {
+ return m_index_to_object.GetAllObjects();
+ }
+
private:
template <typename T> T Read(ValueTag) {
assert(HasData(sizeof(T)));
@@ -512,6 +519,9 @@
/// Replay functions from a buffer.
bool Replay(llvm::StringRef buffer);
+ /// Replay functions from a deserializer.
+ bool Replay(Deserializer &deserializer);
+
/// Returns the ID for a given function address.
unsigned GetID(uintptr_t addr);