acceptance tests: add dbus activation tests 86/202586/4
authorMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Mon, 1 Apr 2019 07:50:20 +0000 (09:50 +0200)
committerMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Thu, 4 Apr 2019 13:13:44 +0000 (15:13 +0200)
Change-Id: I334199b6e8f18c4e64b85c8fcc1c03d02ac21f8d
Signed-off-by: Maciej Slodczyk <m.slodczyk2@partner.samsung.com>
13 files changed:
Makefile.am
modules.conf.d/activation_eh.conf.d/99-acceptance-test.conf
modules.conf.d/activation_eh.conf.d/activation_eh.conf
modules.conf.d/dbus_listener.conf.d/99-acceptance-test.conf [new file with mode: 0644]
tests/activationd-acceptance-tests.h [new file with mode: 0644]
tests/activationd_acceptance_checker.c
tests/activationd_acceptance_test
tests/activationd_acceptance_tests.c [new file with mode: 0644]
tests/activationd_acceptance_tests.h [new file with mode: 0644]
tests/activationd_acceptance_tests_dbus.c [new file with mode: 0644]
tests/activationd_acceptance_tests_dbus.h [new file with mode: 0644]
tests/activationd_acceptance_tests_vconf.c [new file with mode: 0644]
tests/activationd_acceptance_tests_vconf.h [new file with mode: 0644]

index a3f286eed76286bfcc2448b363a3b18982725ff1..038cd537c22063081bcefcdc529b1b6f6704e0e5 100644 (file)
@@ -142,6 +142,7 @@ vconf_listener_config_DATA += modules.conf.d/vconf_listener.conf.d/99-acceptance
 vconf_listener_configdir = $(modulesconfigdir)/vconf_listener.conf.d
 dbus_listener_la_SOURCES = src/listeners/dbus.c
 dbus_listener_config_DATA = modules.conf.d/dbus_listener.conf.d/50-default.conf
+dbus_listener_config_DATA += modules.conf.d/dbus_listener.conf.d/99-acceptance-test.conf
 dbus_listener_configdir = $(modulesconfigdir)/dbus_listener.conf.d
 
 epcd_LDADD = $(LIBSYSTEMD_LIBS) $(GLIB_LIBS) $(JSON_C_LIBS)
@@ -186,6 +187,9 @@ install-data-local:
 bin_PROGRAMS = activationd_acceptance_checker
 
 activationd_acceptance_checker_SOURCES = \
+       tests/activationd_acceptance_tests.c \
+       tests/activationd_acceptance_tests_vconf.c \
+       tests/activationd_acceptance_tests_dbus.c \
        tests/activationd_acceptance_checker.c
 
 activationd_acceptance_checker_CFLAGS = $(AM_CFLAGS)
index 74feee7c897ce7bf1ae327dda2ac2c98c9dd4b1f..f294df42f9b7c4c5bcb7d6235f03b36352ce977e 100644 (file)
        {"event":"vconf_key_changed", "key_name":"file/activationd/acceptance_bool_p", "oldval":true, "newval":true, "action":"RestartUnit", "target":"activationd-acceptance-test-b-p.service"},
        {"event":"vconf_key_changed", "key_name":"file/activationd/acceptance_bool_n", "oldval":true, "newval":true, "action":"StartUnit", "target":"activationd-acceptance-test-b-n.service"},
        {"event":"vconf_key_changed", "key_name":"file/activationd/acceptance_bool_n", "oldval":true, "newval":false, "action":"StopUnit", "target":"activationd-acceptance-test-b-n.service"},
