Add test services 40/154040/5
authorKonrad Kuchciak <k.kuchciak@samsung.com>
Tue, 3 Oct 2017 11:28:57 +0000 (13:28 +0200)
committerKonrad Kuchciak <k.kuchciak@samsung.com>
Thu, 12 Oct 2017 10:34:04 +0000 (12:34 +0200)
This replaces old test programs.
Naming in makefile.am and configure.ac according to unit tests, was also
adjusted to split those two test suites.

Change-Id: I1109e1ab155800e685ae1a5a51a1ff73a94b56e4
Signed-off-by: Konrad Kuchciak <k.kuchciak@samsung.com>
18 files changed:
Makefile.am
configure.ac
packaging/faultd.spec
tests/fail-always.sh [new file with mode: 0755]
tests/fail-only-once.sh [new file with mode: 0755]
tests/faultd-failed.service.conf [deleted file]
tests/faultd-failed.service.in [deleted file]
tests/faultd-leaker.service.conf [deleted file]
tests/faultd-leaker.service.in [deleted file]
tests/faultd-success.service.in [deleted file]
tests/services/faultd-failed-service-always-failed.service.in [new file with mode: 0644]
tests/services/faultd-failed-service-single-restart.service.in [new file with mode: 0644]
tests/services/faultd-failed-service-with-recovery.service.conf [new file with mode: 0644]
tests/services/faultd-failed-service-with-recovery.service.in [new file with mode: 0644]
tests/services/faultd-failed-vip-service.service.conf [new file with mode: 0644]
tests/services/faultd-failed-vip-service.service.in [new file with mode: 0644]
tests/services/faultd-recovery-service.service.in [new file with mode: 0644]
tests/services/faultd-res-leak.service.in [new file with mode: 0644]

index 81433d58e72682a4f178fae789f78917718411fb..bb9655bbba3cf21b52a8d69bb2be16781a1aac5a 100644 (file)
@@ -159,27 +159,35 @@ install-data-local:
        $(MKDIR_P) $(DESTDIR)$(sysconfdir)/faultd/enabled-modules
 
 
-if BUILD_TEST_PROGRAMS
-bin_PROGRAMS = leaker
+if TEST_SERVICES
+testbindir = $(bindir)/faultd
+testbin_PROGRAMS = leaker
 
 leaker_SOURCES = \
     tests/leaker.c
 
+testbin_DATA = \
+    tests/fail-only-once.sh \
+    tests/fail-always.sh
+
 serviceconfig_DATA += \
-    tests/faultd-failed.service.conf \
-    tests/faultd-leaker.service.conf
+    tests/services/faultd-failed-service-with-recovery.service.conf \
+    tests/services/faultd-failed-vip-service.service.conf
 
 TEST_UNIT_FILES = \
-    tests/faultd-leaker.service \
-    tests/faultd-failed.service \
-    tests/faultd-success.service
+    tests/services/faultd-failed-service-always-failed.service \
+    tests/services/faultd-failed-service-single-restart.service \
+    tests/services/faultd-failed-service-with-recovery.service \
+    tests/services/faultd-failed-vip-service.service \
+    tests/services/faultd-recovery-service.service \
+    tests/services/faultd-res-leak.service
 
 nodist_unit_DATA += $(TEST_UNIT_FILES)
 endif
 
 CLEANFILES += $(nodist_unit_DATA)
 
-if ENABLE_TESTS
+if UNIT_TESTS
 check_PROGRAMS = test
 
 test_LDFLAGS = -ldl
index 295ec7ac6cececb1c17c23a4646876805e486fbe..8fad56530e6ceb6807e99288563426e6fc81dba7 100644 (file)
@@ -30,22 +30,22 @@ AC_PREFIX_DEFAULT([/usr])
 AC_PROG_SED
 AC_PROG_MKDIR_P
 
-AC_ARG_ENABLE([test_programs],
-             AS_HELP_STRING([--enable-test-programs], [build test services]),
-             [enable_test_programs=$enableval], [enable_test_programs=no])
+AC_ARG_ENABLE([test_services],
+        AS_HELP_STRING([--enable-test-services], [enable test services]),
+        [enable_test_services=$enableval], [enable_test_services=no])
 
-AM_CONDITIONAL(BUILD_TEST_PROGRAMS, [test "x$enable_test_programs" = xyes])
+AM_CONDITIONAL(TEST_SERVICES, [test "x$enable_test_services" = xyes])
 
