{
struct context *ctx = (struct context *)user_data;
- ctx->result = UNIT_CONTROL_ERROR;
+ ctx->result = UNIT_CONTROL_TIMEOUT;
g_main_loop_quit(ctx->loop);
return FALSE;
}
gboolean func_start(gpointer user_data)
{
struct context *ctx = (struct context *)user_data;
- int ret = ctx->func_sync(ctx->bus_type, TEST_SERVICE, -1);
+ int ret = ctx->func_sync(ctx->bus_type, TEST_SERVICE, UNIT_CONTROL_TIMEOUT_DEFAULT);
- if (ret < 0) {
- ctx->result = UNIT_CONTROL_ERROR;
+ if (ret == UNIT_CONTROL_ERROR || ret == UNIT_CONTROL_TIMEOUT) {
+ ctx->result = ret;
g_main_loop_quit(ctx->loop);
}
-return FALSE;
+ return FALSE;
}
int test_sync_action(struct context *ctx)
{
struct context *ctx = (struct context *)user_data;
ctx->result = status;
- if (status != UNIT_CONTROL_OK)
+ if (status == UNIT_CONTROL_ERROR || status == UNIT_CONTROL_TIMEOUT)
g_main_loop_quit(ctx->loop);
}
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, -1);
- if (ret < 0)
+ ret = ctx->func_async(ctx->bus_type, TEST_SERVICE, handler, ctx, UNIT_CONTROL_TIMEOUT_DEFAULT);
+ if (ret == UNIT_CONTROL_ERROR)
return ret;
g_main_loop_run(ctx->loop);
g_main_loop_unref(ctx->loop);
- return ret;
+ return ctx->result;
}
int test_unit_start_async(struct context *ctx)
int test_unit_restart_async(struct context *ctx)
{
- ctx->unit_state[0] = UNIT_ON;
- ctx->unit_state[1] = UNIT_OFF;
+ 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;
return test_async_action(ctx);
}
+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;
+ }
+}
+
void test(GBusType bus_type, struct unit_test tests[])
{
assert(bus_type == G_BUS_TYPE_SYSTEM || bus_type == G_BUS_TYPE_SESSION);
for (int i = 0; tests[i].id; ++i) {
ret = tests[i].func(&ctx);
- if (ret < 0)
- printf("[FAILED] %s (ret = %d)\n", tests[i].id, ret);
+ if (ret != UNIT_CONTROL_OK)
+ printf("[FAILED] %s (%s)\n", tests[i].id, retval2string(ret));
else
printf("[OK] %s\n", tests[i].id);