include $(top_srcdir)/Makefile.tool-tests.am

SUBDIRS = .
SUBDIRS += scripts

# Arch-specific tests.
if VGCONF_ARCHS_INCLUDE_X86
SUBDIRS += x86
endif
if VGCONF_ARCHS_INCLUDE_AMD64
SUBDIRS += amd64
endif
if VGCONF_ARCHS_INCLUDE_PPC32
SUBDIRS += ppc32
endif
if VGCONF_ARCHS_INCLUDE_PPC64
SUBDIRS += ppc64
endif
if VGCONF_ARCHS_INCLUDE_ARM
SUBDIRS += arm
endif
if VGCONF_ARCHS_INCLUDE_ARM64
SUBDIRS += arm64
endif
if VGCONF_ARCHS_INCLUDE_S390X
SUBDIRS += s390x
endif
if VGCONF_ARCHS_INCLUDE_MIPS32
SUBDIRS += mips32
endif
if VGCONF_ARCHS_INCLUDE_MIPS64
SUBDIRS += mips64
endif
if VGCONF_ARCHS_INCLUDE_TILEGX
SUBDIRS += tilegx
endif

# OS-specific tests
if VGCONF_OS_IS_LINUX
SUBDIRS += linux
endif
if VGCONF_OS_IS_DARWIN
SUBDIRS += darwin
endif
if VGCONF_OS_IS_SOLARIS
SUBDIRS += solaris
endif

# Platform-specific tests
if VGCONF_PLATFORMS_INCLUDE_AMD64_LINUX
SUBDIRS += amd64-linux
endif
if VGCONF_PLATFORMS_INCLUDE_X86_LINUX
SUBDIRS += x86-linux
endif
if VGCONF_PLATFORMS_INCLUDE_AMD64_DARWIN
SUBDIRS += amd64-darwin
endif
if VGCONF_PLATFORMS_INCLUDE_X86_DARWIN
SUBDIRS += x86-darwin
endif
if VGCONF_PLATFORMS_INCLUDE_AMD64_SOLARIS
SUBDIRS += amd64-solaris
endif
if VGCONF_PLATFORMS_INCLUDE_X86_SOLARIS
SUBDIRS += x86-solaris
endif

DIST_SUBDIRS = x86 amd64 ppc32 ppc64 arm arm64 s390x mips32 mips64 tilegx \
               linux darwin solaris amd64-linux x86-linux amd64-darwin \
               x86-darwin amd64-solaris x86-solaris scripts .

dist_noinst_SCRIPTS = \
	filter_cmdline0 \
	filter_cmdline1 \
	filter_fdleak \
	filter_ioctl_moans \
	filter_none_discards \
	filter_stderr \
	filter_timestamp \
	allexec_prepare_prereq

noinst_HEADERS = fdleak.h

