Added prefix matching to test case execution 41/271041/1
authorDavid Steele <david.steele@samsung.com>
Mon, 14 Feb 2022 16:34:52 +0000 (16:34 +0000)
committerDavid Steele <david.steele@samsung.com>
Mon, 14 Feb 2022 16:37:22 +0000 (16:37 +0000)
Change-Id: Ib7ca723ac2236c5d7ee979a94c9b3ad422cfb4bf

automated-tests/execute.sh
automated-tests/scripts/output_summary.pl
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp

index adee84b..35b4939 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-TEMP=`getopt -o dhsSmfq --long debug,help,failnorerun,quiet,serial,tct,modules -n 'execute.sh' -- "$@"`
+TEMP=`getopt -o dhsSmfqp: --long debug,help,failnorerun,quiet,serial,tct,modules,prefix: -n 'execute.sh' -- "$@"`
 
 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
 
@@ -13,6 +13,7 @@ function usage
     echo -e "       execute.sh\t\tExecute test cases from all modules in parallel"
     echo -e "       execute.sh -f \tExecute test cases from all modules in parallel without rerunning failed test cases"
     echo -e "       execute.sh -d <testcase>\tDebug testcase"
+    echo -e "       execute.sh -p <prefix>\tExecute all testcases named with <prefix>"
     echo -e "       execute.sh [module]\tExecute test cases from the given module in parallel"
     echo -e "       execute.sh -s [module]\t\tExecute test cases in serial using Testkit-Lite"
     echo -e "       execute.sh -S [module]\t\tExecute test cases in serial"
@@ -27,6 +28,7 @@ opt_modules=0
 opt_debug=0
 opt_noFailedRerun="";
 opt_quiet="";
+opt_match="";
 while true ; do
     case "$1" in
         -h|--help)     usage ;;
@@ -35,6 +37,7 @@ while true ; do
         -f|--nofailedrerun) opt_noFailedRerun="-f" ; shift ;;
         -S|--serial)   opt_serial="-s" ; shift ;;
         -q|--quiet)    opt_quiet="-q" ; shift ;;
+        -p|--prefix)   opt_match="-m $2" ; shift 2;;
         -m|--modules)  opt_modules=1 ; shift ;;
         --) shift; break;;
         *) echo "Internal error $1!" ; exit 1 ;;
@@ -147,7 +150,7 @@ else
             echo -e "$ASCII_BOLD"
             echo -e "Executing $mod$ASCII_RESET"
             output_start $mod
-            dbus-launch build/src/$mod/tct-$mod-core $opt_serial $opt_noFailedRerun $opt_quiet
+            dbus-launch build/src/$mod/tct-$mod-core $opt_serial $opt_noFailedRerun $opt_quiet $opt_match
             output_end $mod
         done
         summary_end
@@ -159,7 +162,7 @@ else
         module=$1
         shift;
         output_start ${module}
-        dbus-launch build/src/$module/tct-$module-core $opt_serial $opt_noFailedRerun $opt_quiet $*
+        dbus-launch build/src/$module/tct-$module-core $opt_serial $opt_noFailedRerun $opt_quiet $opt_match $*
         output_end ${module}
         summary_end
 
index dec392d..69e4fce 100755 (executable)
@@ -71,7 +71,7 @@ foreach $module (keys(%modules))
     my $numFailures = $modules{$module}->{"fail"};
     $totalFailures += $numFailures;
     print( "$ASCII_BOLD$module results:$ASCII_RESET\n" );
-    printf("Number of test passes:   %s%4d (%5.2f%%)%s\n", $ASCII_BOLD, $numPasses, 100.0 * $numPasses / ($numPasses+$numFailures),  $ASCII_RESET);
+    printf("Number of test passes:   %s%4d (%5.2f%%)%s\n", $ASCII_BOLD, $numPasses, $numPasses>0?100.0 * $numPasses / ($numPasses+$numFailures):0,  $ASCII_RESET);
     printf("%sNumber of test failures:%s %s%4d%s\n\n", $result_colour, $ASCII_RESET, $ASCII_BOLD, $numFailures, $ASCII_RESET);
 }
 
index 587d4a5..86874fd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -229,9 +229,9 @@ void OutputStatistics(const char* processName, int32_t numPasses, int32_t numFai
             basename(processName),
             numPasses + numFailures,
             numPasses,
-            (float)numPasses * 100.0f / (numPasses + numFailures),
+            numPasses > 0 ? (float)numPasses * 100.0f / (numPasses + numFailures) : 0.0f,
             numFailures,
-            (float)numFailures * 100.0f / (numPasses + numFailures));
+            numPasses > 0 ? (float)numFailures * 100.0f / (numPasses + numFailures) : 0.0f);
     fclose(fp);
   }
 }
@@ -362,7 +362,7 @@ int32_t RunTestCaseInChildProcess(TestCase& testCase, bool redirect)
   return testResult;
 }
 
