Skip to content

Commit fdd3dfb

Browse files
committed
Parameterized Test fixtures
1 parent f047650 commit fdd3dfb

12 files changed

+476
-226
lines changed

unittests/CppInterOp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(EXTRA_TEST_SOURCE_FILES Utils.cpp main.cpp)
1+
set(EXTRA_TEST_SOURCE_FILES Utils.cpp)
22

33
if (EMSCRIPTEN)
44
# So we create a html file, as well as the javascript file

unittests/CppInterOp/DynamicLibraryManagerTest.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ std::string GetExecutablePath(const char* Argv0) {
2020
return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
2121
}
2222

23-
TEST(DynamicLibraryManagerTest, Sanity) {
23+
class DynamicLibraryManagerTest : public ::testing::TestWithParam<TestUtils::TestConfig> {
24+
protected:
25+
void SetUp() override {
26+
TestUtils::current_config = GetParam();
27+
}
28+
};
29+
30+
TEST_P(DynamicLibraryManagerTest, Sanity) {
2431
#ifdef EMSCRIPTEN
2532
GTEST_SKIP() << "Test fails for Emscipten builds";
2633
#endif
@@ -67,7 +74,7 @@ TEST(DynamicLibraryManagerTest, Sanity) {
6774
// EXPECT_FALSE(Cpp::GetFunctionAddress("ret_zero"));
6875
}
6976

70-
TEST(DynamicLibraryManagerTest, BasicSymbolLookup) {
77+
TEST_P(DynamicLibraryManagerTest, BasicSymbolLookup) {
7178
#ifndef EMSCRIPTEN
7279
GTEST_SKIP() << "This test is only intended for Emscripten builds.";
7380
#else
@@ -92,3 +99,26 @@ TEST(DynamicLibraryManagerTest, BasicSymbolLookup) {
9299
auto Fn = reinterpret_cast<RetZeroFn>(Addr);
93100
EXPECT_EQ(Fn(), 0);
94101
}
102+
103+
#ifdef LLVM_BUILT_WITH_OOP_JIT
104+
INSTANTIATE_TEST_SUITE_P(
105+
AllJITModes,
106+
DynamicLibraryManagerTest,
107+
::testing::Values(
108+
TestUtils::TestConfig{false, "InProcessJIT"},
109+
TestUtils::TestConfig{true, "OutOfProcessJIT"}
110+
),
111+
[](const ::testing::TestParamInfo<TestUtils::TestConfig>& info) {
112+
return info.param.name;
113+
}
114+
);
115+
#else
116+
INSTANTIATE_TEST_SUITE_P(
117+
AllJITModes,
118+
DynamicLibraryManagerTest,
119+
::testing::Values(TestUtils::TestConfig{false, "InProcessJIT"}),
120+
[](const ::testing::TestParamInfo<TestUtils::TestConfig>& info) {
121+
return info.param.name;
122+
}
123+
);
124+
#endif

unittests/CppInterOp/EnumReflectionTest.cpp

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,14 @@ using namespace TestUtils;
1212
using namespace llvm;
1313
using namespace clang;
1414

15-
TEST(ScopeReflectionTest, IsEnumScope) {
16-
std::vector<Decl *> Decls, SubDecls;
17-
std::string code = R"(
18-
enum Switch {
19-
OFF,
20-
ON
21-
};
22-
23-
Switch s = Switch::OFF;
24-
25-
int i = Switch::ON;
26-
)";
27-
28-
GetAllTopLevelDecls(code, Decls);
29-
GetAllSubDecls(Decls[0], SubDecls);
30-
EXPECT_TRUE(Cpp::IsEnumScope(Decls[0]));
31-
EXPECT_FALSE(Cpp::IsEnumScope(Decls[1]));
32-
EXPECT_FALSE(Cpp::IsEnumScope(Decls[2]));
33-
EXPECT_FALSE(Cpp::IsEnumScope(SubDecls[0]));
34-
EXPECT_FALSE(Cpp::IsEnumScope(SubDecls[1]));
35-
}
36-
37-
TEST(ScopeReflectionTest, IsEnumConstant) {
38-
std::vector<Decl *> Decls, SubDecls;
39-
std::string code = R"(
40-
enum Switch {
41-
OFF,
42-
ON
43-
};
44-
45-
Switch s = Switch::OFF;
46-
47-
int i = Switch::ON;
48-
)";
49-
50-
GetAllTopLevelDecls(code, Decls);
51-
GetAllSubDecls(Decls[0], SubDecls);
52-
EXPECT_FALSE(Cpp::IsEnumConstant(Decls[0]));
53-
EXPECT_FALSE(Cpp::IsEnumConstant(Decls[1]));
54-
EXPECT_FALSE(Cpp::IsEnumConstant(Decls[2]));
55-
EXPECT_TRUE(Cpp::IsEnumConstant(SubDecls[0]));
56-
EXPECT_TRUE(Cpp::IsEnumConstant(SubDecls[1]));
57-
}
58-
59-
TEST(EnumReflectionTest, IsEnumType) {
15+
class EnumReflectionTest : public ::testing::TestWithParam<TestUtils::TestConfig> {
16+
protected:
17+
void SetUp() override {
18+
TestUtils::current_config = GetParam();
19+
}
20+
};
21+
22+
TEST_P(EnumReflectionTest, IsEnumType) {
6023
std::vector<Decl *> Decls;
6124
std::string code = R"(
6225
enum class E {
@@ -84,7 +47,7 @@ TEST(EnumReflectionTest, IsEnumType) {
8447
EXPECT_TRUE(Cpp::IsEnumType(Cpp::GetVariableType(Decls[5])));
8548
}
8649

87-
TEST(EnumReflectionTest, GetIntegerTypeFromEnumScope) {
50+
TEST_P(EnumReflectionTest, GetIntegerTypeFromEnumScope) {
8851
std::vector<Decl *> Decls;
8952
std::string code = R"(
9053
enum Switch : bool {
@@ -134,7 +97,7 @@ TEST(EnumReflectionTest, GetIntegerTypeFromEnumScope) {
13497
EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetIntegerTypeFromEnumScope(Decls[5])),"NULL TYPE");
13598
}
13699

137-
TEST(EnumReflectionTest, GetIntegerTypeFromEnumType) {
100+
TEST_P(EnumReflectionTest, GetIntegerTypeFromEnumType) {
138101
std::vector<Decl *> Decls;
139102
std::string code = R"(
140103
enum Switch : bool {
@@ -194,7 +157,7 @@ TEST(EnumReflectionTest, GetIntegerTypeFromEnumType) {
194157
EXPECT_EQ(get_int_type_from_enum_var(Decls[11]), "NULL TYPE"); // When a non Enum Type variable is used
195158
}
196159

197-
TEST(EnumReflectionTest, GetEnumConstants) {
160+
TEST_P(EnumReflectionTest, GetEnumConstants) {
198161
std::vector<Decl *> Decls;
199162
std::string code = R"(
200163
enum ZeroEnum {
@@ -238,7 +201,7 @@ TEST(EnumReflectionTest, GetEnumConstants) {
238201
EXPECT_EQ(Cpp::GetEnumConstants(Decls[5]).size(), 0);
239202
}
240203

241-
TEST(EnumReflectionTest, GetEnumConstantType) {
204+
TEST_P(EnumReflectionTest, GetEnumConstantType) {
242205
std::vector<Decl *> Decls;
243206
std::string code = R"(
244207
enum Enum0 {
@@ -269,7 +232,7 @@ TEST(EnumReflectionTest, GetEnumConstantType) {
269232
EXPECT_EQ(get_enum_constant_type_as_str(nullptr), "NULL TYPE");
270233
}
271234

272-
TEST(EnumReflectionTest, GetEnumConstantValue) {
235+
TEST_P(EnumReflectionTest, GetEnumConstantValue) {
273236
std::vector<Decl *> Decls;
274237
std::string code = R"(
275238
enum Counter {
@@ -297,7 +260,7 @@ TEST(EnumReflectionTest, GetEnumConstantValue) {
297260
EXPECT_EQ(Cpp::GetEnumConstantValue(Decls[1]), 0); // Checking value of non enum constant
298261
}
299262

300-
TEST(EnumReflectionTest, GetEnums) {
263+
TEST_P(EnumReflectionTest, GetEnums) {
301264
std::string code = R"(
302265
enum Color {
303266
Red,
@@ -359,3 +322,26 @@ TEST(EnumReflectionTest, GetEnums) {
359322
EXPECT_TRUE(std::find(enumNames3.begin(), enumNames3.end(), "Color") != enumNames3.end());
360323
EXPECT_TRUE(enumNames4.empty());
361324
}
325+
326+
#ifdef LLVM_BUILT_WITH_OOP_JIT
327+
INSTANTIATE_TEST_SUITE_P(
328+
AllJITModes,
329+
EnumReflectionTest,
330+
::testing::Values(
331+
TestUtils::TestConfig{false, "InProcessJIT"},
332+
TestUtils::TestConfig{true, "OutOfProcessJIT"}
333+
),
334+
[](const ::testing::TestParamInfo<TestUtils::TestConfig>& info) {
335+
return info.param.name;
336+
}
337+
);
338+
#else
339+
INSTANTIATE_TEST_SUITE_P(
340+
AllJITModes,
341+
EnumReflectionTest,
342+
::testing::Values(TestUtils::TestConfig{false, "InProcessJIT"}),
343+
[](const ::testing::TestParamInfo<TestUtils::TestConfig>& info) {
344+
return info.param.name;
345+
}
346+
);
347+
#endif

0 commit comments

Comments
 (0)