unit control: add dbus api acceptance tests 47/205847/3
authorMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Thu, 9 May 2019 17:05:03 +0000 (19:05 +0200)
committerMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Thu, 6 Jun 2019 16:14:58 +0000 (18:14 +0200)
Change-Id: I5a8375b71eb682d288addb22067329e1713b30f6
Signed-off-by: Maciej Slodczyk <m.slodczyk2@partner.samsung.com>
12 files changed:
Makefile.am
modules.conf.d/unit_control_eh.conf.d/99-acceptance-test.conf [new file with mode: 0644]
packaging/activationd.spec
tests/activationd_acceptance_checker.c
tests/activationd_acceptance_test
tests/activationd_acceptance_tests.c
tests/activationd_acceptance_tests_dbus.c [deleted file]
tests/activationd_acceptance_tests_dbus.h [deleted file]
tests/activationd_acceptance_tests_dbus_signal.c [new file with mode: 0644]
tests/activationd_acceptance_tests_dbus_signal.h [new file with mode: 0644]
tests/activationd_acceptance_tests_unit_control.c [new file with mode: 0644]
tests/activationd_acceptance_tests_unit_control.h [new file with mode: 0644]

index f47dff68c3c6efda8ff023d715b81fd4d74a18b3..b4bc6332e282e3bfd8235a7337e056fdf58becf8 100644 (file)
@@ -144,6 +144,7 @@ activation_dm_config_DATA += modules.conf.d/activation_eh.conf.d/99-acceptance-t
 activation_dm_configdir = $(modulesconfigdir)/activation_eh.conf.d
 unit_control_dm_la_SOURCES = src/decision_makers/unit_control_dm.c
 unit_control_dm_config_DATA = modules.conf.d/unit_control_eh.conf.d/unit_control_eh.conf
+unit_control_dm_config_DATA += modules.conf.d/unit_control_eh.conf.d/99-acceptance-test.conf
 unit_control_dm_configdir = $(modulesconfigdir)/unit_control_eh.conf.d
 vconf_listener_la_SOURCES = src/listeners/vconf.c
 vconf_listener_config_DATA = modules.conf.d/vconf_listener.conf.d/50-default.conf
@@ -214,7 +215,8 @@ 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_tests_dbus_signal.c \
+       tests/activationd_acceptance_tests_unit_control.c \
        tests/activationd_acceptance_checker.c
 
 activationd_acceptance_checker_CFLAGS = $(AM_CFLAGS)
diff --git a/modules.conf.d/unit_control_eh.conf.d/99-acceptance-test.conf b/modules.conf.d/unit_control_eh.conf.d/99-acceptance-test.conf
new file mode 100644 (file)
index 0000000..46a1099
--- /dev/null
@@ -0,0 +1,3 @@
+{
+       "whitelist":[ "activationd-acceptance-test-s-p.service", "activationd-acceptance-test-i-n.service" ]
+}
index 3526f10ba73c69c692dafc1ecf53fc1ed9a144de..1e14ed4978ff70d3b9b857c1605af464d0dea58e 100644 (file)
@@ -189,6 +189,7 @@ mkdir -p %{buildroot}/%{enabled_moduledir}
 %{_unitdir}/activationd-acceptance-test-b-n.service
 %{_libdir}/actd/modules.conf.d/vconf_listener.conf.d/99-acceptance-test.conf
 %{_libdir}/actd/modules.conf.d/activation_eh.conf.d/99-acceptance-test.conf
+%{_libdir}/actd/modules.conf.d/unit_control_eh.conf.d/99-acceptance-test.conf
 
 %files -n event-processing-core
 %license COPYING
index bb5fd0eb05ab24f552cf1c78b4c10ced75206837..3d109f35c45adcc64e58a0fa881d4d45d569265f 100644 (file)
@@ -25,7 +25,8 @@
 #include "common.h"
 #include "systemd_dbus.h"
 #include "activationd_acceptance_tests.h"
-#include "activationd_acceptance_tests_dbus.h"
+#include "activationd_acceptance_tests_dbus_signal.h"
+#include "activationd_acceptance_tests_unit_control.h"
 #include "activationd_acceptance_tests_vconf.h"
 
 #define DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
 enum {
        TEST_TYPE_UNKNOWN,
        TEST_TYPE_VCONF,
-       TEST_TYPE_DBUS
+       TEST_TYPE_DBUS_SIGNAL,
+       TEST_TYPE_UNIT_CONTROL
 };
 
