[PATCH weston v0 10/11] tests: Add support for comparing output against reference images
Bryce Harrington
bryce at osg.samsung.com
Sun Nov 9 13:41:26 PST 2014
This lift's files_equal() routine to do byte comparison of the rendered
files. Note that since the clock time will change run to run we can
only compare against the first frame (which will be black).
Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
---
tests/fadein-test.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 60 insertions(+), 4 deletions(-)
diff --git a/tests/fadein-test.c b/tests/fadein-test.c
index 5b243bf..7ad58ed 100644
--- a/tests/fadein-test.c
+++ b/tests/fadein-test.c
@@ -24,27 +24,73 @@
#include <unistd.h>
#include <stdio.h>
+#include <stdbool.h>
#include "weston-test-client-helper.h"
char *server_parameters="--use-pixman --width=320 --height=240";
static char*
-output_filename(const char* basename) {
+output_filename(const char* basename, int head) {
static const char *path = "./";
char *filename;
- if (asprintf(&filename, "%s%s", path, basename) < 0)
+ if (asprintf(&filename, "%s%s-%d.png", path, basename, head) < 0)
filename = NULL;
return filename;
}
+static char*
+reference_filename(const char* basename, int head) {
+ static const char *path = "./tests/reference/";
+ char *filename;
+
+ if (asprintf(&filename, "%s%s-%d.png", path, basename, head) < 0)
+ filename = NULL;
+
+ return filename;
+}
+
+static bool
+files_equal(const char *test_filename, const char* ref_filename)
+{
+ FILE *test, *ref;
+ int t, p;
+
+ if (test_filename == NULL || ref_filename == NULL)
+ return false;
+
+ test = fopen (test_filename, "rb");
+ if (test == NULL)
+ return false;
+
+ ref = fopen (ref_filename, "rb");
+ if (ref == NULL) {
+ fclose (test);
+ return false;
+ }
+
+ do {
+ t = getc (test);
+ p = getc (ref);
+ if (t != p)
+ break;
+ } while (t != EOF && p != EOF);
+
+ fclose (test);
+ fclose (ref);
+
+ return t == p; /* both EOF */
+}
+
+
TEST(headless)
{
struct client *client;
char basename[32];
char *out_path;
+ char *ref_path;
int i;
client = client_create(100, 100, 100, 100);
@@ -52,11 +98,21 @@ TEST(headless)
for (i = 0; i < 6; i++) {
snprintf(basename, sizeof basename, "fadein-%02d", i);
- out_path = output_filename(basename);
+ // FIXME: Iterate over all heads
+ out_path = output_filename(basename, 0);
+ ref_path = reference_filename(basename, 0);
- wl_test_record_screenshot(client->test->wl_test, out_path);
+ // FIXME: Would be preferred to pass in out_path rather than basename here...
+ wl_test_record_screenshot(client->test->wl_test, basename);
client_roundtrip(client);
+ if (i == 0) {
+ if (files_equal(out_path, ref_path))
+ printf("%s is correct\n", out_path);
+ else
+ printf("%s doesn't match reference %s\n", out_path, ref_path);
+ }
free (out_path);
+ free (ref_path);
usleep(250000);
}
--
1.9.1
More information about the wayland-devel
mailing list