# Copyright 2020 Red Hat Inc.
# All Rights Reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Authors:
#   Steve Grubb <sgrubb@redhat.com>
#

CONFIG_CLEAN_FILES = *.orig *.cur

SUBDIRS =
if WITH_STRESS
SUBDIRS += stress
endif

check_PROGRAMS = avl_test gid_proc_test uid_proc_test escape_test \
attr_sets_test elf_file_test fd_fgets_test file_type_detect_test \
rules_test policy_reload_test policy_concurrent_test failure_action_test \
queue_test event_test message_test \
trustdb_format_test trustdb_lmdb_test lru_test notify_test \
decision_defer_test decision_config_test \
decision_timing_report_test daemon_config_test ignore_mounts_risk_test
check_PROGRAMS += cli_privilege_test

AM_CPPFLAGS = -I${top_srcdir}/src/library/
AM_CFLAGS = -std=gnu11

avl_test_SOURCES = avl_test.c ${top_srcdir}/src/library/avl.c
gid_proc_test_SOURCES = gid_proc_test.c test-stubs.c
gid_proc_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
uid_proc_test_SOURCES = uid_proc_test.c test-stubs.c
uid_proc_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
escape_test_SOURCES = escape_test.c test-stubs.c
escape_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
attr_sets_test_SOURCES = attr_sets_test.c test-stubs.c
attr_sets_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
elf_file_test_SOURCES = elf_file_test.c test-stubs.c
elf_file_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
fd_fgets_test_SOURCES = fd_fgets_test.c test-stubs.c
fd_fgets_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
file_type_detect_test_SOURCES = file_type_detect_test.c test-stubs.c
file_type_detect_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
ignore_mounts_risk_test_SOURCES = ignore_mounts_risk_test.c test-stubs.c
ignore_mounts_risk_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
ignore_mounts_risk_test_CPPFLAGS = \
	-I${top_builddir} \
	-I${top_srcdir}/src/library/ \
	-I${top_srcdir}/src/cli/
cli_privilege_test_SOURCES = cli_privilege_test.c
cli_privilege_test_CPPFLAGS = \
	-I${top_builddir} \
	-I${top_srcdir}/src/cli/
rules_test_SOURCES = rules_test.c
rules_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
rules_test_CPPFLAGS = -I${top_srcdir}/src/library/ -DTEST_BASE=\"${top_srcdir}\"
policy_reload_test_SOURCES = policy_reload_test.c test-stubs.c
policy_reload_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
policy_concurrent_test_SOURCES = policy_concurrent_test.c test-stubs.c
policy_concurrent_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
policy_concurrent_test_LDFLAGS = -pthread
failure_action_test_SOURCES = failure_action_test.c \
	${top_srcdir}/src/library/failure-action.c
queue_test_SOURCES = queue_test.c test-stubs.c
queue_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
message_test_SOURCES = message_test.c test-stubs.c
message_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
message_test_LDFLAGS = -pthread
trustdb_format_test_SOURCES = trustdb_format_test.c
trustdb_lmdb_test_SOURCES = trustdb_lmdb_test.c test-stubs.c
trustdb_lmdb_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
trustdb_lmdb_test_LDFLAGS = -pthread
lru_test_SOURCES = lru_test.c test-stubs.c
lru_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
notify_test_SOURCES = notify_test.c test-stubs.c \
	${top_srcdir}/src/daemon/decision-worker.c \
	${top_srcdir}/src/daemon/worker-health.c \
	${top_srcdir}/src/daemon/fanotify-fs-error.c \
	${top_srcdir}/src/daemon/notify.c \
	${top_srcdir}/src/daemon/mounts.c \
	${top_srcdir}/src/daemon/state-report.c \
	${top_srcdir}/src/daemon/systemd-notify.c
notify_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
notify_test_CPPFLAGS = \
	-I${top_srcdir}/src/library/ \
	-I${top_srcdir}/src/daemon/ \
	-DTEST_SUBJECT_DEFER
decision_defer_test_SOURCES = decision_defer_test.c \
	${top_srcdir}/src/library/decision-defer.c \
	${top_srcdir}/src/library/string-util.c
