From 82dd6ce8302787e2f96ec53a408fe04b4523aeb7 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Fri, 1 Nov 2019 15:39:30 +0200 Subject: [PATCH] tests: stop relying on environment in the new harness Instead of relying on Meson setting up environment so that Weston and tests find all their files, build those values into the tests. This way one can execute a test program successfully wihtout Meson, simply by running it. The old environment variables are still honoured if set. This might change in the future. Baking the source or build directory paths into the tests should not regress reproducible builds, because the binaries where test-config.h values are used will not be installed. Signed-off-by: Pekka Paalanen --- tests/meson.build | 10 ++++++++-- tests/weston-test-client-helper.c | 3 ++- tests/weston-test-fixture-compositor.c | 7 +++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/meson.build b/tests/meson.build index 49135b435..a9cde8960 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -64,7 +64,6 @@ exe_plugin_test = shared_library( name_prefix: '', install: false, ) -config_h.set_quoted('TESTSUITE_PLUGIN_PATH', exe_plugin_test.full_path()) deps_zuc = [ dep_libshared ] if get_option('test-junit-xml') @@ -250,6 +249,13 @@ env_test_weston = [ 'WESTON_DATA_DIR=' + join_paths(meson.current_source_dir(), '..', 'data'), ] +test_config_h = configuration_data() +test_config_h.set_quoted('WESTON_TEST_REFERENCE_PATH', meson.current_source_dir() + '/reference') +test_config_h.set_quoted('WESTON_MODULE_MAP', env_modmap) +test_config_h.set_quoted('WESTON_DATA_DIR', join_paths(meson.current_source_dir(), '..', 'data')) +test_config_h.set_quoted('TESTSUITE_PLUGIN_PATH', exe_plugin_test.full_path()) +configure_file(output: 'test-config.h', configuration: test_config_h) + foreach t : tests t_name = 'test-' + t.get('name') t_sources = t.get('sources', [t.get('name') + '-test.c']) @@ -271,7 +277,7 @@ foreach t : tests install: false, ) - test(t.get('name'), t_exe, depends: t.get('test_deps', []), env: env_test_weston) + test(t.get('name'), t_exe, depends: t.get('test_deps', [])) endforeach # FIXME: the multiple loops is lame. rethink this. diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c index 503ed0983..3fb6b72f8 100644 --- a/tests/weston-test-client-helper.c +++ b/tests/weston-test-client-helper.c @@ -34,6 +34,7 @@ #include #include +#include "test-config.h" #include "shared/os-compatibility.h" #include "shared/xalloc.h" #include @@ -1025,7 +1026,7 @@ reference_path(void) char *path = getenv("WESTON_TEST_REFERENCE_PATH"); if (!path) - return "./tests/reference"; + return WESTON_TEST_REFERENCE_PATH; return path; } diff --git a/tests/weston-test-fixture-compositor.c b/tests/weston-test-fixture-compositor.c index 04c06409b..ea206be01 100644 --- a/tests/weston-test-fixture-compositor.c +++ b/tests/weston-test-fixture-compositor.c @@ -31,6 +31,7 @@ #include "shared/helpers.h" #include "weston-test-fixture-compositor.h" #include "weston.h" +#include "test-config.h" struct prog_args { int argc; @@ -180,6 +181,12 @@ execute_compositor(const struct compositor_setup *setup, const char *ctmp; int ret; + if (setenv("WESTON_MODULE_MAP", WESTON_MODULE_MAP, 0) < 0 || + setenv("WESTON_DATA_DIR", WESTON_DATA_DIR, 0) < 0) { + fprintf(stderr, "Error: environment setup failed.\n"); + return RESULT_HARD_ERROR; + } + #ifndef BUILD_DRM_COMPOSITOR if (setup->backend == WESTON_BACKEND_DRM) { fprintf(stderr, "DRM-backend required but not built, skipping.\n");