1*2f083884Ss.makeev_local // The MIT License (MIT) 2*2f083884Ss.makeev_local // 3*2f083884Ss.makeev_local // Copyright (c) 2015 Sergey Makeev, Vadim Slyusarev 4*2f083884Ss.makeev_local // 5*2f083884Ss.makeev_local // Permission is hereby granted, free of charge, to any person obtaining a copy 6*2f083884Ss.makeev_local // of this software and associated documentation files (the "Software"), to deal 7*2f083884Ss.makeev_local // in the Software without restriction, including without limitation the rights 8*2f083884Ss.makeev_local // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9*2f083884Ss.makeev_local // copies of the Software, and to permit persons to whom the Software is 10*2f083884Ss.makeev_local // furnished to do so, subject to the following conditions: 11*2f083884Ss.makeev_local // 12*2f083884Ss.makeev_local // The above copyright notice and this permission notice shall be included in 13*2f083884Ss.makeev_local // all copies or substantial portions of the Software. 14*2f083884Ss.makeev_local // 15*2f083884Ss.makeev_local // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16*2f083884Ss.makeev_local // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17*2f083884Ss.makeev_local // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18*2f083884Ss.makeev_local // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19*2f083884Ss.makeev_local // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20*2f083884Ss.makeev_local // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21*2f083884Ss.makeev_local // THE SOFTWARE. 22*2f083884Ss.makeev_local 23*2f083884Ss.makeev_local #include "Tests.h" 24*2f083884Ss.makeev_local #include <UnitTest++.h> 25*2f083884Ss.makeev_local #include <MTScheduler.h> 26*2f083884Ss.makeev_local 27*2f083884Ss.makeev_local SUITE(StackSizeTests) 28*2f083884Ss.makeev_local { 29*2f083884Ss.makeev_local //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 30*2f083884Ss.makeev_local struct StandartStackSizeTask 31*2f083884Ss.makeev_local { 32*2f083884Ss.makeev_local MT_DECLARE_TASK(StandartStackSizeTask, MT::StackRequirements::STANDARD, MT::Color::Blue); 33*2f083884Ss.makeev_local 34*2f083884Ss.makeev_local void Do(MT::FiberContext&) 35*2f083884Ss.makeev_local { 36*2f083884Ss.makeev_local byte stackData[28000]; 37*2f083884Ss.makeev_local memset(stackData, 0x0D, MT_ARRAY_SIZE(stackData)); 38*2f083884Ss.makeev_local } 39*2f083884Ss.makeev_local }; 40*2f083884Ss.makeev_local 41*2f083884Ss.makeev_local //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 42*2f083884Ss.makeev_local struct ExtendedStackSizeTask 43*2f083884Ss.makeev_local { 44*2f083884Ss.makeev_local MT_DECLARE_TASK(ExtendedStackSizeTask, MT::StackRequirements::EXTENDED, MT::Color::Red); 45*2f083884Ss.makeev_local 46*2f083884Ss.makeev_local void Do(MT::FiberContext&) 47*2f083884Ss.makeev_local { 48*2f083884Ss.makeev_local byte stackData[262144]; 49*2f083884Ss.makeev_local memset(stackData, 0x0D, MT_ARRAY_SIZE(stackData)); 50*2f083884Ss.makeev_local } 51*2f083884Ss.makeev_local 52*2f083884Ss.makeev_local }; 53*2f083884Ss.makeev_local 54*2f083884Ss.makeev_local 55*2f083884Ss.makeev_local //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 56*2f083884Ss.makeev_local TEST(RunStandartTasks) 57*2f083884Ss.makeev_local { 58*2f083884Ss.makeev_local MT::TaskScheduler scheduler(8); 59*2f083884Ss.makeev_local 60*2f083884Ss.makeev_local StandartStackSizeTask tasks[100]; 61*2f083884Ss.makeev_local scheduler.RunAsync(MT::TaskGroup::Default(), &tasks[0], MT_ARRAY_SIZE(tasks)); 62*2f083884Ss.makeev_local CHECK(scheduler.WaitAll(1000)); 63*2f083884Ss.makeev_local } 64*2f083884Ss.makeev_local 65*2f083884Ss.makeev_local //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 66*2f083884Ss.makeev_local TEST(RunExtendedTasks) 67*2f083884Ss.makeev_local { 68*2f083884Ss.makeev_local MT::TaskScheduler scheduler(8); 69*2f083884Ss.makeev_local 70*2f083884Ss.makeev_local ExtendedStackSizeTask tasks[100]; 71*2f083884Ss.makeev_local scheduler.RunAsync(MT::TaskGroup::Default(), &tasks[0], MT_ARRAY_SIZE(tasks)); 72*2f083884Ss.makeev_local CHECK(scheduler.WaitAll(1000)); 73*2f083884Ss.makeev_local } 74*2f083884Ss.makeev_local 75*2f083884Ss.makeev_local //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 76*2f083884Ss.makeev_local TEST(RunMixedTasks) 77*2f083884Ss.makeev_local { 78*2f083884Ss.makeev_local MT::TaskScheduler scheduler(8); 79*2f083884Ss.makeev_local 80*2f083884Ss.makeev_local MT::TaskPool<ExtendedStackSizeTask, 64> extendedTaskPool; 81*2f083884Ss.makeev_local MT::TaskPool<StandartStackSizeTask, 64> standardTaskPool; 82*2f083884Ss.makeev_local 83*2f083884Ss.makeev_local MT::TaskHandle taskHandles[100]; 84*2f083884Ss.makeev_local for (size_t i = 0; i < MT_ARRAY_SIZE(taskHandles); ++i) 85*2f083884Ss.makeev_local { 86*2f083884Ss.makeev_local MT::TaskHandle handle; 87*2f083884Ss.makeev_local 88*2f083884Ss.makeev_local if (i & 1) 89*2f083884Ss.makeev_local { 90*2f083884Ss.makeev_local handle = extendedTaskPool.Alloc(ExtendedStackSizeTask()); 91*2f083884Ss.makeev_local } else 92*2f083884Ss.makeev_local { 93*2f083884Ss.makeev_local handle = standardTaskPool.Alloc(StandartStackSizeTask()); 94*2f083884Ss.makeev_local } 95*2f083884Ss.makeev_local taskHandles[i] = handle; 96*2f083884Ss.makeev_local } 97*2f083884Ss.makeev_local 98*2f083884Ss.makeev_local scheduler.RunAsync(MT::TaskGroup::Default(), &taskHandles[0], MT_ARRAY_SIZE(taskHandles)); 99*2f083884Ss.makeev_local CHECK(scheduler.WaitAll(1000)); 100*2f083884Ss.makeev_local } 101*2f083884Ss.makeev_local 102*2f083884Ss.makeev_local 103*2f083884Ss.makeev_local 104*2f083884Ss.makeev_local } 105