-       {"event":"vconf_key_changed", "key_name":"file/activationd/acceptance_bool_n", "oldval":true, "newval":true, "action":"RestartUnit", "target":"activationd-acceptance-test-b-n.service"}
+       {"event":"vconf_key_changed", "key_name":"file/activationd/acceptance_bool_n", "oldval":true, "newval":true, "action":"RestartUnit", "target":"activationd-acceptance-test-b-n.service"},
+       {"event":"dbus_signal", "id":"test_sp", "action":"StartUnit", "target":"activationd-acceptance-test-s-p.service", "match":
+               {"arg1":"start"}
+       },
+       {"event":"dbus_signal", "id":"test_sp", "action":"RestartUnit", "target":"activationd-acceptance-test-s-p.service", "match":
+               {"arg1":"restart"}
+       },
+       {"event":"dbus_signal", "id":"test_sp", "action":"StopUnit", "target":"activationd-acceptance-test-s-p.service", "match":
+               {"arg1":"stop"}
+       },
+       {"event":"dbus_signal", "id":"test_sn", "action":"StartUnit", "target":"activationd-acceptance-test-s-n.service", "match":
+               {"arg1":"start"}
+       },
+       {"event":"dbus_signal", "id":"test_sn", "action":"RestartUnit", "target":"activationd-acceptance-test-s-n.service", "match":
+               {"arg1":"res"}
+       },
+       {"event":"dbus_signal", "id":"test_sn", "action":"StopUnit", "target":"activationd-acceptance-test-s-n.service", "match":
+               {"arg1":"stop"}
+       },
+       {"event":"dbus_signal", "id":"test_ip", "action":"StartUnit", "target":"activationd-acceptance-test-i-p.service", "match":
+               {"arg1":1}
+       },
+       {"event":"dbus_signal", "id":"test_ip", "action":"RestartUnit", "target":"activationd-acceptance-test-i-p.service", "match":
+               {"arg1":2}
+       },
+       {"event":"dbus_signal", "id":"test_ip", "action":"StopUnit", "target":"activationd-acceptance-test-i-p.service", "match":
+               {"arg1":3}
+       },
+       {"event":"dbus_signal", "id":"test_in", "action":"StartUnit", "target":"activationd-acceptance-test-i-n.service", "match":
+               {"arg1":4}
+       },
+       {"event":"dbus_signal", "id":"test_in", "action":"RestartUnit", "target":"activationd-acceptance-test-i-n.service", "match":
+               {"arg1":2}
+       },
+       {"event":"dbus_signal", "id":"test_in", "action":"StopUnit", "target":"activationd-acceptance-test-i-n.service", "match":
+               {"arg1":3}
+       },
+       {"event":"dbus_signal", "id":"test_dp", "action":"StartUnit", "target":"activationd-acceptance-test-d-p.service", "match":
+               {"arg1":1.0}
+       },
+       {"event":"dbus_signal", "id":"test_dp", "action":"RestartUnit", "target":"activationd-acceptance-test-d-p.service", "match":
+               {"arg1":2.0}
+       },
+       {"event":"dbus_signal", "id":"test_dp", "action":"StopUnit", "target":"activationd-acceptance-test-d-p.service", "match":
+               {"arg1":3.0}
+       },
+       {"event":"dbus_signal", "id":"test_dn", "action":"StartUnit", "target":"activationd-acceptance-test-d-n.service", "match":
+               {"arg1":1.0}
+       },
+       {"event":"dbus_signal", "id":"test_dn", "action":"RestartUnit", "target":"activationd-acceptance-test-d-n.service", "match":
+               {"arg1":2.0}
+       },
+       {"event":"dbus_signal", "id":"test_dn", "action":"StopUnit", "target":"activationd-acceptance-test-d-n.service", "match":
+               {"arg1":5.0}
+       },
+       {"event":"dbus_signal", "id":"test_bp", "action":"StartUnit", "target":"activationd-acceptance-test-b-p.service", "match":
+               {"arg1":true, "arg2":true}
+       },
+       {"event":"dbus_signal", "id":"test_bp", "action":"RestartUnit", "target":"activationd-acceptance-test-b-p.service", "match":
+               {"arg1":true, "arg2":false}
+       },
+       {"event":"dbus_signal", "id":"test_bp", "action":"StopUnit", "target":"activationd-acceptance-test-b-p.service", "match":
+               {"arg1":false, "arg2":false}
+       },
+       {"event":"dbus_signal", "id":"test_bn", "action":"StartUnit", "target":"activationd-acceptance-test-b-n.service", "match":
+               {"arg1":true, "arg2":true}
+       },
+       {"event":"dbus_signal", "id":"test_bn", "action":"RestartUnit", "target":"activationd-acceptance-test-b-n.service", "match":
+               {"arg1":true, "arg2":false}
+       },
+       {"event":"dbus_signal", "id":"test_bn", "action":"StopUnit", "target":"activationd-acceptance-test-b-n.service", "match":
+               {"arg1":false, "arg2":true}
+       }
+
+
+
+
        ]
 }