EXTRA_DIST = \
	allexec32.stdout.exp allexec32.stderr.exp allexec32.vgtest\
	allexec64.stdout.exp allexec64.stderr.exp allexec64.vgtest\
	ansi.stderr.exp ansi.vgtest \
	args.stderr.exp args.stdout.exp args.vgtest \
	async-sigs.stderr.exp async-sigs.stderr.exp-mips32 \
	async-sigs.vgtest \
	bigcode.vgtest bigcode.stderr.exp bigcode.stdout.exp \
	bitfield1.stderr.exp bitfield1.vgtest \
	bug129866.vgtest bug129866.stderr.exp bug129866.stdout.exp \
	bug234814.vgtest bug234814.stderr.exp bug234814.stdout.exp \
	closeall.stderr.exp closeall.vgtest \
	cmdline0.stderr.exp cmdline0.stdout.exp cmdline0.vgtest \
	cmdline1.stderr.exp cmdline1.stdout.exp cmdline1.vgtest \
	cmdline2.stderr.exp cmdline2.stdout.exp cmdline2.vgtest \
	cmdline3.stderr.exp cmdline3.vgtest \
	cmdline4.stderr.exp cmdline4.vgtest \
	cmdline5.stderr.exp cmdline5.vgtest \
	cmdline6.stderr.exp cmdline6.vgtest \
	cmd-with-special.stderr.exp cmd-with-special.vgtest \
	coolo_sigaction.stderr.exp \
	coolo_sigaction.stdout.exp coolo_sigaction.vgtest \
	coolo_strlen.stderr.exp coolo_strlen.vgtest \
	discard.stderr.exp discard.stdout.exp \
	discard.vgtest \
	empty-exe.vgtest empty-exe.stderr.exp \
	exec-sigmask.vgtest exec-sigmask.stdout.exp \
	exec-sigmask.stdout.exp2 exec-sigmask.stdout.exp3 \
	exec-sigmask.stdout.exp-solaris exec-sigmask.stderr.exp \
	execve.vgtest execve.stdout.exp execve.stderr.exp \
	faultstatus.vgtest faultstatus.stderr.exp faultstatus.stderr.exp-s390x \
	fcntl_setown.vgtest fcntl_setown.stdout.exp fcntl_setown.stderr.exp \
	fdleak_cmsg.stderr.exp fdleak_cmsg.vgtest \
	fdleak_creat.stderr.exp fdleak_creat.vgtest \
	fdleak_dup.stderr.exp fdleak_dup.vgtest \
	fdleak_dup2.stderr.exp fdleak_dup2.vgtest \
	fdleak_fcntl.stderr.exp fdleak_fcntl.vgtest \
	fdleak_ipv4.stderr.exp fdleak_ipv4.stdout.exp fdleak_ipv4.vgtest \
	fdleak_open.stderr.exp fdleak_open.vgtest \
	fdleak_pipe.stderr.exp fdleak_pipe.vgtest \
	fdleak_socketpair.stderr.exp fdleak_socketpair.vgtest \
	floored.stderr.exp floored.stdout.exp floored.vgtest \
	fork.stderr.exp fork.stdout.exp fork.vgtest \
	fucomip.stderr.exp fucomip.vgtest \
	gxx304.stderr.exp gxx304.vgtest \
	ifunc.stderr.exp ifunc.stdout.exp ifunc.vgtest \
	ioctl_moans.stderr.exp ioctl_moans.vgtest \
	libvex_test.stderr.exp libvex_test.vgtest \
	libvexmultiarch_test.stderr.exp libvexmultiarch_test.vgtest \
	manythreads.stdout.exp manythreads.stderr.exp manythreads.vgtest \
	map_unaligned.stderr.exp map_unaligned.vgtest \
	map_unmap.stderr.exp map_unmap.stdout.exp map_unmap.vgtest \
	mmap_fcntl_bug.vgtest mmap_fcntl_bug.stdout.exp \
		mmap_fcntl_bug.stderr.exp \
	mq.stderr.exp mq.vgtest \
	munmap_exe.stderr.exp munmap_exe.vgtest \
	nestedfns.stderr.exp nestedfns.stdout.exp nestedfns.vgtest \
	nodir.stderr.exp nodir.vgtest \
	pending.stdout.exp pending.stderr.exp pending.vgtest \
	procfs-linux.stderr.exp-with-readlinkat \
	procfs-linux.stderr.exp-without-readlinkat \
	procfs-linux.vgtest \
	procfs-non-linux.vgtest \
	procfs-non-linux.stderr.exp-with-readlinkat \
	procfs-non-linux.stderr.exp-without-readlinkat \
	pth_atfork1.stderr.exp pth_atfork1.stdout.exp pth_atfork1.vgtest \
	pth_blockedsig.stderr.exp \
	pth_blockedsig.stdout.exp pth_blockedsig.vgtest \
	pth_cancel1.stderr.exp pth_cancel1.stdout.exp pth_cancel1.vgtest \
	pth_cancel2.stderr.exp pth_cancel2.vgtest \
	pth_cvsimple.stderr.exp pth_cvsimple.stdout.exp pth_cvsimple.vgtest \
	pth_empty.stderr.exp pth_empty.vgtest \
	pth_exit.stderr.exp pth_exit.vgtest \
	pth_exit2.stderr.exp pth_exit2.vgtest \
	pth_mutexspeed.stderr.exp \
	pth_mutexspeed.stdout.exp pth_mutexspeed.vgtest \
	pth_once.stderr.exp pth_once.stdout.exp pth_once.vgtest \
	pth_rwlock.stderr.exp pth_rwlock.vgtest \
	pth_stackalign.stderr.exp \
	pth_stackalign.stdout.exp pth_stackalign.vgtest \
	rcrl.stderr.exp rcrl.stdout.exp rcrl.vgtest \
	readline1.stderr.exp readline1.stdout.exp \
	readline1.vgtest \
	require-text-symbol-1.vgtest \
		require-text-symbol-1.stderr.exp \
	require-text-symbol-2.vgtest \
		require-text-symbol-2.stderr.exp-libcso1 \
		require-text-symbol-2.stderr.exp-libcso6 \
	res_search.stderr.exp res_search.stdout.exp res_search.vgtest \
	resolv.stderr.exp resolv.stdout.exp resolv.vgtest \
	rlimit_nofile.stderr.exp rlimit_nofile.stdout.exp rlimit_nofile.vgtest \
	rlimit64_nofile.stderr.exp rlimit64_nofile.stdout.exp rlimit64_nofile.vgtest \
	selfrun.stderr.exp selfrun.stdout.exp selfrun.vgtest \
	sem.stderr.exp sem.stdout.exp sem.vgtest \
	semlimit.stderr.exp semlimit.stdout.exp semlimit.vgtest \
	sha1_test.stderr.exp sha1_test.vgtest \
	shortpush.stderr.exp shortpush.vgtest \
	shorts.stderr.exp shorts.vgtest \
	sigstackgrowth.stdout.exp sigstackgrowth.stderr.exp sigstackgrowth.vgtest \
	stackgrowth.stdout.exp stackgrowth.stderr.exp stackgrowth.vgtest \
	syscall-restart1.vgtest syscall-restart1.stdout.exp syscall-restart1.stderr.exp \
	syscall-restart2.vgtest syscall-restart2.stdout.exp syscall-restart2.stderr.exp \
	syslog.vgtest syslog.stderr.exp \
	system.stderr.exp system.vgtest \
	thread-exits.stderr.exp thread-exits.stdout.exp thread-exits.vgtest \
	threaded-fork.stderr.exp threaded-fork.stdout.exp threaded-fork.vgtest \
	threadederrno.stderr.exp threadederrno.stdout.exp \
	threadederrno.vgtest \
	timestamp.stderr.exp timestamp.vgtest \
	tls.vgtest tls.stderr.exp tls.stdout.exp  \
	unit_debuglog.stderr.exp unit_debuglog.vgtest \
	vgprintf.stderr.exp vgprintf.vgtest \
	process_vm_readv_writev.stderr.exp process_vm_readv_writev.vgtest

