static void TestSuite_RunTest (TestSuite *suite, /* IN */ Test *test, /* IN */ pthread_mutex_t *mutex, /* IN */ int *count) /* INOUT */ { struct timespec ts1; struct timespec ts2; struct timespec ts3; char name[64]; char buf[256]; int status; snprintf (name, sizeof name, "%s%s", suite->name, test->name); name [sizeof name - 1] = '\0'; if (!test->check || test->check ()) { _Clock_GetMonotonic (&ts1); /* * TODO: If not verbose, close()/dup(/dev/null) for stdout. */ #if !defined(PLATFORM_POSIX) test->func (); status = 0; #else if ((suite->flags & TEST_NOFORK)) { test->func (); status = 0; } else { status = TestSuite_RunFuncInChild (suite, test->func); } #endif _Clock_GetMonotonic (&ts2); _Clock_Subtract (&ts3, &ts2, &ts1); pthread_mutex_lock (mutex); snprintf (buf, sizeof buf, " { \"status\": \"%s\", " "\"name\": \"%s\", " "\"elapsed\": %u.%09u }%s\n", (status == 0) ? "PASS" : "FAIL", name, (unsigned)ts3.tv_sec, (unsigned)ts3.tv_nsec, ((*count) == 1) ? "" : ","); buf [sizeof buf - 1] = 0; fprintf (stdout, "%s", buf); pthread_mutex_unlock (mutex); } else { pthread_mutex_lock (mutex); snprintf (buf, sizeof buf, " { \"status\": \"SKIP\", \"name\": \"%s\" },\n", test->name); buf [sizeof buf - 1] = '\0'; fprintf (stdout, "%s", buf); pthread_mutex_unlock (mutex); } }
static int TestSuite_RunTest (TestSuite *suite, /* IN */ Test *test, /* IN */ int *count) /* INOUT */ { struct timespec ts1; struct timespec ts2; struct timespec ts3; char name[MAX_TEST_NAME_LENGTH]; char buf[MAX_TEST_NAME_LENGTH + 500]; int status = 0; snprintf (name, sizeof name, "%s%s", suite->name, test->name); name [sizeof name - 1] = '\0'; if (!test->check || test->check ()) { _Clock_GetMonotonic (&ts1); /* * TODO: If not verbose, close()/dup(/dev/null) for stdout. */ if (suite->flags & TEST_DEBUGOUTPUT) { _Print_StdOut ("Begin %s\n", name); } if ((suite->flags & TEST_NOFORK)) { #ifdef MONGOC_TRACE if (suite->flags & TEST_TRACE) { mongoc_log_set_handler (mongoc_log_default_handler, NULL); mongoc_log_trace_enable (); } else { mongoc_log_trace_disable (); } #endif srand (test->seed); test->func (test->ctx); status = 0; } else { status = TestSuite_RunFuncInChild (suite, test); } capture_logs (false); if (suite->silent) { return status; } _Clock_GetMonotonic (&ts2); _Clock_Subtract (&ts3, &ts2, &ts1); snprintf (buf, sizeof buf, " { \"status\": \"%s\", " "\"test_file\": \"%s\", " "\"seed\": \"%u\", " "\"start\": %u.%09u, " "\"end\": %u.%09u, " "\"elapsed\": %u.%09u }%s\n", (status == 0) ? "PASS" : "FAIL", name, test->seed, (unsigned)ts1.tv_sec, (unsigned)ts1.tv_nsec, (unsigned)ts2.tv_sec, (unsigned)ts2.tv_nsec, (unsigned)ts3.tv_sec, (unsigned)ts3.tv_nsec, ((*count) == 1) ? "" : ","); buf [sizeof buf - 1] = 0; _Print_StdOut ("%s", buf); if (suite->outfile) { fprintf (suite->outfile, "%s", buf); fflush (suite->outfile); } } else if (!suite->silent) { status = 0; snprintf (buf, sizeof buf, " { \"status\": \"SKIP\", \"test_file\": \"%s\" }%s\n", test->name, ((*count) == 1) ? "" : ","); buf [sizeof buf - 1] = '\0'; _Print_StdOut ("%s", buf); if (suite->outfile) { fprintf (suite->outfile, "%s", buf); fflush (suite->outfile); } } return status ? 1 : 0; }
static int TestSuite_RunTest (TestSuite *suite, /* IN */ Test *test, /* IN */ Mutex *mutex, /* IN */ int *count) /* INOUT */ { struct timespec ts1; struct timespec ts2; struct timespec ts3; char name[MAX_TEST_NAME_LENGTH]; char buf[MAX_TEST_NAME_LENGTH + 500]; int status = 0; snprintf (name, sizeof name, "%s%s", suite->name, test->name); name [sizeof name - 1] = '\0'; if (!test->check || test->check ()) { _Clock_GetMonotonic (&ts1); /* * TODO: If not verbose, close()/dup(/dev/null) for stdout. */ /* Tracing is superduper slow */ #if defined(_WIN32) srand (test->seed); if (suite->flags & TEST_DEBUGOUTPUT) { _Print_StdOut ("Begin %s\n", name); } test->func (test->ctx); status = 0; #else if (suite->flags & TEST_DEBUGOUTPUT) { _Print_StdOut ("Begin %s\n", name); } if ((suite->flags & TEST_NOFORK)) { srand (test->seed); test->func (test->ctx); status = 0; } else { status = TestSuite_RunFuncInChild (suite, test); } #endif _Clock_GetMonotonic (&ts2); _Clock_Subtract (&ts3, &ts2, &ts1); Mutex_Lock (mutex); snprintf (buf, sizeof buf, " { \"status\": \"%s\", " "\"test_file\": \"%s\", " "\"seed\": \"%u\", " "\"start\": %u.%09u, " "\"end\": %u.%09u, " "\"elapsed\": %u.%09u }%s\n", (status == 0) ? "PASS" : "FAIL", name, test->seed, (unsigned)ts1.tv_sec, (unsigned)ts1.tv_nsec, (unsigned)ts2.tv_sec, (unsigned)ts2.tv_nsec, (unsigned)ts3.tv_sec, (unsigned)ts3.tv_nsec, ((*count) == 1) ? "" : ","); buf [sizeof buf - 1] = 0; _Print_StdOut ("%s", buf); if (suite->outfile) { fprintf (suite->outfile, "%s", buf); fflush (suite->outfile); } Mutex_Unlock (mutex); } else { status = 0; Mutex_Lock (mutex); snprintf (buf, sizeof buf, " { \"status\": \"SKIP\", \"test_file\": \"%s\" },\n", test->name); buf [sizeof buf - 1] = '\0'; _Print_StdOut ("%s", buf); if (suite->outfile) { fprintf (suite->outfile, "%s", buf); fflush (suite->outfile); } Mutex_Unlock (mutex); } return status ? 1 : 0; }
static void TestSuite_RunTest (TestSuite *suite, /* IN */ Test *test, /* IN */ Mutex *mutex, /* IN */ int *count) /* INOUT */ { struct timespec ts1; struct timespec ts2; struct timespec ts3; char name[64]; char buf[256]; int status; snprintf (name, sizeof name, "%s%s", suite->name, test->name); name [sizeof name - 1] = '\0'; if (!test->check || test->check ()) { _Clock_GetMonotonic (&ts1); /* * TODO: If not verbose, close()/dup(/dev/null) for stdout. */ #if defined(_WIN32) srand (test->seed); test->func (); status = 0; #else if ((suite->flags & TEST_NOFORK)) { srand (test->seed); test->func (); status = 0; } else { status = TestSuite_RunFuncInChild (suite, test); } #endif _Clock_GetMonotonic (&ts2); _Clock_Subtract (&ts3, &ts2, &ts1); Mutex_Lock (mutex); if (suite->outfile && suite->generatexmlreport){ char *content = malloc(sizeof(char) * 1024); snprintf (content, 1024, "<testcase name=\"%s\" status=\"%s\" time=\"%u.%09u\"/>", name, (status == 0) ? "succ" : "FAIL", (unsigned)ts3.tv_sec, (unsigned)ts3.tv_nsec); Add_XmlNode(suite, name, content); } snprintf (buf, sizeof buf, " { \"status\": \"%s\", " "\"name\": \"%s\", " "\"seed\": \"%u\", " "\"elapsed\": %u.%09u }%s\n", (status == 0) ? "PASS" : "FAIL", name, test->seed, (unsigned)ts3.tv_sec, (unsigned)ts3.tv_nsec, ((*count) == 1) ? "" : ","); buf [sizeof buf - 1] = 0; fprintf (stdout, "%s", buf); if (suite->outfile && !suite->generatexmlreport) { fprintf (suite->outfile, "%s", buf); fflush (suite->outfile); } (status == 0) ? ++(suite->successfulnum):++(suite->failurenum); Mutex_Unlock (mutex); } else { Mutex_Lock (mutex); snprintf (buf, sizeof buf, " { \"status\": \"SKIP\", \"name\": \"%s\" },\n", test->name); buf [sizeof buf - 1] = '\0'; fprintf (stdout, "%s", buf); if (suite->outfile) { fprintf (suite->outfile, "%s", buf); fflush (suite->outfile); } ++(suite->errornum); Mutex_Unlock (mutex); } }