Test: Add option to only rebaseline missing tests
Vicki Pfau vi@endrift.com
Sat, 18 Jul 2020 15:25:48 -0700
1 files changed,
62 insertions(+),
23 deletions(-)
jump to
M
src/platform/test/cinema-main.c
→
src/platform/test/cinema-main.c
@@ -45,12 +45,13 @@ { "dry-run", no_argument, 0, 'n' },
{ "outdir", required_argument, 0, 'o' }, { "quiet", no_argument, 0, 'q' }, { "rebaseline", no_argument, 0, 'r' }, + { "rebaseline-missing", no_argument, 0, 'R' }, { "verbose", no_argument, 0, 'v' }, { "version", no_argument, 0, '\0' }, { 0, 0, 0, 0 } }; -static const char shortOpts[] = "b:dhj:no:qrv"; +static const char shortOpts[] = "b:dhj:no:qRrv"; enum CInemaStatus { CI_PASS,@@ -59,6 +60,12 @@ CI_XPASS,
CI_XFAIL, CI_ERROR, CI_SKIP +}; + +enum CInemaRebaseline { + CI_R_NONE = 0, + CI_R_FAILING, + CI_R_MISSING, }; struct CInemaTest {@@ -97,7 +104,7 @@ static char base[PATH_MAX] = {0};
static char outdir[PATH_MAX] = {'.'}; static bool dryRun = false; static bool diffs = false; -static bool rebaseline = false; +static enum CInemaRebaseline rebaseline = CI_R_NONE; static int verbosity = 0; static struct Table configTree;@@ -228,7 +235,10 @@ case 'q':
--verbosity; break; case 'r': - rebaseline = true; + rebaseline = CI_R_FAILING; + break; + case 'R': + rebaseline = CI_R_MISSING; break; case 'v': ++verbosity;@@ -250,6 +260,7 @@ puts(" -n, --dry-run List all collected tests instead of running them");
puts(" -o, --output [DIR] Path to output applicable results"); puts(" -q, --quiet Decrease log verbosity (can be repeated)"); puts(" -r, --rebaseline Rewrite the baseline for failing tests"); + puts(" -R, --rebaseline-missing Write missing baselines tests only"); puts(" -v, --verbose Increase log verbosity (can be repeated)"); puts(" --version Print version and exit"); }@@ -710,30 +721,46 @@ #ifdef USE_FFMPEG
struct FFmpegDecoder decoder; struct FFmpegEncoder encoder; struct CInemaStream stream = {0}; + + char baselineName[PATH_MAX]; + snprintf(baselineName, sizeof(baselineName), "%s" PATH_SEP "baseline.mkv", test->directory); + bool exists = access(baselineName, 0) == 0; + + char tmpBaselineName[PATH_MAX]; + snprintf(tmpBaselineName, sizeof(tmpBaselineName), "%s" PATH_SEP ".baseline.mkv", test->directory); + if (video) { - char fname[PATH_MAX]; - snprintf(fname, sizeof(fname), "%s" PATH_SEP "baseline.mkv", test->directory); - if (rebaseline) { - FFmpegEncoderInit(&encoder); + FFmpegEncoderInit(&encoder); + FFmpegDecoderInit(&decoder); + + if (rebaseline == CI_R_FAILING || (rebaseline == CI_R_MISSING && !exists)) { FFmpegEncoderSetAudio(&encoder, NULL, 0); FFmpegEncoderSetVideo(&encoder, "png", 0, 0); FFmpegEncoderSetContainer(&encoder, "mkv"); FFmpegEncoderSetDimensions(&encoder, image.width, image.height); - if (!FFmpegEncoderOpen(&encoder, fname)) { + + const char* usedFname = baselineName; + if (exists) { + usedFname = tmpBaselineName; + } + if (!FFmpegEncoderOpen(&encoder, usedFname)) { CIerr(1, "Failed to save baseline video\n"); } else { core->setAVStream(core, &encoder.d); } - } else { - FFmpegDecoderInit(&decoder); + } + + if (exists) { stream.d.postVideoFrame = _cinemaVideoFrame; stream.d.videoDimensionsChanged = _cinemaDimensionsChanged; stream.status = &test->status; decoder.out = &stream.d; - if (!FFmpegDecoderOpen(&decoder, fname)) { + if (!FFmpegDecoderOpen(&decoder, baselineName)) { CIerr(1, "Failed to load baseline video\n"); } + } else if (!rebaseline) { + test->status = CI_FAIL; } } #else@@ -763,7 +790,7 @@ bool baselineFound;
if (video) { baselineFound = false; #ifdef USE_FFMPEG - if (!rebaseline && FFmpegDecoderIsOpen(&decoder)) { + if (FFmpegDecoderIsOpen(&decoder)) { stream.image = &expected; while (!expected.data) { if (!FFmpegDecoderRead(&decoder)) {@@ -845,7 +872,7 @@ if (failed) {
++test->failedFrames; } test->totalPixels += image.height * image.width; - if (rebaseline && failed) { + if (rebaseline == CI_R_FAILING && !video && failed) { _writeBaseline(dir, &image, frame); } if (diff) {@@ -881,23 +908,35 @@ test->status = CI_FAIL;
} } - if (fail) { - if (test->status == CI_FAIL) { - test->status = CI_XFAIL; - } else if (test->status == CI_PASS) { - test->status = CI_XPASS; - } - } - #ifdef USE_FFMPEG if (video) { - if (rebaseline) { + if (FFmpegEncoderIsOpen(&encoder)) { FFmpegEncoderClose(&encoder); - } else { + if (exists) { + if (test->status == CI_FAIL) { +#ifdef _WIN32 + MoveFileEx(tmpBaselineName, baselineName, MOVEFILE_REPLACE_EXISTING); +#else + rename(tmpBaselineName, baselineName); +#endif + } else { + remove(tmpBaselineName); + } + } + } + if (FFmpegDecoderIsOpen(&decoder)) { FFmpegDecoderClose(&decoder); } } #endif + + if (fail) { + if (test->status == CI_FAIL) { + test->status = CI_XFAIL; + } else if (test->status == CI_PASS) { + test->status = CI_XPASS; + } + } free(image.data); mCoreConfigDeinit(&core->config);