Skip to content

Commit 0afd579

Browse files
Add test to run things in parallel
1 parent eb8f966 commit 0afd579

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

unittests/CppInterOp/InterpreterTest.cpp

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "gtest/gtest.h"
2525

2626
#include <algorithm>
27+
#include <thread>
2728
#include <utility>
2829

2930
using ::testing::StartsWith;
@@ -365,25 +366,38 @@ if (llvm::sys::RunningOnValgrind())
365366
}
366367

367368
TEST(InterpreterTest, MultipleInterpreter) {
368-
#if CLANG_VERSION_MAJOR < 20 && defined(EMSCRIPTEN)
369-
GTEST_SKIP() << "Test fails for Emscipten LLVM 20 builds";
369+
#ifdef EMSCRIPTEN
370+
GTEST_SKIP() << "Test fails for Emscipten builds";
370371
#endif
371-
auto* I = Cpp::CreateInterpreter();
372-
EXPECT_TRUE(I);
373-
Cpp::Declare(R"(
374-
void f() {}
375-
)");
376-
Cpp::TCppScope_t f = Cpp::GetNamed("f");
377-
372+
auto* I1 = Cpp::CreateInterpreter();
378373
auto* I2 = Cpp::CreateInterpreter();
374+
auto* I3 = Cpp::CreateInterpreter();
375+
auto* I4 = Cpp::CreateInterpreter();
376+
EXPECT_TRUE(I1);
379377
EXPECT_TRUE(I2);
380-
Cpp::Declare(R"(
381-
void ff() {}
382-
)");
383-
Cpp::TCppScope_t ff = Cpp::GetNamed("ff");
384-
385-
auto f_callable = Cpp::MakeFunctionCallable(f);
386-
EXPECT_EQ(f_callable.getKind(), Cpp::JitCall::Kind::kGenericCall);
387-
auto ff_callable = Cpp::MakeFunctionCallable(ff);
388-
EXPECT_EQ(ff_callable.getKind(), Cpp::JitCall::Kind::kGenericCall);
378+
EXPECT_TRUE(I3);
379+
EXPECT_TRUE(I4);
380+
381+
auto F = [](Cpp::TInterp_t I) {
382+
Cpp::Declare(R"(
383+
void f() {}
384+
class MyKlass {};
385+
)",
386+
false, I);
387+
Cpp::TCppScope_t f = Cpp::GetNamed("f", Cpp::GetGlobalScope(I));
388+
EXPECT_TRUE(f);
389+
auto f_callable = Cpp::MakeFunctionCallable(f);
390+
EXPECT_EQ(f_callable.getKind(), Cpp::JitCall::Kind::kGenericCall);
391+
Cpp::TCppType_t f_type = Cpp::GetType("MyKlass", I);
392+
EXPECT_EQ(Cpp::GetTypeAsString(f_type), "MyKlass");
393+
};
394+
395+
std::thread t1(F, I1);
396+
std::thread t2(F, I2);
397+
std::thread t3(F, I3);
398+
std::thread t4(F, I4);
399+
t1.join();
400+
t2.join();
401+
t3.join();
402+
t4.join();
389403
}

0 commit comments

Comments
 (0)