-AC_ARG_ENABLE([tests],
-             AS_HELP_STRING([--enable-tests], [enable tests]),
-             [enable_test_programs=$enableval], [enable_tests=no])
+AC_ARG_ENABLE([unit_tests],
+AS_HELP_STRING([--enable-unit-tests], [enable unit tests]),
+        [enable_unit_tests=$enableval], [enable_unit_tests=no])
 
-AS_IF([test "x$enable_tests" = xyes], [
-       PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.0.0],
-                         AC_DEFINE(HAS_CMOCKA, 1, [detected cmocka]))
-        AC_DEFINE(ENABLE_TESTS, 1, [Define if testing code is to be enabled])
-])
-AM_CONDITIONAL(ENABLE_TESTS, [test "x$enable_tests" = xyes])
+AS_IF([test "x$enable_unit_tests" = xyes],
+        [PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.0.0],
+        AC_DEFINE(HAS_CMOCKA, 1, [detected cmocka]))
+        AC_DEFINE(UNIT_TESTS, 1, [Define if testing code is to be enabled])])
+
+AM_CONDITIONAL(UNIT_TESTS, [test "x$enable_unit_tests" = xyes])
 
 # Default database backend when not specified by user
 default_db_mod="src/database/ejdb"
index 1899fea32b2b4b917953d5d159d5483cc69ebfc0..5149320c188af0010e6be9f9b5099262a030261e 100644 (file)
@@ -23,12 +23,12 @@ BuildRequires: pkgconfig(audit)
 %description extra
 Set of modules allowing to extend faultd functionality
 
-%package test-programs
-Summary:    faultd test program
+%package test-services
+Summary:    faultd test services
 Group:      System/Monitoring
 
-%description test-programs
-Program used to test resource violation scenario in faultd
+%description test-services
+Services used to test faultd functionality
 
 %prep
 %setup -q
@@ -36,7 +36,7 @@ cp %{SOURCE1001} .
 
 %build
 %autogen
-%configure --enable-test-programs --enable-tests
+%configure --enable-test-services --enable-unit-tests
 make %{?_smp_mflags}
 
 make check
@@ -92,12 +92,17 @@ done
 
 %files extra -f faultd-extra-files
 
-%files test-programs
-%{_bindir}/leaker
-%{_unitdir}/faultd-leaker.service
-%{_unitdir}/faultd-failed.service
-%{_unitdir}/faultd-success.service
-%{_sysconfdir}/faultd/conf.d/faultd-leaker.service.conf
-%{_sysconfdir}/faultd/conf.d/faultd-failed.service.conf
+%files test-services
+%{_bindir}/faultd/leaker
+%attr(755, root, root) %{_bindir}/faultd/fail-only-once.sh
+%attr(755, root, root) %{_bindir}/faultd/fail-always.sh
+%{_unitdir}/faultd-failed-service-always-failed.service
+%{_unitdir}/faultd-failed-service-single-restart.service
+%{_unitdir}/faultd-failed-service-with-recovery.service
+%{_unitdir}/faultd-failed-vip-service.service
+%{_unitdir}/faultd-recovery-service.service
+%{_unitdir}/faultd-res-leak.service
+%{_sysconfdir}/faultd/conf.d/faultd-failed-service-with-recovery.service.conf
+%{_sysconfdir}/faultd/conf.d/faultd-failed-vip-service.service.conf
 
 %docs_package