index 0a09d737c5f451f8a70b11ea4dee60909165f04e..76b23b0abb0e960bd53b270830a7bdf240beb29e 100644 (file)
@@ -1,8 +1,11 @@
 {
        "rules":[
        {"event":"vconf_key_changed", "key_name":"db/test/key3", "action":"StartUnit", "target":"foo.service"},
-       {"event":"dbus_signal", "id":"example_signal", "action":"StartUnit", "target":"bar.service", "match":
+       {"event":"dbus_signal", "id":"example_signal", "action":"StartUnit", "target":"activationd-acceptance-test-s-n.service", "match":
                {"arg1":"hello", "arg2":35}
+       },
+       {"event":"dbus_signal", "id":"example_signal", "action":"StopUnit", "target":"activationd-acceptance-test-s-n.service", "match":
+               {"arg1":"hello", "arg2":34}
        }
        ]
 }
diff --git a/modules.conf.d/dbus_listener.conf.d/99-acceptance-test.conf b/modules.conf.d/dbus_listener.conf.d/99-acceptance-test.conf
new file mode 100644 (file)
index 0000000..5e43ef1
--- /dev/null
@@ -0,0 +1,12 @@
+{
+       "signals":[
+               {"id":"test_sp", "interface":"org.freedesktop.ActivationdTestInterface", "member":"AcceptanceTestSP", "path_namespace":"/org/freedesktop"},
+               {"id":"test_sn", "interface":"org.freedesktop.ActivationdTestInterface", "member":"AcceptanceTestSN", "path_namespace":"/org/freedesktop"},
+               {"id":"test_ip", "interface":"org.freedesktop.ActivationdTestInterface", "member":"AcceptanceTestIP", "path_namespace":"/org/freedesktop"},
+               {"id":"test_in", "interface":"org.freedesktop.ActivationdTestInterface", "member":"AcceptanceTestIN", "path_namespace":"/org/freedesktop"},
+               {"id":"test_dp", "interface":"org.freedesktop.ActivationdTestInterface", "member":"AcceptanceTestDP", "path_namespace":"/org/freedesktop"},
+               {"id":"test_dn", "interface":"org.freedesktop.ActivationdTestInterface", "member":"AcceptanceTestDN", "path_namespace":"/org/freedesktop"},
+               {"id":"test_bp", "interface":"org.freedesktop.ActivationdTestInterface", "member":"AcceptanceTestBP", "path_namespace":"/org/freedesktop"},
+               {"id":"test_bn", "interface":"org.freedesktop.ActivationdTestInterface", "member":"AcceptanceTestBN", "path_namespace":"/org/freedesktop"}
+       ]
+}
diff --git a/tests/activationd-acceptance-tests.h b/tests/activationd-acceptance-tests.h
new file mode 100644 (file)
index 0000000..0723571
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * This file is part of epc.
+ *
+ * Copyright © 2019 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ACTIVATIOND_ACCEPTANCE_TESTS_H
+#define ACTIVATIOND_ACCEPTANCE_TESTS_H
+
+
+#endif /* ACTIVATIOND_ACCEPTANCE_TESTS_H */
index 236e4e34395c5e8d84911b7eac26251fa5b68a40..14d03e59b004d99ddeaaacd13e124c862176e981 100644 (file)
 #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
        }
 };
 
@@ -215,235 +389,6 @@ static const char *test_result(int r)
                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++)
@@ -463,10 +408,10 @@ static int signal_handler(sd_event_source *s,
        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)
@@ -531,7 +476,7 @@ static int call_load_unit(struct test_data *data)
                }
 
                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);
@@ -553,6 +498,38 @@ static int print_results(struct test_data *data)
        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 = {
@@ -561,17 +538,33 @@ int main(int argc, char *argv[])
                .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))
