summaryrefslogtreecommitdiff
path: root/utests/utest.cpp
diff options
context:
space:
mode:
authorSun, Yi <yi.sun@intel.com>2014-04-08 10:53:40 +0800
committerZhigang Gong <zhigang.gong@intel.com>2014-04-21 09:20:51 +0800
commit8f0015e349c1428496a19236c1dd4132ef4554e5 (patch)
treeea83ba74975e69a4aadc6f78d45608fbcc8a3f59 /utests/utest.cpp
parentae1e342c5bf7e0c6e325313aefffa3bd168e5678 (diff)
downloadbeignet-8f0015e349c1428496a19236c1dd4132ef4554e5.tar.gz
Delete the printing of dynamic statistics line.
summary: --------------------- 1. Delete the printing of dynamic statistics line. 2. Add function to catch signals(like CTRL+C,core dumped ...), if caught, reminder user the signal name. core dumped example: ... displacement_map_element() [SUCCESS] compiler_clod() Interrupt signal (SIGSEGV) received. summary: ---------- total: 657 run: 297 pass: 271 fail: 26 pass rate: 0.960426 Signed-off-by: Yi Sun <yi.sun@intel.com> Signed-off-by: Yangwei Shui <yangweix.shui@intel.com> Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
Diffstat (limited to 'utests/utest.cpp')
-rw-r--r--utests/utest.cpp102
1 files changed, 64 insertions, 38 deletions
diff --git a/utests/utest.cpp b/utests/utest.cpp
index e7473090..b491caea 100644
--- a/utests/utest.cpp
+++ b/utests/utest.cpp
@@ -29,8 +29,14 @@
#include <sys/ioctl.h>
#include <unistd.h>
#include <cstring>
+#include <stdlib.h>
+#include <csignal>
-#define MAX_SUM_LINE 256
+struct signalMap
+{
+ const char* signalName;
+ int signalNum;
+};
using namespace std;
vector<UTest> *UTest::utestList = NULL;
@@ -38,7 +44,7 @@ vector<UTest> *UTest::utestList = NULL;
RStatistics UTest::retStatistics;
void releaseUTestList(void) { delete UTest::utestList; }
-void runAllNoIssueAtExit(void) {
+void runSummaryAtExit(void) {
// If case crashes, count it as fail, and accumulate finishrun
if(UTest::retStatistics.finishrun != UTest::utestList->size()) {
UTest::retStatistics.finishrun++;
@@ -50,64 +56,86 @@ void runAllNoIssueAtExit(void) {
printf(" pass: %zu\n",UTest::retStatistics.passCount);
printf(" fail: %zu\n",UTest::retStatistics.failCount);
printf(" pass rate: %f\n",1-(float)UTest::retStatistics.failCount/(float)UTest::utestList->size());
+
+ releaseUTestList();
+}
+
+void signalHandler( int signum )
+{
+ const char* name = NULL;
+
+ signalMap arr[] = {
+ {"SIGILL", SIGILL},
+ {"SIGFPE", SIGFPE},
+ {"SIGABRT", SIGABRT},
+ {"SIGBUS", SIGBUS},
+ {"SIGSEGV", SIGSEGV},
+ {"SIGHUP", SIGHUP},
+ {"SIGINT", SIGINT},
+ {"SIGQUIT", SIGQUIT},
+ {"SIGTERM", SIGTERM},
+ {NULL, -1}
+ };
+
+ for(int i=0; arr[i].signalNum != -1 && arr[i].signalName != NULL; i++) {
+ if(arr[i].signalNum == signum)
+
+ name = arr[i].signalName;
}
+ printf(" Interrupt signal (%s) received.", name);
+
+ exit(signum);
+}
+
+void catch_signal(void){
+ struct sigaction sa;
+ int sigs[] = {
+ SIGILL, SIGFPE, SIGABRT, SIGBUS,
+ SIGSEGV, SIGHUP, SIGINT, SIGQUIT,
+ SIGTERM
+ };
+
+ sa.sa_handler = signalHandler;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = SA_RESETHAND;
+
+ for(unsigned int i = 0; i < sizeof(sigs)/sizeof(sigs[0]); ++i) {
+ if (sigaction(sigs[i], &sa, NULL) == -1)
+ perror("Could not set signal handler");
+ }
+}
+
UTest::UTest(Function fn, const char *name, bool haveIssue, bool needDestroyProgram)
: fn(fn), name(name), haveIssue(haveIssue), needDestroyProgram(needDestroyProgram) {
if (utestList == NULL) {
utestList = new vector<UTest>;
- atexit(releaseUTestList);
+
+ catch_signal();
+ atexit(runSummaryAtExit);
}
utestList->push_back(*this);
}
+
static bool strequal(const char *s1, const char *s2) {
if (strcmp(s1, s2) == 0) return true;
return false;
}
void UTest::do_run(struct UTest utest){
- // winsize is a struct in ioctl.h, contains terminal column number
- struct winsize size;
- char spaceList[MAX_SUM_LINE] = {0};
-
- //Obtain terminal column size
- ioctl(STDOUT_FILENO, TIOCGWINSZ, &size);
-
- //A string contain MAX_SUM_LINE spaces, to hide the statistic line in stdout
- for (size_t j = 0; j < size.ws_col; j++){
- if ( j >= MAX_SUM_LINE - 1 ) break;
- spaceList[j] = ' ';
- spaceList[j+1] = '\0';
- }
- printf("\r%s\r%s()", spaceList, utest.name);
+ // Print function name
+ printf("%s()", utest.name);
+ fflush(stdout);
- // Run one case in utestList
+ // Run one case in utestList, print result [SUCCESS] or [FAILED]
(utest.fn)();
-
- // Print dynamic statistics line
- sprintf(spaceList, "\n [run/total: %zu/%zu]\
- pass: %zu; fail: %zu; pass rate: %f\r",
- retStatistics.finishrun+1, utestList->size(),
- retStatistics.passCount,
- retStatistics.failCount,
- 1-(float)retStatistics.failCount/(float)utestList->size());
-
- // If terminal column size lower than length of statistic line, print nothing, If not, print the statistics line
- if (size.ws_col > strlen(spaceList))
- printf("%s", spaceList);
- else
- printf("\n");
-
- // Refresh console
- fflush(stdout);
}
void UTest::run(const char *name) {
if (name == NULL) return;
if (utestList == NULL) return;
- atexit(runAllNoIssueAtExit);
for (; retStatistics.finishrun < utestList->size(); ++retStatistics.finishrun) {
const UTest &utest = (*utestList)[retStatistics.finishrun];
@@ -122,7 +150,6 @@ void UTest::run(const char *name) {
void UTest::runAll(void) {
if (utestList == NULL) return;
- atexit(runAllNoIssueAtExit);
for (; retStatistics.finishrun < utestList->size(); ++retStatistics.finishrun) {
const UTest &utest = (*utestList)[retStatistics.finishrun];
@@ -135,7 +162,6 @@ void UTest::runAll(void) {
void UTest::runAllNoIssue(void) {
if (utestList == NULL) return;
- atexit(runAllNoIssueAtExit);
for (; retStatistics.finishrun < utestList->size(); ++retStatistics.finishrun) {
const UTest &utest = (*utestList)[retStatistics.finishrun];