xref: /TaskScheduler/SchedulerTests/main.cpp (revision 3a3d248d)
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 #ifdef _WIN32
242f083884Ss.makeev_local 
252f083884Ss.makeev_local #include <stdlib.h>
262f083884Ss.makeev_local #include <crtdbg.h>
272f083884Ss.makeev_local #include <windows.h>
282f083884Ss.makeev_local 
292f083884Ss.makeev_local 
302f083884Ss.makeev_local #if _MSC_VER > 1600
312f083884Ss.makeev_local #include <timeapi.h>
322f083884Ss.makeev_local #endif
332f083884Ss.makeev_local 
342f083884Ss.makeev_local #pragma comment( lib, "winmm.lib" )
352f083884Ss.makeev_local 
362f083884Ss.makeev_local #endif
372f083884Ss.makeev_local 
382f083884Ss.makeev_local #include <stdio.h>
392f083884Ss.makeev_local #include <string>
402f083884Ss.makeev_local #include <set>
412f083884Ss.makeev_local 
422f083884Ss.makeev_local #include <MTScheduler.h>
432f083884Ss.makeev_local #include "Tests/Tests.h"
442f083884Ss.makeev_local 
45*3a3d248dSs.makeev_local #if !defined(_WIN32)
462f083884Ss.makeev_local 
472f083884Ss.makeev_local #include <execinfo.h>
482f083884Ss.makeev_local 
492f083884Ss.makeev_local void PosixSignalHandler(int signum)
502f083884Ss.makeev_local {
512f083884Ss.makeev_local 	pthread_t currentThread = pthread_self();
522f083884Ss.makeev_local 
532f083884Ss.makeev_local 	const char* name = "Unknown";
542f083884Ss.makeev_local 	switch( signum )
552f083884Ss.makeev_local 	{
562f083884Ss.makeev_local 		case SIGABRT: name = "SIGABRT";  break;
572f083884Ss.makeev_local 		case SIGSEGV: name = "SIGSEGV";  break;
582f083884Ss.makeev_local 		case SIGBUS:  name = "SIGBUS";   break;
592f083884Ss.makeev_local 		case SIGILL:  name = "SIGILL";   break;
602f083884Ss.makeev_local 		case SIGFPE:  name = "SIGFPE";   break;
612f083884Ss.makeev_local         case SIGTRAP: name = "SIGTRAP";  break;
622f083884Ss.makeev_local 	}
632f083884Ss.makeev_local 
642f083884Ss.makeev_local 	void *callStack[32];
652f083884Ss.makeev_local   size_t size = backtrace(callStack, 32);
662f083884Ss.makeev_local 
672f083884Ss.makeev_local 	printf("Error: signal %s:\n", name);
682f083884Ss.makeev_local 
692f083884Ss.makeev_local   char** symbollist = backtrace_symbols( callStack, size );
702f083884Ss.makeev_local 
712f083884Ss.makeev_local    // print the stack trace.
722f083884Ss.makeev_local   for ( size_t i = 0; i < size; i++ )
732f083884Ss.makeev_local   {
742f083884Ss.makeev_local       printf("[%zu, %lu] %s\n", i, (unsigned long int)currentThread, symbollist[i]);
752f083884Ss.makeev_local 	}
762f083884Ss.makeev_local 
772f083884Ss.makeev_local   free(symbollist);
782f083884Ss.makeev_local 
792f083884Ss.makeev_local   exit(1);
802f083884Ss.makeev_local }
812f083884Ss.makeev_local #endif
822f083884Ss.makeev_local 
832f083884Ss.makeev_local 
84*3a3d248dSs.makeev_local void MyFiberEntryPoint( void* userData )
85*3a3d248dSs.makeev_local {
86*3a3d248dSs.makeev_local 	MT_UNUSED(userData);
87*3a3d248dSs.makeev_local 
88*3a3d248dSs.makeev_local }
89*3a3d248dSs.makeev_local 
902f083884Ss.makeev_local int main(int argc, char ** argv)
912f083884Ss.makeev_local {
922f083884Ss.makeev_local 
932f083884Ss.makeev_local #if defined(_WIN32)
942f083884Ss.makeev_local 	timeBeginPeriod(1);
952f083884Ss.makeev_local 	_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
962f083884Ss.makeev_local 	_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );
97*3a3d248dSs.makeev_local #else
982f083884Ss.makeev_local 	// install signal handler
992f083884Ss.makeev_local 	signal(SIGSEGV, PosixSignalHandler);
1002f083884Ss.makeev_local 	signal(SIGTRAP, PosixSignalHandler);
1012f083884Ss.makeev_local #endif
1022f083884Ss.makeev_local 
1032f083884Ss.makeev_local 	int passCount = 1;
1042f083884Ss.makeev_local 	if (argc >= 2)
1052f083884Ss.makeev_local 	{
1062f083884Ss.makeev_local 		passCount = atoi(argv[1]);
1072f083884Ss.makeev_local 	}
1082f083884Ss.makeev_local 
1092f083884Ss.makeev_local 	int res = 0;
1102f083884Ss.makeev_local 	printf("Tests will run %d times\n", passCount);
1112f083884Ss.makeev_local 	for(int pass = 0; pass < passCount; pass++)
1122f083884Ss.makeev_local 	{
1132f083884Ss.makeev_local 		printf("---- [ attempt #%d] ----\n", pass + 1);
1142f083884Ss.makeev_local 
1152f083884Ss.makeev_local 		res = Tests::RunAll();
1162f083884Ss.makeev_local 	}
1172f083884Ss.makeev_local 
1182f083884Ss.makeev_local #if defined(_WIN32)
1192f083884Ss.makeev_local 	 timeEndPeriod(1);
1202f083884Ss.makeev_local #endif
1212f083884Ss.makeev_local 
1222f083884Ss.makeev_local 	return res;
1232f083884Ss.makeev_local }
1242f083884Ss.makeev_local 
1252f083884Ss.makeev_local 
1262f083884Ss.makeev_local 
127