#!/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
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"
opt_debug=0
opt_noFailedRerun="";
opt_quiet="";
+opt_match="";
while true ; do
case "$1" in
-h|--help) usage ;;
-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 ;;
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
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
/*
- * 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.
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);
}
}
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;
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();
}
// 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;
// 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.
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
case 'q':
optQuiet = true;
break;
+ case 'm':
+ optMatch = optarg;
+ break;
case '?':
TestHarness::Usage(argv[0]);
exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT);
{
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