summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>2015-06-22 15:35:49 +0900
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2015-06-25 11:39:10 +0300
commita10352e5c3418f9539cb53f4aecc537d2b412a4b (patch)
tree9411e4e2dcce54a82bed599dd8cb0eaf6d88eeb6 /tests
parent83c20bcbd5aaf579ee8d7d61cd090bcd0f9ecbc7 (diff)
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/ivi_layout-test-plugin.c45
1 files changed, 35 insertions, 10 deletions
diff --git a/tests/ivi_layout-test-plugin.c b/tests/ivi_layout-test-plugin.c
index d24c9a18..a134a149 100644
--- a/tests/ivi_layout-test-plugin.c
+++ b/tests/ivi_layout-test-plugin.c
@@ -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",