-static struct test_sequence dbus_acceptance_tests[] = {
+static struct test_sequence unit_control_acceptance_tests[] = {
+       {
+               .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}
+               },
+               .id = "AcceptanceTestSP",
+               .unit = SERVICE_NAME_S_P,
+               .path = NULL,
+               .expected_result = TEST_SUCCESS,
+               .result = TEST_UNKNOWN,
+               .current_action = 0,
+               .step = unit_control_step
+       },
+       {
+               .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}
+               },
+               .id = "AcceptanceTestIN",
+               .unit = SERVICE_NAME_I_N,
+               .path = NULL,
+               .expected_result = TEST_FAIL,
+               .result = TEST_UNKNOWN,
+               .current_action = 0,
+               .step = unit_control_step
+       },
+       {
+               .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}
+               },
+               .id = "AcceptanceTestSN",
+               .unit = SERVICE_NAME_S_N,
+               .path = NULL,
+               .expected_result = TEST_FAIL,
+               .result = TEST_UNKNOWN,
+               .current_action = 0,
+               .step = unit_control_step
+       }
+};
+
+static struct test_sequence dbus_signal_acceptance_tests[] = {
        {
                .desc = "string (positive test)",
                .actions = {
                        {{
-                                {.type = VKC_STRING, .value.s = "start"}
+                               {.type = VKC_STRING, .value.s = "start"}
                         },
                        {ACTIVE, UNKNOWN}, 1, 1, 0},
                        {{
-                                {.type = VKC_STRING, .value.s = "restart"}
+                               {.type = VKC_STRING, .value.s = "restart"}
                         },
                        {INACTIVE, ACTIVE}, 1, 2, 0},
                        {{
-                                {.type = VKC_STRING, .value.s = "stop"}
+                               {.type = VKC_STRING, .value.s = "stop"}
                         },
                        {INACTIVE, UNKNOWN}, 1, 1, 0}
                },
@@ -75,21 +152,21 @@ static struct test_sequence dbus_acceptance_tests[] = {
                .expected_result = TEST_SUCCESS,
                .result = TEST_UNKNOWN,
                .current_action = 0,
-               .step = dbus_step
+               .step = dbus_signal_step
        },
        {
                .desc = "string (negative test)",
                .actions = {
                        {{
-                                {.type = VKC_STRING, .value.s = "start"}
+                               {.type = VKC_STRING, .value.s = "start"}
                         },
                        {ACTIVE, UNKNOWN}, 1, 1, 0},
                        {{
-                                {.type = VKC_STRING, .value.s = "restart"}
+                               {.type = VKC_STRING, .value.s = "restart"}
                         },
                        {INACTIVE, ACTIVE}, 1, 2, 0},
                        {{
-                                {.type = VKC_STRING, .value.s = "stop"}
+                               {.type = VKC_STRING, .value.s = "stop"}
                         },
                        {INACTIVE, UNKNOWN}, 1, 1, 0}
                },
@@ -99,21 +176,21 @@ static struct test_sequence dbus_acceptance_tests[] = {
                .expected_result = TEST_FAIL,
                .result = TEST_UNKNOWN,
                .current_action = 0,
-               .step = dbus_step
+               .step = dbus_signal_step
        },
        {
                .desc = "int (positive test)",
                .actions = {
                        {{
-                                {.type = VKC_INT, .value.i = 1}
+                               {.type = VKC_INT, .value.i = 1}
                         },
                        {ACTIVE, UNKNOWN}, 1, 1, 0},
                        {{
-                                {.type = VKC_INT, .value.i = 2}
+                               {.type = VKC_INT, .value.i = 2}
                         },
                        {INACTIVE, ACTIVE}, 1, 2, 0},
                        {{
-                                {.type = VKC_INT, .value.i = 3}
+                               {.type = VKC_INT, .value.i = 3}
                         },
                        {INACTIVE, UNKNOWN}, 1, 1, 0}
                },
@@ -123,21 +200,21 @@ static struct test_sequence dbus_acceptance_tests[] = {
                .expected_result = TEST_SUCCESS,
                .result = TEST_UNKNOWN,
                .current_action = 0,
-               .step = dbus_step
+               .step = dbus_signal_step
        },
        {
                .desc = "int (negative test)",
                .actions = {
                        {{
-                                {.type = VKC_INT, .value.i = 1}
+                               {.type = VKC_INT, .value.i = 1}
                         },
                        {ACTIVE, UNKNOWN}, 1, 1, 0},
                        {{
-                                {.type = VKC_INT, .value.i = 2}
+                               {.type = VKC_INT, .value.i = 2}
                         },
                        {INACTIVE, ACTIVE}, 1, 2, 0},
                        {{
-                                {.type = VKC_INT, .value.i = 3}
+                               {.type = VKC_INT, .value.i = 3}
                         },
                        {INACTIVE, UNKNOWN}, 1, 1, 0}
                },
@@ -147,21 +224,21 @@ static struct test_sequence dbus_acceptance_tests[] = {
                .expected_result = TEST_FAIL,
                .result = TEST_UNKNOWN,
                .current_action = 0,
-               .step = dbus_step
+               .step = dbus_signal_step
        },
        {
                .desc = "double (positive test)",
                .actions = {
                        {{
-                                {.type = VKC_DOUBLE, .value.d = 1.0}
+                               {.type = VKC_DOUBLE, .value.d = 1.0}
                         },
                        {ACTIVE, UNKNOWN}, 1, 1, 0},
                        {{
-                                {.type = VKC_DOUBLE, .value.d = 2.0}
+                               {.type = VKC_DOUBLE, .value.d = 2.0}
                         },
                        {INACTIVE, ACTIVE}, 1, 2, 0},
                        {{
-                                {.type = VKC_DOUBLE, .value.d = 3.0}
+                               {.type = VKC_DOUBLE, .value.d = 3.0}
                         },
                        {INACTIVE, UNKNOWN}, 1, 1, 0}
                },
@@ -171,21 +248,21 @@ static struct test_sequence dbus_acceptance_tests[] = {
                .expected_result = TEST_SUCCESS,
                .result = TEST_UNKNOWN,
                .current_action = 0,
-               .step = dbus_step
+               .step = dbus_signal_step
        },
        {
                .desc = "double (negative test)",
                .actions = {
                        {{
-                                {.type = VKC_DOUBLE, .value.d = 1.0}
+                               {.type = VKC_DOUBLE, .value.d = 1.0}
                         },
                        {ACTIVE, UNKNOWN}, 1, 1, 0},
                        {{
-                                {.type = VKC_DOUBLE, .value.d = 2.0}
+                               {.type = VKC_DOUBLE, .value.d = 2.0}
                         },
                        {INACTIVE, ACTIVE}, 1, 2, 0},
                        {{
-                                {.type = VKC_DOUBLE, .value.d = 3.0}
+                               {.type = VKC_DOUBLE, .value.d = 3.0}
                         },
                        {INACTIVE, UNKNOWN}, 1, 1, 0}
                },
@@ -195,24 +272,24 @@ static struct test_sequence dbus_acceptance_tests[] = {
                .expected_result = TEST_FAIL,
                .result = TEST_UNKNOWN,
                .current_action = 0,
-               .step = dbus_step
+               .step = dbus_signal_step
        },
        {
                .desc = "bool (positive test)",
                .actions = {
                        {{
-                                {.type = VKC_BOOL, .value.b = true},
-                                {.type = VKC_BOOL, .value.b = true}
+                               {.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}
+                               {.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}
+                               {.type = VKC_BOOL, .value.b = false},
+                               {.type = VKC_BOOL, .value.b = false}
                         },
                        {INACTIVE, UNKNOWN}, 2, 1, 0}
                },
@@ -222,24 +299,24 @@ static struct test_sequence dbus_acceptance_tests[] = {
                .expected_result = TEST_SUCCESS,
                .result = TEST_UNKNOWN,
                .current_action = 0,
-               .step = dbus_step
+               .step = dbus_signal_step
        },
        {
                .desc = "bool (negative test)",
                .actions = {
                        {{
-                                {.type = VKC_BOOL, .value.b = true},
-                                {.type = VKC_BOOL, .value.b = true}
+                               {.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}
+                               {.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}
+                               {.type = VKC_BOOL, .value.b = false},
+                               {.type = VKC_BOOL, .value.b = false}
                         },
                        {INACTIVE, UNKNOWN}, 2, 1, 0}
                },
@@ -249,7 +326,7 @@ static struct test_sequence dbus_acceptance_tests[] = {
                .expected_result = TEST_FAIL,
                .result = TEST_UNKNOWN,
                .current_action = 0,
-               .step = dbus_step
+               .step = dbus_signal_step
        }
 };
 
@@ -275,9 +352,6 @@ static struct test_sequence vconf_acceptance_tests[] = {
                        {{{.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}
                },
                .id = VCONF_KEY_S_N,
                .unit = SERVICE_NAME_S_N,
@@ -500,7 +574,7 @@ static int print_results(struct test_data *data)
 
 static void print_usage(const char *name)
 {
-       printf("usage: %s -t vconf|dbus\n", name);
+       printf("usage: %s -t vconf|signal|unit_control\n", name);
        return;
 }
 
@@ -515,8 +589,10 @@ static int parse_cmdline(int argc, char *argv[], int *type)
                        case 't':
                                if (!strcmp(optarg, "vconf"))
                                        *type = TEST_TYPE_VCONF;
-                               else if (!strcmp(optarg, "dbus"))
-                                       *type = TEST_TYPE_DBUS;
+                               else if (!strcmp(optarg, "signal"))
+                                       *type = TEST_TYPE_DBUS_SIGNAL;
+                               else if (!strcmp(optarg, "unit_control"))
+                                       *type = TEST_TYPE_UNIT_CONTROL;
                                break;
                        default:
                                return -EINVAL;
@@ -557,9 +633,12 @@ int main(int argc, char *argv[])
        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 if (test_type == TEST_TYPE_DBUS_SIGNAL) {
+               data.tests = dbus_signal_acceptance_tests;
+               data.tests_count = ARRAY_SIZE(dbus_signal_acceptance_tests);
+       } else if (test_type == TEST_TYPE_UNIT_CONTROL) {
+               data.tests = unit_control_acceptance_tests;
+               data.tests_count = ARRAY_SIZE(unit_control_acceptance_tests);
        } else {
                fprintf(stderr, "Unknown test type\n");
                goto fail;
index b241f2defcf04d8bc23c6edaac5b5935ace0b82c..1327ffcbc4ba57b1edcee2f0f62e93696881e131 100755 (executable)
@@ -36,7 +36,7 @@ ACTD_PID=$!
 sleep 2
 
 echo "Testing vconf:"
-/usr/bin/activationd_acceptance_checker -t vconf
+/usr/bin/activationd_acceptance_checker -t vconf 2> /dev/null
 if [ "$?" -eq "0" ]; then
        echo "all tests passed"
 else
@@ -45,8 +45,18 @@ fi
 
 stop_services
 echo ""
-echo "Testing dbus:"
-/usr/bin/activationd_acceptance_checker -t dbus
+echo "Testing dbus signals:"
+/usr/bin/activationd_acceptance_checker -t signal 2> /dev/null
+if [ "$?" -eq "0" ]; then
+       echo "all tests passed"
+else
+       echo "some tests failed"
+fi
+
+stop_services
+echo ""
+echo "Testing unit control dbus api:"
+/usr/bin/activationd_acceptance_checker -t unit_control 2> /dev/null
 if [ "$?" -eq "0" ]; then
        echo "all tests passed"
 else
index 52a86dbefb303851f5ede55ce76eb324303d1360..2cc7e1510205773c98f7d2dd30c036282f9c8331 100644 (file)
@@ -18,7 +18,7 @@
 
 #include "vconf_key_changed_event.h"
 #include "activationd_acceptance_tests.h"
-#include "activationd_acceptance_tests_dbus.h"
+#include "activationd_acceptance_tests_dbus_signal.h"
 #include "activationd_acceptance_tests_vconf.h"
 
 int test_step(struct test_data *data);
@@ -98,10 +98,11 @@ static int check_test_result(struct test_data *data)
 
 
        if (data->state != exp_state) {
-               fprintf(stderr, "test failed (%s instead of %s at step %d of test %d)\n",
+               fprintf(stderr, "test failed (%s instead of %s at step %d of action %d of test %d)\n",
                                from_unit_state(data->state),
                                from_unit_state(exp_state),
                                a->current_state,
+                               test->current_action,
                                data->current_test);
                test->result = TEST_FAIL;
                next_test(data);
diff --git a/tests/activationd_acceptance_tests_dbus.c b/tests/activationd_acceptance_tests_dbus.c
deleted file mode 100644 (file)
index efc9743..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * This file is part of activationd.
- *
- * 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
deleted file mode 100644 (file)
index 0f43ddb..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * This file is part of activationd.
- *
- * 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_dbus_signal.c b/tests/activationd_acceptance_tests_dbus_signal.c
new file mode 100644 (file)
index 0000000..a041434
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * This file is part of activationd.
+ *
+ * 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_signal.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_signal_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_signal.h b/tests/activationd_acceptance_tests_dbus_signal.h
new file mode 100644 (file)
index 0000000..7274d2c
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * This file is part of activationd.
+ *
+ * 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_SIGNAL_H
+#define ACTIVATIOND_ACCEPTANCE_TESTS_DBUS_SIGNAL_H
+
+struct test_data;
+
+int dbus_signal_step(struct test_data *data);
+
+#endif /* ACTIVATIOND_ACCEPTANCE_TESTS_DBUS_SIGNAL_H */
diff --git a/tests/activationd_acceptance_tests_unit_control.c b/tests/activationd_acceptance_tests_unit_control.c
new file mode 100644 (file)
index 0000000..5cd7538
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * This file is part of activationd.
+ *
+ * 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_unit_control.h"
+#include "unit_control.h"
+
+#define ACTD_DBUS_API_INTERFACE_NAME "org.tizen.Activationd"
+#define ACTD_DBUS_API_SERVICE_NAME "org.tizen.Activationd"
+#define ACTD_DBUS_API_OBJECT_PATH "/org/tizen/activationd"
+
+static int unit_control_call(sd_bus *bus, const char *unit, int param_cnt, const struct vkc_value *params)
+{
+       assert(bus);
+       assert(unit);
+       assert(params);
+
+       _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
+       int ret;
+       char err[512];
+
+       if (param_cnt != 1) {
+               fprintf(stderr, "invalid param count (%d)\n", param_cnt);
+               ret = -EINVAL;
+               goto fail;
+       }
+
+       if (params[0].type != VKC_STRING) {
+               fprintf(stderr, "invalid param type\n");
+               ret = -EINVAL;
+               goto fail;
+       }
+
+       ret = sd_bus_message_new_method_call(
+                       bus,
+                       &m,
+                       ACTD_DBUS_API_SERVICE_NAME,
+                       ACTD_DBUS_API_OBJECT_PATH,
+                       ACTD_DBUS_API_INTERFACE_NAME,
+                       params[0].value.s);
+
+       if (ret < 0) {
+               if (strerror_r(-ret, err, sizeof err))
+                       fprintf(stderr, "failed to issue dbus api method call: %s", err);
+               goto fail;
+       }
+
+       ret = sd_bus_message_append(m, "s", unit);
+       if (ret < 0) {
+               fprintf(stderr, "failed to create dbus api call\n");
+               goto fail;
+       }
+
+
+       sd_bus_call(bus, m, 0, NULL, NULL);
+       /* return value of sd_bus_call is useless because it will always fail on negative tests,
+        * always return 0 instead */
+       return 0;
+fail:
+       return ret;
+}
+
+int unit_control_step(struct test_data *data)
+{
+       assert(data);
+       struct test_sequence *test = &data->tests[data->current_test];
+       return unit_control_call(data->bus, test->unit, test->actions[test->current_action].param_count, test->actions[test->current_action].params);
+}
diff --git a/tests/activationd_acceptance_tests_unit_control.h b/tests/activationd_acceptance_tests_unit_control.h
new file mode 100644 (file)
index 0000000..6ff38bd
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * This file is part of activationd.
+ *
+ * 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_API_H
+#define ACTIVATIOND_ACCEPTANCE_TESTS_DBUS_API_H
+
+struct test_data;
+
+int unit_control_step(struct test_data *data);
+
+#endif /* ACTIVATIOND_ACCEPTANCE_TESTS_DBUS_API_H */