tests: ivi_layout test infrastructure
Testing the ivi_layout API requires two things: - the tests must be written as a controller module to access the API - the tests need a helper client to create some objects that can then be managed via the API This patch adds all the infrastructure and two different kinds of example tests. Internal ivi-shell (ivi_layout) API tests are listed as ivi-*.la files in TESTS in Makefile.am. Weston-tests-env detects these, and runs Weston with ivi-shell, and loads the given module as a controller module, not as a normal plugin. The test controller module ivi-*.la will launch a helper client. For ivi-layout-test.la the helper client is ivi-layout.ivi. The helper client uses the weston-test-runner framework to fork and exec each TEST with a fresh connection to the compositor. The actual test is triggered by the weston_test_runner protocol interface, a new addition to weston-test.xml. The helper client uses weston_test_runner to trigger a test, and the server side of the interface is implemented by the test controller module (ivi-layout-test.la). The server side of weston_test_runner uses the same trick as weston-test-runner.h to gather a list of defined tests. A test is defined with the RUNNER_TEST macro. If a test defined by RUNNER_TEST succeeds, an event is sent to the helper client that it can continue (or exit). If a test fails, a fatal protocol error is sent to the helper client. Once the helper client has iterated over all of its tests, it signals the batch success/failure via process exit code. That is cought in the test controller module, and forwarded as Weston's exit code. In summary: each ivi_layout test is a combination of a client side helper/setup and server side actual tests. v2: Load weston-test.so, because create_client() needs it. v3: add a comment about IVI_TEST_SURFACE_ID_BASE. v4: Rebased to upstream weston-tests-env changes. Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Reviewed-by: Derek Foreman <derekf@osg.samsung.com> (v2)
This commit is contained in:
parent
0eb09412b3
commit
f5b74f7ded
|
@ -89,6 +89,7 @@ spring-tool
|
|||
|
||||
*.weston
|
||||
*.test
|
||||
*.ivi
|
||||
wcap-decode
|
||||
matrix-test
|
||||
setbacklight
|
||||
|
|
24
Makefile.am
24
Makefile.am
|
@ -1096,6 +1096,19 @@ matrix_test_CPPFLAGS = -DUNIT_TEST
|
|||
matrix_test_LDADD = -lm -lrt
|
||||
|
||||
if ENABLE_IVI_SHELL
|
||||
module_tests += \
|
||||
ivi-layout-test.la
|
||||
|
||||
ivi_layout_test_la_LIBADD = $(COMPOSITOR_LIBS)
|
||||
ivi_layout_test_la_LDFLAGS = $(test_module_ldflags)
|
||||
ivi_layout_test_la_CFLAGS = $(GCC_CFLAGS) $(COMPOSITOR_CFLAGS)
|
||||
ivi_layout_test_la_SOURCES = \
|
||||
tests/ivi_layout-test-plugin.c \
|
||||
tests/ivi-test.h
|
||||
nodist_ivi_layout_test_la_SOURCES = \
|
||||
protocol/weston-test-protocol.c \
|
||||
protocol/weston-test-server-protocol.h
|
||||
|
||||
ivi_tests += \
|
||||
ivi-shell-app.weston
|
||||
|
||||
|
@ -1105,6 +1118,17 @@ nodist_ivi_shell_app_weston_SOURCES = \
|
|||
protocol/ivi-application-client-protocol.h
|
||||
ivi_shell_app_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
|
||||
ivi_shell_app_weston_LDADD = libtest-client.la
|
||||
|
||||
noinst_PROGRAMS += ivi-layout.ivi
|
||||
|
||||
ivi_layout_ivi_SOURCES = \
|
||||
tests/ivi_layout-test.c \
|
||||
tests/ivi-test.h
|
||||
nodist_ivi_layout_ivi_SOURCES = \
|
||||
protocol/ivi-application-protocol.c \
|
||||
protocol/ivi-application-client-protocol.h
|
||||
ivi_layout_ivi_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
|
||||
ivi_layout_ivi_LDADD = libtest-client.la
|
||||
endif
|
||||
|
||||
if BUILD_SETBACKLIGHT
|
||||
|
|
|
@ -74,4 +74,39 @@
|
|||
<arg name="n" type="uint"/>
|
||||
</event>
|
||||
</interface>
|
||||
|
||||
<interface name="weston_test_runner" version="1">
|
||||
<description summary="weston internal testing">
|
||||
This is a global singleton interface for Weston internal tests.
|
||||
|
||||
This interface allows a test client to trigger compositor-side
|
||||
test procedures. This is useful for cases, where the actual tests
|
||||
are in compositor plugins, but they also require the presence of
|
||||
a particular client.
|
||||
|
||||
This interface is implemented by the compositor plugins containing
|
||||
the testing code.
|
||||
|
||||
A test client starts a test with the "run" request. It must not send
|
||||
another "run" request until receiving the "finished" event. If the
|
||||
compositor-side test succeeds, the "finished" event is sent. If the
|
||||
compositor-side test fails, the compositor should send the protocol
|
||||
error "test_failed", but it may also exit with an error (e.g. SEGV).
|
||||
|
||||
Unknown test name will raise "unknown_test" protocol error.
|
||||
</description>
|
||||
|
||||
<enum name="error">
|
||||
<entry name="test_failed" value="0" summary="compositor test failed"/>
|
||||
<entry name="unknown_test" value="1" summary="unrecognized test name"/>
|
||||
</enum>
|
||||
|
||||
<request name="destroy" type="destructor"/>
|
||||
|
||||
<request name="run">
|
||||
<arg name="test_name" type="string"/>
|
||||
</request>
|
||||
|
||||
<event name="finished"/>
|
||||
</interface>
|
||||
</protocol>
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright © 2015 Collabora, Ltd.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of the copyright holders not be used in
|
||||
* advertising or publicity pertaining to distribution of the software
|
||||
* without specific, written prior permission. The copyright holders make
|
||||
* no representations about the suitability of this software for any
|
||||
* purpose. It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
||||
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
||||
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
||||
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef IVI_TEST_H
|
||||
#define IVI_TEST_H
|
||||
|
||||
/*
|
||||
* IVI_TEST_SURFACE_ID_BASE is an arbitrary number picked for the
|
||||
* IVI tests. The only requirement is that it does not clash with
|
||||
* any other ivi-id range used in Weston.
|
||||
*/
|
||||
#define IVI_TEST_SURFACE_ID_BASE 0xffc01200
|
||||
#define IVI_TEST_SURFACE_ID(i) (IVI_TEST_SURFACE_ID_BASE + i)
|
||||
|
||||
#endif /* IVI_TEST_H */
|
|
@ -0,0 +1,368 @@
|
|||
/*
|
||||
* Copyright © 2012 Intel Corporation
|
||||
* Copyright © 2013 DENSO CORPORATION
|
||||
* Copyright © 2015 Collabora, Ltd.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of the copyright holders not be used in
|
||||
* advertising or publicity pertaining to distribution of the software
|
||||
* without specific, written prior permission. The copyright holders make
|
||||
* no representations about the suitability of this software for any
|
||||
* purpose. It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
||||
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
||||
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
||||
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../src/compositor.h"
|
||||
#include "weston-test-server-protocol.h"
|
||||
#include "ivi-test.h"
|
||||
#include "../ivi-shell/ivi-layout-export.h"
|
||||
|
||||
struct test_context;
|
||||
|
||||
struct runner_test {
|
||||
const char *name;
|
||||
void (*run)(struct test_context *);
|
||||
} __attribute__ ((aligned (32)));
|
||||
|
||||
#define RUNNER_TEST(name) \
|
||||
static void runner_func_##name(struct test_context *); \
|
||||
\
|
||||
const struct runner_test runner_test_##name \
|
||||
__attribute__ ((section ("test_section"))) = \
|
||||
{ \
|
||||
#name, runner_func_##name \
|
||||
}; \
|
||||
\
|
||||
static void runner_func_##name(struct test_context *ctx)
|
||||
|
||||
extern const struct runner_test __start_test_section;
|
||||
extern const struct runner_test __stop_test_section;
|
||||
|
||||
static const struct runner_test *
|
||||
find_runner_test(const char *name)
|
||||
{
|
||||
const struct runner_test *t;
|
||||
|
||||
for (t = &__start_test_section; t < &__stop_test_section; t++) {
|
||||
if (strcmp(t->name, name) == 0)
|
||||
return t;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct test_launcher {
|
||||
struct weston_compositor *compositor;
|
||||
char exe[2048];
|
||||
struct weston_process process;
|
||||
const struct ivi_controller_interface *controller_interface;
|
||||
};
|
||||
|
||||
static void
|
||||
runner_destroy_handler(struct wl_client *client, struct wl_resource *resource)
|
||||
{
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
struct test_context {
|
||||
const struct ivi_controller_interface *controller_interface;
|
||||
struct wl_resource *runner_resource;
|
||||
};
|
||||
|
||||
static void
|
||||
runner_run_handler(struct wl_client *client, struct wl_resource *resource,
|
||||
const char *test_name)
|
||||
{
|
||||
struct test_launcher *launcher;
|
||||
const struct runner_test *t;
|
||||
struct test_context ctx;
|
||||
|
||||
launcher = wl_resource_get_user_data(resource);
|
||||
ctx.controller_interface = launcher->controller_interface;
|
||||
ctx.runner_resource = resource;
|
||||
|
||||
t = find_runner_test(test_name);
|
||||
if (!t) {
|
||||
weston_log("Error: runner test \"%s\" not found.\n",
|
||||
test_name);
|
||||
wl_resource_post_error(resource,
|
||||
WESTON_TEST_RUNNER_ERROR_UNKNOWN_TEST,
|
||||
"weston_test_runner: unknown: '%s'",
|
||||
test_name);
|
||||
return;
|
||||
}
|
||||
|
||||
weston_log("weston_test_runner.run(\"%s\")\n", test_name);
|
||||
|
||||
t->run(&ctx);
|
||||
|
||||
weston_test_runner_send_finished(resource);
|
||||
}
|
||||
|
||||
static const struct weston_test_runner_interface runner_implementation = {
|
||||
runner_destroy_handler,
|
||||
runner_run_handler
|
||||
};
|
||||
|
||||
static void
|
||||
bind_runner(struct wl_client *client, void *data,
|
||||
uint32_t version, uint32_t id)
|
||||
{
|
||||
struct test_launcher *launcher = data;
|
||||
struct wl_resource *resource;
|
||||
|
||||
resource = wl_resource_create(client, &weston_test_runner_interface,
|
||||
1, id);
|
||||
if (!resource) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
|
||||
wl_resource_set_implementation(resource, &runner_implementation,
|
||||
launcher, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
test_client_sigchld(struct weston_process *process, int status)
|
||||
{
|
||||
struct test_launcher *launcher =
|
||||
container_of(process, struct test_launcher, process);
|
||||
struct weston_compositor *c = launcher->compositor;
|
||||
|
||||
/* Chain up from weston-test-runner's exit code so that automake
|
||||
* knows the exit status and can report e.g. skipped tests. */
|
||||
if (WIFEXITED(status))
|
||||
weston_compositor_exit_with_code(c, WEXITSTATUS(status));
|
||||
else
|
||||
weston_compositor_exit_with_code(c, EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void
|
||||
idle_launch_client(void *data)
|
||||
{
|
||||
struct test_launcher *launcher = data;
|
||||
pid_t pid;
|
||||
sigset_t allsigs;
|
||||
|
||||
pid = fork();
|
||||
if (pid == -1) {
|
||||
weston_log("fatal: failed to fork '%s': %m\n", launcher->exe);
|
||||
weston_compositor_exit_with_code(launcher->compositor,
|
||||
EXIT_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
sigfillset(&allsigs);
|
||||
sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
|
||||
execl(launcher->exe, launcher->exe, NULL);
|
||||
weston_log("compositor: executing '%s' failed: %m\n",
|
||||
launcher->exe);
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
launcher->process.pid = pid;
|
||||
launcher->process.cleanup = test_client_sigchld;
|
||||
weston_watch_process(&launcher->process);
|
||||
}
|
||||
|
||||
int
|
||||
controller_module_init(struct weston_compositor *compositor,
|
||||
int *argc, char *argv[],
|
||||
const struct ivi_controller_interface *iface,
|
||||
size_t iface_version);
|
||||
|
||||
WL_EXPORT int
|
||||
controller_module_init(struct weston_compositor *compositor,
|
||||
int *argc, char *argv[],
|
||||
const struct ivi_controller_interface *iface,
|
||||
size_t iface_version)
|
||||
{
|
||||
struct wl_event_loop *loop;
|
||||
struct test_launcher *launcher;
|
||||
const char *path;
|
||||
|
||||
/* strict check, since this is an internal test module */
|
||||
if (iface_version != sizeof(*iface)) {
|
||||
weston_log("fatal: controller interface mismatch\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
path = getenv("WESTON_BUILD_DIR");
|
||||
if (!path) {
|
||||
weston_log("test setup failure: WESTON_BUILD_DIR not set\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
launcher = zalloc(sizeof *launcher);
|
||||
if (!launcher)
|
||||
return -1;
|
||||
|
||||
launcher->compositor = compositor;
|
||||
launcher->controller_interface = iface;
|
||||
snprintf(launcher->exe, sizeof launcher->exe,
|
||||
"%s/ivi-layout.ivi", path);
|
||||
|
||||
if (wl_global_create(compositor->wl_display,
|
||||
&weston_test_runner_interface, 1,
|
||||
launcher, bind_runner) == NULL)
|
||||
return -1;
|
||||
|
||||
loop = wl_display_get_event_loop(compositor->wl_display);
|
||||
wl_event_loop_add_idle(loop, idle_launch_client, launcher);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
runner_assert_fail(const char *cond, const char *file, int line,
|
||||
const char *func, struct test_context *ctx)
|
||||
{
|
||||
weston_log("Assert failure in %s:%d, %s: '%s'\n",
|
||||
file, line, func, cond);
|
||||
wl_resource_post_error(ctx->runner_resource,
|
||||
WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
|
||||
"Assert failure in %s:%d, %s: '%s'\n",
|
||||
file, line, func, cond);
|
||||
}
|
||||
|
||||
#define runner_assert(cond) ({ \
|
||||
bool b_ = (cond); \
|
||||
if (!b_) \
|
||||
runner_assert_fail(#cond, __FILE__, __LINE__, \
|
||||
__func__, ctx); \
|
||||
b_; \
|
||||
})
|
||||
|
||||
#define runner_assert_or_return(cond) do { \
|
||||
bool b_ = (cond); \
|
||||
if (!b_) { \
|
||||
runner_assert_fail(#cond, __FILE__, __LINE__, \
|
||||
__func__, ctx); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/*************************** tests **********************************/
|
||||
|
||||
/*
|
||||
* This is a controller module: a plugin to ivi-shell.so, i.e. a sub-plugin.
|
||||
* This module is specially written to execute tests that target the
|
||||
* ivi_layout API.
|
||||
*
|
||||
* This module is listed in TESTS in Makefile.am. weston-tests-env handles
|
||||
* this module specially by loading it in ivi-shell.
|
||||
*
|
||||
* Once Weston init completes, this module launches one test program:
|
||||
* ivi-layout.ivi (ivi_layout-test.c). That program uses the weston-test-runner
|
||||
* framework to fork and exec each TEST() in ivi_layout-test.c with a fresh
|
||||
* connection to the single compositor instance.
|
||||
*
|
||||
* Each TEST() in ivi_layout-test.c will bind to weston_test_runner global
|
||||
* interface. A TEST() will set up the client state, and issue
|
||||
* weston_test_runner.run request to execute the compositor-side of the test.
|
||||
*
|
||||
* The compositor-side parts of the tests are in this file. They are specified
|
||||
* by RUNNER_TEST() macro, where the name argument matches the name string
|
||||
* passed to weston_test_runner.run.
|
||||
*
|
||||
* A RUNNER_TEST() function simply returns when it succeeds. If it fails,
|
||||
* a fatal protocol error is sent to the client from runner_assert() or
|
||||
* runner_assert_or_return(). This module catches the test program exit
|
||||
* code and passes it out of Weston to the test harness.
|
||||
*
|
||||
* A single TEST() in ivi_layout-test.c may use multiple RUNNER_TEST()s to
|
||||
* achieve multiple test points over a client action sequence.
|
||||
*/
|
||||
|
||||
RUNNER_TEST(surface_create_p1)
|
||||
{
|
||||
const struct ivi_controller_interface *ctl = ctx->controller_interface;
|
||||
struct ivi_layout_surface *ivisurf[2];
|
||||
uint32_t ivi_id;
|
||||
|
||||
ivisurf[0] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
|
||||
runner_assert_or_return(ivisurf[0]);
|
||||
|
||||
ivisurf[1] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(1));
|
||||
runner_assert_or_return(ivisurf[1]);
|
||||
|
||||
ivi_id = ctl->get_id_of_surface(ivisurf[0]);
|
||||
runner_assert_or_return(ivi_id == IVI_TEST_SURFACE_ID(0));
|
||||
|
||||
ivi_id = ctl->get_id_of_surface(ivisurf[1]);
|
||||
runner_assert_or_return(ivi_id == IVI_TEST_SURFACE_ID(1));
|
||||
}
|
||||
|
||||
RUNNER_TEST(surface_create_p2)
|
||||
{
|
||||
const struct ivi_controller_interface *ctl = ctx->controller_interface;
|
||||
struct ivi_layout_surface *ivisurf;
|
||||
|
||||
/* the ivi_surface was destroyed by the client */
|
||||
ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
|
||||
runner_assert_or_return(ivisurf == NULL);
|
||||
}
|
||||
|
||||
RUNNER_TEST(surface_visibility)
|
||||
{
|
||||
const struct ivi_controller_interface *ctl = ctx->controller_interface;
|
||||
struct ivi_layout_surface *ivisurf;
|
||||
int32_t ret;
|
||||
bool visibility;
|
||||
const struct ivi_layout_surface_properties *prop;
|
||||
|
||||
ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
|
||||
runner_assert_or_return(ivisurf);
|
||||
|
||||
ret = ctl->surface_set_visibility(ivisurf, true);
|
||||
runner_assert_or_return(ret == IVI_SUCCEEDED);
|
||||
|
||||
ctl->commit_changes();
|
||||
|
||||
visibility = ctl->surface_get_visibility(ivisurf);
|
||||
runner_assert_or_return(visibility == true);
|
||||
|
||||
prop = ctl->get_properties_of_surface(ivisurf);
|
||||
runner_assert_or_return(prop->visibility == true);
|
||||
}
|
||||
|
||||
RUNNER_TEST(surface_opacity)
|
||||
{
|
||||
const struct ivi_controller_interface *ctl = ctx->controller_interface;
|
||||
struct ivi_layout_surface *ivisurf;
|
||||
int32_t ret;
|
||||
wl_fixed_t opacity;
|
||||
const struct ivi_layout_surface_properties *prop;
|
||||
|
||||
ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
|
||||
runner_assert_or_return(ivisurf);
|
||||
|
||||
ret = ctl->surface_set_opacity(ivisurf, wl_fixed_from_double(0.5));
|
||||
runner_assert_or_return(ret == IVI_SUCCEEDED);
|
||||
|
||||
ctl->commit_changes();
|
||||
|
||||
opacity = ctl->surface_get_opacity(ivisurf);
|
||||
runner_assert_or_return(opacity == wl_fixed_from_double(0.5));
|
||||
|
||||
prop = ctl->get_properties_of_surface(ivisurf);
|
||||
runner_assert_or_return(prop->opacity == wl_fixed_from_double(0.5));
|
||||
}
|
|
@ -0,0 +1,230 @@
|
|||
/*
|
||||
* Copyright © 2015 Collabora, Ltd.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of the copyright holders not be used in
|
||||
* advertising or publicity pertaining to distribution of the software
|
||||
* without specific, written prior permission. The copyright holders make
|
||||
* no representations about the suitability of this software for any
|
||||
* purpose. It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
||||
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
||||
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
||||
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "weston-test-client-helper.h"
|
||||
#include "ivi-application-client-protocol.h"
|
||||
#include "ivi-test.h"
|
||||
|
||||
struct runner {
|
||||
struct client *client;
|
||||
struct weston_test_runner *test_runner;
|
||||
int done;
|
||||
};
|
||||
|
||||
static void
|
||||
runner_finished_handler(void *data, struct weston_test_runner *test_runner)
|
||||
{
|
||||
struct runner *runner = data;
|
||||
|
||||
runner->done = 1;
|
||||
}
|
||||
|
||||
static const struct weston_test_runner_listener test_runner_listener = {
|
||||
runner_finished_handler
|
||||
};
|
||||
|
||||
static struct runner *
|
||||
client_create_runner(struct client *client)
|
||||
{
|
||||
struct runner *runner;
|
||||
struct global *g;
|
||||
struct global *global_runner = NULL;
|
||||
|
||||
runner = xzalloc(sizeof(*runner));
|
||||
runner->client = client;
|
||||
|
||||
wl_list_for_each(g, &client->global_list, link) {
|
||||
if (strcmp(g->interface, "weston_test_runner"))
|
||||
continue;
|
||||
|
||||
if (global_runner)
|
||||
assert(0 && "multiple weston_test_runner objects");
|
||||
|
||||
global_runner = g;
|
||||
}
|
||||
|
||||
assert(global_runner && "no weston_test_runner found");
|
||||
assert(global_runner->version == 1);
|
||||
|
||||
runner->test_runner = wl_registry_bind(client->wl_registry,
|
||||
global_runner->name,
|
||||
&weston_test_runner_interface,
|
||||
1);
|
||||
assert(runner->test_runner);
|
||||
|
||||
weston_test_runner_add_listener(runner->test_runner,
|
||||
&test_runner_listener, runner);
|
||||
|
||||
return runner;
|
||||
}
|
||||
|
||||
static void
|
||||
runner_destroy(struct runner *runner)
|
||||
{
|
||||
weston_test_runner_destroy(runner->test_runner);
|
||||
client_roundtrip(runner->client);
|
||||
free(runner);
|
||||
}
|
||||
|
||||
static void
|
||||
runner_run(struct runner *runner, const char *test_name)
|
||||
{
|
||||
fprintf(stderr, "weston_test_runner.run(\"%s\")\n", test_name);
|
||||
|
||||
runner->done = 0;
|
||||
weston_test_runner_run(runner->test_runner, test_name);
|
||||
|
||||
while (!runner->done) {
|
||||
if (wl_display_dispatch(runner->client->wl_display) < 0)
|
||||
assert(0 && "runner wait");
|
||||
}
|
||||
}
|
||||
|
||||
static struct ivi_application *
|
||||
get_ivi_application(struct client *client)
|
||||
{
|
||||
struct global *g;
|
||||
struct global *global_iviapp = NULL;
|
||||
static struct ivi_application *iviapp;
|
||||
|
||||
if (iviapp)
|
||||
return iviapp;
|
||||
|
||||
wl_list_for_each(g, &client->global_list, link) {
|
||||
if (strcmp(g->interface, "ivi_application"))
|
||||
continue;
|
||||
|
||||
if (global_iviapp)
|
||||
assert(0 && "multiple ivi_application objects");
|
||||
|
||||
global_iviapp = g;
|
||||
}
|
||||
|
||||
assert(global_iviapp && "no ivi_application found");
|
||||
|
||||
assert(global_iviapp->version == 1);
|
||||
|
||||
iviapp = wl_registry_bind(client->wl_registry, global_iviapp->name,
|
||||
&ivi_application_interface, 1);
|
||||
assert(iviapp);
|
||||
|
||||
return iviapp;
|
||||
}
|
||||
|
||||
struct ivi_window {
|
||||
struct wl_surface *wl_surface;
|
||||
struct ivi_surface *ivi_surface;
|
||||
uint32_t ivi_id;
|
||||
};
|
||||
|
||||
static struct ivi_window *
|
||||
client_create_ivi_window(struct client *client, uint32_t ivi_id)
|
||||
{
|
||||
struct ivi_application *iviapp;
|
||||
struct ivi_window *wnd;
|
||||
|
||||
iviapp = get_ivi_application(client);
|
||||
|
||||
wnd = xzalloc(sizeof(*wnd));
|
||||
wnd->wl_surface = wl_compositor_create_surface(client->wl_compositor);
|
||||
wnd->ivi_surface = ivi_application_surface_create(iviapp, ivi_id,
|
||||
wnd->wl_surface);
|
||||
wnd->ivi_id = ivi_id;
|
||||
|
||||
return wnd;
|
||||
}
|
||||
|
||||
static void
|
||||
ivi_window_destroy(struct ivi_window *wnd)
|
||||
{
|
||||
ivi_surface_destroy(wnd->ivi_surface);
|
||||
wl_surface_destroy(wnd->wl_surface);
|
||||
free(wnd);
|
||||
}
|
||||
|
||||
/******************************** tests ********************************/
|
||||
|
||||
/*
|
||||
* This is a test program, launched by ivi_layout-test-plugin.c. Each TEST()
|
||||
* is forked and exec'd as usual with the weston-test-runner framework.
|
||||
*
|
||||
* These tests make use of weston_test_runner global interface exposed by
|
||||
* ivi_layout-test-plugin.c. This allows these tests to trigger compositor-side
|
||||
* checks.
|
||||
*
|
||||
* See ivi_layout-test-plugin.c for further details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* RUNNER_TEST() names are defined in ivi_layout-test-plugin.c.
|
||||
* Each RUNNER_TEST name listed here uses the same simple initial client setup.
|
||||
*/
|
||||
const char * const basic_test_names[] = {
|
||||
"surface_visibility",
|
||||
"surface_opacity",
|
||||
};
|
||||
|
||||
TEST_P(ivi_layout_runner, basic_test_names)
|
||||
{
|
||||
/* an element from basic_test_names */
|
||||
const char * const *test_name = data;
|
||||
struct client *client;
|
||||
struct runner *runner;
|
||||
struct ivi_window *wnd;
|
||||
|
||||
client = create_client();
|
||||
runner = client_create_runner(client);
|
||||
|
||||
wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
|
||||
|
||||
runner_run(runner, *test_name);
|
||||
|
||||
ivi_window_destroy(wnd);
|
||||
runner_destroy(runner);
|
||||
}
|
||||
|
||||
TEST(ivi_layout_surface_create)
|
||||
{
|
||||
struct client *client;
|
||||
struct runner *runner;
|
||||
struct ivi_window *winds[2];
|
||||
|
||||
client = create_client();
|
||||
runner = client_create_runner(client);
|
||||
|
||||
winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
|
||||
winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1));
|
||||
|
||||
runner_run(runner, "surface_create_p1");
|
||||
|
||||
ivi_window_destroy(winds[0]);
|
||||
|
||||
runner_run(runner, "surface_create_p2");
|
||||
|
||||
ivi_window_destroy(winds[1]);
|
||||
runner_destroy(runner);
|
||||
}
|
|
@ -27,6 +27,19 @@ TEST_PLUGIN=$MODDIR/weston-test.so
|
|||
XWAYLAND_PLUGIN=$MODDIR/xwayland.so
|
||||
|
||||
case $TEST_FILE in
|
||||
ivi-*.la|ivi-*.so)
|
||||
SHELL_PLUGIN=$MODDIR/ivi-shell.so
|
||||
|
||||
WESTON_BUILD_DIR=$abs_builddir \
|
||||
$WESTON --backend=$MODDIR/$BACKEND \
|
||||
--config=$abs_builddir/tests/weston-ivi.ini \
|
||||
--shell=$SHELL_PLUGIN \
|
||||
--socket=test-${TEST_NAME} \
|
||||
--modules=$TEST_PLUGIN \
|
||||
--ivi-module=$MODDIR/${TEST_FILE/.la/.so} \
|
||||
--log="$SERVERLOG" \
|
||||
&> "$OUTLOG"
|
||||
;;
|
||||
*.la|*.so)
|
||||
WESTON_BUILD_DIR=$abs_builddir \
|
||||
$WESTON --backend=$MODDIR/$BACKEND \
|
||||
|
|
Loading…
Reference in New Issue