-int32_t RunAll(const char* processName, ::testcase tc_array[], bool quiet)
+int32_t RunAll(const char* processName, ::testcase tc_array[], std::string match, bool quiet)
 {
   int32_t       numFailures = 0;
   int32_t       numPasses   = 0;
@@ -381,23 +381,35 @@ int32_t RunAll(const char* processName, ::testcase tc_array[], bool quiet)
     std::string startTime(buffer);
 
     TestCase testCase(i, &tc_array[i]);
-    testCase.result = RunTestCaseInChildProcess(testCase, quiet);
-
-    tt = system_clock::to_time_t(system_clock::now());
-    strftime(buffer, BUFSIZE, "%c", localtime(&tt));
-    std::string endTime(buffer);
-
-    if(testCase.result == 0)
+    bool     run = true;
+    if(!match.empty())
     {
-      numPasses++;
-    }
-    else
-    {
-      numFailures++;
+      if(match.compare(0, match.size(), testCase.name, match.size()))
+      {
+        run = false;
+      }
     }
-    if(!quiet)
+
+    if(run)
     {
-      OutputTestResult(ofs, processName, moduleName, testCase, startTime, endTime);
+      testCase.result = RunTestCaseInChildProcess(testCase, quiet);
+
+      tt = system_clock::to_time_t(system_clock::now());
+      strftime(buffer, BUFSIZE, "%c", localtime(&tt));
+      std::string endTime(buffer);
+
+      if(testCase.result == 0)
+      {
+        numPasses++;
+      }
+      else
+      {
+        numFailures++;
+      }
+      if(!quiet)
+      {
+        OutputTestResult(ofs, processName, moduleName, testCase, startTime, endTime);
+      }
     }
   }
   ofs.close();
@@ -408,7 +420,7 @@ int32_t RunAll(const char* processName, ::testcase tc_array[], bool quiet)
 }
 
 // Constantly runs up to MAX_NUM_CHILDREN processes
-int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], bool reRunFailed, bool quiet)
+int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], std::string match, bool reRunFailed, bool quiet)
 {
   int32_t numFailures = 0;
   int32_t numPasses   = 0;
@@ -427,34 +439,54 @@ int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], bool re
     // Create more children (up to the max number or til the end of the array)
     while(numRunningChildren < MAX_NUM_CHILDREN && tc_array[nextTestCase].name)
     {
-      int32_t pid = fork();
-      if(pid == 0) // Child process
+      bool run = true;
+      if(!match.empty())
       {
-        TestCase testCase(nextTestCase, &tc_array[nextTestCase]);
-        int      status = RunTestCaseRedirectOutput(testCase, quiet);
-        exit(status);
+        if(match.compare(0, match.size(), tc_array[nextTestCase].name, match.size()))
+        {
+          run = false;
+        }
       }
-      else if(pid == -1)
+      if(run)
       {
-        perror("fork");
-        exit(EXIT_STATUS_FORK_FAILED);
+        int32_t pid = fork();
+        if(pid == 0) // Child process
+        {
+          TestCase testCase(nextTestCase, &tc_array[nextTestCase]);
+          int      status = RunTestCaseRedirectOutput(testCase, quiet);
+          exit(status);
+        }
+        else if(pid == -1)
+        {
+          perror("fork");
+          exit(EXIT_STATUS_FORK_FAILED);
+        }
+        else // Parent process
+        {
+          TestCase tc(nextTestCase, tc_array[nextTestCase].name);
+          tc.startTime       = steady_clock::now();
+          tc.startSystemTime = system_clock::now();
+          tc.childPid        = pid;
+
+          children[pid] = tc;
+          nextTestCase++;
+          numRunningChildren++;
+        }
       }
-      else // Parent process
+      else
       {
-        TestCase tc(nextTestCase, tc_array[nextTestCase].name);
-        tc.startTime       = steady_clock::now();
-        tc.startSystemTime = system_clock::now();
-        tc.childPid        = pid;
-
-        children[pid] = tc;
         nextTestCase++;
-        numRunningChildren++;
       }
     }
 
-    // Check to see if any children have finished yet
     int32_t status   = 0;
-    int32_t childPid = waitpid(-1, &status, WNOHANG);
+    int32_t childPid = 0;
+    if(numRunningChildren > 0) // Only wait if there are running children.
+    {
+      // Check to see if any children have finished yet
+      childPid = waitpid(-1, &status, WNOHANG);
+    }
+
     if(childPid == 0)
     {
       // No children have finished.
@@ -581,10 +613,11 @@ void Usage(const char* program)
 int RunTests(int argc, char* const argv[], ::testcase tc_array[])
 {
   int         result    = TestHarness::EXIT_STATUS_BAD_ARGUMENT;
-  const char* optString = "sfq";
+  const char* optString = "sfqm:";
   bool        optRerunFailed(true);
   bool        optRunSerially(false);
   bool        optQuiet(false);
+  std::string optMatch;
 
   int nextOpt = 0;
   do
@@ -601,6 +634,9 @@ int RunTests(int argc, char* const argv[], ::testcase tc_array[])
       case 'q':
         optQuiet = true;
         break;
+      case 'm':
+        optMatch = optarg;
+        break;
       case '?':
         TestHarness::Usage(argv[0]);
         exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT);
@@ -612,11 +648,11 @@ int RunTests(int argc, char* const argv[], ::testcase tc_array[])
   {
     if(optRunSerially)
     {
-      result = TestHarness::RunAll(argv[0], tc_array, optQuiet);
+      result = TestHarness::RunAll(argv[0], tc_array, optMatch, optQuiet);
     }
     else
     {
-      result = TestHarness::RunAllInParallel(argv[0], tc_array, optRerunFailed, optQuiet);
+      result = TestHarness::RunAllInParallel(argv[0], tc_array, optMatch, optRerunFailed, optQuiet);
     }
   }
   else