{
.desc = "unit control positive test",
.actions = {
- {{
- {.type = VKC_STRING, .value.s = "Start"}
- },
- {ACTIVE, UNKNOWN}, 1, 1, 0},
- {{
- {.type = VKC_STRING, .value.s = "Restart"}
- },
- {INACTIVE, ACTIVE}, 1, 2, 0},
- {{
- {.type = VKC_STRING, .value.s = "Stop"}
- },
- {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_STRING, .value.s = "Start"}),
+ _with_expected_states(INACTIVE,ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_STRING, .value.s = "Restart"}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_STRING, .value.s = "Stop"}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = "AcceptanceTestSP",
.unit = SERVICE_NAME_S_P,
{
.desc = "unit control negative test",
.actions = {
- {{
- {.type = VKC_STRING, .value.s = "Start"}
- },
- {INACTIVE, UNKNOWN}, 1, 1, 0},
- {{
- {.type = VKC_STRING, .value.s = "Restart"}
- },
- {INACTIVE, INACTIVE}, 1, 2, 0},
- {{
- {.type = VKC_STRING, .value.s = "Stoo"}
- },
- {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_STRING, .value.s = "Start"}),
+ _with_expected_states(INACTIVE,ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_STRING, .value.s = "Restart"}),
+ _with_expected_states(INACTIVE, INACTIVE)
+ },
+ {
+ _with_params({.type = VKC_STRING, .value.s = "Stoo"}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = "AcceptanceTestIN",
.unit = SERVICE_NAME_I_N,
{
.desc = "unit control whitelist negative test",
.actions = {
- {{
- {.type = VKC_STRING, .value.s = "Start"}
- },
- {INACTIVE, UNKNOWN}, 1, 1, 0},
- {{
- {.type = VKC_STRING, .value.s = "Restart"}
- },
- {INACTIVE, INACTIVE}, 1, 2, 0},
- {{
- {.type = VKC_STRING, .value.s = "Stop"}
- },
- {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_STRING, .value.s = "Start"}),
+ _with_expected_states(INACTIVE,ACTIVE),
+ },
+ {
+ _with_params({.type = VKC_STRING, .value.s = "Restart"}),
+ _with_expected_states(INACTIVE, INACTIVE)
+ },
+ {
+ _with_params({.type = VKC_STRING, .value.s = "Stop"}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = "AcceptanceTestSN",
.unit = SERVICE_NAME_S_N,
{
.desc = "string (positive test)",
.actions = {
- {{
- {.type = VKC_STRING, .value.s = "start"}
- },
- {ACTIVE, UNKNOWN}, 1, 1, 0},
- {{
- {.type = VKC_STRING, .value.s = "restart"}
- },
- {INACTIVE, ACTIVE}, 1, 2, 0},
- {{
- {.type = VKC_STRING, .value.s = "stop"}
- },
- {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_STRING, .value.s = "start"}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_STRING, .value.s = "restart"}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_STRING, .value.s = "stop"}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = "AcceptanceTestSP",
.unit = SERVICE_NAME_S_P,
{
.desc = "string (negative test)",
.actions = {
- {{
- {.type = VKC_STRING, .value.s = "start"}
- },
- {ACTIVE, UNKNOWN}, 1, 1, 0},
- {{
- {.type = VKC_STRING, .value.s = "restart"}
- },
- {INACTIVE, ACTIVE}, 1, 2, 0},
- {{
- {.type = VKC_STRING, .value.s = "stop"}
- },
- {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_STRING, .value.s = "start"}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_STRING, .value.s = "restart"}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_STRING, .value.s = "stop"}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = "AcceptanceTestSN",
.unit = SERVICE_NAME_S_N,
{
.desc = "int (positive test)",
.actions = {
- {{
- {.type = VKC_INT, .value.i = 1}
- },
- {ACTIVE, UNKNOWN}, 1, 1, 0},
- {{
- {.type = VKC_INT, .value.i = 2}
- },
- {INACTIVE, ACTIVE}, 1, 2, 0},
- {{
- {.type = VKC_INT, .value.i = 3}
- },
- {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_INT, .value.i = 1}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_INT, .value.i = 2}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_INT, .value.i = 3}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = "AcceptanceTestIP",
.unit = SERVICE_NAME_I_P,
{
.desc = "int (negative test)",
.actions = {
- {{
- {.type = VKC_INT, .value.i = 1}
- },
- {ACTIVE, UNKNOWN}, 1, 1, 0},
- {{
- {.type = VKC_INT, .value.i = 2}
- },
- {INACTIVE, ACTIVE}, 1, 2, 0},
- {{
- {.type = VKC_INT, .value.i = 3}
- },
- {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_INT, .value.i = 1}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_INT, .value.i = 2}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_INT, .value.i = 3}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = "AcceptanceTestIN",
.unit = SERVICE_NAME_I_N,
{
.desc = "double (positive test)",
.actions = {
- {{
- {.type = VKC_DOUBLE, .value.d = 1.0}
- },
- {ACTIVE, UNKNOWN}, 1, 1, 0},
- {{
- {.type = VKC_DOUBLE, .value.d = 2.0}
- },
- {INACTIVE, ACTIVE}, 1, 2, 0},
- {{
- {.type = VKC_DOUBLE, .value.d = 3.0}
- },
- {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_DOUBLE, .value.d = 1.0}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_DOUBLE, .value.d = 2.0}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_DOUBLE, .value.d = 3.0}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = "AcceptanceTestDP",
.unit = SERVICE_NAME_D_P,
{
.desc = "double (negative test)",
.actions = {
- {{
- {.type = VKC_DOUBLE, .value.d = 1.0}
- },
- {ACTIVE, UNKNOWN}, 1, 1, 0},
- {{
- {.type = VKC_DOUBLE, .value.d = 2.0}
- },
- {INACTIVE, ACTIVE}, 1, 2, 0},
- {{
- {.type = VKC_DOUBLE, .value.d = 3.0}
- },
- {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_DOUBLE, .value.d = 1.0}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_DOUBLE, .value.d = 2.0}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_DOUBLE, .value.d = 3.0}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = "AcceptanceTestDN",
.unit = SERVICE_NAME_D_N,
{
.desc = "bool (positive test)",
.actions = {
- {{
- {.type = VKC_BOOL, .value.b = true},
- {.type = VKC_BOOL, .value.b = true}
- },
- {ACTIVE, UNKNOWN}, 2, 1, 0},
- {{
- {.type = VKC_BOOL, .value.b = true},
- {.type = VKC_BOOL, .value.b = false}
- },
- {INACTIVE, ACTIVE}, 2, 2, 0},
- {{
- {.type = VKC_BOOL, .value.b = false},
- {.type = VKC_BOOL, .value.b = false}
- },
- {INACTIVE, UNKNOWN}, 2, 1, 0}
+ {
+ _with_params(
+ {.type = VKC_BOOL, .value.b = true},
+ {.type = VKC_BOOL, .value.b = true}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params(
+ {.type = VKC_BOOL, .value.b = true},
+ {.type = VKC_BOOL, .value.b = false}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params(
+ {.type = VKC_BOOL, .value.b = false},
+ {.type = VKC_BOOL, .value.b = false}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = "AcceptanceTestBP",
.unit = SERVICE_NAME_B_P,
{
.desc = "bool (negative test)",
.actions = {
- {{
- {.type = VKC_BOOL, .value.b = true},
- {.type = VKC_BOOL, .value.b = true}
- },
- {ACTIVE, UNKNOWN}, 2, 1, 0},
- {{
- {.type = VKC_BOOL, .value.b = true},
- {.type = VKC_BOOL, .value.b = false}
- },
- {INACTIVE, ACTIVE}, 2, 2, 0},
- {{
- {.type = VKC_BOOL, .value.b = false},
- {.type = VKC_BOOL, .value.b = false}
- },
- {INACTIVE, UNKNOWN}, 2, 1, 0}
+ {
+ _with_params(
+ {.type = VKC_BOOL, .value.b = true},
+ {.type = VKC_BOOL, .value.b = true}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params(
+ {.type = VKC_BOOL, .value.b = true},
+ {.type = VKC_BOOL, .value.b = false}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params(
+ {.type = VKC_BOOL, .value.b = false},
+ {.type = VKC_BOOL, .value.b = false}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = "AcceptanceTestBN",
.unit = SERVICE_NAME_B_N,
{
.desc = "string (positive test)",
.actions = {
- {{{.type = VKC_STRING, .value.s = "START"}}, {ACTIVE, UNKNOWN}, 1, 1, 0},
- {{{.type = VKC_STRING, .value.s = "RELOAD"}}, {INACTIVE, ACTIVE}, 1, 2, 0},
- {{{.type = VKC_STRING, .value.s = "STOP"}}, {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_STRING, .value.s = "START"}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_STRING, .value.s = "RELOAD"}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_STRING, .value.s = "STOP"}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = VCONF_KEY_S_P,
.unit = SERVICE_NAME_S_P,
.current_action = 0,
.step = vconf_step
},
- {
- .desc = "string (negative test)",
+ { .desc = "string (negative test)",
.actions = {
- {{{.type = VKC_STRING, .value.s = "START"}}, {ACTIVE, UNKNOWN}, 1, 1, 0},
- {{{.type = VKC_STRING, .value.s = "RELOAD"}}, {INACTIVE, ACTIVE}, 1, 2, 0},
- {{{.type = VKC_STRING, .value.s = "STOP"}}, {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_STRING, .value.s = "START"}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_STRING, .value.s = "RELOAD"}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_STRING, .value.s = "STOP"}),
+ _with_expected_states(INACTIVE, INACTIVE)
+ }
},
.id = VCONF_KEY_S_N,
.unit = SERVICE_NAME_S_N,
{
.desc = "int (positive test)",
.actions = {
- {{{.type = VKC_INT, .value.i = 1}}, {ACTIVE, UNKNOWN}, 1, 1, 0},
- {{{.type = VKC_INT, .value.i = 2}}, {INACTIVE, ACTIVE}, 1, 2, 0},
- {{{.type = VKC_INT, .value.i = 3}}, {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_INT, .value.i = 1}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_INT, .value.i = 2}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_INT, .value.i = 3}),
+ _with_expected_states(INACTIVE),
+ }
},
.id = VCONF_KEY_I_P,
.unit = SERVICE_NAME_I_P,
{
.desc = "int (negative test)",
.actions = {
- {{{.type = VKC_INT, .value.i = 1}}, {ACTIVE, UNKNOWN}, 1, 1, 0},
- {{{.type = VKC_INT, .value.i = 2}}, {INACTIVE, ACTIVE}, 1, 2, 0},
- {{{.type = VKC_INT, .value.i = 3}}, {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_INT, .value.i = 1}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_INT, .value.i = 2}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_INT, .value.i = 3}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = VCONF_KEY_I_N,
.unit = SERVICE_NAME_I_N,
{
.desc = "double (positive test)",
.actions = {
- {{{.type = VKC_DOUBLE, .value.d = 1.1}}, {ACTIVE, UNKNOWN}, 1, 1, 0},
- {{{.type = VKC_DOUBLE, .value.d = 1.2}}, {INACTIVE, ACTIVE}, 1, 2, 0},
- {{{.type = VKC_DOUBLE, .value.d = 1.3}}, {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_DOUBLE, .value.d = 1.1}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_DOUBLE, .value.d = 1.2}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_DOUBLE, .value.d = 1.3}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = VCONF_KEY_D_P,
.unit = SERVICE_NAME_D_P,
{
.desc = "double (negative test)",
.actions = {
- {{{.type = VKC_DOUBLE, .value.d = 1.1}}, {ACTIVE, UNKNOWN}, 1, 1, 0},
- {{{.type = VKC_DOUBLE, .value.d = 1.2}}, {INACTIVE, ACTIVE}, 1, 2, 0},
- {{{.type = VKC_DOUBLE, .value.d = 1.3}}, {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_DOUBLE, .value.d = 1.1}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_DOUBLE, .value.d = 1.2}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_DOUBLE, .value.d = 1.3}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = VCONF_KEY_D_N,
.unit = SERVICE_NAME_D_N,
{
.desc = "bool (positive test)",
.actions = {
- {{{.type = VKC_BOOL, .value.b = true}}, {ACTIVE, UNKNOWN}, 1, 1, 0},
- {{{.type = VKC_BOOL, .value.b = true}}, {INACTIVE, ACTIVE}, 1, 2, 0},
- {{{.type = VKC_BOOL, .value.b = false}}, {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_BOOL, .value.b = true}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_BOOL, .value.b = true}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_BOOL, .value.b = false}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = VCONF_KEY_B_P,
.unit = SERVICE_NAME_B_P,
{
.desc = "bool (negative test)",
.actions = {
- {{{.type = VKC_BOOL, .value.b = true}}, {ACTIVE, UNKNOWN}, 1, 1, 0},
- {{{.type = VKC_BOOL, .value.b = true}}, {INACTIVE, ACTIVE}, 1, 2, 0},
- {{{.type = VKC_BOOL, .value.b = false}}, {INACTIVE, UNKNOWN}, 1, 1, 0}
+ {
+ _with_params({.type = VKC_BOOL, .value.b = true}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_BOOL, .value.b = true}),
+ _with_expected_states(INACTIVE, ACTIVE)
+ },
+ {
+ _with_params({.type = VKC_BOOL, .value.b = false}),
+ _with_expected_states(INACTIVE)
+ }
},
.id = VCONF_KEY_B_N,
.unit = SERVICE_NAME_B_N,
return 0;
}
-
int main(int argc, char *argv[])
{
struct test_data data = {
goto fail;
}
+ setup_states_and_params_counters(&data);
+
g_err = NULL;
data.bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &g_err);
if (g_err) {
#include <glib.h>
#include <gio/gio.h>
-#define TEST_SERVICE "activationd-acceptance-test-s-p.service"
-
-enum unit_state {
- UNIT_OFF,
- UNIT_ON,
- UNIT_UNKNOWN
-};
-
-struct context {
- GDBusConnection *bus;
- GBusType bus_type;
- int unit_state[2];
- int unit_state_pos;
- int unit_state_cnt;
- guint subscription_id;
- GMainLoop *loop;
- guint func_timeout, test_timeout;
- int result;
- int (*func_sync)(BusType bus_type, const char *unit, int timeout);
- int (*func_async)(BusType bus_type, const char *unit, actd_unit_cb cb, void *user_data, int timeout);
-};
-
-struct unit_test {
- const char *id;
- int (*func)(struct context *);
-};
+#include "unit_tests.h"
+
static int translate_unit_state(const gchar *value)
{
return bus;
}
-static guint signal_subscribe(struct context *ctx)
-{
- assert(ctx);
- assert(ctx->bus);
-
- GVariant *msg = NULL;
- char *path = NULL;
- GError *error = NULL;
+static GVariant *conn_call_sync (GDBusConnection *bus, const gchar *method, GVariant *parameters, GError *error) {
- /*load unit/get path */
- msg = g_dbus_connection_call_sync(ctx->bus,
+ return g_dbus_connection_call_sync(bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
- "LoadUnit",
- g_variant_new("(s)", TEST_SERVICE),
+ method,
+ parameters,
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
+}
+
+static guint signal_subscribe(GDBusConnection *bus, struct context *ctx) {
+
+ GVariant *msg = NULL;
+ GError *error = NULL;
+
+ /*load unit/get path */
+ msg = conn_call_sync(bus, "LoadUnit", g_variant_new("(s)", TEST_SERVICE), error);
+
if (!msg) {
if (error) {
printf("LoadUnit method call error: %s\n", error->message);
g_error_free(error);
} else {
printf("LoadUnit method call error\n");
- }
-
- goto cleanup;
+ }
+ return 0;
}
+ char *path = NULL;
g_variant_get(msg, "(o)", &path);
/* PropertiesChanged signal subscribe */
- ctx->subscription_id = g_dbus_connection_signal_subscribe(
- ctx->bus,
+ guint subscription_id = g_dbus_connection_signal_subscribe(
+ bus,
NULL,
"org.freedesktop.DBus.Properties",
"PropertiesChanged",
(gpointer)ctx,
NULL
);
- if (ctx->subscription_id == 0) {
+ if (subscription_id == 0) {
printf("signal subscription error\n");
goto cleanup;
}
cleanup:
g_free(path);
- return ctx->subscription_id;
+ return subscription_id;
}
static gboolean test_timeout(gpointer user_data)
static gboolean func_start(gpointer user_data)
{
struct context *ctx = (struct context *)user_data;
- int ret = ctx->func_sync(ctx->bus_type, TEST_SERVICE, UNIT_CONTROL_TIMEOUT_DEFAULT);
+
+ struct test_sync_action_data_t *sync_action_data = (struct test_sync_action_data_t *)ctx->test_exec_action_data;
+
+ int ret = sync_action_data->actd_action_unit( ctx->bus_type, TEST_SERVICE, UNIT_CONTROL_TIMEOUT_DEFAULT);
if (ret == UNIT_CONTROL_ERROR || ret == UNIT_CONTROL_TIMEOUT) {
ctx->result = ret;
return ctx->result;
}
-static int test_unit_start(struct context *ctx)
-{
- assert(ctx);
-
- ctx->unit_state[0] = UNIT_ON;
- ctx->unit_state_pos = 0;
- ctx->unit_state_cnt = 1;
- ctx->result = UNIT_CONTROL_OK;
- ctx->func_sync = actd_start_unit;
- return test_sync_action(ctx);
-}
-
-static int test_unit_stop(struct context *ctx)
-{
- assert(ctx);
-
- ctx->unit_state[0] = UNIT_OFF;
- ctx->unit_state_pos = 0;
- ctx->unit_state_cnt = 1;
- ctx->result = UNIT_CONTROL_OK;
- ctx->func_sync = actd_stop_unit;
- return test_sync_action(ctx);
-}
-
-static int test_unit_restart(struct context *ctx)
-{
- assert(ctx);
-
- ctx->unit_state[0] = UNIT_OFF;
- ctx->unit_state[1] = UNIT_ON;
- ctx->unit_state_pos = 0;
- ctx->unit_state_cnt = 2;
- ctx->result = UNIT_CONTROL_OK;
- ctx->func_sync = actd_restart_unit;
- return test_sync_action(ctx);
-}
-
static void handler(int status, void *user_data)
{
struct context *ctx = (struct context *)user_data;
static int test_async_action(struct context *ctx)
{
assert(ctx);
- assert(ctx->func_async);
int ret;
ctx->loop = g_main_loop_new(NULL, FALSE);
ctx->test_timeout = g_timeout_add_seconds(10, test_timeout, ctx);
- ret = ctx->func_async(ctx->bus_type, TEST_SERVICE, handler, ctx, UNIT_CONTROL_TIMEOUT_DEFAULT);
+ struct test_async_action_data_t *async_action_data = (struct test_async_action_data_t *)ctx->test_exec_action_data;
+
+ ret = async_action_data->actd_action_unit(ctx->bus_type, TEST_SERVICE, handler, ctx, UNIT_CONTROL_TIMEOUT_DEFAULT);
if (ret == UNIT_CONTROL_ERROR)
return ret;
return ctx->result;
}
-static int test_unit_start_async(struct context *ctx)
+static int run_tests(struct test_sequence tests)
{
- assert(ctx);
+ while (tests.actions->desc != NULL) {
- ctx->unit_state[0] = UNIT_ON;
- ctx->unit_state_pos = 0;
- ctx->unit_state_cnt = 1;
- ctx->result = UNIT_CONTROL_OK;
- ctx->func_async = actd_start_unit_async;
- return test_async_action(ctx);
-}
+ GDBusConnection *bus_conn = get_bus(tests.actions->ctx.bus_type);
-static int test_unit_stop_async(struct context *ctx)
-{
- ctx->unit_state[0] = UNIT_OFF;
- ctx->unit_state_pos = 0;
- ctx->unit_state_cnt = 1;
- ctx->result = UNIT_CONTROL_OK;
- ctx->func_async = actd_stop_unit_async;
- return test_async_action(ctx);
-}
+ printf(_Run " Test: %s\n", tests.actions->desc);
-static int test_unit_restart_async(struct context *ctx)
-{
- ctx->unit_state[0] = UNIT_OFF;
- ctx->unit_state[1] = UNIT_ON;
- ctx->unit_state_pos = 0;
- ctx->unit_state_cnt = 2;
- ctx->result = UNIT_CONTROL_OK;
- ctx->func_async = actd_restart_unit_async;
- return test_async_action(ctx);
-}
+ if (!bus_conn) {
+ if (tests.actions->ctx.expected_result == UNIT_CONTROL_OK) {
+ printf(_Fail " => unable to open dbus connection\n");
+ } else {
+ printf(_Pass " => expected error: unable to open dbus connection\n");
+ }
+ printf(_Finish "\n");
-static const char *retval2string(int r)
-{
- switch (r) {
- case UNIT_CONTROL_REQUEST_SENT:
- return "request sent";
- break;
- case UNIT_CONTROL_TIMEOUT:
- return "timeout";
- break;
- case UNIT_CONTROL_OK:
- return "ok";
- break;
- default:
- return "error";
- break;
- }
-}
+ tests.actions++;
+ continue;
+ }
-static void test(GBusType bus_type, struct unit_test tests[])
-{
- assert(bus_type == G_BUS_TYPE_SYSTEM || bus_type == G_BUS_TYPE_SESSION);
- int ret;
- struct context ctx = {};
+ guint subscription_id = signal_subscribe(bus_conn, &tests.actions->ctx);
+ if (subscription_id == 0) {
+ printf(_Fail " => unable to subscribe to dbus signal");
+ printf(_Finish "\n");
- ctx.bus = get_bus(bus_type);
- if (!ctx.bus)
- exit(EXIT_FAILURE);
+ tests.actions++;
+ continue;
+ }
- ctx.bus_type = bus_type;
+ int i = 0;
+ while(tests.actions->ctx.unit_state[i] != UNIT_NO_STATE) {
+ i++;
+ }
+ tests.actions->ctx.unit_state_cnt = i;
+
+ int ret = tests.actions->exec_test_func(&tests.actions->ctx);
+ if (ret == tests.actions->ctx.expected_result) {
+ printf(_Pass " => Test: %s\n", tests.actions->desc);
+ } else {
+ printf(_Fail " => Test: %s", tests.actions->desc);
+ }
- if (signal_subscribe(&ctx) == 0)
- exit(EXIT_FAILURE);
+ printf(_Finish "\n");
- for (int i = 0; tests[i].id; ++i) {
- ret = tests[i].func(&ctx);
- if (ret != UNIT_CONTROL_OK)
- printf("[FAILED] %s (%s)\n", tests[i].id, retval2string(ret));
- else
- printf("[OK] %s\n", tests[i].id);
- usleep(100000);
+ g_dbus_connection_signal_unsubscribe (bus_conn, subscription_id);
+ tests.actions++;
}
- return;
+ return 0;
}
int main(int argc, char *argv[])
{
- struct unit_test tests[] = {
- {"UnitStart", test_unit_start},
- {"UnitRestart", test_unit_restart},
- {"UnitStop", test_unit_stop},
- {"UnitStartAsync", test_unit_start_async},
- {"UnitRestartAsync", test_unit_restart_async},
- {"UnitStopAsync", test_unit_stop_async},
- {NULL, NULL},
- };
-
- printf("bus type SYSTEM tests:\n");
- test(G_BUS_TYPE_SYSTEM, tests);
-
- printf("bus type SESSION tests:\n");
- test(G_BUS_TYPE_SESSION, tests);
-
- return EXIT_SUCCESS;
+ // beware of temporary lifetime of array items
+ return run_tests( _test_sequence(
+ .actions = test_actions(
+ { .desc = "UnitStart Sync",
+ _sync_ctx (
+ .bus_type = G_BUS_TYPE_SYSTEM,
+ _with_states(UNIT_ON),
+ _with_sync_action ( actd_start_unit ),
+ .expected_result = UNIT_CONTROL_OK
+ ),
+ },
+ { .desc = "UnitRestart Sync",
+ _sync_ctx (
+ .bus_type = G_BUS_TYPE_SYSTEM,
+ _with_states(UNIT_OFF, UNIT_ON),
+ _with_sync_action ( actd_restart_unit ),
+ .expected_result = UNIT_CONTROL_OK
+ ),
+ },
+ { .desc = "UnitStop Sync",
+ _sync_ctx (
+ .bus_type = G_BUS_TYPE_SYSTEM,
+ _with_states(UNIT_OFF),
+ _with_sync_action ( actd_stop_unit ),
+ .expected_result = UNIT_CONTROL_OK
+ ),
+ },
+
+ { .desc = "UnitStart Async",
+ _async_ctx (
+ .bus_type = G_BUS_TYPE_SYSTEM,
+ _with_states(UNIT_ON),
+ _with_async_action ( actd_start_unit_async ),
+ .expected_result = UNIT_CONTROL_OK
+ ),
+ },
+ { .desc = "UnitRestart Async",
+ _async_ctx (
+ .bus_type = G_BUS_TYPE_SYSTEM,
+ _with_states(UNIT_OFF, UNIT_ON),
+ _with_async_action ( actd_restart_unit_async ),
+ .expected_result = UNIT_CONTROL_OK
+ ),
+ },
+ { .desc = "UnitStop Async",
+ _async_ctx (
+ .bus_type = G_BUS_TYPE_SYSTEM,
+ _with_states(UNIT_OFF),
+ _with_async_action ( actd_stop_unit_async ),
+ .expected_result = UNIT_CONTROL_OK
+ ),
+ },
+ { .desc = "UnitStart Sync Negative with wrong bus type (SESSION)",
+ _sync_ctx (
+ .bus_type = G_BUS_TYPE_SESSION,
+ _with_states(UNIT_ON),
+ _with_sync_action ( actd_start_unit ),
+ .expected_result = UNIT_CONTROL_ERROR
+ ),
+ },
+ { .desc = "UnitRestart Sync Negative with wrong bus type (SESSION)",
+ _sync_ctx (
+ .bus_type = G_BUS_TYPE_SESSION,
+ _with_states(UNIT_OFF, UNIT_ON),
+ _with_sync_action ( actd_restart_unit ),
+ .expected_result = UNIT_CONTROL_ERROR
+ ),
+ },
+ { .desc = "UnitStop Sync Negative with wrong bus type (SESSION)",
+ _sync_ctx (
+ .bus_type = G_BUS_TYPE_SESSION,
+ _with_states(UNIT_OFF),
+ _with_sync_action ( actd_stop_unit ),
+ .expected_result = UNIT_CONTROL_ERROR
+ ),
+ },
+ { .desc = "UnitStart Async Negative with wrong bus type (SESSION)",
+ _async_ctx (
+ .bus_type = G_BUS_TYPE_SESSION,
+ _with_states(UNIT_ON),
+ _with_async_action ( actd_start_unit_async ),
+ .expected_result = UNIT_CONTROL_ERROR
+ ),
+ },
+ { .desc = "UnitRestart Async Negative with wrong bus type (SESSION)",
+ _async_ctx (
+ .bus_type = G_BUS_TYPE_SESSION,
+ _with_states(UNIT_OFF, UNIT_ON),
+ _with_async_action ( actd_restart_unit_async ),
+ .expected_result = UNIT_CONTROL_ERROR
+ ),
+ },
+ { .desc = "UnitStop Async Negative with wrong bus type (SESSION)",
+ _async_ctx (
+ .bus_type = G_BUS_TYPE_SESSION,
+ _with_states(UNIT_OFF),
+ _with_async_action ( actd_stop_unit_async ),
+ .expected_result = UNIT_CONTROL_ERROR
+ ),
+ }
+ )
+ ));
}