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 #ifdef _WIN32 24*2f083884Ss.makeev_local 25*2f083884Ss.makeev_local #include <stdlib.h> 26*2f083884Ss.makeev_local #include <crtdbg.h> 27*2f083884Ss.makeev_local #include <windows.h> 28*2f083884Ss.makeev_local 29*2f083884Ss.makeev_local 30*2f083884Ss.makeev_local #if _MSC_VER > 1600 31*2f083884Ss.makeev_local #include <timeapi.h> 32*2f083884Ss.makeev_local #endif 33*2f083884Ss.makeev_local 34*2f083884Ss.makeev_local #pragma comment( lib, "winmm.lib" ) 35*2f083884Ss.makeev_local 36*2f083884Ss.makeev_local #endif 37*2f083884Ss.makeev_local 38*2f083884Ss.makeev_local #include <stdio.h> 39*2f083884Ss.makeev_local #include <string> 40*2f083884Ss.makeev_local #include <set> 41*2f083884Ss.makeev_local 42*2f083884Ss.makeev_local #include <MTScheduler.h> 43*2f083884Ss.makeev_local #include "Tests/Tests.h" 44*2f083884Ss.makeev_local 45*2f083884Ss.makeev_local #if !defined(_WIN32) && !defined(__ORBIS__) 46*2f083884Ss.makeev_local 47*2f083884Ss.makeev_local #include <execinfo.h> 48*2f083884Ss.makeev_local 49*2f083884Ss.makeev_local void PosixSignalHandler(int signum) 50*2f083884Ss.makeev_local { 51*2f083884Ss.makeev_local pthread_t currentThread = pthread_self(); 52*2f083884Ss.makeev_local 53*2f083884Ss.makeev_local const char* name = "Unknown"; 54*2f083884Ss.makeev_local switch( signum ) 55*2f083884Ss.makeev_local { 56*2f083884Ss.makeev_local case SIGABRT: name = "SIGABRT"; break; 57*2f083884Ss.makeev_local case SIGSEGV: name = "SIGSEGV"; break; 58*2f083884Ss.makeev_local case SIGBUS: name = "SIGBUS"; break; 59*2f083884Ss.makeev_local case SIGILL: name = "SIGILL"; break; 60*2f083884Ss.makeev_local case SIGFPE: name = "SIGFPE"; break; 61*2f083884Ss.makeev_local case SIGTRAP: name = "SIGTRAP"; break; 62*2f083884Ss.makeev_local } 63*2f083884Ss.makeev_local 64*2f083884Ss.makeev_local void *callStack[32]; 65*2f083884Ss.makeev_local size_t size = backtrace(callStack, 32); 66*2f083884Ss.makeev_local 67*2f083884Ss.makeev_local printf("Error: signal %s:\n", name); 68*2f083884Ss.makeev_local 69*2f083884Ss.makeev_local char** symbollist = backtrace_symbols( callStack, size ); 70*2f083884Ss.makeev_local 71*2f083884Ss.makeev_local // print the stack trace. 72*2f083884Ss.makeev_local for ( size_t i = 0; i < size; i++ ) 73*2f083884Ss.makeev_local { 74*2f083884Ss.makeev_local printf("[%zu, %lu] %s\n", i, (unsigned long int)currentThread, symbollist[i]); 75*2f083884Ss.makeev_local } 76*2f083884Ss.makeev_local 77*2f083884Ss.makeev_local free(symbollist); 78*2f083884Ss.makeev_local 79*2f083884Ss.makeev_local exit(1); 80*2f083884Ss.makeev_local } 81*2f083884Ss.makeev_local #endif 82*2f083884Ss.makeev_local 83*2f083884Ss.makeev_local 84*2f083884Ss.makeev_local int main(int argc, char ** argv) 85*2f083884Ss.makeev_local { 86*2f083884Ss.makeev_local 87*2f083884Ss.makeev_local #if defined(_WIN32) 88*2f083884Ss.makeev_local timeBeginPeriod(1); 89*2f083884Ss.makeev_local _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); 90*2f083884Ss.makeev_local _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG ); 91*2f083884Ss.makeev_local #elif !defined(__ORBIS__) 92*2f083884Ss.makeev_local // install signal handler 93*2f083884Ss.makeev_local signal(SIGSEGV, PosixSignalHandler); 94*2f083884Ss.makeev_local signal(SIGTRAP, PosixSignalHandler); 95*2f083884Ss.makeev_local #endif 96*2f083884Ss.makeev_local 97*2f083884Ss.makeev_local int passCount = 1; 98*2f083884Ss.makeev_local if (argc >= 2) 99*2f083884Ss.makeev_local { 100*2f083884Ss.makeev_local passCount = atoi(argv[1]); 101*2f083884Ss.makeev_local } 102*2f083884Ss.makeev_local 103*2f083884Ss.makeev_local int res = 0; 104*2f083884Ss.makeev_local printf("Tests will run %d times\n", passCount); 105*2f083884Ss.makeev_local for(int pass = 0; pass < passCount; pass++) 106*2f083884Ss.makeev_local { 107*2f083884Ss.makeev_local printf("---- [ attempt #%d] ----\n", pass + 1); 108*2f083884Ss.makeev_local 109*2f083884Ss.makeev_local res = Tests::RunAll(); 110*2f083884Ss.makeev_local } 111*2f083884Ss.makeev_local 112*2f083884Ss.makeev_local #if defined(_WIN32) 113*2f083884Ss.makeev_local timeEndPeriod(1); 114*2f083884Ss.makeev_local #endif 115*2f083884Ss.makeev_local 116*2f083884Ss.makeev_local return res; 117*2f083884Ss.makeev_local } 118*2f083884Ss.makeev_local 119*2f083884Ss.makeev_local 120*2f083884Ss.makeev_local 121