tests/ref-test: Allow updating only non-existing reference images

This makes it a bit more reliable to add more reference images, but be
sure not to touch any existing ones.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3859>
This commit is contained in:
Jonas Ådahl 2024-11-22 13:01:35 +01:00 committed by Sebastian Wick
parent 9cc5bec0a3
commit 129ead488b
3 changed files with 33 additions and 6 deletions

View File

@ -315,6 +315,7 @@ meta_ref_test_verify (MetaRefTestAdaptor adaptor,
g_autofree char *ref_image_path = NULL;
cairo_surface_t *ref_image;
cairo_status_t ref_status;
gboolean maybe_update;
image = adaptor (adaptor_data);
@ -330,11 +331,21 @@ meta_ref_test_verify (MetaRefTestAdaptor adaptor,
g_assert_nonnull (ref_image);
ref_status = cairo_surface_status (ref_image);
if (flags & META_REFTEST_FLAG_UPDATE_REF)
{
g_assert_true (ref_status == CAIRO_STATUS_FILE_NOT_FOUND ||
ref_status == CAIRO_STATUS_SUCCESS);
g_assert_true (ref_status == CAIRO_STATUS_FILE_NOT_FOUND ||
ref_status == CAIRO_STATUS_SUCCESS);
if (ref_status == CAIRO_STATUS_FILE_NOT_FOUND)
{
maybe_update = ((flags & META_REFTEST_FLAG_UPDATE_REF) ||
(flags & META_REFTEST_FLAG_ENSURE_REF));
}
else
{
maybe_update = !!(flags & META_REFTEST_FLAG_UPDATE_REF);
}
if (maybe_update)
{
if (ref_status == CAIRO_STATUS_SUCCESS)
ensure_expected_format (&ref_image);
@ -428,6 +439,10 @@ meta_ref_test_verify (MetaRefTestAdaptor adaptor,
result_image_path,
diff_image_path);
}
else
{
g_message ("Image matched the reference image '%s'.", ref_image_path);
}
}
cairo_surface_destroy (image);

View File

@ -24,6 +24,7 @@ typedef enum _MetaReftestFlag
{
META_REFTEST_FLAG_NONE = 0,
META_REFTEST_FLAG_UPDATE_REF = 1 << 0,
META_REFTEST_FLAG_ENSURE_REF = 1 << 1,
} MetaReftestFlag;
typedef cairo_surface_t * (* MetaRefTestAdaptor) (gpointer adaptor_data);

View File

@ -24,6 +24,10 @@
* expressions, the test reference image will be updated, unless the
* existing reference image is pixel identical to the newly created one.
*
* If MUTTER_REF_TEST_ENSURE_ONLY is set to "1", in combination with
* MUTTER_REF_TEST_UPDATE being set, only reference images that doesn't already
* exist are updated.
*
* Updating test reference images also requires using a software OpenGL
* renderer, which can be achieved using MESA_LOADER_DRIVER_OVERRIDE=swrast
*
@ -210,18 +214,24 @@ meta_ref_test_verify_view (ClutterStageView *view,
MetaReftestFlag
meta_ref_test_determine_ref_test_flag (void)
{
gboolean ensure_only;
const char *update_tests;
char **update_test_rules;
int n_update_test_rules;
MetaReftestFlag flags;
int i;
ensure_only = g_strcmp0 (getenv ("MUTTER_REF_TEST_ENSURE_ONLY"), "1") == 0;
update_tests = g_getenv ("MUTTER_REF_TEST_UPDATE");
if (!update_tests)
return META_REFTEST_FLAG_NONE;
if (strcmp (update_tests, "all") == 0)
return META_REFTEST_FLAG_UPDATE_REF;
{
return ensure_only ? META_REFTEST_FLAG_ENSURE_REF
: META_REFTEST_FLAG_UPDATE_REF;
}
update_test_rules = g_strsplit (update_tests, ",", -1);
n_update_test_rules = g_strv_length (update_test_rules);
@ -234,7 +244,8 @@ meta_ref_test_determine_ref_test_flag (void)
if (g_regex_match_simple (rule, g_test_get_path (), 0, 0))
{
flags |= META_REFTEST_FLAG_UPDATE_REF;
flags |= ensure_only ? META_REFTEST_FLAG_ENSURE_REF
: META_REFTEST_FLAG_UPDATE_REF;
break;
}
}