Add rudimentary mode setting test

Add a test that uses vkms to test that mode setting works, and that
rendering works. It renders 10 frames in a row after mode setting, then
exits.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2151>
This commit is contained in:
Jonas Ådahl
2021-05-17 19:18:08 +02:00
committed by Marge Bot
parent 51368227f2
commit c8c9d49f79
9 changed files with 178 additions and 8 deletions

View File

@ -273,6 +273,17 @@ if have_native_tests
install: have_installed_tests,
install_dir: mutter_installed_tests_libexecdir,
)
native_kms_render_tests = executable('mutter-native-kms-render',
sources: [
'native-kms-render.c',
],
include_directories: tests_includes,
c_args: tests_c_args,
dependencies: libmutter_test_dep,
install: have_installed_tests,
install_dir: mutter_installed_tests_libexecdir,
)
endif
stacking_tests = [
@ -380,4 +391,11 @@ if have_native_tests
is_parallel: false,
timeout: 60,
)
test('native-kms-render', native_kms_render_tests,
suite: ['core', 'mutter/native/kms/render'],
env: test_env,
is_parallel: false,
timeout: 60,
)
endif

View File

@ -162,6 +162,17 @@ create_headless_backend (MetaContext *context,
"mode", META_BACKEND_NATIVE_MODE_HEADLESS,
NULL);
}
static MetaBackend *
create_native_backend (MetaContext *context,
GError **error)
{
return g_initable_new (META_TYPE_BACKEND_NATIVE,
NULL, error,
"context", context,
"mode", META_BACKEND_NATIVE_MODE_TEST,
NULL);
}
#endif /* HAVE_NATIVE_BACKEND */
static MetaBackend *
@ -179,6 +190,8 @@ meta_context_test_create_backend (MetaContext *context,
#ifdef HAVE_NATIVE_BACKEND
case META_CONTEXT_TEST_TYPE_HEADLESS:
return create_headless_backend (context, error);
case META_CONTEXT_TEST_TYPE_VKMS:
return create_native_backend (context, error);
#endif /* HAVE_NATIVE_BACKEND */
}
@ -233,8 +246,22 @@ meta_context_test_run_tests (MetaContextTest *context_test,
if (!meta_context_setup (context, &error))
{
g_printerr ("Test case failed to start: %s\n", error->message);
return EXIT_FAILURE;
if ((flags & META_TEST_RUN_FLAG_CAN_SKIP) &&
((g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) &&
strstr (error->message, "No GPUs found")) ||
(g_error_matches (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR) &&
strstr (error->message, "Could not take control")) ||
(g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD) &&
strstr (error->message, "Could not take control"))))
{
g_printerr ("Test skipped: %s\n", error->message);
return 77;
}
else
{
g_printerr ("Test case failed to setup: %s\n", error->message);
return EXIT_FAILURE;
}
}
if (!meta_context_start (context, &error))

View File

@ -27,6 +27,7 @@
typedef enum _MetaContextTestType
{
META_CONTEXT_TEST_TYPE_HEADLESS,
META_CONTEXT_TEST_TYPE_VKMS,
META_CONTEXT_TEST_TYPE_NESTED,
} MetaContextTestType;
@ -40,6 +41,7 @@ typedef enum _MetaContextTestFlag
typedef enum _MetaTestRunFlags
{
META_TEST_RUN_FLAG_NONE = 0,
META_TEST_RUN_FLAG_CAN_SKIP = 1 << 0,
} MetaTestRunFlags;
#define META_TYPE_CONTEXT_TEST (meta_context_test_get_type ())

View File

@ -0,0 +1,86 @@
/*
* Copyright (C) 2021 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
*/
#include "config.h"
#include "meta/meta-backend.h"
#include "meta-test/meta-context-test.h"
typedef struct
{
int number_of_frames_left;
GMainLoop *loop;
} KmsRenderingTest;
static void
on_after_update (ClutterStage *stage,
ClutterStageView *stage_view,
KmsRenderingTest *test)
{
test->number_of_frames_left--;
if (test->number_of_frames_left == 0)
g_main_loop_quit (test->loop);
else
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
}
static void
meta_test_kms_render_basic (void)
{
MetaBackend *backend = meta_get_backend ();
ClutterActor *stage = meta_backend_get_stage (backend);
KmsRenderingTest test;
test = (KmsRenderingTest) {
.number_of_frames_left = 10,
.loop = g_main_loop_new (NULL, FALSE),
};
g_signal_connect (stage, "after-update", G_CALLBACK (on_after_update), &test);
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
g_main_loop_run (test.loop);
g_main_loop_unref (test.loop);
g_assert_cmpint (test.number_of_frames_left, ==, 0);
}
static void
init_tests (void)
{
g_test_add_func ("/backends/native/kms/render/basic",
meta_test_kms_render_basic);
}
int
main (int argc,
char **argv)
{
g_autoptr (MetaContext) context = NULL;
g_autoptr (GError) error = NULL;
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_VKMS,
META_CONTEXT_TEST_FLAG_NO_X11);
g_assert (meta_context_configure (context, &argc, &argv, NULL));
init_tests ();
return meta_context_test_run_tests (META_CONTEXT_TEST (context),
META_TEST_RUN_FLAG_CAN_SKIP);
}