tests/etnaviv_2d_test: check whether the rendering is correct
authorLubomir Rintel <lkundrak@v3.sk>
Tue, 1 Dec 2020 20:38:29 +0000 (21:38 +0100)
committerChristian Gmeiner <christian.gmeiner@gmail.com>
Wed, 9 Dec 2020 15:00:51 +0000 (16:00 +0100)
Instead of always dumping the rendered picture, check whether it matches
the expectations. This makes more sense for automated testing.

Retain the ability to dump the picture instead of checking it when a
file name is given as an argument. This also removes use of a hardcoded
file name in a world writable directory, which is an unsafe thing to
do anyway.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
tests/etnaviv/etnaviv_2d_test.c

index a75a4a8..9fcdae1 100644 (file)
@@ -147,6 +147,27 @@ static void gen_cmd_stream(struct etna_cmd_stream *stream, struct etna_bo *bmp,
        etna_set_state(stream, VIVS_GL_FLUSH_CACHE, VIVS_GL_FLUSH_CACHE_PE2D);
 }
 
+int etna_check_image(uint32_t *p, int width, int height)
+{
+       int i;
+       uint32_t expected;
+
+       for (i = 0; i < width * height; i++) {
+               if (i%8 < 4 && i%(width*8) < width*4 && i%width < 8*16 && i < width*8*16)
+                       expected = 0xff40ff40;
+               else
+                       expected = 0x00000000;
+
+               if (p[i] != expected) {
+                       fprintf(stderr, "Offset %d: expected: 0x%08x, got: 0x%08x\n",
+                               i, expected, p[i]);
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
 int main(int argc, char *argv[])
 {
        const int width = 256;
@@ -165,7 +186,7 @@ int main(int argc, char *argv[])
        int core = 0;
 
        if (argc < 2) {
-               fprintf(stderr, "Usage: %s /dev/dri/<device>\n", argv[0]);
+               fprintf(stderr, "Usage: %s /dev/dri/<device> [<etna.bmp>]\n", argv[0]);
                return 1;
        }
 
@@ -242,7 +263,11 @@ int main(int argc, char *argv[])
 
        etna_cmd_stream_finish(stream);
 
-       bmp_dump32(etna_bo_map(bmp), width, height, false, "/tmp/etna.bmp");
+       if (argc > 2)
+               bmp_dump32(etna_bo_map(bmp), width, height, false, argv[2]);
+
+       if (etna_check_image(etna_bo_map(bmp), width, height))
+               ret = 7;
 
        etna_cmd_stream_del(stream);