@@ -641,7 +634,7 @@ int main(int argc, char *argv[])
                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);
index 30f7c6fb54df419647d4d0e97cad23a28e0a653e..96ad897e422e40181686553d81c5a06e5c364eca 100755 (executable)
@@ -2,7 +2,7 @@
 
 EPCD_PID=-1
 
-cleanup() {
+stop_services() {
        systemctl stop activationd-acceptance-test-s-p
        systemctl stop activationd-acceptance-test-s-n
        systemctl stop activationd-acceptance-test-i-p
@@ -11,6 +11,9 @@ cleanup() {
        systemctl stop activationd-acceptance-test-d-n
        systemctl stop activationd-acceptance-test-b-p
        systemctl stop activationd-acceptance-test-b-n
+}
+
+cleanup() {
        [ $EPCD_PID -ne -1 ] && kill $EPCD_PID > /dev/null 2>&1
        vconftool unset  file/activationd/acceptance
        exit 0
@@ -32,11 +35,20 @@ epcd > /dev/null 2>&1 &
 EPCD_PID=$!
 sleep 2
 
-/usr/bin/activationd_acceptance_checker
-
+echo "Testing vconf:"
+/usr/bin/activationd_acceptance_checker -t vconf
 if [ "$?" -eq "0" ]; then
        echo "all tests passed"
 else
        echo "some tests failed"
 fi
 
+stop_services
+echo ""
+echo "Testing dbus:"
+/usr/bin/activationd_acceptance_checker -t dbus
+if [ "$?" -eq "0" ]; then
+       echo "all tests passed"
+else
+       echo "some tests failed"
+fi
diff --git a/tests/activationd_acceptance_tests.c b/tests/activationd_acceptance_tests.c
new file mode 100644 (file)
index 0000000..39e91bd
--- /dev/null
@@ -0,0 +1,227 @@
+/*
+ * This file is part of epc.
+ *
+ * Copyright © 2019 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "vconf_key_changed_event.h"
+#include "activationd_acceptance_tests.h"
+#include "activationd_acceptance_tests_dbus.h"
+#include "activationd_acceptance_tests_vconf.h"
+
+int test_step(struct test_data *data);
+
+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 void next_test(struct test_data *data)
+{
+       data->state = UNKNOWN;
+       data->prev_state = UNKNOWN;
+       data->current_test++;
+
+       test_step(data);
+}
+
+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 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 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;
+}
+
+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;
+}
+
+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;
+       if (!test->step || test->step(data) != 0)
+               return -1;
+
+       start_test_step_timeout(data);
+       return 0;
+}
+
+int start_test(struct test_data *data)
+{
+       return test_step(data);
+}
+
+
+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;
+}
+
diff --git a/tests/activationd_acceptance_tests.h b/tests/activationd_acceptance_tests.h
new file mode 100644 (file)
index 0000000..bfdd560
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * This file is part of epc.
+ *
+ * Copyright © 2019 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ACTIVATIOND_ACCEPTANCE_TESTS_H
+#define ACTIVATIOND_ACCEPTANCE_TESTS_H
+
+#include <systemd/sd-bus.h>
+#include "vconf_key_changed_event.h"
+
+struct vkc_value;
+struct test_data;
+
+enum unit_state {
+       UNKNOWN,
+       ACTIVE,
+       INACTIVE
+};
+
+enum {
+       TEST_FAIL,
+       TEST_SUCCESS,
+       TEST_UNKNOWN
+};
+
+struct action {
+       struct vkc_value params[3];
+       enum unit_state expected_states[2];
+       int param_count;
+       int state_count;
+       int current_state;
+};
+
+struct test_sequence {
+       const char *desc;
+       struct action actions[3];
+       const char *id; /* vconf key or dbus method */
+       int current_action;
+       int expected_result;
+       int result;
+       char *unit;
+       char *path;
+       int (*step)(struct test_data *test);
+};
+
+
+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;
+};
+
+int start_test(struct test_data *data);
+int on_properties_changed(sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
+
+#endif /* ACTIVATIOND_ACCEPTANCE_TESTS_H */
diff --git a/tests/activationd_acceptance_tests_dbus.c b/tests/activationd_acceptance_tests_dbus.c
new file mode 100644 (file)
index 0000000..35459ee
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * This file is part of epc.
+ *
+ * Copyright © 2019 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "activationd_acceptance_tests.h"
+#include "activationd_acceptance_tests_dbus.h"
+
+#define DBUS_TEST_INTERFACE "org.freedesktop.ActivationdTestInterface"
+#define DBUS_TEST_PATH "/org/freedesktop/activationd/test/object"
+
+static int send_dbus_signal(sd_bus *bus, const char *method, int param_cnt, const struct vkc_value *params)
+{
+       _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
+       int ret;
+
+       ret = sd_bus_message_new_signal(bus, &m, DBUS_TEST_PATH, DBUS_TEST_INTERFACE, method);
+       if (ret < 0)
+               goto fail;
+
+       for (int i = 0; i < param_cnt; i++) {
+               switch(params[i].type) {
+               case VKC_STRING:
+                       ret = sd_bus_message_append(m, "s", params[i].value.s);
+                       if (ret < 0)
+                               goto fail;
+                       break;
+               case VKC_DOUBLE:
+                       ret = sd_bus_message_append(m, "d", params[i].value.d);
+                       if (ret < 0)
+                               goto fail;
+                       break;
+               case VKC_INT:
+                       ret = sd_bus_message_append(m, "i", params[i].value.i);
+                       if (ret < 0)
+                               goto fail;
+                       break;
+               case VKC_BOOL:
+                       ret = sd_bus_message_append(m, "b", params[i].value.b);
+                       if (ret < 0)
+                               goto fail;
+                       break;
+               }
+       }
+       sd_bus_send(bus, m, NULL);
+       /* return value of sd_bus_send is useless because it will always fail on negative tests,
+        * always return 0 instead */
+       return 0;
+fail:
+       return ret;
+}
+
+int dbus_step(struct test_data *data)
+{
+       assert(data);
+       struct test_sequence *test = &data->tests[data->current_test];
+       return send_dbus_signal(data->bus, test->id, test->actions[test->current_action].param_count, test->actions[test->current_action].params);
+}
diff --git a/tests/activationd_acceptance_tests_dbus.h b/tests/activationd_acceptance_tests_dbus.h
new file mode 100644 (file)
index 0000000..4e9a336
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * This file is part of epc.
+ *
+ * Copyright © 2019 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ACTIVATIOND_ACCEPTANCE_TESTS_DBUS_H
+#define ACTIVATIOND_ACCEPTANCE_TESTS_DBUS_H
+
+struct test_data;
+
+int dbus_step(struct test_data *data);
+
+#endif /* ACTIVATIOND_ACCEPTANCE_TESTS_DBUS_H */
diff --git a/tests/activationd_acceptance_tests_vconf.c b/tests/activationd_acceptance_tests_vconf.c
new file mode 100644 (file)
index 0000000..062507e
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * This file is part of epc.
+ *
+ * Copyright © 2019 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "activationd_acceptance_tests.h"
+#include "activationd_acceptance_tests_vconf.h"
+#include "vconf_key_changed_event.h"
+#include <vconf.h>
+
+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;
+}
+
+int vconf_step(struct test_data *data)
+{
+       assert(data);
+       struct test_sequence *test = &data->tests[data->current_test];
+       return set_vconf_key(test->id, test->actions[test->current_action].params);
+}
diff --git a/tests/activationd_acceptance_tests_vconf.h b/tests/activationd_acceptance_tests_vconf.h
new file mode 100644 (file)
index 0000000..b7601dc
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * This file is part of epc.
+ *
+ * Copyright © 2019 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ACTIVATIOND_ACCEPTANCE_TESTS_VCONF_H
+#define ACTIVATIOND_ACCEPTANCE_TESTS_VCONF_H
+
+struct test_data;
+
+int vconf_step(struct test_data *data);
+
+#endif /* ACTIVATIOND_ACCEPTANCE_TESTS_VCONF_H */