check_PROGRAMS = \
	args \
	async-sigs \
	bitfield1 \
	bug129866 bug234814 \
	closeall coolo_strlen \
	discard exec-sigmask execve faultstatus fcntl_setown \
	fdleak_cmsg fdleak_creat fdleak_dup fdleak_dup2 \
	fdleak_fcntl fdleak_ipv4 fdleak_open fdleak_pipe \
	fdleak_socketpair \
	floored fork fucomip \
	ioctl_moans \
	libvex_test \
	libvexmultiarch_test \
	manythreads \
	mmap_fcntl_bug \
	munmap_exe map_unaligned map_unmap mq \
	pending \
	procfs-cmdline-exe \
	pth_atfork1 pth_blockedsig pth_cancel1 pth_cancel2 pth_cvsimple \
	pth_empty pth_exit pth_exit2 pth_mutexspeed pth_once pth_rwlock \
	pth_stackalign \
	rcrl readline1 \
	require-text-symbol \
	res_search resolv \
	rlimit_nofile selfrun sem semlimit sha1_test \
	shortpush shorts stackgrowth sigstackgrowth \
	syscall-restart1 syscall-restart2 \
	syslog \
	system \
	thread-exits \
	threaded-fork \
	threadederrno \
	timestamp \
	tls \
	tls.so \
	tls2.so \
	unit_debuglog \
	valgrind_cpp_test \
	vgprintf \
	coolo_sigaction \
	gxx304 \
	process_vm_readv_writev

if HAVE_NESTED_FUNCTIONS
   check_PROGRAMS += nestedfns
endif

# This doesn't appear to be compilable on Darwin.
if ! VGCONF_OS_IS_DARWIN
   check_PROGRAMS += rlimit64_nofile 
endif

# clang does not know -ansi
if ! COMPILER_IS_CLANG
   check_PROGRAMS += ansi
endif

if BUILD_IFUNC_TESTS
   check_PROGRAMS += ifunc
endif

AM_CFLAGS   += $(AM_FLAG_M3264_PRI)
AM_CXXFLAGS += $(AM_FLAG_M3264_PRI)

