|
24 | 24 | #include "gtest/gtest.h" |
25 | 25 |
|
26 | 26 | #include <algorithm> |
| 27 | +#include <thread> |
27 | 28 | #include <utility> |
28 | 29 |
|
29 | 30 | using ::testing::StartsWith; |
@@ -365,25 +366,38 @@ if (llvm::sys::RunningOnValgrind()) |
365 | 366 | } |
366 | 367 |
|
367 | 368 | 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"; |
370 | 371 | #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(); |
378 | 373 | auto* I2 = Cpp::CreateInterpreter(); |
| 374 | + auto* I3 = Cpp::CreateInterpreter(); |
| 375 | + auto* I4 = Cpp::CreateInterpreter(); |
| 376 | + EXPECT_TRUE(I1); |
379 | 377 | 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(); |
389 | 403 | } |
0 commit comments