diff --git a/src/tests/kvm/virtme-run.sh b/src/tests/kvm/virtme-run.sh index d07965494..d712864e0 100755 --- a/src/tests/kvm/virtme-run.sh +++ b/src/tests/kvm/virtme-run.sh @@ -23,6 +23,9 @@ $VM_ENV \ if [ ! -v $MUTTER_DEBUG_FORCE_KMS_MODE ]; then VIRTME_ENV="$VIRTME_ENV MUTTER_DEBUG_FORCE_KMS_MODE=$MUTTER_DEBUG_FORCE_KMS_MODE" fi +if [ ! -v $MUTTER_DEBUG_KMS_THREAD_TYPE ]; then + VIRTME_ENV="$VIRTME_ENV MUTTER_DEBUG_KMS_THREAD_TYPE=$MUTTER_DEBUG_KMS_THREAD_TYPE" +fi if [[ "$(stat -c '%t:%T' -L /proc/$$/fd/0)" == "0:0" ]]; then mkfifo $XDG_RUNTIME_DIR/fake-stdin.$$ diff --git a/src/tests/meson.build b/src/tests/meson.build index f18ec47c9..2377d2831 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -385,19 +385,34 @@ if have_native_tests # KMS tests kms_test_variants = [] - kms_atomic_variables = {'MUTTER_DEBUG_FORCE_KMS_MODE': 'atomic'} - kms_simple_variables = {'MUTTER_DEBUG_FORCE_KMS_MODE': 'simple'} - kms_variants = [ - ['atomic', kms_atomic_variables], - ['simple', kms_simple_variables], + kms_mode_atomic_variables = {'MUTTER_DEBUG_FORCE_KMS_MODE': 'atomic'} + kms_mode_simple_variables = {'MUTTER_DEBUG_FORCE_KMS_MODE': 'simple'} + kms_thread_kernel_variables = {'MUTTER_DEBUG_KMS_THREAD_TYPE': 'kernel'} + kms_thread_user_variables = {'MUTTER_DEBUG_KMS_THREAD_TYPE': 'user'} + kms_mode_variants = [ + ['atomic', kms_mode_atomic_variables], + ['simple', kms_mode_simple_variables], + ] + kms_thread_variants = [ + ['kernel-thread', kms_thread_kernel_variables], + ['user-thread', kms_thread_user_variables], ] - foreach variant: kms_variants - name = variant[0] - variables = variant[1] - suffix = '-@0@'.format(name) - kms_test_env_variables = test_env_variables + variables - kms_test_variants += [[suffix, kms_test_env_variables]] + foreach kms_mode_variant: kms_mode_variants + kms_mode_name = kms_mode_variant[0] + kms_mode_variables = kms_mode_variant[1] + + foreach kms_thread_variant: kms_thread_variants + kms_thread_name = kms_thread_variant[0] + kms_thread_variables = kms_thread_variant[1] + suffix = '-@0@-@1@'.format(kms_thread_name, kms_mode_name) + + kms_test_env_variables = \ + test_env_variables + \ + kms_mode_variables + \ + kms_thread_variables + kms_test_variants += [[suffix, kms_test_env_variables]] + endforeach endforeach kms_test_cases = [ @@ -407,7 +422,7 @@ if have_native_tests 'sources': [ 'native-kms-force-atomic-sanity.c', ], - 'variants': [['', test_env_variables + kms_atomic_variables]], + 'variants': [['', test_env_variables + kms_mode_atomic_variables]], }, { 'name': 'kms-force-simple-sanity', @@ -415,7 +430,23 @@ if have_native_tests 'sources': [ 'native-kms-force-simple-sanity.c', ], - 'variants': [['', test_env_variables + kms_simple_variables]], + 'variants': [['', test_env_variables + kms_mode_simple_variables]], + }, + { + 'name': 'kms-force-kernel-thread-sanity', + 'suite': 'backends/native/kms', + 'sources': [ + 'native-kms-force-kernel-thread-sanity.c', + ], + 'variants': [['', test_env_variables + kms_thread_kernel_variables]], + }, + { + 'name': 'kms-force-user-thread-sanity', + 'suite': 'backends/native/kms', + 'sources': [ + 'native-kms-force-user-thread-sanity.c', + ], + 'variants': [['', test_env_variables + kms_thread_user_variables]], }, { 'name': 'kms-render', diff --git a/src/tests/native-kms-force-kernel-thread-sanity.c b/src/tests/native-kms-force-kernel-thread-sanity.c new file mode 100644 index 000000000..62550eea1 --- /dev/null +++ b/src/tests/native-kms-force-kernel-thread-sanity.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2022 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 "backends/native/meta-backend-native.h" +#include "backends/native/meta-thread-private.h" +#include "meta-test/meta-context-test.h" + +static MetaContext *test_context; + +static gpointer +assert_thread_equal (MetaThreadImpl *thread_impl, + gpointer user_data, + GError **error) +{ + GThread *thread = user_data; + + g_assert_true (thread != g_thread_self ()); + + return NULL; +} + +static void +meta_test_kms_force_kernel_thread_sanity (void) +{ + MetaBackend *backend = meta_context_get_backend (test_context); + MetaKms *kms = meta_backend_native_get_kms (META_BACKEND_NATIVE (backend)); + + g_assert_cmpint (meta_thread_get_thread_type (META_THREAD (kms)), ==, + META_THREAD_TYPE_KERNEL); + meta_thread_run_impl_task_sync (META_THREAD (kms), + assert_thread_equal, g_thread_self (), + NULL); +} + +static void +init_tests (void) +{ + g_test_add_func ("/backends/native/kms/force-kernel-thread-sanity", + meta_test_kms_force_kernel_thread_sanity); +} + +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)); + + test_context = context; + + init_tests (); + + return meta_context_test_run_tests (META_CONTEXT_TEST (context), + META_TEST_RUN_FLAG_CAN_SKIP); +} diff --git a/src/tests/native-kms-force-user-thread-sanity.c b/src/tests/native-kms-force-user-thread-sanity.c new file mode 100644 index 000000000..8195d9055 --- /dev/null +++ b/src/tests/native-kms-force-user-thread-sanity.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2022 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 "backends/native/meta-backend-native.h" +#include "backends/native/meta-thread-private.h" +#include "meta-test/meta-context-test.h" + +static MetaContext *test_context; + +static gpointer +assert_thread_equal (MetaThreadImpl *thread_impl, + gpointer user_data, + GError **error) +{ + GThread *thread = user_data; + + g_assert_true (thread == g_thread_self ()); + + return NULL; +} + +static void +meta_test_kms_force_user_thread_sanity (void) +{ + MetaBackend *backend = meta_context_get_backend (test_context); + MetaKms *kms = meta_backend_native_get_kms (META_BACKEND_NATIVE (backend)); + + g_assert_cmpint (meta_thread_get_thread_type (META_THREAD (kms)), ==, + META_THREAD_TYPE_USER); + meta_thread_run_impl_task_sync (META_THREAD (kms), + assert_thread_equal, g_thread_self (), + NULL); +} + +static void +init_tests (void) +{ + g_test_add_func ("/backends/native/kms/force-user-thread-sanity", + meta_test_kms_force_user_thread_sanity); +} + +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)); + + test_context = context; + + init_tests (); + + return meta_context_test_run_tests (META_CONTEXT_TEST (context), + META_TEST_RUN_FLAG_CAN_SKIP); +}