diff --git a/tests/internal-screenshot-test.c b/tests/internal-screenshot-test.c index 6c1b774e3..b9e0a16b2 100644 --- a/tests/internal-screenshot-test.c +++ b/tests/internal-screenshot-test.c @@ -42,7 +42,11 @@ fixture_setup(struct weston_test_harness *harness) setup.width = 320; setup.height = 240; setup.shell = SHELL_DESKTOP; - setup.config_file = TESTSUITE_INTERNAL_SCREENSHOT_CONFIG_PATH; + + weston_ini_setup (&setup, + cfgln("[shell]"), + cfgln("startup-animation=%s", "none"), + cfgln("background-color=%s", "0xCC336699")); return weston_test_harness_execute_as_client(harness, &setup); } diff --git a/tests/internal-screenshot.ini b/tests/internal-screenshot.ini deleted file mode 100644 index abc046e9c..000000000 --- a/tests/internal-screenshot.ini +++ /dev/null @@ -1,3 +0,0 @@ -[shell] -startup-animation=none -background-color=0xCC336699 diff --git a/tests/ivi-shell-app-test.c b/tests/ivi-shell-app-test.c index 5652c0de7..7e7819ad8 100644 --- a/tests/ivi-shell-app-test.c +++ b/tests/ivi-shell-app-test.c @@ -40,7 +40,8 @@ fixture_setup(struct weston_test_harness *harness) compositor_setup_defaults(&setup); setup.shell = SHELL_IVI; - setup.config_file = TESTSUITE_IVI_CONFIG_PATH; + /** TODO: Convert this test to use weston_ini_setup */ + setup.config_file = strdup(TESTSUITE_IVI_CONFIG_PATH); setup.logging_scopes = "log,test-harness-plugin,proto"; return weston_test_harness_execute_as_client(harness, &setup); diff --git a/tests/meson.build b/tests/meson.build index 1b9ecdc89..b82f1abd9 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -267,7 +267,6 @@ 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()) test_config_h.set_quoted('TESTSUITE_IVI_CONFIG_PATH', join_paths(meson.current_build_dir(), '../ivi-shell/weston-ivi-test.ini')) -test_config_h.set_quoted('TESTSUITE_INTERNAL_SCREENSHOT_CONFIG_PATH', join_paths(meson.current_source_dir(), 'internal-screenshot.ini')) configure_file(output: 'test-config.h', configuration: test_config_h) foreach t : tests diff --git a/tests/weston-test-fixture-compositor.c b/tests/weston-test-fixture-compositor.c index 0c9855f60..1c32959c8 100644 --- a/tests/weston-test-fixture-compositor.c +++ b/tests/weston-test-fixture-compositor.c @@ -30,6 +30,10 @@ #include #include #include +#include +#include +#include +#include #include #include "shared/helpers.h" @@ -393,6 +397,7 @@ execute_compositor(const struct compositor_setup *setup, if (setup->config_file) { asprintf(&tmp, "--config=%s", setup->config_file); prog_args_take(&args, tmp); + free(setup->config_file); } else { prog_args_take(&args, strdup("--no-config")); } @@ -425,3 +430,77 @@ execute_compositor(const struct compositor_setup *setup, return ret; } + +static void +write_cfg(va_list entry_list, FILE *weston_ini) +{ + char *entry = va_arg(entry_list, char *); + int ret; + assert(entry); + + while (entry) { + ret = fprintf(weston_ini, "%s\n", entry); + assert(ret >= 0); + free(entry); + entry = va_arg(entry_list, char *); + } +} + +static FILE * +open_ini_file(struct compositor_setup *setup) +{ + char *wd, *tmp_path = NULL; + FILE *weston_ini = NULL; + + assert(!setup->config_file); + + wd = realpath(".", NULL); + assert(wd); + + if (asprintf(&tmp_path, "%s/%s.ini", wd, setup->testset_name) == -1) { + fprintf(stderr, "Fail formating Weston.ini file name.\n"); + goto out; + } + + weston_ini = fopen(tmp_path, "w"); + assert(weston_ini); + setup->config_file = tmp_path; + +out: + free(wd); + return weston_ini; +} + +void +weston_ini_setup_(struct compositor_setup *setup, ...) +{ + FILE *weston_ini = NULL; + int ret; + va_list entry_list; + + weston_ini = open_ini_file(setup); + assert(weston_ini); + + va_start(entry_list, setup); + write_cfg(entry_list, weston_ini); + va_end(entry_list); + + ret = fclose(weston_ini); + assert(ret != EOF); +} + +char * +cfgln(const char *fmt, ...) +{ + char *str; + int ret; + va_list ap; + + va_start(ap, fmt); + ret = vasprintf(&str, fmt, ap); + assert(ret >= 0); + va_end(ap); + + return str; +} + diff --git a/tests/weston-test-fixture-compositor.h b/tests/weston-test-fixture-compositor.h index fd8d0e5c6..a9d440d77 100644 --- a/tests/weston-test-fixture-compositor.h +++ b/tests/weston-test-fixture-compositor.h @@ -88,8 +88,9 @@ struct compositor_setup { /** Default output transform, one of WL_OUTPUT_TRANSFORM_*. */ enum wl_output_transform transform; /** The absolute path to \c weston.ini to use, - * or NULL for \c --no-config . */ - const char *config_file; + * or NULL for \c --no-config . + * To properly fill this entry use weston_ini_setup() */ + char *config_file; /** Full path to an extra plugin to load, or NULL for none. */ const char *extra_module; /** Debug scopes for the compositor log, @@ -131,4 +132,27 @@ int execute_compositor(const struct compositor_setup *setup, struct wet_testsuite_data *data); +/* This function creates and fills a Weston.ini file + * + * \param setup a compositor_setup + * \param ... Variadic number of strings that will be used to compose + * the Weston.ini + * + * This function receives a compositor_setup and a variable number of + * strings that will compose the weston.ini. And will create a + * .ini and fill it with the entries. + * This function will assert if anything goes wrong, then it will not + * have a return value to indicate success or failure. + * + * \ingroup testharness + */ +#define weston_ini_setup(setup, ...) \ + weston_ini_setup_(setup, __VA_ARGS__, NULL) + +void +weston_ini_setup_(struct compositor_setup *setup, ...); + +char * +cfgln(const char *fmt, ...); + #endif /* WESTON_TEST_FIXTURE_COMPOSITOR_H */