Update of acceptation tests 35/287235/3 accepted/tizen/unified/20230210.160929
authorArkadiusz Nowak <a.nowak3@samsung.com>
Tue, 24 Jan 2023 14:55:47 +0000 (15:55 +0100)
committerArkadiusz Nowak <a.nowak3@samsung.com>
Tue, 31 Jan 2023 11:46:26 +0000 (12:46 +0100)
Rewritten unit tests.
Change state machine in tests for proper dbus signal catching.
Additional stop test services in script
to ensure that anything still are running.
Named field initializers covered by macros in acceptance checker.
Additional functions that sets params and states array
length variable (state_count, param_count).
Macros for expected states and params array definitions (_with_params, _with_expected_states).
Named field initializers covered by macros in acceptance checker.
Change-Id: Ia4ee2a4b638bb7bb6451803218616b7df45b876d

Makefile.am
modules.conf.d/dbus_listener.conf.d/99-acceptance-test.conf
packaging/activationd.spec
tests/activationd-acceptance-tests.h [deleted file]
tests/activationd_acceptance_checker.c
tests/activationd_acceptance_test
tests/activationd_acceptance_tests.c
tests/activationd_acceptance_tests.h
tests/unit_tests.c
tests/unit_tests.h [new file with mode: 0644]

index 6bc5d2e32fc011bcdc2a3cb943a270b4bb81e987..a114e4647d58f89444a1ac5f5703056888905955 100644 (file)
@@ -236,9 +236,6 @@ bin_PROGRAMS += activationd_acceptance_service
 activationd_acceptance_service_SOURCES = \
        tests/activationd_acceptance_service.c
 
-activationd_acceptance_service_CFLAGS = $(AM_CFLAGS)
-activationd_acceptance_service_LDFLAGS =
-
 bin_SCRIPTS = tests/activationd_acceptance_test
 
 unitdir = $(prefix)/lib/systemd/system
index 044bdb36b233622ce332d36ddbc801a7fc8d131f..a09a6572d318da8a6b63ad02c5616b9f85764df9 100644 (file)
@@ -8,7 +8,6 @@
                {"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"},
-
                {"id":"test_unicast_signal_001", "interface":"org.tizen.activationd.eventtest", "member":"Test001", "path_namespace":"/"},
                {"id":"test_unicast_signal_002", "interface":"org.tizen.activationd.eventtest", "member":"Test002", "path_namespace":"/"}
        ]
index 25dce2bb72dfeee813e23c3b9ce6c6eaceacbba0..2a36c360ba7c7414ef92766d478f7560eb9ef5b7 100644 (file)
@@ -29,7 +29,7 @@ Summary:    activationd test services
 Group:      System/Monitoring
 BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(glib-2.0)
-Requires:   actd
+Requires:   activationd
 
 %description -n activationd-test-services
 Services used to test activationd functionality
@@ -65,7 +65,6 @@ cp %{SOURCE1001} .
 %autogen
 %configure \
        --libdir=%{_libdir} \
-       --enable-test-services \
 %if %{with_activationd_glib_support}
        --enable-glib-mainloop \
 %endif
@@ -144,10 +143,10 @@ mkdir -p %{buildroot}/%{enabled_moduledir}
 %files -n activationd-test-services
 %license COPYING
 %manifest %{name}.manifest
-%{_bindir}/activationd_acceptance_service
+%{_bindir}/activationd_unit_tests
 %{_bindir}/activationd_acceptance_checker
 %{_bindir}/activationd_acceptance_test
-%{_bindir}/activationd_unit_tests
+%{_bindir}/activationd_acceptance_service
 %{_unitdir_user}/activationd-acceptance-test-s-p.service
 %{_unitdir}/activationd-acceptance-test-s-p.service
 %{_unitdir}/activationd-acceptance-test-s-n.service
diff --git a/tests/activationd-acceptance-tests.h b/tests/activationd-acceptance-tests.h
deleted file mode 100644 (file)
index 7a6daf7..0000000
+++ /dev/null
@@ -1,23 +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_H
-#define ACTIVATIOND_ACCEPTANCE_TESTS_H
-
-
-#endif /* ACTIVATIOND_ACCEPTANCE_TESTS_H */
index 91c2bc79897de5dd38d407fb958887578194da13..95438e1cae130ef042e297afcb236ea6657da192 100644 (file)
@@ -60,18 +60,18 @@ 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}
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "Start"}),
+                               _with_expected_states(INACTIVE,ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "Restart"}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "Stop"}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = "AcceptanceTestSP",
                .unit = SERVICE_NAME_S_P,
@@ -84,18 +84,18 @@ static struct test_sequence unit_control_acceptance_tests[] = {
        {
                .desc = "unit control negative test",
                .actions = {
-                       {{
-                               {.type = VKC_STRING, .value.s = "Start"}
-                        },
-                       {INACTIVE, UNKNOWN}, 1, 1, 0},
-                       {{
-                               {.type = VKC_STRING, .value.s = "Restart"}
-                        },
-                       {INACTIVE, INACTIVE}, 1, 2, 0},
-                       {{
-                               {.type = VKC_STRING, .value.s = "Stoo"}
-                        },
-                       {INACTIVE, UNKNOWN}, 1, 1, 0}
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "Start"}),
+                               _with_expected_states(INACTIVE,ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "Restart"}),
+                               _with_expected_states(INACTIVE, INACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "Stoo"}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = "AcceptanceTestIN",
                .unit = SERVICE_NAME_I_N,
@@ -108,18 +108,18 @@ static struct test_sequence unit_control_acceptance_tests[] = {
        {
                .desc = "unit control whitelist negative test",
                .actions = {
-                       {{
-                               {.type = VKC_STRING, .value.s = "Start"}
-                        },
-                       {INACTIVE, UNKNOWN}, 1, 1, 0},
-                       {{
-                               {.type = VKC_STRING, .value.s = "Restart"}
-                        },
-                       {INACTIVE, INACTIVE}, 1, 2, 0},
-                       {{
-                               {.type = VKC_STRING, .value.s = "Stop"}
-                        },
-                       {INACTIVE, UNKNOWN}, 1, 1, 0}
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "Start"}),
+                               _with_expected_states(INACTIVE,ACTIVE),
+                       },
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "Restart"}),
+                               _with_expected_states(INACTIVE, INACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "Stop"}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = "AcceptanceTestSN",
                .unit = SERVICE_NAME_S_N,
