[Spice-commits] 4 commits - tests/test-quic.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Mar 2 09:59:33 UTC 2020


 tests/test-quic.c |   47 +++++++++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 20 deletions(-)

New commits:
commit 2cec5f99afd40604b7a59ca1b473a04d9aea3588
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Sun Mar 1 09:32:38 2020 +0000

    test-quic: Run 1 random quic test per color mode
    
    Reduce execution time. No need to run so much tests, coverage
    stays more or less the same.
    We iterate twice to check RGB mode with alpha, otherwise the
    coverage reduce about 10-20%.
    
    Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Marc-André Lureau <marcandre.lureau at gmail.com>

diff --git a/tests/test-quic.c b/tests/test-quic.c
index efc4245..6a5e3cf 100644
--- a/tests/test-quic.c
+++ b/tests/test-quic.c
@@ -27,6 +27,8 @@ typedef enum {
     COLOR_MODE_RGB,
     COLOR_MODE_RGB16,
     COLOR_MODE_GRAY,
+
+    COLOR_MODE_END
 } color_mode_t;
 
 static color_mode_t color_mode = COLOR_MODE_RGB;
@@ -339,9 +341,9 @@ static void pixbuf_compare(GdkPixbuf *pixbuf_a, GdkPixbuf *pixbuf_b)
     }
 }
 
