Line data Source code
1 : /////////////////////////////////////////////////////////////////////////// 2 : // Spetabaru - Berenger Bramas MPCDF - 2017 3 : // Under LGPL Licence, please you must read the LICENCE file. 4 : /////////////////////////////////////////////////////////////////////////// 5 : 6 : #include "UTester.hpp" 7 : 8 : #include "Data/SpDataAccessMode.hpp" 9 : #include "Utils/SpUtils.hpp" 10 : 11 : #include "Task/SpTask.hpp" 12 : #include "Legacy/SpRuntime.hpp" 13 : 14 : class WeakPlusStrongDependency : public UTester< WeakPlusStrongDependency> { 15 : using Parent = UTester< WeakPlusStrongDependency >; 16 : 17 : template <SpSpeculativeModel Spm> 18 3 : void Test(){ 19 3 : int a=0, b=0, c=0; 20 : 21 6 : std::promise<bool> promise1; 22 : 23 6 : SpRuntime<Spm> runtime; 24 : 25 3 : runtime.setSpeculationTest([](const int /*inNbReadyTasks*/, const SpProbability& /*inProbability*/) -> bool{ 26 0 : return true; 27 : }); 28 : 29 12 : runtime.task(SpPotentialWrite(a), [&promise1]([[maybe_unused]] int ¶m_a) -> bool{ 30 3 : promise1.get_future().get(); 31 3 : return false; 32 : }); 33 : 34 64 : runtime.task(SpRead(a), SpPotentialWrite(b), SpWrite(c), [](const int ¶m_a, int ¶m_b, int ¶m_c) -> bool{ 35 3 : bool res = false; 36 3 : if(param_a != 0) { 37 0 : param_b = 1; 38 0 : res = true; 39 : } 40 3 : param_c = 1; 41 3 : return res; 42 : }); 43 : 44 6 : runtime.task(SpRead(b), SpRead(c), [this](const int ¶m_b, [[maybe_unused]] const int ¶m_c){ 45 3 : if(param_b == 0) { 46 3 : UASSERTEDIFF(param_c, 0); 47 : } 48 : }); 49 : 50 3 : promise1.set_value(true); 51 : 52 3 : runtime.waitAllTasks(); 53 3 : runtime.stopAllThreads(); 54 3 : } 55 : 56 1 : void Test1() { Test<SpSpeculativeModel::SP_MODEL_1>(); } 57 1 : void Test2() { Test<SpSpeculativeModel::SP_MODEL_2>(); } 58 1 : void Test3() { Test<SpSpeculativeModel::SP_MODEL_3>(); } 59 : 60 1 : void SetTests() { 61 1 : Parent::AddTest(&WeakPlusStrongDependency::Test1, "Test behavior when there are weak as well strong dependencies between speculative tasks (model 1)"); 62 1 : Parent::AddTest(&WeakPlusStrongDependency::Test2, "Test behavior when there are weak as well strong dependencies between speculative tasks (model 2)"); 63 1 : Parent::AddTest(&WeakPlusStrongDependency::Test3, "Test behavior when there are weak as well strong dependencies between speculative tasks (model 3)"); 64 1 : } 65 : }; 66 : 67 : // You must do this 68 1 : TestClass(WeakPlusStrongDependency)