@@ -135,18 +135,18 @@ static struct test_sequence dbus_signal_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}
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "start"}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "restart"}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "stop"}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = "AcceptanceTestSP",
                .unit = SERVICE_NAME_S_P,
@@ -159,18 +159,18 @@ static struct test_sequence dbus_signal_acceptance_tests[] = {
        {
                .desc = "string (negative test)",
                .actions = {
-                       {{
-                               {.type = VKC_STRING, .value.s = "start"}
-                        },
-                       {ACTIVE, UNKNOWN}, 1, 1, 0},
-                       {{
-                               {.type = VKC_STRING, .value.s = "restart"}
-                        },
-                       {INACTIVE, ACTIVE}, 1, 2, 0},
-                       {{
-                               {.type = VKC_STRING, .value.s = "stop"}
-                        },
-                       {INACTIVE, UNKNOWN}, 1, 1, 0}
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "start"}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "restart"}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "stop"}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = "AcceptanceTestSN",
                .unit = SERVICE_NAME_S_N,
@@ -183,18 +183,18 @@ static struct test_sequence dbus_signal_acceptance_tests[] = {
        {
                .desc = "int (positive test)",
                .actions = {
-                       {{
-                               {.type = VKC_INT, .value.i = 1}
-                        },
-                       {ACTIVE, UNKNOWN}, 1, 1, 0},
-                       {{
-                               {.type = VKC_INT, .value.i = 2}
-                        },
-                       {INACTIVE, ACTIVE}, 1, 2, 0},
-                       {{
-                               {.type = VKC_INT, .value.i = 3}
-                        },
-                       {INACTIVE, UNKNOWN}, 1, 1, 0}
+                       {
+                               _with_params({.type = VKC_INT, .value.i = 1}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_INT, .value.i = 2}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_INT, .value.i = 3}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = "AcceptanceTestIP",
                .unit = SERVICE_NAME_I_P,
@@ -207,18 +207,18 @@ static struct test_sequence dbus_signal_acceptance_tests[] = {
        {
                .desc = "int (negative test)",
                .actions = {
-                       {{
-                               {.type = VKC_INT, .value.i = 1}
-                        },
-                       {ACTIVE, UNKNOWN}, 1, 1, 0},
-                       {{
-                               {.type = VKC_INT, .value.i = 2}
-                        },
-                       {INACTIVE, ACTIVE}, 1, 2, 0},
-                       {{
-                               {.type = VKC_INT, .value.i = 3}
-                        },
-                       {INACTIVE, UNKNOWN}, 1, 1, 0}
+                       {
+                               _with_params({.type = VKC_INT, .value.i = 1}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_INT, .value.i = 2}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_INT, .value.i = 3}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = "AcceptanceTestIN",
                .unit = SERVICE_NAME_I_N,
@@ -231,18 +231,18 @@ static struct test_sequence dbus_signal_acceptance_tests[] = {
        {
                .desc = "double (positive test)",
                .actions = {
-                       {{
-                               {.type = VKC_DOUBLE, .value.d = 1.0}
-                        },
-                       {ACTIVE, UNKNOWN}, 1, 1, 0},
-                       {{
-                               {.type = VKC_DOUBLE, .value.d = 2.0}
-                        },
-                       {INACTIVE, ACTIVE}, 1, 2, 0},
-                       {{
-                               {.type = VKC_DOUBLE, .value.d = 3.0}
-                        },
-                       {INACTIVE, UNKNOWN}, 1, 1, 0}
+                       {
+                               _with_params({.type = VKC_DOUBLE, .value.d = 1.0}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_DOUBLE, .value.d = 2.0}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_DOUBLE, .value.d = 3.0}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = "AcceptanceTestDP",
                .unit = SERVICE_NAME_D_P,
@@ -255,18 +255,18 @@ static struct test_sequence dbus_signal_acceptance_tests[] = {
        {
                .desc = "double (negative test)",
                .actions = {
-                       {{
-                               {.type = VKC_DOUBLE, .value.d = 1.0}
-                        },
-                       {ACTIVE, UNKNOWN}, 1, 1, 0},
-                       {{
-                               {.type = VKC_DOUBLE, .value.d = 2.0}
-                        },
-                       {INACTIVE, ACTIVE}, 1, 2, 0},
-                       {{
-                               {.type = VKC_DOUBLE, .value.d = 3.0}
-                        },
-                       {INACTIVE, UNKNOWN}, 1, 1, 0}
+                       {
+                               _with_params({.type = VKC_DOUBLE, .value.d = 1.0}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_DOUBLE, .value.d = 2.0}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_DOUBLE, .value.d = 3.0}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = "AcceptanceTestDN",
                .unit = SERVICE_NAME_D_N,
@@ -279,21 +279,24 @@ static struct test_sequence dbus_signal_acceptance_tests[] = {
        {
                .desc = "bool (positive test)",
                .actions = {
-                       {{
-                               {.type = VKC_BOOL, .value.b = true},
-                               {.type = VKC_BOOL, .value.b = true}
-                        },
-                       {ACTIVE, UNKNOWN}, 2, 1, 0},
-                       {{
-                               {.type = VKC_BOOL, .value.b = true},
-                               {.type = VKC_BOOL, .value.b = false}
-                        },
-                       {INACTIVE, ACTIVE}, 2, 2, 0},
-                       {{
-                               {.type = VKC_BOOL, .value.b = false},
-                               {.type = VKC_BOOL, .value.b = false}
-                        },
-                       {INACTIVE, UNKNOWN}, 2, 1, 0}
+                       {
+                               _with_params(
+                                       {.type = VKC_BOOL, .value.b = true},
+                                       {.type = VKC_BOOL, .value.b = true}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params(
+                                       {.type = VKC_BOOL, .value.b = true},
+                                       {.type = VKC_BOOL, .value.b = false}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params(
+                                       {.type = VKC_BOOL, .value.b = false},
+                                       {.type = VKC_BOOL, .value.b = false}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = "AcceptanceTestBP",
                .unit = SERVICE_NAME_B_P,
@@ -306,21 +309,24 @@ static struct test_sequence dbus_signal_acceptance_tests[] = {
        {
                .desc = "bool (negative test)",
                .actions = {
-                       {{
-                               {.type = VKC_BOOL, .value.b = true},
-                               {.type = VKC_BOOL, .value.b = true}
-                        },
-                       {ACTIVE, UNKNOWN}, 2, 1, 0},
-                       {{
-                               {.type = VKC_BOOL, .value.b = true},
-                               {.type = VKC_BOOL, .value.b = false}
-                        },
-                       {INACTIVE, ACTIVE}, 2, 2, 0},
-                       {{
-                               {.type = VKC_BOOL, .value.b = false},
-                               {.type = VKC_BOOL, .value.b = false}
-                        },
-                       {INACTIVE, UNKNOWN}, 2, 1, 0}
+                       {
+                               _with_params(
+                                       {.type = VKC_BOOL, .value.b = true},
+                                       {.type = VKC_BOOL, .value.b = true}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params(
+                                       {.type = VKC_BOOL, .value.b = true},
+                                       {.type = VKC_BOOL, .value.b = false}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params(
+                                       {.type = VKC_BOOL, .value.b = false},
+                                       {.type = VKC_BOOL, .value.b = false}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = "AcceptanceTestBN",
                .unit = SERVICE_NAME_B_N,
@@ -336,9 +342,18 @@ static struct test_sequence vconf_acceptance_tests[] = {
        {
                .desc = "string (positive test)",
                .actions = {
-                       {{{.type = VKC_STRING, .value.s = "START"}}, {ACTIVE, UNKNOWN}, 1, 1, 0},
-                       {{{.type = VKC_STRING, .value.s = "RELOAD"}}, {INACTIVE, ACTIVE}, 1, 2, 0},
-                       {{{.type = VKC_STRING, .value.s = "STOP"}}, {INACTIVE, UNKNOWN}, 1, 1, 0}
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "START"}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "RELOAD"}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "STOP"}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = VCONF_KEY_S_P,
                .unit = SERVICE_NAME_S_P,
@@ -348,12 +363,20 @@ static struct test_sequence vconf_acceptance_tests[] = {
                .current_action = 0,
                .step = vconf_step
        },
-       {
-               .desc = "string (negative test)",
+       {       .desc = "string (negative test)",
                .actions = {
-                       {{{.type = VKC_STRING, .value.s = "START"}}, {ACTIVE, UNKNOWN}, 1, 1, 0},
-                       {{{.type = VKC_STRING, .value.s = "RELOAD"}}, {INACTIVE, ACTIVE}, 1, 2, 0},
-                       {{{.type = VKC_STRING, .value.s = "STOP"}}, {INACTIVE, UNKNOWN}, 1, 1, 0}
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "START"}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "RELOAD"}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_STRING, .value.s = "STOP"}),
+                               _with_expected_states(INACTIVE, INACTIVE)
+                       }
                },
                .id = VCONF_KEY_S_N,
                .unit = SERVICE_NAME_S_N,
@@ -366,9 +389,18 @@ static struct test_sequence vconf_acceptance_tests[] = {
        {
                .desc = "int (positive test)",
                .actions = {
-                       {{{.type = VKC_INT, .value.i = 1}}, {ACTIVE, UNKNOWN}, 1, 1, 0},
-                       {{{.type = VKC_INT, .value.i = 2}}, {INACTIVE, ACTIVE}, 1, 2, 0},
-                       {{{.type = VKC_INT, .value.i = 3}}, {INACTIVE, UNKNOWN}, 1, 1, 0}
+                       {
+                               _with_params({.type = VKC_INT, .value.i = 1}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_INT, .value.i = 2}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_INT, .value.i = 3}),
+                               _with_expected_states(INACTIVE),
+                       }
                },
                .id = VCONF_KEY_I_P,
                .unit = SERVICE_NAME_I_P,
@@ -381,9 +413,18 @@ static struct test_sequence vconf_acceptance_tests[] = {
        {
                .desc = "int (negative test)",
                .actions = {
-                       {{{.type = VKC_INT, .value.i = 1}}, {ACTIVE, UNKNOWN}, 1, 1, 0},
-                       {{{.type = VKC_INT, .value.i = 2}}, {INACTIVE, ACTIVE}, 1, 2, 0},
-                       {{{.type = VKC_INT, .value.i = 3}}, {INACTIVE, UNKNOWN}, 1, 1, 0}
+                       {
+                               _with_params({.type = VKC_INT, .value.i = 1}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_INT, .value.i = 2}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_INT, .value.i = 3}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = VCONF_KEY_I_N,
                .unit = SERVICE_NAME_I_N,
@@ -396,9 +437,18 @@ static struct test_sequence vconf_acceptance_tests[] = {
        {
                .desc = "double (positive test)",
                .actions = {
-                       {{{.type = VKC_DOUBLE, .value.d = 1.1}}, {ACTIVE, UNKNOWN}, 1, 1, 0},
-                       {{{.type = VKC_DOUBLE, .value.d = 1.2}}, {INACTIVE, ACTIVE}, 1, 2, 0},
-                       {{{.type = VKC_DOUBLE, .value.d = 1.3}}, {INACTIVE, UNKNOWN}, 1, 1, 0}
+                       {
+                               _with_params({.type = VKC_DOUBLE, .value.d = 1.1}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_DOUBLE, .value.d = 1.2}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_DOUBLE, .value.d = 1.3}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = VCONF_KEY_D_P,
                .unit = SERVICE_NAME_D_P,
@@ -411,9 +461,18 @@ static struct test_sequence vconf_acceptance_tests[] = {
        {
                .desc = "double (negative test)",
                .actions = {
-                       {{{.type = VKC_DOUBLE, .value.d = 1.1}}, {ACTIVE, UNKNOWN}, 1, 1, 0},
-                       {{{.type = VKC_DOUBLE, .value.d = 1.2}}, {INACTIVE, ACTIVE}, 1, 2, 0},
-                       {{{.type = VKC_DOUBLE, .value.d = 1.3}}, {INACTIVE, UNKNOWN}, 1, 1, 0}
+                       {
+                               _with_params({.type = VKC_DOUBLE, .value.d = 1.1}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_DOUBLE, .value.d = 1.2}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_DOUBLE, .value.d = 1.3}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = VCONF_KEY_D_N,
                .unit = SERVICE_NAME_D_N,
@@ -426,9 +485,18 @@ static struct test_sequence vconf_acceptance_tests[] = {
        {
                .desc = "bool (positive test)",
                .actions = {
-                       {{{.type = VKC_BOOL, .value.b = true}}, {ACTIVE, UNKNOWN}, 1, 1, 0},
-                       {{{.type = VKC_BOOL, .value.b = true}}, {INACTIVE, ACTIVE}, 1, 2, 0},
-                       {{{.type = VKC_BOOL, .value.b = false}}, {INACTIVE, UNKNOWN}, 1, 1, 0}
+                       {
+                               _with_params({.type = VKC_BOOL, .value.b = true}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_BOOL, .value.b = true}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_BOOL, .value.b = false}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = VCONF_KEY_B_P,
                .unit = SERVICE_NAME_B_P,
@@ -441,9 +509,18 @@ static struct test_sequence vconf_acceptance_tests[] = {
        {
                .desc = "bool (negative test)",
                .actions = {
-                       {{{.type = VKC_BOOL, .value.b = true}}, {ACTIVE, UNKNOWN}, 1, 1, 0},
-                       {{{.type = VKC_BOOL, .value.b = true}}, {INACTIVE, ACTIVE}, 1, 2, 0},
-                       {{{.type = VKC_BOOL, .value.b = false}}, {INACTIVE, UNKNOWN}, 1, 1, 0}
+                       {
+                               _with_params({.type = VKC_BOOL, .value.b = true}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_BOOL, .value.b = true}),
+                               _with_expected_states(INACTIVE, ACTIVE)
+                       },
+                       {
+                               _with_params({.type = VKC_BOOL, .value.b = false}),
+                               _with_expected_states(INACTIVE)
+                       }
                },
                .id = VCONF_KEY_B_N,
                .unit = SERVICE_NAME_B_N,
@@ -626,7 +703,6 @@ static int parse_cmdline(int argc, char *argv[], int *type)
        return 0;
 }
 
-
 int main(int argc, char *argv[])
 {
        struct test_data data = {
@@ -665,6 +741,8 @@ int main(int argc, char *argv[])
                goto fail;
        }
 
+       setup_states_and_params_counters(&data);
+
        g_err = NULL;
        data.bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &g_err);
        if (g_err) {
index 1327ffcbc4ba57b1edcee2f0f62e93696881e131..5510822ef4457134289db54d05ed3e70e0e07ffd 100755 (executable)
@@ -33,8 +33,10 @@ vconftool -f set -t bool file/activationd/acceptance_bool_n 0
 # assumes there's no epcd service running
 actd > /dev/null 2>&1 &
 ACTD_PID=$!
-sleep 2
+sleep 4
 
+stop_services
+echo ""
 echo "Testing vconf:"
 /usr/bin/activationd_acceptance_checker -t vconf 2> /dev/null
 if [ "$?" -eq "0" ]; then
@@ -62,3 +64,5 @@ if [ "$?" -eq "0" ]; then
 else
        echo "some tests failed"
 fi
+
+stop_services
index a3f5279a7ff6117de688891d0aeef189c5ab1433..7b8f12185ebdb837b1ee2ba8c8db824d13367d69 100644 (file)
@@ -45,13 +45,12 @@ static enum unit_state to_unit_state(const char *state)
                return UNKNOWN;
 }
 
-static void next_test(struct test_data *data)
+static int next_test(struct test_data *data)
 {
        data->state = UNKNOWN;
        data->prev_state = UNKNOWN;
        data->current_test++;
-
-       test_step(data);
+       return test_step(data);
 }
 
 static void stop_test_step_timeout(struct test_data *data)
@@ -67,8 +66,7 @@ static gboolean on_test_step_timeout(gpointer 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;
+       return next_test(data);
 }
 
 static int start_test_step_timeout(struct test_data *data)
@@ -83,8 +81,20 @@ static int start_test_step_timeout(struct test_data *data)
 
 static int check_test_result(struct test_data *data)
 {
+       if (data->current_test >= data->tests_count) {
+               return -EINVAL;
+       }
+
        struct test_sequence *test = &data->tests[data->current_test];
        struct action *a = &test->actions[test->current_action];
+
+       if (a->current_state >= a->state_count) {
+               fprintf(stderr, "Test error: too many states for action %d of test %d\n",
+                               test->current_action,
+                               data->current_test);
+               test->result = TEST_FAIL;
+               return next_test(data);
+       }
        enum unit_state exp_state = a->expected_states[a->current_state];
 
        if (data->state != exp_state) {
@@ -95,14 +105,12 @@ static int check_test_result(struct test_data *data)
                                test->current_action,
                                data->current_test);
                test->result = TEST_FAIL;
-               next_test(data);
-               return -1;
+               return next_test(data);
        }
        a->current_state++;
-       if (a->current_state == a->state_count) {
+       if (a->current_state >= a->state_count) {
                test->current_action++;
-               if (test_step(data) < 0)
-                       return -1;
+               return test_step(data);
        }
        return 0;
 }
@@ -110,18 +118,17 @@ static int check_test_result(struct test_data *data)
 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 check_test_result(data);
        }
        return 0;
 }
 
-int test_step(struct test_data *data)
-{
+int test_step(struct test_data *data) {
+
        struct test_sequence *test;
 
        stop_test_step_timeout(data);
@@ -135,8 +142,7 @@ int test_step(struct test_data *data)
 
        if (test->current_action == ARRAY_SIZE(test->actions)) {
                test->result = TEST_SUCCESS;
-               next_test(data);
-               return 0;
+               return next_test(data);
        }
 
        if (!test->step || test->step(data) != 0)
@@ -166,16 +172,32 @@ void on_properties_changed(GDBusConnection *connection,
        gchar *key;
        struct test_data *data = (struct test_data*)user_data;
 
+       if (data == NULL) {
+               return;
+       }
+
+       if (parameters == NULL) {
+                       return;
+       }
+
        g_variant_iter_init (&iter, parameters);
 
        /* skip 's' - interface name */
        child = g_variant_iter_next_value (&iter);
-       g_variant_unref(child);
+       if (child != NULL) {
+               g_variant_unref(child);
+       } else {
+               return;
+       }
 
        /* next is 'a{sv}' where ActiveState is */
        child = g_variant_iter_next_value (&iter);
+       if (child == NULL) {
+               return;
+       }
 
        g_variant_iter_init (&iter1, child);
+
        while (g_variant_iter_loop (&iter1, "{sv}", &key, &variant)) {
                if (!g_strcmp0(key, "ActiveState")) {
                        if (g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) {
@@ -191,6 +213,34 @@ void on_properties_changed(GDBusConnection *connection,
                check_unit_state(data, value);
                free(value);
        }
+}
+
+int take_states_number(enum unit_state *states)
+{
+       int i = 0;
+       while (states[i] != UNKNOWN) {
+               i++;
+       }
+       return i;
+}
 
+int take_params_number(struct vkc_value *params)
+{
+       int i = 0;
+       while (params[i].type != VKC_NONE ) {
+               i++;
+       }
+       return i;
+}
+
+void setup_states_and_params_counters(struct test_data *data)
+{
+       for (int i = 0; i < data->tests_count; i++) {
+               for (int j = 0; j < MAX_ACTIONS; j++) {
+                       data->tests[i].actions[j].state_count = take_states_number(data->tests[i].actions[j].expected_states);
+                       data->tests[i].actions[j].current_state = 0;
+                       data->tests[i].actions[j].param_count = take_params_number(data->tests[i].actions[j].params);
+               }
+       }
 }
 
index a7666ab96244184022a612e3bfb6102bc39fd94e..4eecec382e0406033753b15769ea900b67dffbfb 100644 (file)
@@ -38,17 +38,35 @@ enum {
        TEST_UNKNOWN
 };
 
+#define MAX_ACTIONS 3
+
 struct action {
-       struct vkc_value params[3];
-       enum unit_state expected_states[2];
+       struct vkc_value *params;
+       enum unit_state *expected_states;
        int param_count;
        int state_count;
        int current_state;
 };
 
+#define VKC_NONE 100 // used only for testing
+
+#define _with_params(...) \
+       .params = (struct vkc_value[]){ __VA_ARGS__, {.type = VKC_NONE}}, \
+       .param_count = 0
+
+int take_params_number(struct vkc_value *params);
+
+#define _with_expected_states(...) \
+       .expected_states = (enum unit_state[]){ __VA_ARGS__, UNKNOWN}, \
+       .state_count = 0, .current_state = 0
+
+int take_states_number(enum unit_state *states);
+
+void setup_states_and_params_counters(struct test_data *data);
+
 struct test_sequence {
        const char *desc;
-       struct action actions[3];
+       struct action actions[MAX_ACTIONS];
        const char *id; /* vconf key or dbus method */
        int current_action;
        int expected_result;
@@ -59,7 +77,6 @@ struct test_sequence {
        int (*step)(struct test_data *test);
 };
 
-
 struct test_data {
        GDBusConnection *bus;
        GMainLoop *loop;
index f6a9e3222209f222ba31d44c7f8f3cd516837ab3..f3f5f34b08d895c1ac72449dc867307c3c48e0da 100644 (file)
@@ -6,32 +6,8 @@
 #include <glib.h>
 #include <gio/gio.h>
 
-#define TEST_SERVICE "activationd-acceptance-test-s-p.service"
-
-enum unit_state {
-       UNIT_OFF,
-       UNIT_ON,
-       UNIT_UNKNOWN
-};
-
-struct context {
-       GDBusConnection *bus;
-       GBusType bus_type;
-       int unit_state[2];
-       int unit_state_pos;
-       int unit_state_cnt;
-       guint subscription_id;
-       GMainLoop *loop;
-       guint func_timeout, test_timeout;
-       int result;
-       int (*func_sync)(BusType bus_type, const char *unit, int timeout);
-       int (*func_async)(BusType bus_type, const char *unit, actd_unit_cb cb, void *user_data, int timeout);
-};
-
-struct unit_test {
-       const char *id;
-       int (*func)(struct context *);
-};
+#include "unit_tests.h"
+
 
 static int translate_unit_state(const gchar *value)
 {
@@ -101,43 +77,45 @@ static GDBusConnection *get_bus(GBusType bus_type)
        return bus;
 }
 
-static guint signal_subscribe(struct context *ctx)
-{
-       assert(ctx);
-       assert(ctx->bus);
-
-       GVariant *msg = NULL;
-       char *path = NULL;
-       GError *error = NULL;
+static GVariant *conn_call_sync (GDBusConnection *bus, const gchar *method, GVariant *parameters, GError *error) {
 
-       /*load unit/get path */
-       msg = g_dbus_connection_call_sync(ctx->bus,
+       return g_dbus_connection_call_sync(bus,
                        "org.freedesktop.systemd1",
                        "/org/freedesktop/systemd1",
                        "org.freedesktop.systemd1.Manager",
-                       "LoadUnit",
-                       g_variant_new("(s)", TEST_SERVICE),
+                       method,
+                       parameters,
                        NULL,
                        G_DBUS_CALL_FLAGS_NONE,
                        -1,
                        NULL,
                        &error);
+}
+
+static guint signal_subscribe(GDBusConnection *bus, struct context *ctx) {
+
+       GVariant *msg = NULL;
+       GError *error = NULL;
+
+       /*load unit/get path */
+       msg = conn_call_sync(bus, "LoadUnit", g_variant_new("(s)", TEST_SERVICE), error);
+
        if (!msg) {
                if (error) {
                        printf("LoadUnit method call error: %s\n", error->message);
                        g_error_free(error);
                } else {
                        printf("LoadUnit method call error\n");
-               }
-
-               goto cleanup;
+       }
+               return 0;
        }
 
+       char *path = NULL;
        g_variant_get(msg, "(o)", &path);
 
        /* PropertiesChanged signal subscribe */
-       ctx->subscription_id = g_dbus_connection_signal_subscribe(
-                               ctx->bus,
+       guint subscription_id = g_dbus_connection_signal_subscribe(
+                               bus,
                                NULL,
                                "org.freedesktop.DBus.Properties",
                                "PropertiesChanged",
@@ -148,14 +126,14 @@ static guint signal_subscribe(struct context *ctx)
                                (gpointer)ctx,
                                NULL
                        );
-       if (ctx->subscription_id == 0) {
+       if (subscription_id == 0) {
                printf("signal subscription error\n");
                goto cleanup;
        }
 
 cleanup:
        g_free(path);
-       return ctx->subscription_id;
+       return subscription_id;
 }
 
 static gboolean test_timeout(gpointer user_data)
@@ -170,7 +148,10 @@ static gboolean test_timeout(gpointer user_data)
 static gboolean func_start(gpointer user_data)
 {
        struct context *ctx = (struct context *)user_data;
-       int ret = ctx->func_sync(ctx->bus_type, TEST_SERVICE, UNIT_CONTROL_TIMEOUT_DEFAULT);
+
+       struct test_sync_action_data_t *sync_action_data = (struct test_sync_action_data_t *)ctx->test_exec_action_data;
+
+       int ret = sync_action_data->actd_action_unit( ctx->bus_type, TEST_SERVICE, UNIT_CONTROL_TIMEOUT_DEFAULT);
 
        if (ret == UNIT_CONTROL_ERROR || ret == UNIT_CONTROL_TIMEOUT) {
                ctx->result = ret;
@@ -202,43 +183,6 @@ finish_run_sync_test:
        return ctx->result;
 }
 
-static int test_unit_start(struct context *ctx)
-{
-       assert(ctx);
-
-       ctx->unit_state[0] = UNIT_ON;
-       ctx->unit_state_pos = 0;
-       ctx->unit_state_cnt = 1;
-       ctx->result = UNIT_CONTROL_OK;
-       ctx->func_sync = actd_start_unit;
-       return test_sync_action(ctx);
-}
-
-static int test_unit_stop(struct context *ctx)
-{
-       assert(ctx);
-
-       ctx->unit_state[0] = UNIT_OFF;
-       ctx->unit_state_pos = 0;
-       ctx->unit_state_cnt = 1;
-       ctx->result = UNIT_CONTROL_OK;
-       ctx->func_sync = actd_stop_unit;
-       return test_sync_action(ctx);
-}
-
-static int test_unit_restart(struct context *ctx)
-{
-       assert(ctx);
-
-       ctx->unit_state[0] = UNIT_OFF;
-       ctx->unit_state[1] = UNIT_ON;
-       ctx->unit_state_pos = 0;
-       ctx->unit_state_cnt = 2;
-       ctx->result = UNIT_CONTROL_OK;
-       ctx->func_sync = actd_restart_unit;
-       return test_sync_action(ctx);
-}
-
 static void handler(int status, void *user_data)
 {
        struct context *ctx = (struct context *)user_data;
@@ -250,13 +194,14 @@ static void handler(int status, void *user_data)
 static int test_async_action(struct context *ctx)
 {
        assert(ctx);
-       assert(ctx->func_async);
        int ret;
 
        ctx->loop = g_main_loop_new(NULL, FALSE);
        ctx->test_timeout = g_timeout_add_seconds(10, test_timeout, ctx);
 
-       ret = ctx->func_async(ctx->bus_type, TEST_SERVICE, handler, ctx, UNIT_CONTROL_TIMEOUT_DEFAULT);
+       struct test_async_action_data_t *async_action_data = (struct test_async_action_data_t *)ctx->test_exec_action_data;
+
+       ret = async_action_data->actd_action_unit(ctx->bus_type, TEST_SERVICE, handler, ctx, UNIT_CONTROL_TIMEOUT_DEFAULT);
        if (ret == UNIT_CONTROL_ERROR)
                return ret;
 
@@ -266,101 +211,159 @@ static int test_async_action(struct context *ctx)
        return ctx->result;
 }
 
-static int test_unit_start_async(struct context *ctx)
+static int run_tests(struct test_sequence tests)
 {
-       assert(ctx);
+       while (tests.actions->desc != NULL) {
 
-       ctx->unit_state[0] = UNIT_ON;
-       ctx->unit_state_pos = 0;
-       ctx->unit_state_cnt = 1;
-       ctx->result = UNIT_CONTROL_OK;
-       ctx->func_async = actd_start_unit_async;
-       return test_async_action(ctx);
-}
+               GDBusConnection *bus_conn = get_bus(tests.actions->ctx.bus_type);
 
-static int test_unit_stop_async(struct context *ctx)
-{
-       ctx->unit_state[0] = UNIT_OFF;
-       ctx->unit_state_pos = 0;
-       ctx->unit_state_cnt = 1;
-       ctx->result = UNIT_CONTROL_OK;
-       ctx->func_async = actd_stop_unit_async;
-       return test_async_action(ctx);
-}
+               printf(_Run " Test: %s\n", tests.actions->desc);
 
-static int test_unit_restart_async(struct context *ctx)
-{
-       ctx->unit_state[0] = UNIT_OFF;
-       ctx->unit_state[1] = UNIT_ON;
-       ctx->unit_state_pos = 0;
-       ctx->unit_state_cnt = 2;
-       ctx->result = UNIT_CONTROL_OK;
-       ctx->func_async = actd_restart_unit_async;
-       return test_async_action(ctx);
-}
+               if (!bus_conn) {
+                       if (tests.actions->ctx.expected_result == UNIT_CONTROL_OK) {
+                               printf(_Fail " => unable to open dbus connection\n");
+                       } else {
+                               printf(_Pass " => expected error: unable to open dbus connection\n");
+                       }
+                       printf(_Finish "\n");
 
-static const char *retval2string(int r)
-{
-       switch (r) {
-       case UNIT_CONTROL_REQUEST_SENT:
-               return "request sent";
-               break;
-       case UNIT_CONTROL_TIMEOUT:
-               return "timeout";
-               break;
-       case UNIT_CONTROL_OK:
-               return "ok";
-               break;
-       default:
-               return "error";
-               break;
-       }
-}
+                       tests.actions++;
+                       continue;
+               }
 
-static void test(GBusType bus_type, struct unit_test tests[])
-{
-       assert(bus_type == G_BUS_TYPE_SYSTEM || bus_type == G_BUS_TYPE_SESSION);
-       int ret;
-       struct context ctx = {};
+               guint subscription_id = signal_subscribe(bus_conn, &tests.actions->ctx);
+               if (subscription_id == 0) {
+                       printf(_Fail " => unable to subscribe to dbus signal");
+                       printf(_Finish "\n");
 
-       ctx.bus = get_bus(bus_type);
-       if (!ctx.bus)
-               exit(EXIT_FAILURE);
+                       tests.actions++;
+                       continue;
+               }
 
-       ctx.bus_type = bus_type;
+               int i = 0;
+               while(tests.actions->ctx.unit_state[i] != UNIT_NO_STATE) {
+                       i++;
+               }
+               tests.actions->ctx.unit_state_cnt = i;
+
+               int ret = tests.actions->exec_test_func(&tests.actions->ctx);
+               if (ret == tests.actions->ctx.expected_result) {
+                       printf(_Pass " => Test: %s\n", tests.actions->desc);
+               } else {
+                       printf(_Fail " => Test: %s", tests.actions->desc);
+               }
 
-       if (signal_subscribe(&ctx) == 0)
-               exit(EXIT_FAILURE);
+               printf(_Finish "\n");
 
-       for (int i = 0; tests[i].id; ++i) {
-               ret = tests[i].func(&ctx);
-               if (ret != UNIT_CONTROL_OK)
-                       printf("[FAILED] %s (%s)\n", tests[i].id, retval2string(ret));
-               else
-                       printf("[OK] %s\n", tests[i].id);
 
-               usleep(100000);
+               g_dbus_connection_signal_unsubscribe (bus_conn, subscription_id);
+               tests.actions++;
        }
-       return;
+       return 0;
 }
 
 int main(int argc, char *argv[])
 {
-       struct unit_test tests[] = {
-               {"UnitStart", test_unit_start},
-               {"UnitRestart", test_unit_restart},
-               {"UnitStop", test_unit_stop},
-               {"UnitStartAsync", test_unit_start_async},
-               {"UnitRestartAsync", test_unit_restart_async},
-               {"UnitStopAsync", test_unit_stop_async},
-               {NULL, NULL},
-       };
-
-       printf("bus type SYSTEM tests:\n");
-       test(G_BUS_TYPE_SYSTEM, tests);
-
-       printf("bus type SESSION tests:\n");
-       test(G_BUS_TYPE_SESSION, tests);
-
-       return EXIT_SUCCESS;
+       // beware of temporary lifetime of array items
+       return run_tests( _test_sequence(
+               .actions = test_actions(
+                       {       .desc = "UnitStart Sync",
+                               _sync_ctx (
+                                       .bus_type = G_BUS_TYPE_SYSTEM,
+                                       _with_states(UNIT_ON),
+                                       _with_sync_action ( actd_start_unit ),
+                                       .expected_result = UNIT_CONTROL_OK
+                               ),
+                       },
+                       {       .desc = "UnitRestart Sync",
+                               _sync_ctx (
+                                       .bus_type = G_BUS_TYPE_SYSTEM,
+                                       _with_states(UNIT_OFF, UNIT_ON),
+                                       _with_sync_action ( actd_restart_unit ),
+                                       .expected_result = UNIT_CONTROL_OK
+                               ),
+                       },
+                       {       .desc = "UnitStop Sync",
+                               _sync_ctx (
+                                       .bus_type = G_BUS_TYPE_SYSTEM,
+                                       _with_states(UNIT_OFF),
+                                       _with_sync_action ( actd_stop_unit ),
+                                       .expected_result = UNIT_CONTROL_OK
+                               ),
+                       },
+
+                       {       .desc = "UnitStart Async",
+                               _async_ctx (
+                                       .bus_type = G_BUS_TYPE_SYSTEM,
+                                       _with_states(UNIT_ON),
+                                       _with_async_action ( actd_start_unit_async ),
+                                       .expected_result = UNIT_CONTROL_OK
+                               ),
+                       },
+                       {       .desc = "UnitRestart Async",
+                               _async_ctx (
+                                       .bus_type = G_BUS_TYPE_SYSTEM,
+                                       _with_states(UNIT_OFF, UNIT_ON),
+                                       _with_async_action ( actd_restart_unit_async ),
+                                       .expected_result = UNIT_CONTROL_OK
+                               ),
+                       },
+                       {       .desc = "UnitStop Async",
+                               _async_ctx (
+                                       .bus_type = G_BUS_TYPE_SYSTEM,
+                                       _with_states(UNIT_OFF),
+                                       _with_async_action ( actd_stop_unit_async ),
+                                       .expected_result = UNIT_CONTROL_OK
+                               ),
+                       },
+                       {       .desc = "UnitStart Sync Negative with wrong bus type (SESSION)",
+                               _sync_ctx (
+                                       .bus_type = G_BUS_TYPE_SESSION,
+                                       _with_states(UNIT_ON),
+                                       _with_sync_action ( actd_start_unit ),
+                                       .expected_result = UNIT_CONTROL_ERROR
+                               ),
+                       },
+                       {       .desc = "UnitRestart Sync Negative with wrong bus type (SESSION)",
+                               _sync_ctx (
+                                       .bus_type = G_BUS_TYPE_SESSION,
+                                       _with_states(UNIT_OFF, UNIT_ON),
+                                       _with_sync_action ( actd_restart_unit ),
+                                       .expected_result = UNIT_CONTROL_ERROR
+                               ),
+                       },
+                       {       .desc = "UnitStop Sync Negative with wrong bus type (SESSION)",
+                               _sync_ctx (
+                                       .bus_type = G_BUS_TYPE_SESSION,
+                                       _with_states(UNIT_OFF),
+                                       _with_sync_action ( actd_stop_unit ),
+                                       .expected_result = UNIT_CONTROL_ERROR
+                               ),
+                       },
+                       {       .desc = "UnitStart Async Negative with wrong bus type (SESSION)",
+                               _async_ctx (
+                                       .bus_type = G_BUS_TYPE_SESSION,
+                                       _with_states(UNIT_ON),
+                                       _with_async_action ( actd_start_unit_async ),
+                                       .expected_result = UNIT_CONTROL_ERROR
+                               ),
+                       },
+                       {       .desc = "UnitRestart Async Negative with wrong bus type (SESSION)",
+                               _async_ctx (
+                                       .bus_type = G_BUS_TYPE_SESSION,
+                                       _with_states(UNIT_OFF, UNIT_ON),
+                                       _with_async_action ( actd_restart_unit_async ),
+                                       .expected_result = UNIT_CONTROL_ERROR
+                               ),
+                       },
+                       {       .desc = "UnitStop Async Negative with wrong bus type (SESSION)",
+                               _async_ctx (
+                                       .bus_type = G_BUS_TYPE_SESSION,
+                                       _with_states(UNIT_OFF),
+                                       _with_async_action ( actd_stop_unit_async ),
+                                       .expected_result = UNIT_CONTROL_ERROR
+                               ),
+                       }
+               )
+       ));
 }
diff --git a/tests/unit_tests.h b/tests/unit_tests.h
new file mode 100644 (file)
index 0000000..37677db
--- /dev/null
@@ -0,0 +1,104 @@
+#ifndef UNIT_TESTS_H
+#define UNIT_TESTS_H
+#include "unit_control.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <unistd.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#define _Red     "\033[0;31m"
+#define _Green   "\033[0;32m"
+#define _Yellow  "\033[0;33m"
+#define _Blue    "\033[0;34m"
+#define _Default "\033[0m"
+
+#define _Run    _Yellow "[RUN      ]" _Default
+#define _Pass   _Green  "[  PASSED ]" _Default
+#define _Fail   _Red    "[  FAILED ]" _Default
+#define _Finish _Blue   "[FINISH   ]" _Default
+
+#define TEST_SERVICE "activationd-acceptance-test-s-p.service"
+
+#define tests_array(...) \
+       static struct test_action test_def[] = { __VA_ARGS__,  {.desc = NULL}}
+
+enum unit_state {
+       UNIT_OFF,
+       UNIT_ON,
+       UNIT_UNKNOWN,
+       UNIT_NO_STATE
+};
+
+struct context {
+       BusType bus_type;
+       int *unit_state;
+       int unit_state_pos;
+       int unit_state_cnt;
+       int result;
+       int expected_result;
+       guint func_timeout, test_timeout;
+       GMainLoop *loop;
+       void *test_exec_action_data;
+};
+
+#define _with_states(...) \
+       .unit_state = (int[]){ __VA_ARGS__, UNIT_NO_STATE} \
+
+#define _expected_result(val) .expected_result = val \
+       .result = UNIT_CONTROL_ERROR
+
+#define _ctx(...)  \
+       .ctx = (struct context) { __VA_ARGS__ , .result = UNIT_CONTROL_ERROR, .loop = NULL }
+
+#define _sync_ctx(...)  \
+       .ctx = (struct context) { __VA_ARGS__ , \
+       .unit_state_pos = 0, \
+       .result = UNIT_CONTROL_ERROR, \
+       .loop = NULL \
+       }, \
+       .exec_test_func = test_sync_action
+
+struct test_sync_action_data_t {
+       int (* actd_action_unit)(BusType bus_type, const char *unit, int timeout_ms);
+};
+
+#define _test_sync_action_data(...) \
+       (void *)(struct test_sync_action_data_t[]) {{ __VA_ARGS__}, {NULL}}
+
+#define _with_sync_action(_sync_action) \
+       .test_exec_action_data = (void *)(struct test_sync_action_data_t[]) {{ .actd_action_unit = _sync_action }, {NULL}}
+
+#define _async_ctx(...)  \
+       .ctx = (struct context) { __VA_ARGS__ , \
+       .unit_state_pos = 0, \
+       .result = UNIT_CONTROL_ERROR, \
+       .loop = NULL \
+       }, \
+       .exec_test_func = test_async_action
+
+struct test_async_action_data_t {
+       int (* actd_action_unit)(BusType bus_type, const char *unit, actd_unit_cb cb, void *user_data, int timeout_ms);
+};
+
+#define _with_async_action(_async_action) \
+       .test_exec_action_data = (void *)(struct test_async_action_data_t[]) {{ .actd_action_unit = _async_action }, {NULL}}
+
+struct test_sequence {
+       struct test_action *actions;
+};
+
+struct test_action {
+       const char *desc;
+       struct context ctx;
+       int (*exec_test_func)(struct context *ctx);
+};
+
+#define _test_sequence(...) \
+       (struct test_sequence) { __VA_ARGS__  }
+
+#define test_actions(...) \
+       (struct test_action[]) { __VA_ARGS__,  {.desc = NULL}}
+
+#endif /* UNIT_TESTS_H */