@@ -70,8 +70,9 @@ class LLVMCodeBuilderTest : public testing::Test
7070 void createBuilder (Target *target, BlockPrototype *procedurePrototype, Compiler::CodeType codeType = Compiler::CodeType::Script)
7171 {
7272 if (m_contexts.find (target) == m_contexts.cend () || !target)
73- m_contexts[target] = std::make_unique <LLVMCompilerContext>(&m_engine, target);
73+ m_contexts[target] = std::make_shared <LLVMCompilerContext>(&m_engine, target);
7474
75+ m_contextList.push_back (m_contexts[target]);
7576 m_builder = std::make_unique<LLVMCodeBuilder>(m_contexts[target].get (), procedurePrototype, codeType);
7677 }
7778
@@ -433,7 +434,8 @@ class LLVMCodeBuilderTest : public testing::Test
433434 ASSERT_THAT (testing::internal::GetCapturedStdout (), Eq (expected)) << quotes << v.toString () << quotes;
434435 };
435436
436- std::unordered_map<Target *, std::unique_ptr<LLVMCompilerContext>> m_contexts;
437+ std::unordered_map<Target *, std::shared_ptr<LLVMCompilerContext>> m_contexts;
438+ std::vector<std::shared_ptr<LLVMCompilerContext>> m_contextList;
437439 std::unique_ptr<LLVMCodeBuilder> m_builder;
438440 std::shared_ptr<BlockPrototype> m_procedurePrototype;
439441 EngineMock m_engine;
@@ -2854,6 +2856,34 @@ TEST_F(LLVMCodeBuilderTest, Yield)
28542856 ASSERT_EQ (testing::internal::GetCapturedStdout (), expected2);
28552857 ASSERT_TRUE (code->isFinished (ctx.get ()));
28562858
2859+ // Terminate unfinished coroutine
2860+ EXPECT_CALL (m_target, isStage ()).Times (3 );
2861+ testing::internal::CaptureStdout ();
2862+ code->reset (ctx.get ());
2863+ code->run (ctx.get ());
2864+ ASSERT_EQ (testing::internal::GetCapturedStdout (), expected1);
2865+ ASSERT_FALSE (code->isFinished (ctx.get ()));
2866+
2867+ code->kill (ctx.get ());
2868+ ASSERT_TRUE (code->isFinished (ctx.get ()));
2869+
2870+ // Reset unfinished coroutine
2871+ EXPECT_CALL (m_target, isStage ()).Times (3 );
2872+ testing::internal::CaptureStdout ();
2873+ code->reset (ctx.get ());
2874+ code->run (ctx.get ());
2875+ ASSERT_EQ (testing::internal::GetCapturedStdout (), expected1);
2876+ ASSERT_FALSE (code->isFinished (ctx.get ()));
2877+
2878+ code->reset (ctx.get ());
2879+
2880+ EXPECT_CALL (m_target, isStage ()).Times (3 );
2881+ testing::internal::CaptureStdout ();
2882+ code->reset (ctx.get ());
2883+ code->run (ctx.get ());
2884+ ASSERT_EQ (testing::internal::GetCapturedStdout (), expected1);
2885+ ASSERT_FALSE (code->isFinished (ctx.get ())); // leave unfinished coroutine
2886+
28572887 // With warp
28582888 createBuilder (true );
28592889 build ();
0 commit comments