[PATCH 10/14] tests: make the test context persistent
Nobuhiko Tanibata
nobuhiko_tanibata at xddp.denso.co.jp
Sun Jun 21 23:35:49 PDT 2015
From: Nobuhiko Tanibata <NOBUHIKO_TANIBATA at xddp.denso.co.jp>
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 at collabora.co.uk>
---
tests/ivi_layout-test-plugin.c | 45 ++++++++++++++++++++++++++++++++----------
1 file changed, 35 insertions(+), 10 deletions(-)
diff --git a/tests/ivi_layout-test-plugin.c b/tests/ivi_layout-test-plugin.c
index d24c9a1..a134a14 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",
--
1.8.3.1
More information about the wayland-devel
mailing list