X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Fdali-toolkit-test-utils%2Ftest-harness.cpp;h=840ef0da682c8fd7c590132b248b607a5d0f2882;hp=3fed0a20726ec7d3f5d6be02a66bbc81312036e6;hb=24ea337df1049251ab2e47c556edc6e8458f9c93;hpb=869f6dc6c56e97f9bfb2460c84afa8d6ebf06ea5 diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp index 3fed0a2..840ef0d 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,40 +29,39 @@ namespace TestHarness typedef std::map RunningTestCases; -namespace +const char* basename(const char* path) { -const char* RED_COLOR="\e[1;31m"; -const char* GREEN_COLOR="\e[1;32m"; -const char* ASCII_RESET="\e[0m"; -const char* ASCII_BOLD="\e[1m"; + const char* ptr=path; + const char* slash=NULL; + for( ; *ptr != '\0' ; ++ptr ) + { + if(*ptr == '/') slash=ptr; + } + if(slash != NULL) ++slash; + return slash; } - int RunTestCase( struct ::testcase_s& testCase ) { int result = EXIT_STATUS_TESTCASE_FAILED; - try +// dont want to catch exception as we want to be able to get +// gdb stack trace from the first error +// by default tests should all always pass with no exceptions + if( testCase.startup ) { - if( testCase.startup ) - { - testCase.startup(); - } - result = testCase.function(); - if( testCase.cleanup ) - { - testCase.cleanup(); - } + testCase.startup(); } - catch (...) + result = testCase.function(); + if( testCase.cleanup ) { - printf("Caught exception in test case.\n"); - result = EXIT_STATUS_TESTCASE_ABORTED; + testCase.cleanup(); } return result; } + int RunTestCaseInChildProcess( struct ::testcase_s& testCase, bool suppressOutput ) { int testResult = EXIT_STATUS_TESTCASE_FAILED; @@ -75,7 +74,24 @@ int RunTestCaseInChildProcess( struct ::testcase_s& testCase, bool suppressOutpu close(STDOUT_FILENO); close(STDERR_FILENO); } - exit( RunTestCase( testCase ) ); + else + { + printf("\n"); + for(int i=0; i<80; ++i) printf("#"); + printf("\nTC: %s\n", testCase.name); + fflush(stdout); + } + + int status = RunTestCase( testCase ); + + if( ! suppressOutput ) + { + fflush(stdout); + fflush(stderr); + fclose(stdout); + fclose(stderr); + } + exit( status ); } else if(pid == -1) { @@ -85,7 +101,7 @@ int RunTestCaseInChildProcess( struct ::testcase_s& testCase, bool suppressOutpu else // Parent process { int status = 0; - int childPid = waitpid(-1, &status, 0); + int childPid = waitpid(pid, &status, 0); if( childPid == -1 ) { perror("waitpid"); @@ -104,38 +120,55 @@ int RunTestCaseInChildProcess( struct ::testcase_s& testCase, bool suppressOutpu } else if(WIFSIGNALED(status) ) { + int signal = WTERMSIG(status); testResult = EXIT_STATUS_TESTCASE_ABORTED; - -#ifdef WCOREDUMP - if(WCOREDUMP(status)) + if( signal == SIGABRT ) { - printf("Test case %s crashed\n", testCase.name); + printf("Test case %s failed: test case asserted\n", testCase.name ); + } + else + { + printf("Test case %s failed: exit with signal %s\n", testCase.name, strsignal(WTERMSIG(status))); } -#endif - printf("Test case %s exited with signal %s\n", testCase.name, strsignal(WTERMSIG(status))); } else if(WIFSTOPPED(status)) { - printf("Test case %s stopped with signal %s\n", testCase.name, strsignal(WSTOPSIG(status))); + printf("Test case %s failed: stopped with signal %s\n", testCase.name, strsignal(WSTOPSIG(status))); } } + fflush(stdout); + fflush(stderr); return testResult; } -void OutputStatistics( int numPasses, int numFailures ) +void OutputStatistics( const char* processName, int numPasses, int numFailures ) { - const char* failureColor = GREEN_COLOR; - if( numFailures > 0 ) + FILE* fp=fopen("summary.xml", "a"); + if( fp != NULL ) { - failureColor = RED_COLOR; + fprintf( fp, + " \n" + " %d\n" + " %d\n" + " %5.2f\n" + " %d\n" + " %5.2f\n" + " 0\n" + " 0.00\n" + " 0\n" + " 0.00\n" + " \n", + basename(processName), + numPasses+numFailures, + numPasses, + (float)numPasses/(numPasses+numFailures), + numFailures, + (float)numFailures/(numPasses+numFailures) ); + fclose(fp); } - printf("\rNumber of test passes: %s%4d (%5.2f%%)%s\n", ASCII_BOLD, numPasses, 100.0f * (float)numPasses / (numPasses+numFailures), ASCII_RESET); - printf("%sNumber of test failures:%s %s%4d%s\n", failureColor, ASCII_RESET, ASCII_BOLD, numFailures, ASCII_RESET); - } - -int RunAll(const char* processName, ::testcase tc_array[], bool reRunFailed) +int RunAll( const char* processName, ::testcase tc_array[] ) { int numFailures = 0; int numPasses = 0; @@ -143,7 +176,7 @@ int RunAll(const char* processName, ::testcase tc_array[], bool reRunFailed) // Run test cases in child process( to kill output/handle signals ), but run serially. for( unsigned int i=0; tc_array[i].name; i++) { - int result = RunTestCaseInChildProcess( tc_array[i], true ); + int result = RunTestCaseInChildProcess( tc_array[i], false ); if( result == 0 ) { numPasses++; @@ -154,13 +187,11 @@ int RunAll(const char* processName, ::testcase tc_array[], bool reRunFailed) } } - OutputStatistics(numPasses, numFailures); + OutputStatistics( processName, numPasses, numFailures); return numFailures; } - - // Constantly runs up to MAX_NUM_CHILDREN processes int RunAllInParallel( const char* processName, ::testcase tc_array[], bool reRunFailed) { @@ -254,7 +285,7 @@ int RunAllInParallel( const char* processName, ::testcase tc_array[], bool reRu } } - OutputStatistics( numPasses, numFailures ); + OutputStatistics( processName, numPasses, numFailures ); if( reRunFailed ) { @@ -298,8 +329,9 @@ void Usage(const char* program) printf("Usage: \n" " %s \t\t Execute a test case\n" " %s \t\t Execute all test cases in parallel\n" - " %s -r\t\t Execute all test cases in parallel, rerunning failed test cases\n", - program, program, program); + " %s -r\t\t Execute all test cases in parallel, rerunning failed test cases\n" + " %s -s\t\t Execute all test cases serially\n", + program, program, program, program); } } // namespace