12f083884Ss.makeev_local // The MIT License (MIT)
22f083884Ss.makeev_local //
32f083884Ss.makeev_local // 	Copyright (c) 2015 Sergey Makeev, Vadim Slyusarev
42f083884Ss.makeev_local //
52f083884Ss.makeev_local // 	Permission is hereby granted, free of charge, to any person obtaining a copy
62f083884Ss.makeev_local // 	of this software and associated documentation files (the "Software"), to deal
72f083884Ss.makeev_local // 	in the Software without restriction, including without limitation the rights
82f083884Ss.makeev_local // 	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
92f083884Ss.makeev_local // 	copies of the Software, and to permit persons to whom the Software is
102f083884Ss.makeev_local // 	furnished to do so, subject to the following conditions:
112f083884Ss.makeev_local //
122f083884Ss.makeev_local //  The above copyright notice and this permission notice shall be included in
132f083884Ss.makeev_local // 	all copies or substantial portions of the Software.
142f083884Ss.makeev_local //
152f083884Ss.makeev_local // 	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
162f083884Ss.makeev_local // 	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
172f083884Ss.makeev_local // 	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
182f083884Ss.makeev_local // 	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
192f083884Ss.makeev_local // 	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
202f083884Ss.makeev_local // 	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
212f083884Ss.makeev_local // 	THE SOFTWARE.
222f083884Ss.makeev_local 
232f083884Ss.makeev_local #include "Tests.h"
242f083884Ss.makeev_local #include <UnitTest++.h>
252f083884Ss.makeev_local #include <MTScheduler.h>
262f083884Ss.makeev_local 
272f083884Ss.makeev_local SUITE(StackSizeTests)
282f083884Ss.makeev_local {
292f083884Ss.makeev_local ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
302f083884Ss.makeev_local struct StandartStackSizeTask
312f083884Ss.makeev_local {
322f083884Ss.makeev_local 	MT_DECLARE_TASK(StandartStackSizeTask, MT::StackRequirements::STANDARD, MT::Color::Blue);
332f083884Ss.makeev_local 
342f083884Ss.makeev_local 	void Do(MT::FiberContext&)
352f083884Ss.makeev_local 	{
364d1eed22Ss.makeev_local 		byte stackData[20000];
37*3c31c0cbSs.makeev_local 		for (uint32 i = 0; i < MT_ARRAY_SIZE(stackData); i++)
38*3c31c0cbSs.makeev_local 		{
39*3c31c0cbSs.makeev_local 			stackData[i] = 0x0D;
40*3c31c0cbSs.makeev_local 		}
412f083884Ss.makeev_local 	}
422f083884Ss.makeev_local };
432f083884Ss.makeev_local 
442f083884Ss.makeev_local ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
452f083884Ss.makeev_local struct ExtendedStackSizeTask
462f083884Ss.makeev_local {
472f083884Ss.makeev_local 	MT_DECLARE_TASK(ExtendedStackSizeTask, MT::StackRequirements::EXTENDED, MT::Color::Red);
482f083884Ss.makeev_local 
492f083884Ss.makeev_local 	void Do(MT::FiberContext&)
502f083884Ss.makeev_local 	{
512f083884Ss.makeev_local 		byte stackData[262144];
52*3c31c0cbSs.makeev_local 		for (uint32 i = 0; i < MT_ARRAY_SIZE(stackData); i++)
53*3c31c0cbSs.makeev_local 		{
54*3c31c0cbSs.makeev_local 			stackData[i] = 0x0D;
55*3c31c0cbSs.makeev_local 		}
562f083884Ss.makeev_local 	}
572f083884Ss.makeev_local 
582f083884Ss.makeev_local };
592f083884Ss.makeev_local 
602f083884Ss.makeev_local 
612f083884Ss.makeev_local ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
622f083884Ss.makeev_local TEST(RunStandartTasks)
632f083884Ss.makeev_local {
64d7cf17b1Ss.makeev_local 	MT::TaskScheduler scheduler;
652f083884Ss.makeev_local 
662f083884Ss.makeev_local 	StandartStackSizeTask tasks[100];
672f083884Ss.makeev_local 	scheduler.RunAsync(MT::TaskGroup::Default(), &tasks[0], MT_ARRAY_SIZE(tasks));
682f083884Ss.makeev_local 	CHECK(scheduler.WaitAll(1000));
692f083884Ss.makeev_local }
702f083884Ss.makeev_local 
712f083884Ss.makeev_local ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
722f083884Ss.makeev_local TEST(RunExtendedTasks)
732f083884Ss.makeev_local {
74d7cf17b1Ss.makeev_local 	MT::TaskScheduler scheduler;
752f083884Ss.makeev_local 
762f083884Ss.makeev_local 	ExtendedStackSizeTask tasks[100];
772f083884Ss.makeev_local 	scheduler.RunAsync(MT::TaskGroup::Default(), &tasks[0], MT_ARRAY_SIZE(tasks));
782f083884Ss.makeev_local 	CHECK(scheduler.WaitAll(1000));
792f083884Ss.makeev_local }
802f083884Ss.makeev_local 
812f083884Ss.makeev_local ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
822f083884Ss.makeev_local TEST(RunMixedTasks)
832f083884Ss.makeev_local {
84d7cf17b1Ss.makeev_local 	MT::TaskScheduler scheduler;
852f083884Ss.makeev_local 
862f083884Ss.makeev_local 	MT::TaskPool<ExtendedStackSizeTask, 64> extendedTaskPool;
872f083884Ss.makeev_local 	MT::TaskPool<StandartStackSizeTask, 64> standardTaskPool;
882f083884Ss.makeev_local 
892f083884Ss.makeev_local 	MT::TaskHandle taskHandles[100];
902f083884Ss.makeev_local 	for (size_t i = 0; i < MT_ARRAY_SIZE(taskHandles); ++i)
912f083884Ss.makeev_local 	{
922f083884Ss.makeev_local 		MT::TaskHandle handle;
932f083884Ss.makeev_local 
942f083884Ss.makeev_local 		if (i & 1)
952f083884Ss.makeev_local 		{
962f083884Ss.makeev_local 			handle = extendedTaskPool.Alloc(ExtendedStackSizeTask());
972f083884Ss.makeev_local 		} else
982f083884Ss.makeev_local 		{
992f083884Ss.makeev_local 			handle = standardTaskPool.Alloc(StandartStackSizeTask());
1002f083884Ss.makeev_local 		}
1012f083884Ss.makeev_local 		taskHandles[i] = handle;
1022f083884Ss.makeev_local 	}
1032f083884Ss.makeev_local 
1042f083884Ss.makeev_local 	scheduler.RunAsync(MT::TaskGroup::Default(), &taskHandles[0], MT_ARRAY_SIZE(taskHandles));
1052f083884Ss.makeev_local 	CHECK(scheduler.WaitAll(1000));
1062f083884Ss.makeev_local }
1072f083884Ss.makeev_local 
1082f083884Ss.makeev_local 
1092f083884Ss.makeev_local 
1102f083884Ss.makeev_local }
111