-static GdkPixbuf *pixbuf_new_random(void)
+static GdkPixbuf *pixbuf_new_random(int alpha)
 {
-    gboolean has_alpha = g_random_boolean();
+    gboolean has_alpha = alpha >= 0 ? alpha : g_random_boolean();
     gint width = g_random_int_range(100, 2000);
     gint height = g_random_int_range(100, 500);
     GdkPixbuf *random_pixbuf;
@@ -392,13 +394,17 @@ int main(int argc, char **argv)
             g_object_unref(source_pixbuf);
         }
     } else if (argc == 1) {
-        unsigned int count;
-
-        for (count = 0; count < 50; count++) {
-            color_mode = (color_mode_t) (count % 3);
-            GdkPixbuf *pixbuf = pixbuf_new_random();
-            test_pixbuf(pixbuf);
-            g_object_unref(pixbuf);
+        int alpha;
+        for (alpha = 0; alpha < 2; alpha++) {
+            for (color_mode = COLOR_MODE_RGB; color_mode < COLOR_MODE_END; color_mode++) {
+                /* alpha affects only COLOR_MODE_RGB more, reduce number of tests */
+                if (color_mode != COLOR_MODE_RGB && alpha) {
+                    continue;
+                }
+                GdkPixbuf *pixbuf = pixbuf_new_random(alpha);
+                test_pixbuf(pixbuf);
+                g_object_unref(pixbuf);
+            }
         }
     } else {
         g_assert_not_reached();
commit 27fd63ff727c0d818d8be9b1e5b6235afd2dc788
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Sun Mar 1 09:30:16 2020 +0000

    test-quic: Reduce height of test image
    
    There's no much need for than size to be so big, limit to
    reduce execution time, coverage stays more or less the same.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Marc-André Lureau <marcandre.lureau at gmail.com>

diff --git a/tests/test-quic.c b/tests/test-quic.c
index 3ed20ec..efc4245 100644
--- a/tests/test-quic.c
+++ b/tests/test-quic.c
@@ -343,7 +343,7 @@ static GdkPixbuf *pixbuf_new_random(void)
 {
     gboolean has_alpha = g_random_boolean();
     gint width = g_random_int_range(100, 2000);
-    gint height = g_random_int_range(100, 2000);
+    gint height = g_random_int_range(100, 500);
     GdkPixbuf *random_pixbuf;
     guint i, size;
     guint8 *pixels;
commit df66d9a15121bac9428e88c31cc8b65fd8c78347
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Sun Mar 1 09:29:04 2020 +0000

    test-quic: Cache gdk_pixbuf_get_byte_length value
    
    Do not call the function for every iteration
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Marc-André Lureau <marcandre.lureau at gmail.com>

diff --git a/tests/test-quic.c b/tests/test-quic.c
index 632eed8..3ed20ec 100644
--- a/tests/test-quic.c
+++ b/tests/test-quic.c
@@ -345,12 +345,13 @@ static GdkPixbuf *pixbuf_new_random(void)
     gint width = g_random_int_range(100, 2000);
     gint height = g_random_int_range(100, 2000);
     GdkPixbuf *random_pixbuf;
-    guint i;
+    guint i, size;
     guint8 *pixels;
 
     random_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, has_alpha, 8, width, height);
     pixels = gdk_pixbuf_get_pixels(random_pixbuf);
-    for (i = 0; i < gdk_pixbuf_get_byte_length(random_pixbuf); i++) {
+    size = gdk_pixbuf_get_byte_length(random_pixbuf);
+    for (i = 0; i < size; i++) {
         pixels[i] = g_random_int_range(0, 256);
     }
 
commit 8e82bf5661da6613437682681ad1f6d1d61fe17e
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Sat Feb 29 10:50:15 2020 +0000

    test-quic: Avoid namespace conflict with Gdk API
    
    Avoid possible conflict in the future.
    
    Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Marc-André Lureau <marcandre.lureau at gmail.com>

diff --git a/tests/test-quic.c b/tests/test-quic.c
index a410483..632eed8 100644
--- a/tests/test-quic.c
+++ b/tests/test-quic.c
@@ -132,7 +132,7 @@ static inline void rgb16_to_pixel(uint16_t color, uint8_t *p)
 }
 
 #define CONVERT_PROC(TYPE, FUNC) \
-static void gdk_pixbuf_convert_to_##FUNC(GdkPixbuf *pixbuf, TYPE *dest_line, int dest_stride) \
+static void pixbuf_convert_to_##FUNC(GdkPixbuf *pixbuf, TYPE *dest_line, int dest_stride) \
 { \
     int width = gdk_pixbuf_get_width(pixbuf); \
     int height = gdk_pixbuf_get_height(pixbuf); \
@@ -159,7 +159,7 @@ CONVERT_PROC(uint8_t, gray)
 CONVERT_PROC(uint16_t, rgb16)
 
 #define UNCONVERT_PROC(TYPE, FUNC) \
-static void gdk_pixbuf_unconvert_to_##FUNC(GdkPixbuf *pixbuf) \
+static void pixbuf_unconvert_to_##FUNC(GdkPixbuf *pixbuf) \
 { \
     const int width = gdk_pixbuf_get_width(pixbuf); \
     const int height = gdk_pixbuf_get_height(pixbuf); \
@@ -212,14 +212,14 @@ static ImageBuf *image_buf_init(ImageBuf *imgbuf, GdkPixbuf *pixbuf)
     if (color_mode == COLOR_MODE_GRAY) {
         int stride = gdk_pixbuf_get_width(pixbuf);
         uint8_t *pixels = g_malloc(stride * gdk_pixbuf_get_height(pixbuf));
-        gdk_pixbuf_convert_to_gray(pixbuf, pixels, stride);
+        pixbuf_convert_to_gray(pixbuf, pixels, stride);
         imgbuf->stride = stride;
         imgbuf->pixels = pixels;
         imgbuf->quic_type = QUIC_IMAGE_TYPE_GRAY;
     } else if (color_mode == COLOR_MODE_RGB16) {
         int stride = gdk_pixbuf_get_width(pixbuf)*2;
         uint16_t *pixels = g_malloc(stride * gdk_pixbuf_get_height(pixbuf));
-        gdk_pixbuf_convert_to_rgb16(pixbuf, pixels, stride);
+        pixbuf_convert_to_rgb16(pixbuf, pixels, stride);
         imgbuf->stride = stride;
         imgbuf->pixels = (uint8_t*)pixels;
         imgbuf->quic_type = QUIC_IMAGE_TYPE_RGB16;
@@ -231,11 +231,11 @@ static ImageBuf *image_buf_init(ImageBuf *imgbuf, GdkPixbuf *pixbuf)
 static void image_buf_free(ImageBuf *imgbuf, GdkPixbuf *pixbuf)
 {
     if (imgbuf->quic_type == QUIC_IMAGE_TYPE_GRAY) {
-        gdk_pixbuf_unconvert_to_gray(pixbuf);
+        pixbuf_unconvert_to_gray(pixbuf);
     }
 
     if (imgbuf->quic_type == QUIC_IMAGE_TYPE_RGB16) {
-        gdk_pixbuf_unconvert_to_rgb16(pixbuf);
+        pixbuf_unconvert_to_rgb16(pixbuf);
     }
 
     if (imgbuf->pixels != gdk_pixbuf_get_pixels(imgbuf->pixbuf)) {
@@ -304,7 +304,7 @@ static GdkPixbuf *quic_decode_to_pixbuf(GByteArray *compressed_data)
     return pixbuf;
 }
 
-static void gdk_pixbuf_compare(GdkPixbuf *pixbuf_a, GdkPixbuf *pixbuf_b)
+static void pixbuf_compare(GdkPixbuf *pixbuf_a, GdkPixbuf *pixbuf_b)
 {
     int width = gdk_pixbuf_get_width(pixbuf_a);
     int height = gdk_pixbuf_get_height(pixbuf_a);
@@ -339,7 +339,7 @@ static void gdk_pixbuf_compare(GdkPixbuf *pixbuf_a, GdkPixbuf *pixbuf_b)
     }
 }
 
-static GdkPixbuf *gdk_pixbuf_new_random(void)
+static GdkPixbuf *pixbuf_new_random(void)
 {
     gboolean has_alpha = g_random_boolean();
     gint width = g_random_int_range(100, 2000);
@@ -373,7 +373,7 @@ static void test_pixbuf(GdkPixbuf *pixbuf)
     image_buf_free(imgbuf, uncompressed_pixbuf);
 
     //g_assert(memcmp(gdk_pixbuf_get_pixels(pixbuf), gdk_pixbuf_get_pixels(uncompressed_pixbuf), gdk_pixbuf_get_byte_length(uncompressed_pixbuf)));
-    gdk_pixbuf_compare(pixbuf, uncompressed_pixbuf);
+    pixbuf_compare(pixbuf, uncompressed_pixbuf);
 
     g_byte_array_free(compressed_data, TRUE);
     g_object_unref(uncompressed_pixbuf);
@@ -395,7 +395,7 @@ int main(int argc, char **argv)
 
         for (count = 0; count < 50; count++) {
             color_mode = (color_mode_t) (count % 3);
-            GdkPixbuf *pixbuf = gdk_pixbuf_new_random();
+            GdkPixbuf *pixbuf = pixbuf_new_random();
             test_pixbuf(pixbuf);
             g_object_unref(pixbuf);
         }


More information about the Spice-commits mailing list