testsuite: Make memorytexture tests random
authorBenjamin Otte <otte@redhat.com>
Thu, 8 Jun 2023 23:04:27 +0000 (01:04 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 8 Jun 2023 23:12:32 +0000 (01:12 +0200)
Instead of picking a few numbers in advance and running them through the
test gauntlet every time, pick the random numbers at runtime.

This both increases the test coverage in that it ultimately tests more
combinations across many runs and it reduces the runtime of individual
runs because every tun only runs the download tests twice (with 1px and
the random size) instead of 5 times.

And that speedup benefits the CI, where the asan runs would cause this
test to timeout sometimes.

testsuite/gdk/memorytexture.c

index 62329f61e721de2f73fc81d870fa8a20495c83f2..138eb6844b51e7edd7efae124b0f2996712d4b96 100644 (file)
@@ -1188,30 +1188,22 @@ test_download_1x1 (gconstpointer data)
 }
 
 static void
-test_download_4x4 (gconstpointer data)
+test_download_random (gconstpointer data)
 {
-  test_download (data, 4, 4);
-}
+  int width, height;
 
-/* odd sizes, to trigger alignment issues */
-static void
-test_download_17x7 (gconstpointer data)
-{
-  test_download (data, 17, 7);
-}
-
-/* larger than what GSK puts into the icon cache */
-static void
-test_download_192x192 (gconstpointer data)
-{
-  test_download (data, 192, 192);
-}
+  /* Make sure the maximum is:
+   * - larger than what GSK puts into the icon cache
+   * - larger than the small max-texture-size we test against
+   */
+  do
+    {
+      width = g_test_rand_int_range (1, 40) * g_test_rand_int_range (1, 40);
+      height = g_test_rand_int_range (1, 40) * g_test_rand_int_range (1, 40);
+    }
+  while (width * height >= 1024 * 1024);
 
-/* larger than the small max-texture-size we test against */
-static void
-test_download_1065x17 (gconstpointer data)
-{
-  test_download (data, 1065, 17);
+  test_download (data, width, height);
 }
 
 static void
@@ -1285,9 +1277,9 @@ test_conversion_1x1 (gconstpointer data)
 }
 
 static void
-test_conversion_4x4 (gconstpointer data)
+test_conversion_random (gconstpointer data)
 {
-  test_conversion (data, 4);
+  test_conversion (data, g_test_rand_int_range (2, 18));
 }
 
 static void
@@ -1346,12 +1338,9 @@ main (int argc, char *argv[])
   gtk_test_init (&argc, &argv, NULL);
 
   add_test ("/memorytexture/download_1x1", test_download_1x1);
-  add_test ("/memorytexture/download_4x4", test_download_4x4);
-  add_test ("/memorytexture/download_17x7", test_download_17x7);
-  add_test ("/memorytexture/download_192x192", test_download_192x192);
-  add_test ("/memorytexture/download_1065x17", test_download_1065x17);
+  add_test ("/memorytexture/download_random", test_download_random);
   add_conversion_test ("/memorytexture/conversion_1x1", test_conversion_1x1);
-  add_conversion_test ("/memorytexture/conversion_4x4", test_conversion_4x4);
+  add_conversion_test ("/memorytexture/conversion_random", test_conversion_random);
 
   gl_context = gdk_display_create_gl_context (gdk_display_get_default (), NULL);
   if (!gdk_gl_context_realize (gl_context, NULL))