tests: Add a way to write a Weston.ini inside the test
Currently doesn't exist a standard way to write a weston.ini inside a test. Here, two new functions `weston_ini_setup` and `cfgln` are introduced to help the test writer to write a weston.ini file and load it to the test. And `internal-screenshot-test` is converted to use the new method of write a weston.ini. This conversion serves as example and initial API test. The tester needs to call `weston_test_harness_execute_as_client` or `weston_test_harness_execute_as_plugin` in the same way as before. The `weston_ini_setup` will fill the setup->config_file with the correct path to the weston.ini file. The main design goal is to avoid pre-made or build-made weston.ini(s) and keep the test as self-contained as possible. Closes:#410 Signed-off-by: Igor Matheus Andrade Torrente <igormtorrente@gmail.com>
This commit is contained in:
committed by
Pekka Paalanen
parent
ebcf4f35b4
commit
ad41a88535
@@ -42,7 +42,11 @@ fixture_setup(struct weston_test_harness *harness)
|
|||||||
setup.width = 320;
|
setup.width = 320;
|
||||||
setup.height = 240;
|
setup.height = 240;
|
||||||
setup.shell = SHELL_DESKTOP;
|
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);
|
return weston_test_harness_execute_as_client(harness, &setup);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
[shell]
|
|
||||||
startup-animation=none
|
|
||||||
background-color=0xCC336699
|
|
||||||
@@ -40,7 +40,8 @@ fixture_setup(struct weston_test_harness *harness)
|
|||||||
|
|
||||||
compositor_setup_defaults(&setup);
|
compositor_setup_defaults(&setup);
|
||||||
setup.shell = SHELL_IVI;
|
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";
|
setup.logging_scopes = "log,test-harness-plugin,proto";
|
||||||
|
|
||||||
return weston_test_harness_execute_as_client(harness, &setup);
|
return weston_test_harness_execute_as_client(harness, &setup);
|
||||||
|
|||||||
@@ -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('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_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_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)
|
configure_file(output: 'test-config.h', configuration: test_config_h)
|
||||||
|
|
||||||
foreach t : tests
|
foreach t : tests
|
||||||
|
|||||||
@@ -30,6 +30,10 @@
|
|||||||
#include <libudev.h>
|
#include <libudev.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "shared/helpers.h"
|
#include "shared/helpers.h"
|
||||||
@@ -393,6 +397,7 @@ execute_compositor(const struct compositor_setup *setup,
|
|||||||
if (setup->config_file) {
|
if (setup->config_file) {
|
||||||
asprintf(&tmp, "--config=%s", setup->config_file);
|
asprintf(&tmp, "--config=%s", setup->config_file);
|
||||||
prog_args_take(&args, tmp);
|
prog_args_take(&args, tmp);
|
||||||
|
free(setup->config_file);
|
||||||
} else {
|
} else {
|
||||||
prog_args_take(&args, strdup("--no-config"));
|
prog_args_take(&args, strdup("--no-config"));
|
||||||
}
|
}
|
||||||
@@ -425,3 +430,77 @@ execute_compositor(const struct compositor_setup *setup,
|
|||||||
|
|
||||||
return ret;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,8 +88,9 @@ struct compositor_setup {
|
|||||||
/** Default output transform, one of WL_OUTPUT_TRANSFORM_*. */
|
/** Default output transform, one of WL_OUTPUT_TRANSFORM_*. */
|
||||||
enum wl_output_transform transform;
|
enum wl_output_transform transform;
|
||||||
/** The absolute path to \c weston.ini to use,
|
/** The absolute path to \c weston.ini to use,
|
||||||
* or NULL for \c --no-config . */
|
* or NULL for \c --no-config .
|
||||||
const char *config_file;
|
* To properly fill this entry use weston_ini_setup() */
|
||||||
|
char *config_file;
|
||||||
/** Full path to an extra plugin to load, or NULL for none. */
|
/** Full path to an extra plugin to load, or NULL for none. */
|
||||||
const char *extra_module;
|
const char *extra_module;
|
||||||
/** Debug scopes for the compositor log,
|
/** Debug scopes for the compositor log,
|
||||||
@@ -131,4 +132,27 @@ int
|
|||||||
execute_compositor(const struct compositor_setup *setup,
|
execute_compositor(const struct compositor_setup *setup,
|
||||||
struct wet_testsuite_data *data);
|
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
|
||||||
|
* <test-name>.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 */
|
#endif /* WESTON_TEST_FIXTURE_COMPOSITOR_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user