summaryrefslogtreecommitdiffstats
path: root/test/tests.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-11-08 17:20:57 +0100
committerwm4 <wm4@nowhere>2019-11-08 21:22:49 +0100
commit1edb3d061bd88e86cba05e9383d6decb4a13950b (patch)
tree18b5438f040464f841c5e0b9ae0a877175759c75 /test/tests.c
parenta6c8b4efa59628a755755c510aa9ee6db2728fb9 (diff)
downloadmpv-1edb3d061bd88e86cba05e9383d6decb4a13950b.tar.bz2
mpv-1edb3d061bd88e86cba05e9383d6decb4a13950b.tar.xz
test: add dumping of img_format metadata
This is fragile enough that it warrants getting "monitored". This takes the commented test program code from img_format.c, makes it output to a text file, and then compares it to a "ref" file stored in git. Originally, I wanted to do the comparison etc. in a shell or Python script. But why not do it in C. So mpv calls /usr/bin/diff as a sub-process now. This test will start producing different output if FFmpeg adds new pixel formats or pixel format flags, or if mpv adds new IMGFMT (either aliases to FFmpeg formats or own formats). That is unavoidable, and requires manual inspection of the results, and then updating the ref file. The changes in the non-test code are to guarantee that the format ID conversion functions only translate between valid IDs.
Diffstat (limited to 'test/tests.c')
-rw-r--r--test/tests.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/tests.c b/test/tests.c
index 68245d2df1..5fe486e2ec 100644
--- a/test/tests.c
+++ b/test/tests.c
@@ -1,9 +1,12 @@
+#include "options/path.h"
+#include "osdep/subprocess.h"
#include "player/core.h"
#include "tests.h"
static const struct unittest *unittests[] = {
&test_chmap,
&test_gl_video,
+ &test_img_format,
&test_json,
&test_linked_list,
NULL
@@ -25,8 +28,17 @@ bool run_tests(struct MPContext *mpctx)
struct test_ctx ctx = {
.global = mpctx->global,
.log = mpctx->log,
+ .ref_path = "test/ref",
+ .out_path = "test/out",
};
+ if (!mp_path_isdir(ctx.ref_path)) {
+ MP_FATAL(mpctx, "Must be run from git repo root dir.\n");
+ abort();
+ }
+ mp_mkdirp(ctx.out_path);
+ assert(mp_path_isdir(ctx.out_path));
+
int num_run = 0;
for (int n = 0; unittests[n]; n++) {
@@ -81,3 +93,33 @@ void assert_float_equal_impl(const char *file, int line,
abort();
}
}
+
+FILE *test_open_out(struct test_ctx *ctx, const char *name)
+{
+ char *path = mp_tprintf(4096, "%s/%s", ctx->out_path, name);
+ FILE *f = fopen(path, "wb");
+ if (!f) {
+ MP_FATAL(ctx, "Could not open '%s' for writing.\n", path);
+ abort();
+ }
+ return f;
+}
+
+void assert_text_files_equal_impl(const char *file, int line,
+ struct test_ctx *ctx, const char *ref,
+ const char *new, const char *err)
+{
+ char *path_ref = mp_tprintf(4096, "%s/%s", ctx->ref_path, ref);
+ char *path_new = mp_tprintf(4096, "%s/%s", ctx->out_path, new);
+
+ char *errstr = NULL;
+ int res = mp_subprocess((char*[]){"diff", "-u", "--", path_ref, path_new, 0},
+ NULL, NULL, NULL, NULL, &errstr);
+
+ if (res) {
+ if (res == 1)
+ MP_WARN(ctx, "Note: %s\n", err);
+ MP_FATAL(ctx, "Giving up.\n");
+ abort();
+ }
+}