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>
$(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
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"
%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
%build
%autogen
-%configure --enable-test-programs --enable-tests
+%configure --enable-test-services --enable-unit-tests
make %{?_smp_mflags}
make check
%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
--- /dev/null
+#!/bin/sh
+
+sleep 3
+echo "Failing..."
+exit 1
--- /dev/null
+#!/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
+++ /dev/null
-{
- "RecoveryUnit": "faultd-success.service"
-}
-
+++ /dev/null
-# 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
+++ /dev/null
-{"ServiceType": "org.tizen.faultd.service.VIP"}
-
+++ /dev/null
-[Unit]
-Description=Service which leaks file descriptors
-
-[Service]
-Type=simple
-LimitNOFILE=16
-ExecStart=@bindir@/leaker
-SuccessExitStatus=0 SIGTERM
-
+++ /dev/null
-[Unit]
-Description="recovery handler test"
-
-[Service]
-ExecStart=/bin/sh -c 'sleep 1; exit 0'
--- /dev/null
+[Unit]
+Description=Service which always fails
+
+[Service]
+ExecStart=@bindir@/faultd/fail-always.sh
+Restart=no
+
+[Install]
+WantedBy=multi-user.target
--- /dev/null
+[Unit]
+Description=Service which fails only once
+
+[Service]
+ExecStart=@bindir@/faultd/fail-only-once.sh
+Restart=no
--- /dev/null
+{
+ "RecoveryUnit": "faultd-recovery-service.service"
+}
--- /dev/null
+[Unit]
+Description=Service with recovery which fails only once
+
+[Service]
+ExecStart=@bindir@/faultd/fail-only-once.sh
+Restart=no
--- /dev/null
+{
+ "ServiceType": "org.tizen.faultd.service.VIP"
+}
--- /dev/null
+[Unit]
+Description=VIP service which always fails
+
+[Service]
+ExecStart=@bindir@/faultd/fail-always.sh
+Restart=no
+
+[Install]
+WantedBy=multi-user.target
--- /dev/null
+[Unit]
+Description=Recovery service
+
+[Service]
+ExecStart=/bin/sh -c 'exit 0'
+Restart=no
--- /dev/null
+[Unit]
+Description=Service which leaks file descriptors
+
+[Service]
+Type=simple
+LimitNOFILE=16
+ExecStart=@bindir@/faultd/leaker
+SuccessExitStatus=0 SIGTERM