#include <stdlib.h>
#include <string.h>
#include <sys/timerfd.h>
-#include <vconf.h>
#include "common.h"
#include "systemd_dbus.h"
-#include "systemd_dbus.h"
-#include "vconf_key_changed_event.h"
+#include "activationd_acceptance_tests.h"
+#include "activationd_acceptance_tests_dbus.h"
+#include "activationd_acceptance_tests_vconf.h"
#define DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
#define SERVICE_NAME_S_P "activationd-acceptance-test-s-p.service"
#define VCONF_KEY_B_P "file/activationd/acceptance_bool_p"
#define VCONF_KEY_B_N "file/activationd/acceptance_bool_n"
-enum unit_state {
- UNKNOWN,
- ACTIVE,
- INACTIVE
-};
-
enum {
- TEST_FAIL,
- TEST_SUCCESS,
- TEST_UNKNOWN
-};
-
-struct action {
- struct vkc_value action;
- enum unit_state expected_states[2];
- int state_count;
- int current_state;
-};
-
-struct test_sequence {
- const char *desc;
- struct action actions[3];
- const char *key;
- int current_action;
- int expected_result;
- int result;
- char *unit;
- char *path;
+ TEST_TYPE_UNKNOWN,
+ TEST_TYPE_VCONF,
+ TEST_TYPE_DBUS
};
-
-struct test_data {
- sd_bus *bus;
- sd_event *loop;
- sd_event_source *step_timer;
- struct test_sequence *tests;
- int tests_count;
- int current_test;
- enum unit_state state;
- enum unit_state prev_state;
+static struct test_sequence dbus_acceptance_tests[] = {
+ {
+ .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}
+ },
+ .id = "AcceptanceTestSP",
+ .unit = SERVICE_NAME_S_P,
+ .path = NULL,
+ .expected_result = TEST_SUCCESS,
+ .result = TEST_UNKNOWN,
+ .current_action = 0,
+ .step = dbus_step
+ },
+ {
+ .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}
+ },
+ .id = "AcceptanceTestSN",
+ .unit = SERVICE_NAME_S_N,
+ .path = NULL,
+ .expected_result = TEST_FAIL,
+ .result = TEST_UNKNOWN,
+ .current_action = 0,
+ .step = dbus_step
+ },
+ {
+ .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}
+ },
+ .id = "AcceptanceTestIP",
+ .unit = SERVICE_NAME_I_P,
+ .path = NULL,
+ .expected_result = TEST_SUCCESS,
+ .result = TEST_UNKNOWN,
+ .current_action = 0,
+ .step = dbus_step
+ },
+ {
+ .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}
+ },
+ .id = "AcceptanceTestIN",
+ .unit = SERVICE_NAME_I_N,
+ .path = NULL,
+ .expected_result = TEST_FAIL,
+ .result = TEST_UNKNOWN,
+ .current_action = 0,
+ .step = dbus_step
+ },
+ {
+ .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}
+ },
+ .id = "AcceptanceTestDP",
+ .unit = SERVICE_NAME_D_P,
+ .path = NULL,
+ .expected_result = TEST_SUCCESS,
+ .result = TEST_UNKNOWN,
+ .current_action = 0,
+ .step = dbus_step
+ },
+ {
+ .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}
+ },
+ .id = "AcceptanceTestDN",
+ .unit = SERVICE_NAME_D_N,
+ .path = NULL,
+ .expected_result = TEST_FAIL,
+ .result = TEST_UNKNOWN,
+ .current_action = 0,
+ .step = dbus_step
+ },
+ {
+ .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}
+ },
+ .id = "AcceptanceTestBP",
+ .unit = SERVICE_NAME_B_P,
+ .path = NULL,
+ .expected_result = TEST_SUCCESS,
+ .result = TEST_UNKNOWN,
+ .current_action = 0,
+ .step = dbus_step
+ },
+ {
+ .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}
+ },
+ .id = "AcceptanceTestBN",
+ .unit = SERVICE_NAME_B_N,
+ .path = NULL,
+ .expected_result = TEST_FAIL,
+ .result = TEST_UNKNOWN,
+ .current_action = 0,
+ .step = dbus_step
+ }
};
-int test_step(struct test_data *data);
-
-static struct test_sequence acceptance_tests[] = {
+static struct test_sequence vconf_acceptance_tests[] = {
{
.desc = "string (positive test)",
.actions = {
- {{.type = VKC_STRING, .value.s = "START"}, {ACTIVE, UNKNOWN}, 1, 0},
- {{.type = VKC_STRING, .value.s = "RELOAD"}, {INACTIVE, ACTIVE}, 2, 0},
- {{.type = VKC_STRING, .value.s = "STOP"}, {INACTIVE, UNKNOWN}, 1, 0}
+ {{{.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}
},
- .key = VCONF_KEY_S_P,
+ .id = VCONF_KEY_S_P,
.unit = SERVICE_NAME_S_P,
.path = NULL,
.expected_result = TEST_SUCCESS,
.result = TEST_UNKNOWN,
- .current_action = 0
+ .current_action = 0,
+ .step = vconf_step
},
{
.desc = "string (negative test)",
.actions = {
- {{.type = VKC_STRING, .value.s = "START"}, {ACTIVE, UNKNOWN}, 1, 0},
- {{.type = VKC_STRING, .value.s = "RELOAD"}, {INACTIVE, ACTIVE}, 2, 0},
- {{.type = VKC_STRING, .value.s = "STOP"}, {INACTIVE, UNKNOWN}, 1, 0}
+ {{{.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}
+ //{{{.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}
},
- .key = VCONF_KEY_S_N,
+ .id = VCONF_KEY_S_N,
.unit = SERVICE_NAME_S_N,
.path = NULL,
.expected_result = TEST_FAIL,
.result = TEST_UNKNOWN,
- .current_action = 0
+ .current_action = 0,
+ .step = vconf_step
},
{
.desc = "int (positive test)",
.actions = {
- {{.type = VKC_INT, .value.i = 1}, {ACTIVE, UNKNOWN}, 1, 0},
- {{.type = VKC_INT, .value.i = 2}, {INACTIVE, ACTIVE}, 2, 0},
- {{.type = VKC_INT, .value.i = 3}, {INACTIVE, UNKNOWN}, 1, 0}
+ {{{.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}
},
- .key = VCONF_KEY_I_P,
+ .id = VCONF_KEY_I_P,
.unit = SERVICE_NAME_I_P,
.path = NULL,
.expected_result = TEST_SUCCESS,
.result = TEST_UNKNOWN,
- .current_action = 0
+ .current_action = 0,
+ .step = vconf_step
},
{
.desc = "int (negative test)",
.actions = {
- {{.type = VKC_INT, .value.i = 1}, {ACTIVE, UNKNOWN}, 1, 0},
- {{.type = VKC_INT, .value.i = 2}, {INACTIVE, ACTIVE}, 2, 0},
- {{.type = VKC_INT, .value.i = 3}, {INACTIVE, UNKNOWN}, 1, 0}
+ {{{.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}
},
- .key = VCONF_KEY_I_N,
+ .id = VCONF_KEY_I_N,
.unit = SERVICE_NAME_I_N,
.path = NULL,
.expected_result = TEST_FAIL,
.result = TEST_UNKNOWN,
- .current_action = 0
+ .current_action = 0,
+ .step = vconf_step
},
{
.desc = "double (positive test)",
.actions = {
- {{.type = VKC_DOUBLE, .value.d = 1.1}, {ACTIVE, UNKNOWN}, 1, 0},
- {{.type = VKC_DOUBLE, .value.d = 1.2}, {INACTIVE, ACTIVE}, 2, 0},
- {{.type = VKC_DOUBLE, .value.d = 1.3}, {INACTIVE, UNKNOWN}, 1, 0}
+ {{{.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}
},
- .key = VCONF_KEY_D_P,
+ .id = VCONF_KEY_D_P,
.unit = SERVICE_NAME_D_P,
.path = NULL,
.expected_result = TEST_SUCCESS,
.result = TEST_UNKNOWN,
- .current_action = 0
+ .current_action = 0,
+ .step = vconf_step
},
{
.desc = "double (negative test)",
.actions = {
- {{.type = VKC_DOUBLE, .value.d = 1.1}, {ACTIVE, UNKNOWN}, 1, 0},
- {{.type = VKC_DOUBLE, .value.d = 1.2}, {INACTIVE, ACTIVE}, 2, 0},
- {{.type = VKC_DOUBLE, .value.d = 1.3}, {INACTIVE, UNKNOWN}, 1, 0}
+ {{{.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}
},
- .key = VCONF_KEY_D_N,
+ .id = VCONF_KEY_D_N,
.unit = SERVICE_NAME_D_N,
.path = NULL,
.expected_result = TEST_FAIL,
.result = TEST_UNKNOWN,
- .current_action = 0
+ .current_action = 0,
+ .step = vconf_step
},
{
.desc = "bool (positive test)",
.actions = {
- {{.type = VKC_BOOL, .value.b = true}, {ACTIVE, UNKNOWN}, 1, 0},
- {{.type = VKC_BOOL, .value.b = true}, {INACTIVE, ACTIVE}, 2, 0},
- {{.type = VKC_BOOL, .value.b = false}, {INACTIVE, UNKNOWN}, 1, 0}
+ {{{.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}
},
- .key = VCONF_KEY_B_P,
+ .id = VCONF_KEY_B_P,
.unit = SERVICE_NAME_B_P,
.path = NULL,
.expected_result = TEST_SUCCESS,
.result = TEST_UNKNOWN,
- .current_action = 0
+ .current_action = 0,
+ .step = vconf_step
},
{
.desc = "bool (negative test)",
.actions = {
- {{.type = VKC_BOOL, .value.b = true}, {ACTIVE, UNKNOWN}, 1, 0},
- {{.type = VKC_BOOL, .value.b = true}, {INACTIVE, ACTIVE}, 2, 0},
- {{.type = VKC_BOOL, .value.b = false}, {INACTIVE, UNKNOWN}, 1, 0}
+ {{{.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}
},
- .key = VCONF_KEY_B_N,
+ .id = VCONF_KEY_B_N,
.unit = SERVICE_NAME_B_N,
.path = NULL,
.expected_result = TEST_FAIL,
.result = TEST_UNKNOWN,
- .current_action = 0
+ .current_action = 0,
+ .step = vconf_step
}
};
return "unknown";
}
-static const char *from_unit_state(enum unit_state state)
-{
- switch (state) {
- case UNKNOWN:
- return "unknown";
- case ACTIVE:
- return "active";
- default:
- return "inactive";
- }
-}
-
-static enum unit_state to_unit_state(const char *state)
-{
- if (!strncmp (state, "active", 6))
- return ACTIVE;
- else if (!strncmp (state, "inactive", 8) || !strncmp (state, "deactivating", 12))
- return INACTIVE;
- else
- return UNKNOWN;
-}
-
-static int set_vconf_key(const char *key, const struct vkc_value val)
-{
- assert (key);
-
- keylist_t *kl = NULL;
- kl = vconf_keylist_new();
- if (!kl) {
- fprintf(stderr, "error creating vconf keylists\n");
- return -1;
- }
- switch (val.type) {
- case VKC_STRING:
- vconf_keylist_add_str(kl, key, val.value.s);
- break;
- case VKC_INT:
- vconf_keylist_add_int(kl, key, val.value.i);
- break;
- case VKC_DOUBLE:
- vconf_keylist_add_dbl(kl, key, val.value.d);
- break;
- case VKC_BOOL:
- vconf_keylist_add_bool(kl, key, val.value.b);
- break;
- default:
- vconf_keylist_free(kl);
- return -1;
- }
- if (vconf_set(kl) < 0) {
- fprintf(stderr, "error saving vconf key\n");
- vconf_keylist_free(kl);
- return -1;
- }
-
- vconf_keylist_free(kl);
- return 0;
-}
-
-static void next_test(struct test_data *data)
-{
- data->state = UNKNOWN;
- data->prev_state = UNKNOWN;
- data->current_test++;
-
- test_step(data);
-}
-
-static int on_test_step_timeout(sd_event_source *s, uint64_t usec, void *userdata)
-{
- struct test_data *data = (struct test_data *)userdata;
- struct test_sequence *test = &data->tests[data->current_test];
-
- test->result = TEST_FAIL;
- next_test(data);
- return 0;
-}
-
-static void stop_test_step_timeout(struct test_data *data)
-{
- int enabled;
- sd_event_source_get_enabled(data->step_timer, &enabled);
-
- if (enabled != SD_EVENT_OFF)
- sd_event_source_set_enabled(data->step_timer, SD_EVENT_OFF);
-}
-
-static int start_test_step_timeout(struct test_data *data)
-{
- int r;
- uint64_t now;
- char err[512];
-
- sd_event_now(data->loop, CLOCK_REALTIME, &now);
- r = sd_event_add_time(data->loop, &data->step_timer, CLOCK_REALTIME, now+2000000, 0, on_test_step_timeout, data);
- if (r < 0) {
- if (strerror_r(-r, err, sizeof err))
- fprintf(stderr, "Failed to attach timer to event loop: %s\n", err);
- return r;
- }
-
- return 0;
-}
-
-int test_step(struct test_data *data)
-{
- struct test_sequence *test;
-
- stop_test_step_timeout(data);
-
- /* last test */
- if (data->current_test == data->tests_count) {
- sd_event_exit(data->loop, EXIT_SUCCESS);
- return 0;
- }
- test = &data->tests[data->current_test];
-
- if (test->current_action == ARRAY_SIZE(test->actions)) {
- test->result = TEST_SUCCESS;
- next_test(data);
- return 0;
- }
-
- if (set_vconf_key(test->key, test->actions[test->current_action].action))
- return -1;
- start_test_step_timeout(data);
- return 0;
-}
-
-static int check_test_result(struct test_data *data)
-{
- struct test_sequence *test = &data->tests[data->current_test];
- struct action *a = &test->actions[test->current_action];
- enum unit_state exp_state = a->expected_states[a->current_state];
-
-
- if (data->state != exp_state) {
- fprintf(stderr, "test failed (%s instead of %s at step %d of test %d)\n",
- from_unit_state(data->state),
- from_unit_state(exp_state),
- a->current_state,
- data->current_test);
- test->result = TEST_FAIL;
- next_test(data);
- return -1;
- }
- a->current_state++;
- if (a->current_state == a->state_count) {
- test->current_action++;
- if (test_step(data) < 0)
- return -1;
- }
- return 0;
-}
-
-static int check_unit_state(struct test_data *data, const char *state)
-{
- enum unit_state new_state;
-
- new_state = to_unit_state(state);
- if (data->state != new_state) {
- data->prev_state = data->state;
- data->state = new_state;
- check_test_result(data);
- }
- return 0;
-}
-
-static int on_properties_changed(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
- int r;
- struct test_data *data = (struct test_data*)userdata;
- const char *iface;
- const char *member;
- const char *value = NULL;
- const char *contents;
-
- r = sd_bus_message_read(m, "s", &iface);
- if (r < 0) {
- fprintf(stderr, "Failed to parse PropertiesChanged\n");
- return r;
- }
-
- r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}");
- if (r < 0)
- return r;
-
- while ((r = sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, "sv")) > 0) {
- char type;
-
- r = sd_bus_message_read(m, "s", &member);
- if (r < 0)
- return r;
-
- r = sd_bus_message_peek_type(m, &type, &contents);
- if (r < 0)
- return r;
-
- r = sd_bus_message_enter_container(m, SD_BUS_TYPE_VARIANT, contents);
- if (r < 0)
- return r;
-
- if (strcmp(member, "ActiveState") == 0) {
- r = sd_bus_message_read(m, "s", &value);
- if (r < 0)
- return r;
- } else {
- r = sd_bus_message_skip(m, contents);
- if (r < 0)
- return r;
- }
-
- r = sd_bus_message_exit_container(m);
- if (r < 0)
- return r;
-
- r = sd_bus_message_exit_container(m);
- if (r < 0)
- return r;
- }
-
- r = sd_bus_message_exit_container(m);
- if (r < 0)
- return r;
-
- if (value)
- check_unit_state(data, value);
- return 0;
-}
-
static void cleanup(struct test_data *data)
{
for (int i = 0; i < data->tests_count; i++)
return 0;
}
-static int start_test(sd_event_source *s, uint64_t usec, void *userdata)
+static int start(sd_event_source *s, uint64_t usec, void *userdata)
{
struct test_data *data = (struct test_data*)userdata;
- return test_step(data);
+ return start_test(data);
}
static int timeout_handler(sd_event_source *s, uint64_t usec, void *userdata)
}
if (!path) {
- fprintf(stderr, "ould not get object path\n");
+ fprintf(stderr, "could not get object path\n");
return -1;
}
data->tests[i].path = strdup(path);
return ret;
}
+static void print_usage(const char *name)
+{
+ printf("usage: %s -t vconf|dbus\n", name);
+ return;
+}
+
+static int parse_cmdline(int argc, char *argv[], int *type)
+{
+ int option;
+
+ *type = TEST_TYPE_UNKNOWN;
+
+ while ((option = getopt(argc, argv, "t:")) != -1) {
+ switch (option) {
+ case 't':
+ if (!strcmp(optarg, "vconf"))
+ *type = TEST_TYPE_VCONF;
+ else if (!strcmp(optarg, "dbus"))
+ *type = TEST_TYPE_DBUS;
+ break;
+ default:
+ return -EINVAL;
+ }
+ }
+
+ if (*type == TEST_TYPE_UNKNOWN)
+ return -EINVAL;
+
+ return 0;
+}
+
+
int main(int argc, char *argv[])
{
struct test_data data = {
.step_timer = NULL,
.state = UNKNOWN,
.prev_state = UNKNOWN,
- .tests = acceptance_tests,
- .tests_count = ARRAY_SIZE(acceptance_tests),
.current_test = 0
};
+ int test_type;
int r;
uint64_t now;
sigset_t ss;
char buf[512];
char err[512];
+ r = parse_cmdline(argc, argv, &test_type);
+ if (r < 0) {
+ print_usage(argv[0]);
+ goto fail;
+ }
+
+ if (test_type == TEST_TYPE_VCONF) {
+ data.tests = vconf_acceptance_tests;
+ data.tests_count = ARRAY_SIZE(vconf_acceptance_tests);
+ } else if (test_type == TEST_TYPE_DBUS) {
+ data.tests = dbus_acceptance_tests;
+ data.tests_count = ARRAY_SIZE(dbus_acceptance_tests);
+ } else {
+ fprintf(stderr, "Unknown test type\n");
+ goto fail;
+ }
+
r = sd_bus_open_system(&data.bus);
if (r < 0) {
if (strerror_r(-r, err, sizeof err))
goto fail;
}
- r = sd_event_add_time(data.loop, NULL, CLOCK_REALTIME, 0, 0, start_test, &data);
+ r = sd_event_add_time(data.loop, NULL, CLOCK_REALTIME, 0, 0, start, &data);
if (r < 0) {
if (strerror_r(-r, err, sizeof err))
fprintf(stderr, "Failed to attach timer to event loop: %s\n", err);