Test: End test early if a fatal error occurs

This commit is contained in:
Vicki Pfau 2020-07-17 02:55:11 -07:00
parent 3b30aef14b
commit ee50cc7656
1 changed files with 13 additions and 2 deletions

View File

@ -109,6 +109,7 @@ static Mutex jobMutex;
static Thread jobThreads[MAX_JOBS]; static Thread jobThreads[MAX_JOBS];
static int jobStatus; static int jobStatus;
static ThreadLocal stringBuilder; static ThreadLocal stringBuilder;
static ThreadLocal currentTest;
bool CInemaTestInit(struct CInemaTest*, const char* directory, const char* filename); bool CInemaTestInit(struct CInemaTest*, const char* directory, const char* filename);
void CInemaTestRun(struct CInemaTest*); void CInemaTestRun(struct CInemaTest*);
@ -771,6 +772,9 @@ void CInemaTestRun(struct CInemaTest* test) {
} else { } else {
baselineFound = _loadBaselinePNG(dir, &expected, frame, &test->status); baselineFound = _loadBaselinePNG(dir, &expected, frame, &test->status);
} }
if (test->status == CI_ERROR) {
break;
}
if (baselineFound) { if (baselineFound) {
uint8_t* testPixels = image.data; uint8_t* testPixels = image.data;
uint8_t* expectPixels = expected.data; uint8_t* expectPixels = expected.data;
@ -864,8 +868,6 @@ void CInemaTestRun(struct CInemaTest* test) {
free(diff); free(diff);
} }
free(expected.data); free(expected.data);
} else if (test->status == CI_ERROR) {
break;
} else if (rebaseline && !video) { } else if (rebaseline && !video) {
_writeBaseline(dir, &image, frame); _writeBaseline(dir, &image, frame);
} else if (!rebaseline) { } else if (!rebaseline) {
@ -905,7 +907,10 @@ static bool CInemaTask(struct CInemaTestList* tests, size_t i) {
} else { } else {
CIlog(1, "%s: ", test->name); CIlog(1, "%s: ", test->name);
fflush(stdout); fflush(stdout);
ThreadLocalSetKey(currentTest, test);
CInemaTestRun(test); CInemaTestRun(test);
ThreadLocalSetKey(currentTest, NULL);
switch (test->status) { switch (test->status) {
case CI_PASS: case CI_PASS:
CIlog(1, "pass\n"); CIlog(1, "pass\n");
@ -975,6 +980,10 @@ static THREAD_ENTRY CInemaJob(void* context) {
void _log(struct mLogger* log, int category, enum mLogLevel level, const char* format, va_list args) { void _log(struct mLogger* log, int category, enum mLogLevel level, const char* format, va_list args) {
UNUSED(log); UNUSED(log);
if (level == mLOG_FATAL) {
struct CInemaTest* test = ThreadLocalGetValue(currentTest);
test->status = CI_ERROR;
}
if (verbosity < 0) { if (verbosity < 0) {
return; return;
} }
@ -1071,6 +1080,8 @@ int main(int argc, char** argv) {
HashTableInit(&configTree, 0, free); HashTableInit(&configTree, 0, free);
MutexInit(&configMutex); MutexInit(&configMutex);
ThreadLocalInitKey(&currentTest);
ThreadLocalSetKey(currentTest, NULL);
if (jobs == 1) { if (jobs == 1) {
size_t i; size_t i;