TestingRegistry();
};
-static llvm::Optional<Serializer> g_serializer;
static llvm::Optional<TestingRegistry> g_registry;
+static llvm::Optional<Serializer> g_serializer;
+
+inline InstrumentationData GetTestInstrumentationData() {
+ if (g_serializer)
+ return InstrumentationData(*g_serializer, *g_registry);
+ return InstrumentationData();
+}
+
+class TestInstrumentationDataRAII {
+public:
+ TestInstrumentationDataRAII(llvm::raw_string_ostream &os) {
+ g_registry.emplace();
+ g_serializer.emplace(os);
+ }
+
+ ~TestInstrumentationDataRAII() {
+ g_registry.reset();
+ g_serializer.reset();
+ }
+};
-#define LLDB_GET_INSTRUMENTATION_DATA() \
- g_serializer ? InstrumentationData(*g_serializer, *g_registry) \
- : InstrumentationData()
+#define LLDB_GET_INSTRUMENTATION_DATA() GetTestInstrumentationData()
enum class Class {
Foo,
double InstrumentedFoo::g_e = 0;
bool InstrumentedFoo::g_f = false;
-void ClearObjects() {
- g_registry.reset();
- g_serializer.reset();
-}
-
struct Validator {
enum Validation { valid, invalid };
Validator(Class clazz, Validation validation)
TEST(RecordReplayTest, InstrumentedFoo) {
std::string str;
llvm::raw_string_ostream os(str);
- g_registry.emplace();
- g_serializer.emplace(os);
{
+ TestInstrumentationDataRAII data(os);
+
int b = 200;
float c = 300.3f;
double e = 400.4;
foo.Validate();
}
- ClearObjects();
-
TestingRegistry registry;
Deserializer deserializer(os.str());
registry.Replay(deserializer);
TEST(RecordReplayTest, InstrumentedFooSameThis) {
std::string str;
llvm::raw_string_ostream os(str);
- g_registry.emplace();
- g_serializer.emplace(os);
- int b = 200;
- float c = 300.3f;
- double e = 400.4;
+ {
+ TestInstrumentationDataRAII data(os);
- InstrumentedFoo *foo = new InstrumentedFoo(0);
- foo->A(100);
- foo->B(b);
- foo->C(&c);
- foo->D("bar");
- InstrumentedFoo::E(e);
- InstrumentedFoo::F();
- foo->Validate();
- foo->~InstrumentedFoo();
-
- InstrumentedFoo *foo2 = new (foo) InstrumentedFoo(0);
- foo2->A(100);
- foo2->B(b);
- foo2->C(&c);
- foo2->D("bar");
- InstrumentedFoo::E(e);
- InstrumentedFoo::F();
- foo2->Validate();
- delete foo2;
-
- ClearObjects();
+ int b = 200;
+ float c = 300.3f;
+ double e = 400.4;
+
+ InstrumentedFoo *foo = new InstrumentedFoo(0);
+ foo->A(100);
+ foo->B(b);
+ foo->C(&c);
+ foo->D("bar");
+ InstrumentedFoo::E(e);
+ InstrumentedFoo::F();
+ foo->Validate();
+ foo->~InstrumentedFoo();
+
+ InstrumentedFoo *foo2 = new (foo) InstrumentedFoo(0);
+ foo2->A(100);
+ foo2->B(b);
+ foo2->C(&c);
+ foo2->D("bar");
+ InstrumentedFoo::E(e);
+ InstrumentedFoo::F();
+ foo2->Validate();
+ delete foo2;
+ }
TestingRegistry registry;
Deserializer deserializer(os.str());
TEST(RecordReplayTest, InstrumentedBar) {
std::string str;
llvm::raw_string_ostream os(str);
- g_registry.emplace();
- g_serializer.emplace(os);
{
+ TestInstrumentationDataRAII data(os);
+
InstrumentedBar bar;
InstrumentedFoo foo = bar.GetInstrumentedFoo();
bar.Validate();
}
- ClearObjects();
-
TestingRegistry registry;
Deserializer deserializer(os.str());
registry.Replay(deserializer);
TEST(RecordReplayTest, InstrumentedBarRef) {
std::string str;
llvm::raw_string_ostream os(str);
- g_registry.emplace();
- g_serializer.emplace(os);
{
+ TestInstrumentationDataRAII data(os);
+
InstrumentedBar bar;
InstrumentedFoo &foo = bar.GetInstrumentedFooRef();
bar.Validate();
}
- ClearObjects();
-
TestingRegistry registry;
Deserializer deserializer(os.str());
registry.Replay(deserializer);
TEST(RecordReplayTest, InstrumentedBarPtr) {
std::string str;
llvm::raw_string_ostream os(str);
- g_registry.emplace();
- g_serializer.emplace(os);
{
+ TestInstrumentationDataRAII data(os);
+
InstrumentedBar bar;
InstrumentedFoo &foo = *(bar.GetInstrumentedFooPtr());
bar.Validate();
}
- ClearObjects();
-
TestingRegistry registry;
Deserializer deserializer(os.str());
registry.Replay(deserializer);