tests: make the test context persistent
The TESTs in ivi_layout-test.c may have several server-side parts (RUNNER_TEST in ivi_layout-test-plugin.c) each. Sometimes we need to carry state from one RUNNER_TEST to another within one TEST, but not across multiple TESTs. The correct lifetime of that state would be the lifetime (and identity) of the runner_resource, as one TEST creates and uses at most one weston_test_runner during its lifetime. However, tests are executed one by one. Take a shortcut, and use a static global for storing that state. This turns the test_context into a singleton. To ensure it is not confused between multiple TESTs, add asserts to verify its identity. Following patches will add tests for notification callbacks. These will be using the carried state. [Pekka: add serialization checks, rename the global, rewrite commit message.] Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
This commit is contained in:
parent
83c20bcbd5
commit
a10352e5c3
|
@ -30,6 +30,7 @@
|
|||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "src/compositor.h"
|
||||
#include "weston-test-server-protocol.h"
|
||||
|
@ -78,28 +79,42 @@ struct test_launcher {
|
|||
const struct ivi_controller_interface *controller_interface;
|
||||
};
|
||||
|
||||
struct test_context {
|
||||
const struct ivi_controller_interface *controller_interface;
|
||||
struct wl_resource *runner_resource;
|
||||
};
|
||||
|
||||
static struct test_context static_context;
|
||||
|
||||
static void
|
||||
destroy_runner(struct wl_resource *resource)
|
||||
{
|
||||
assert(static_context.runner_resource == NULL ||
|
||||
static_context.runner_resource == resource);
|
||||
|
||||
static_context.controller_interface = NULL;
|
||||
static_context.runner_resource = NULL;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
assert(static_context.runner_resource == NULL ||
|
||||
static_context.runner_resource == resource);
|
||||
|
||||
launcher = wl_resource_get_user_data(resource);
|
||||
ctx.controller_interface = launcher->controller_interface;
|
||||
ctx.runner_resource = resource;
|
||||
static_context.controller_interface = launcher->controller_interface;
|
||||
static_context.runner_resource = resource;
|
||||
|
||||
t = find_runner_test(test_name);
|
||||
if (!t) {
|
||||
|
@ -114,7 +129,7 @@ runner_run_handler(struct wl_client *client, struct wl_resource *resource,
|
|||
|
||||
weston_log("weston_test_runner.run(\"%s\")\n", test_name);
|
||||
|
||||
t->run(&ctx);
|
||||
t->run(&static_context);
|
||||
|
||||
weston_test_runner_send_finished(resource);
|
||||
}
|
||||
|
@ -139,7 +154,15 @@ bind_runner(struct wl_client *client, void *data,
|
|||
}
|
||||
|
||||
wl_resource_set_implementation(resource, &runner_implementation,
|
||||
launcher, NULL);
|
||||
launcher, destroy_runner);
|
||||
|
||||
if (static_context.runner_resource != NULL) {
|
||||
weston_log("test FATAL: "
|
||||
"attempting to run several tests in parallel.\n");
|
||||
wl_resource_post_error(resource,
|
||||
WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
|
||||
"attempt to run parallel tests");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -240,6 +263,8 @@ runner_assert_fail(const char *cond, const char *file, int line,
|
|||
{
|
||||
weston_log("Assert failure in %s:%d, %s: '%s'\n",
|
||||
file, line, func, cond);
|
||||
|
||||
assert(ctx->runner_resource);
|
||||
wl_resource_post_error(ctx->runner_resource,
|
||||
WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
|
||||
"Assert failure in %s:%d, %s: '%s'\n",
|
||||
|
|
Loading…
Reference in New Issue