tests: Make common test code a shared library

This will require some symbol exporting, but the benefit is that have
better control of what external test cases can do in terms of creating
more testing specific contexts.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1861>
This commit is contained in:
Jonas Ådahl 2021-05-06 23:37:35 +02:00
parent d8107027ef
commit 9cda0bd719
23 changed files with 121 additions and 65 deletions

View File

@ -31,7 +31,7 @@
#include "clutter/clutter-color.h"
#include "clutter/clutter-private.h"
#include "meta/common.h"
#include "tests/meta-context-test.h"
#include "meta-test/meta-context-test.h"
G_BEGIN_DECLS

View File

@ -13,9 +13,7 @@ clutter_test_accessibility_c_args = [
clutter_test_accessibility_c_args += clutter_debug_c_args
clutter_accessibility_tests_dependencies = [
clutter_deps,
libmutter_clutter_dep,
libmutter_dep,
libmutter_test_dep,
]
clutter_accessibility_tests = [

View File

@ -66,9 +66,7 @@ foreach test : clutter_conform_tests
c_args: clutter_tests_conform_c_args,
link_args: clutter_tests_conform_link_args,
dependencies: [
clutter_deps,
libmutter_clutter_dep,
libmutter_dep
libmutter_test_dep,
],
install: false,
)

View File

@ -62,16 +62,13 @@ executable('test-interactive',
sources: clutter_tests_interactive_sources,
include_directories: [
clutter_includes,
clutter_tests_includepath,
clutter_tests_includes,
clutter_tests_interactive_includepath,
],
c_args: clutter_tests_interactive_c_args,
link_args: clutter_tests_interactive_link_args,
dependencies: [
clutter_deps,
libmutter_clutter_dep,
libmutter_dep,
gdk_pixbuf_dep,
libmutter_test_dep,
],
install: false,
)

View File

@ -6,8 +6,8 @@
#include <gmodule.h>
#include "backends/x11/nested/meta-backend-x11-nested.h"
#include "meta-test/meta-context-test.h"
#include "tests/clutter-test-utils.h"
#include "tests/meta-context-test.h"
#include "test-unit-names.h"

View File

@ -1,4 +1,8 @@
clutter_tests_includepath = include_directories('.')
clutter_tests_includes = [
tests_includepath,
clutter_tests_includepath,
]
subdir('accessibility')
subdir('conform')

View File

@ -24,9 +24,7 @@ foreach test : clutter_tests_micro_bench_tests
include_directories: clutter_includes,
c_args: clutter_tests_micro_bench_c_args,
dependencies: [
clutter_deps,
libmutter_clutter_dep,
libmutter_dep,
libmutter_test_dep,
],
install: false,
)

View File

@ -23,13 +23,11 @@ foreach test : clutter_tests_performance_tests
],
include_directories: [
clutter_includes,
clutter_tests_includepath,
clutter_tests_includes,
],
c_args: clutter_tests_performance_c_args,
dependencies: [
clutter_deps,
libmutter_clutter_dep,
libmutter_dep,
libmutter_test_dep,
],
install: false,
)

View File

@ -23,7 +23,7 @@
#include "backends/meta-crtc.h"
#include "backends/meta-output.h"
#include "core/display-private.h"
#include "tests/meta-context-test.h"
#include "meta-test/meta-context-test.h"
#include "tests/meta-monitor-manager-test.h"
static void

View File

