From 39d02dd42829f16a6585205992c07117ed965fce Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Tue, 9 Feb 2021 19:20:21 +0000 Subject: [PATCH] Added test that verifies memory violation sequence --- test/TestMultipleAlgoExecutions.cpp | 36 +++++++++++++++++++++++++++++ test/TestSequence.cpp | 1 + 2 files changed, 37 insertions(+) diff --git a/test/TestMultipleAlgoExecutions.cpp b/test/TestMultipleAlgoExecutions.cpp index 4d2a44a9f..b6eaea540 100644 --- a/test/TestMultipleAlgoExecutions.cpp +++ b/test/TestMultipleAlgoExecutions.cpp @@ -314,3 +314,39 @@ TEST(TestMultipleAlgoExecutions, ManagerEvalMultSourceStrMgrCreate) EXPECT_EQ(tensorOut->data(), std::vector({ 0.0, 4.0, 12.0 })); } + +TEST(TestMultipleAlgoExecutions, SequenceAlgoDestroyOutsideManagerScope) +{ + std::shared_ptr tensorA{ new kp::Tensor({ 0, 0, 0 }) }; + + std::string shader(R"( + #version 450 + layout (local_size_x = 1) in; + layout(set = 0, binding = 0) buffer a { float pa[]; }; + void main() { + uint index = gl_GlobalInvocationID.x; + pa[index] = pa[index] + 1; + })"); + + { + std::shared_ptr sq = nullptr; + + { + kp::Manager mgr; + + mgr.rebuildTensors({ tensorA }); + + sq = mgr.createManagedSequence(); + + sq->begin(); + sq->record( + { tensorA }, std::vector(shader.begin(), shader.end())); + sq->end(); + + sq->eval(); + + mgr.evalOpDefault({ tensorA }); + } + } + EXPECT_EQ(tensorA->data(), std::vector({ 1, 1, 1 })); +} diff --git a/test/TestSequence.cpp b/test/TestSequence.cpp index 882729dcf..2d0a8a4b7 100644 --- a/test/TestSequence.cpp +++ b/test/TestSequence.cpp @@ -39,3 +39,4 @@ TEST(TestSequence, SequenceDestructorViaManager) EXPECT_FALSE(sq->isInit()); } +