diff --git a/tests/fail-always.sh b/tests/fail-always.sh
new file mode 100755 (executable)
index 0000000..f4b5a03
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+sleep 3
+echo "Failing..."
+exit 1
diff --git a/tests/fail-only-once.sh b/tests/fail-only-once.sh
new file mode 100755 (executable)
index 0000000..869d136
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+RUNDIR='/run/faultd'
+
+if [ ! -d $RUNDIR ]
+then
+       mkdir $RUNDIR
+fi
+
+if [ ! -e "${RUNDIR}/failed_flag" ]
+then
+       touch "${RUNDIR}/failed_flag"
+       echo "Failing..."
+       exit 1
+fi
+
+echo "Already failed, exitting normally"
+exit 0
diff --git a/tests/faultd-failed.service.conf b/tests/faultd-failed.service.conf
deleted file mode 100644 (file)
index 2efa696..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-{
-        "RecoveryUnit": "faultd-success.service"
-}
-
diff --git a/tests/faultd-failed.service.in b/tests/faultd-failed.service.in
deleted file mode 100644 (file)
index 3ec4433..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-# copy to /run/systemd/system and run systemctl daemon-reload
-[Unit]
-Description="restart test"
-
-[Service]
-Restart=always
-ExecStart=/bin/sh -c 'sleep 1; exit 1'
-
-[X-Fault]
-FaultHandler=/bin/true
diff --git a/tests/faultd-leaker.service.conf b/tests/faultd-leaker.service.conf
deleted file mode 100644 (file)
index 308cc20..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-{"ServiceType": "org.tizen.faultd.service.VIP"}
-
diff --git a/tests/faultd-leaker.service.in b/tests/faultd-leaker.service.in
deleted file mode 100644 (file)
index 287c375..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-[Unit]
-Description=Service which leaks file descriptors
-
-[Service]
-Type=simple
-LimitNOFILE=16
-ExecStart=@bindir@/leaker
-SuccessExitStatus=0 SIGTERM
-
diff --git a/tests/faultd-success.service.in b/tests/faultd-success.service.in
deleted file mode 100644 (file)
index 7c76282..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-[Unit]
-Description="recovery handler test"
-
-[Service]
-ExecStart=/bin/sh -c 'sleep 1; exit 0'
diff --git a/tests/services/faultd-failed-service-always-failed.service.in b/tests/services/faultd-failed-service-always-failed.service.in
new file mode 100644 (file)
index 0000000..bcd95fb
--- /dev/null
@@ -0,0 +1,9 @@
+[Unit]
+Description=Service which always fails
+
+[Service]
+ExecStart=@bindir@/faultd/fail-always.sh
+Restart=no
+
+[Install]
+WantedBy=multi-user.target
diff --git a/tests/services/faultd-failed-service-single-restart.service.in b/tests/services/faultd-failed-service-single-restart.service.in
new file mode 100644 (file)
index 0000000..13dede5
--- /dev/null
@@ -0,0 +1,6 @@
+[Unit]
+Description=Service which fails only once
+
+[Service]
+ExecStart=@bindir@/faultd/fail-only-once.sh
+Restart=no
diff --git a/tests/services/faultd-failed-service-with-recovery.service.conf b/tests/services/faultd-failed-service-with-recovery.service.conf
new file mode 100644 (file)
index 0000000..a590e34
--- /dev/null
@@ -0,0 +1,3 @@
+{
+       "RecoveryUnit": "faultd-recovery-service.service"
+}
diff --git a/tests/services/faultd-failed-service-with-recovery.service.in b/tests/services/faultd-failed-service-with-recovery.service.in
new file mode 100644 (file)
index 0000000..49101ff
--- /dev/null
@@ -0,0 +1,6 @@
+[Unit]
+Description=Service with recovery which fails only once
+
+[Service]
+ExecStart=@bindir@/faultd/fail-only-once.sh
+Restart=no
diff --git a/tests/services/faultd-failed-vip-service.service.conf b/tests/services/faultd-failed-vip-service.service.conf
new file mode 100644 (file)
index 0000000..b84638e
--- /dev/null
@@ -0,0 +1,3 @@
+{
+       "ServiceType": "org.tizen.faultd.service.VIP"
+}
diff --git a/tests/services/faultd-failed-vip-service.service.in b/tests/services/faultd-failed-vip-service.service.in
new file mode 100644 (file)
index 0000000..76e3337
--- /dev/null
@@ -0,0 +1,9 @@
+[Unit]
+Description=VIP service which always fails
+
+[Service]
+ExecStart=@bindir@/faultd/fail-always.sh
+Restart=no
+
+[Install]
+WantedBy=multi-user.target
diff --git a/tests/services/faultd-recovery-service.service.in b/tests/services/faultd-recovery-service.service.in
new file mode 100644 (file)
index 0000000..8c32351
--- /dev/null
@@ -0,0 +1,6 @@
+[Unit]
+Description=Recovery service
+
+[Service]
+ExecStart=/bin/sh -c 'exit 0'
+Restart=no
diff --git a/tests/services/faultd-res-leak.service.in b/tests/services/faultd-res-leak.service.in
new file mode 100644 (file)
index 0000000..3bf1065
--- /dev/null
@@ -0,0 +1,8 @@
+[Unit]
+Description=Service which leaks file descriptors
+
+[Service]
+Type=simple
+LimitNOFILE=16
+ExecStart=@bindir@/faultd/leaker
+SuccessExitStatus=0 SIGTERM