@ -1,8 +1,7 @@
test_context_sources = [
mutter_test_sources = [
'meta-backend-test.c',
'meta-backend-test.h',
'meta-context-test.c',
'meta-context-test.h',
'meta-gpu-test.c',
'meta-gpu-test.h',
'meta-monitor-manager-test.c',
@ -13,17 +12,15 @@ test_context_sources = [
'meta-test-utils.h',
]
libmutter_test_name = 'mutter-test-' + libmutter_api_version
clutter_test_utils = files (
test_context_sources,
'clutter-test-utils.c',
'clutter-test-utils.h',
)
if have_clutter_tests
subdir('clutter')
endif
tests_includepath = mutter_includes
tests_includepath = include_directories('.')
tests_includes = mutter_includes
tests_c_args = mutter_c_args
tests_deps = [
@ -33,6 +30,41 @@ tests_deps = [
libmutter_clutter_dep,
]
libmutter_test = shared_library(libmutter_test_name,
mutter_test_sources,
gnu_symbol_visibility: 'hidden',
include_directories: tests_includes,
c_args: tests_c_args,
dependencies: tests_deps,
install_rpath: pkglibdir,
install_dir: libdir,
install: true,
)
libmutter_test_dep = declare_dependency(
link_with: libmutter_test,
include_directories: tests_includes,
dependencies: tests_deps,
)
pkg.generate(libmutter_test,
name: 'Meta (test framework)',
filebase: 'libmutter-test-' + libmutter_api_version,
description: 'Mutter test framework',
subdirs: pkgname,
requires: ['libmutter-' + libmutter_api_version],
version: meson.project_version(),
variables: [
'apiversion=' + libmutter_api_version,
],
install_dir: pcdir,
)
if have_clutter_tests
subdir('clutter')
endif
subdir('meta-test')
subdir('wayland-test-clients')
if have_installed_tests
@ -60,7 +92,7 @@ test_env.set('MUTTER_TEST_PLUGIN_PATH', '@0@'.format(default_plugin.full_path())
test_client = executable('mutter-test-client',
sources: ['test-client.c'],
include_directories: tests_includepath,
include_directories: tests_includes,
c_args: tests_c_args,
dependencies: [
gtk3_dep,
@ -74,19 +106,17 @@ test_client = executable('mutter-test-client',
test_runner = executable('mutter-test-runner',
sources: [
test_context_sources,
'test-runner.c',
],
include_directories: tests_includepath,
include_directories: tests_includes,
c_args: tests_c_args,
dependencies: [tests_deps],
dependencies: libmutter_test_dep,
install: have_installed_tests,
install_dir: mutter_installed_tests_libexecdir,
)
unit_tests = executable('mutter-test-unit-tests',
sources: [
test_context_sources,
'unit-tests.c',
'boxes-tests.c',
'boxes-tests.h',
@ -107,35 +137,33 @@ unit_tests = executable('mutter-test-unit-tests',
test_driver_server_header,
test_driver_protocol_code,
],
include_directories: tests_includepath,
include_directories: tests_includes,
c_args: tests_c_args,
dependencies: [tests_deps],
dependencies: libmutter_test_dep,
install: have_installed_tests,
install_dir: mutter_installed_tests_libexecdir,
)
headless_start_test = executable('mutter-headless-start-test',
sources: [
test_context_sources,
'headless-start-test.c',
],
include_directories: tests_includepath,
include_directories: tests_includes,
c_args: tests_c_args,
dependencies: [tests_deps],
dependencies: libmutter_test_dep,
install: have_installed_tests,
install_dir: mutter_installed_tests_libexecdir,
)
stage_view_tests = executable('mutter-stage-view-tests',
sources: [
test_context_sources,
'monitor-test-utils.c',
'monitor-test-utils.h',
'stage-view-tests.c',
],
include_directories: tests_includepath,
include_directories: tests_includes,
c_args: tests_c_args,
dependencies: [tests_deps],
dependencies: libmutter_test_dep,
install: have_installed_tests,
install_dir: mutter_installed_tests_libexecdir,
)
@ -144,7 +172,7 @@ anonymous_file_test = executable('anonymous-file-tests',
sources: [
'anonymous-file.c',
],
include_directories: tests_includepath,
include_directories: tests_includes,
c_args: tests_c_args,
dependencies: [tests_deps],
install: have_installed_tests,
@ -170,7 +198,6 @@ if have_native_tests
native_headless_tests = executable('mutter-native-headless-tests',
sources: [
test_context_sources,
'native-headless.c',
'native-screen-cast.c',
'native-screen-cast.h',
@ -178,22 +205,21 @@ if have_native_tests
'native-virtual-monitor.h',
ref_test_sources,
],
include_directories: tests_includepath,
include_directories: tests_includes,
c_args: tests_c_args,
dependencies: [tests_deps],
dependencies: libmutter_test_dep,
install: have_installed_tests,
install_dir: mutter_installed_tests_libexecdir,
)
ref_test_sanity = executable('mutter-ref-test-sanity',
sources: [
test_context_sources,
'ref-test-sanity.c',
ref_test_sources,
],
include_directories: tests_includepath,
include_directories: tests_includes,
c_args: tests_c_args,
dependencies: [tests_deps],
dependencies: libmutter_test_dep,
install: have_installed_tests,
install_dir: mutter_installed_tests_libexecdir,
)
@ -203,7 +229,7 @@ if have_native_tests
'screen-cast-client.c',
dbus_screen_cast_built_sources,
],
include_directories: tests_includepath,
include_directories: tests_includes,
c_args: tests_c_args,
dependencies: [
gio_dep,
@ -216,12 +242,11 @@ if have_native_tests
native_persistent_virtual_monitor = executable(
'mutter-persistent-virtual-monitor',
sources: [
test_context_sources,
'native-persistent-virtual-monitor.c',
],
include_directories: tests_includepath,
include_directories: tests_includes,
c_args: tests_c_args,
dependencies: [tests_deps],
dependencies: libmutter_test_dep,
install: have_installed_tests,
install_dir: mutter_installed_tests_libexecdir,
)

View File

@ -23,12 +23,15 @@
#include "backends/x11/nested/meta-backend-x11-nested.h"
#define META_TYPE_BACKEND_TEST (meta_backend_test_get_type ())
META_EXPORT
G_DECLARE_FINAL_TYPE (MetaBackendTest, meta_backend_test,
META, BACKEND_TEST, MetaBackendX11Nested)
META_EXPORT
void meta_backend_test_set_is_lid_closed (MetaBackendTest *backend_test,
gboolean is_lid_closed);
META_EXPORT
MetaGpu * meta_backend_test_get_gpu (MetaBackendTest *backend_test);
#endif /* META_BACKEND_TEST_H */

View File

@ -20,7 +20,7 @@
#include "config.h"
#include "tests/meta-context-test.h"
#include "meta-test/meta-context-test.h"
#include <glib.h>
#include <gio/gio.h>
@ -267,6 +267,9 @@ meta_context_test_wait_for_x11_display (MetaContextTest *context_test)
g_assert_nonnull (meta_display_get_x11_display (display));
}
/**
* meta_create_test_context: (skip)
*/
MetaContext *
meta_create_test_context (MetaContextTestType type,
MetaContextTestFlag flags)

View File

@ -46,29 +46,36 @@ struct _MetaOutputTest
typedef MetaMonitorTestSetup * (* CreateTestSetupFunc) (void);
#define META_TYPE_CRTC_TEST (meta_crtc_test_get_type ())
META_EXPORT
G_DECLARE_FINAL_TYPE (MetaCrtcTest, meta_crtc_test,
META, CRTC_TEST,
MetaCrtc)
#define META_TYPE_OUTPUT_TEST (meta_output_test_get_type ())
META_EXPORT
G_DECLARE_FINAL_TYPE (MetaOutputTest, meta_output_test,
META, OUTPUT_TEST,
MetaOutput)
#define META_TYPE_MONITOR_MANAGER_TEST (meta_monitor_manager_test_get_type ())
META_EXPORT
G_DECLARE_FINAL_TYPE (MetaMonitorManagerTest, meta_monitor_manager_test,
META, MONITOR_MANAGER_TEST, MetaMonitorManager)
META_EXPORT
void meta_monitor_manager_test_init_test_setup (CreateTestSetupFunc func);
void meta_monitor_manager_test_read_current (MetaMonitorManager *manager);
META_EXPORT
void meta_monitor_manager_test_emulate_hotplug (MetaMonitorManagerTest *manager_test,
MetaMonitorTestSetup *test_setup);
META_EXPORT
void meta_monitor_manager_test_set_handles_transforms (MetaMonitorManagerTest *manager_test,
gboolean handles_transforms);
META_EXPORT
int meta_monitor_manager_test_get_tiled_monitor_count (MetaMonitorManagerTest *manager_test);
#endif /* META_MONITOR_MANAGER_TEST_H */

View File

@ -27,7 +27,7 @@
#include "core/display-private.h"
#include "core/window-private.h"
#include "tests/meta-context-test.h"
#include "meta-test/meta-context-test.h"
#include "wayland/meta-wayland.h"
#include "wayland/meta-xwayland.h"
#include "x11/meta-x11-display-private.h"

View File

@ -35,51 +35,66 @@ typedef enum _MetaClientError
META_TEST_CLIENT_ERROR_ASSERTION_FAILED
} MetaClientError;
META_EXPORT
GQuark meta_test_client_error_quark (void);
typedef struct _MetaAsyncWaiter MetaAsyncWaiter;
typedef struct _MetaTestClient MetaTestClient;
META_EXPORT
gboolean meta_async_waiter_process_x11_event (MetaAsyncWaiter *waiter,
MetaX11Display *display,
XSyncAlarmNotifyEvent *event);
META_EXPORT
void meta_async_waiter_set_and_wait (MetaAsyncWaiter *waiter);
META_EXPORT
MetaAsyncWaiter * meta_async_waiter_new (void);
META_EXPORT
void meta_async_waiter_destroy (MetaAsyncWaiter *waiter);
META_EXPORT
char * meta_test_client_get_id (MetaTestClient *client);
META_EXPORT
gboolean meta_test_client_process_x11_event (MetaTestClient *client,
MetaX11Display *x11_display,
XSyncAlarmNotifyEvent *event);
META_EXPORT
gboolean meta_test_client_wait (MetaTestClient *client,
GError **error);
META_EXPORT
gboolean meta_test_client_do (MetaTestClient *client,
GError **error,
...) G_GNUC_NULL_TERMINATED;
META_EXPORT
MetaWindow * meta_test_client_find_window (MetaTestClient *client,
const char *window_id,
GError **error);
META_EXPORT
void meta_test_client_wait_for_window_shown (MetaTestClient *client,
MetaWindow *window);
META_EXPORT
gboolean meta_test_client_quit (MetaTestClient *client,
GError **error);
META_EXPORT
MetaTestClient * meta_test_client_new (MetaContext *context,
const char *id,
MetaWindowClientType type,
GError **error);
META_EXPORT
void meta_test_client_destroy (MetaTestClient *client);
META_EXPORT
const char * meta_test_get_plugin_name (void);
#endif /* TEST_UTILS_H */

View File

@ -0,0 +1,9 @@
mutter_test_includesubdir = join_paths(pkgname, 'meta-test')
mutter_test_public_headers = [
'meta-context-test.h',
]
install_headers(mutter_test_public_headers,
subdir: mutter_test_includesubdir
)

View File

@ -21,13 +21,12 @@
#ifndef META_CONTEXT_TEST_H
#define META_CONTEXT_TEST_H
#include "meta/meta-context.h"
#include <meta/common.h>
#include <meta/meta-context.h>
typedef enum _MetaContextTestType
{
#ifdef HAVE_NATIVE_BACKEND
META_CONTEXT_TEST_TYPE_HEADLESS,
#endif
META_CONTEXT_TEST_TYPE_NESTED,
} MetaContextTestType;
@ -39,14 +38,16 @@ typedef enum _MetaContextTestFlag
} MetaContextTestFlag;
#define META_TYPE_CONTEXT_TEST (meta_context_test_get_type ())
META_EXPORT
G_DECLARE_DERIVABLE_TYPE (MetaContextTest, meta_context_test,
META, CONTEXT_TEST,
MetaContext)
META_EXPORT
MetaContext * meta_create_test_context (MetaContextTestType type,
MetaContextTestFlag flags);
META_EXPORT
int meta_context_test_run_tests (MetaContextTest *context_test);
META_EXPORT

View File

@ -20,7 +20,7 @@
#include "config.h"
#include "tests/meta-context-test.h"
#include "meta-test/meta-context-test.h"
#include "tests/native-screen-cast.h"
#include "tests/native-virtual-monitor.h"

View File

@ -20,7 +20,7 @@
#include "backends/meta-virtual-monitor.h"
#include "backends/native/meta-renderer-native.h"
#include "tests/meta-context-test.h"
#include "meta-test/meta-context-test.h"
#include "tests/meta-ref-test.h"
static MetaVirtualMonitor *virtual_monitor;

View File

@ -19,8 +19,8 @@
#include "clutter/clutter.h"
#include "clutter/clutter-stage-view-private.h"
#include "meta-test/meta-context-test.h"
#include "tests/meta-backend-test.h"
#include "tests/meta-context-test.h"
#include "tests/monitor-test-utils.h"
static MonitorTestCaseSetup initial_test_case_setup = {

View File

@ -25,9 +25,9 @@
#include <string.h>
#include "core/window-private.h"
#include "meta-test/meta-context-test.h"
#include "meta/util.h"
#include "meta/window.h"
#include "tests/meta-context-test.h"
#include "tests/meta-test-utils.h"
#include "ui/ui.h"
#include "wayland/meta-wayland.h"

View File

@ -28,9 +28,9 @@
#include <meta/util.h>
#include "core/boxes-private.h"
#include "meta-test/meta-context-test.h"
#include "meta/meta-context.h"
#include "tests/boxes-tests.h"
#include "tests/meta-context-test.h"
#include "tests/monitor-config-migration-unit-tests.h"
#include "tests/monitor-unit-tests.h"
#include "tests/monitor-store-unit-tests.h"

View File

@ -58,7 +58,7 @@ foreach test : wayland_test_clients
'@0@.c'.format(test),
common_sources,
],
include_directories: tests_includepath,
include_directories: tests_includes,
c_args: tests_c_args,
dependencies: [
glib_dep,