# Extra stuff for C tests
ansi_CFLAGS		= $(AM_CFLAGS) -ansi
execve_CFLAGS		= $(AM_CFLAGS) @FLAG_W_NO_NONNULL@
if VGCONF_OS_IS_SOLARIS
fcntl_setown_LDADD	= -lsocket -lnsl
fdleak_cmsg_CFLAGS	= $(AM_CFLAGS) -D_XOPEN_SOURCE=500
fdleak_cmsg_LDADD	= -lsocket -lnsl
fdleak_ipv4_LDADD	= -lsocket -lnsl
fdleak_creat_LDADD	= -lsocket -lnsl
fdleak_socketpair_LDADD	= -lsocket -lnsl
endif
floored_LDADD 		= -lm
manythreads_LDADD	= -lpthread
if VGCONF_OS_IS_DARWIN
 nestedfns_CFLAGS	= $(AM_CFLAGS) -fnested-functions
else
 nestedfns_CFLAGS	= $(AM_CFLAGS)
 mq_LDADD		= -lrt
endif
libvex_test_CFLAGS      = $(AM_CFLAGS) @FLAG_FSANITIZE@
libvex_test_LDADD       = ../../VEX/libvex-@VGCONF_ARCH_PRI@-@VGCONF_OS@.a \
			   @LIB_UBSAN@
libvexmultiarch_test_CFLAGS= $(AM_CFLAGS) @FLAG_FSANITIZE@
libvexmultiarch_test_LDADD = \
	../../VEX/libvexmultiarch-@VGCONF_ARCH_PRI@-@VGCONF_OS@.a \
	../../VEX/libvex-@VGCONF_ARCH_PRI@-@VGCONF_OS@.a @LIB_UBSAN@
libvexmultiarch_test_SOURCES = libvex_test.c
pth_atfork1_LDADD	= -lpthread
pth_blockedsig_LDADD	= -lpthread
pth_cancel1_CFLAGS	= $(AM_CFLAGS) -Wno-shadow
pth_cancel1_LDADD	= -lpthread
pth_cancel2_LDADD	= -lpthread
pth_cvsimple_LDADD	= -lpthread
pth_empty_LDADD 	= -lpthread
pth_exit_LDADD	 	= -lpthread
pth_exit2_LDADD	 	= -lpthread
pth_mutexspeed_LDADD	= -lpthread
pth_once_LDADD		= -lpthread
pth_rwlock_LDADD	= -lpthread
pth_rwlock_CFLAGS	= $(AM_CFLAGS)
if VGCONF_OS_IS_SOLARIS
pth_rwlock_CFLAGS	+= --std=c99
endif
pth_stackalign_LDADD	= -lpthread
res_search_LDADD        = -lresolv -lpthread
resolv_CFLAGS		= $(AM_CFLAGS)
resolv_LDADD            = -lresolv -lpthread
if VGCONF_OS_IS_SOLARIS
resolv_CFLAGS		+= -U_REENTRANT
endif
semlimit_LDADD		= -lpthread
sha1_test_CFLAGS	= $(AM_CFLAGS)
if VGCONF_OS_IS_SOLARIS
sha1_test_CFLAGS	+= -Du_int32_t=uint32_t
endif
thread_exits_LDADD	= -lpthread
threaded_fork_LDADD	= -lpthread
threadederrno_CFLAGS	= $(AM_CFLAGS)
threadederrno_LDADD	= -lpthread
if VGCONF_OS_IS_SOLARIS
threadederrno_CFLAGS	+= --std=c99
endif
tls_SOURCES		= tls.c tls2.c
tls_DEPENDENCIES	= tls.so tls2.so
tls_LDFLAGS		= -Wl,-rpath,$(abs_top_builddir)/none/tests
tls_LDADD		= tls.so tls2.so -lpthread
tls_so_SOURCES		= tls_so.c
tls_so_DEPENDENCIES	= tls2.so
if VGCONF_OS_IS_DARWIN
 tls_so_LDFLAGS		= -dynamic -dynamiclib -all_load -fpic
 tls_so_LDADD		= `pwd`/tls2.so
else
 tls_so_LDFLAGS		= -Wl,-rpath,$(abs_top_builddir)/none/tests -shared -fPIC
 tls_so_LDADD		= tls2.so
endif
tls_so_CFLAGS		= $(AM_CFLAGS) -fPIC
tls2_so_SOURCES		= tls2_so.c
if VGCONF_OS_IS_DARWIN
 tls2_so_LDFLAGS	= -dynamic -dynamiclib -all_load
else
 tls2_so_LDFLAGS	= -shared
endif

valgrind_cpp_test_SOURCES = valgrind_cpp_test.cpp
valgrind_cpp_test_LDADD   = -lstdc++

# C++ tests
coolo_sigaction_SOURCES	= coolo_sigaction.cpp
gxx304_SOURCES		= gxx304.cpp