decision_defer_test_CPPFLAGS = \
	-I${top_builddir} \
	-I${top_srcdir}/src/library/ \
	-I${top_srcdir}/src/daemon/
decision_defer_test_LDFLAGS = -pthread
decision_config_test_SOURCES = decision_config_test.c
decision_config_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
daemon_config_test_SOURCES = daemon_config_test.c test-stubs.c
daemon_config_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
decision_timing_report_test_SOURCES = decision_timing_report_test.c \
	${top_srcdir}/src/library/decision-timing.c
decision_timing_report_test_CPPFLAGS = \
	-I${top_builddir} \
	-I${top_srcdir}/src/library/ \
	-DTEST_DECISION_TIMING_REPORT
event_test_SOURCES = event_test.c
event_test_LDADD = \
	${top_builddir}/src/library/libfapolicyd_la-attr-lookup-metrics.o \
	${top_builddir}/src/library/libfapolicyd_la-decision-defer.o \
	${top_builddir}/src/library/libfapolicyd_la-event.o \
	${top_builddir}/src/library/libfapolicyd_la-lru.o \
	${top_builddir}/src/library/libfapolicyd_la-subject.o \
	${top_builddir}/src/library/libfapolicyd_la-subject-attr.o \
	${top_builddir}/src/library/libfapolicyd_la-object.o \
	${top_builddir}/src/library/libfapolicyd_la-object-attr.o \
	${top_builddir}/src/library/libfapolicyd_la-attr-sets.o \
	${top_builddir}/src/library/libfapolicyd_la-avl.o \
	${top_builddir}/src/library/libfapolicyd_la-decision-timing.o \
	${top_builddir}/src/library/libfapolicyd_la-string-util.o
event_test_DEPENDENCIES = $(event_test_LDADD)

if WITH_RPM
check_PROGRAMS += filter_test
filter_test_SOURCES = filter_test.c
filter_test_SOURCES += test-stubs.c
filter_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
filter_test_CPPFLAGS = -I${top_srcdir}/src/library/ -DTEST_BASE=\"${top_srcdir}\"
filter_test_LDFLAGS = -pthread
check_PROGRAMS += file_filter_test
file_filter_test_SOURCES = file_filter_test.c
file_filter_test_SOURCES += test-stubs.c
file_filter_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
file_filter_test_CPPFLAGS = -I${top_srcdir}/src/library/ -DTEST_BASE=\"${top_srcdir}\"
check_PROGRAMS += rpm_backend_test
rpm_backend_test_SOURCES = rpm_backend_test.c test-stubs.c
rpm_backend_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la
endif

if WITH_DEB
check_PROGRAMS += deb_test md5_backend_test deb_filter_test
LIBS += -ldpkg -lmd
deb_test_CFLAGS = -std=gnu11 -fPIE -DPIE -pthread -g -W -Wall -Wshadow -Wundef -Wno-unused-result -Wno-unused-parameter -D_GNU_SOURCE -DLIBDPKG_VOLATILE_API
deb_test_CPPFLAGS = \
	-I${top_srcdir}/src/library/ \
	-DTEST_BASE=\"${top_srcdir}\"
deb_test_LDFLAGS = -pie -Wl,-z,relro -Wl,-z,now
deb_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la -ldpkg -lmd
deb_test_SOURCES = deb_test.c test-stubs.c
md5_backend_test_CFLAGS = $(deb_test_CFLAGS)
md5_backend_test_LDFLAGS = $(deb_test_LDFLAGS)
md5_backend_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la -ldpkg -lmd
md5_backend_test_SOURCES = md5_backend_test.c test-stubs.c
deb_filter_test_CFLAGS = $(deb_test_CFLAGS)
deb_filter_test_CPPFLAGS = \
	-I${top_srcdir}/src/library/ \
	-DTEST_BASE=\"${top_srcdir}\"
deb_filter_test_LDFLAGS = $(deb_test_LDFLAGS)
deb_filter_test_LDADD = ${top_builddir}/src/.libs/libfapolicyd.la -ldpkg -lmd
deb_filter_test_SOURCES = deb_filter_test.c test-stubs.c
endif

TESTS = $(check_PROGRAMS)
