# uClibc-ng NPTL tests
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.

ifeq ($(TARGET_ARCH),metag)
TESTS_DISABLED := tst-cleanup0 tst-cleanupx0
endif

# qemu crash
ifeq ($(TARGET_ARCH),microblaze)
TESTS_DISABLED := tst-tls2
endif

# deadlock
ifeq ($(TARGET_ARCH),sh)
TESTS_DISABLED := tst-cond1 tst-cond4 tst-cond6 tst-cond7 tst-cond10 \
	tst-cond13 tst-cond14 tst-cond15 tst-cond18 tst-cond20 \
	tst-cond21 tst-cond22 tst-cputimer1 tst-cputimer2 tst-cputimer3 \
	tst-mutex8 tst-timer4 tst-timer5
endif

TESTS := tst-align tst-align2 tst-atfork1 tst-attr1 tst-attr2 tst-attr3	\
	tst-barrier1 tst-barrier2 tst-barrier3 tst-barrier4 tst-basic1	\
	tst-basic2 tst-basic3 tst-basic4 tst-basic5 tst-basic6		\
	tst-cancel1 tst-cancel2 tst-cancel3 tst-cancel6 tst-cancel7	\
	tst-cancel8 tst-cancel9 tst-cancel10 tst-cancel11 tst-cancel12	\
	tst-cancel13 tst-cancel14 tst-cancel15 tst-cancel16		\
	tst-cancel19 tst-cancel20 tst-cancel21 tst-cancel22		\
	tst-cleanup0 tst-cleanup1 tst-cleanup2 tst-cleanup3		\
	tst-cleanup4 tst-clock1 tst-clock2 tst-cond1 tst-cond2		\
	tst-cond3 tst-cond4 tst-cond5 tst-cond6 tst-cond7 tst-cond8	\
	tst-cond9 tst-cond10 tst-cond11 tst-cond12 tst-cond13		\
	tst-cond14 tst-cond15 tst-cond16 tst-cond17 tst-cond18		\
	tst-cond19 tst-cond20 tst-cond21 tst-detach1 tst-eintr1		\
	tst-eintr2 tst-eintr3 tst-eintr4 tst-eintr5 tst-exec2 tst-exec3	\
	tst-exec4 tst-exit1 tst-exit2 tst-exit3 tst-flock1 tst-flock2	\
	tst-fork1 tst-fork2 tst-fork3 tst-fork4 tst-initializers1	\
	tst-join1 tst-join2 tst-join3 tst-join4 tst-join5 tst-key1	\
	tst-key2 tst-key3 tst-key4 tst-kill1 tst-kill2 tst-kill3	\
	tst-kill4 tst-kill5 tst-kill6 tst-mutex1 tst-mutex2 tst-mutex3	\
	tst-mutex4 tst-mutex5 tst-mutex6 tst-mutex7 tst-mutex8		\
	tst-mutex9 tst-mutex5a tst-mutex7a tst-once1 tst-once2		\
	tst-once3 tst-once4 tst-popen1 tst-raise1 tst-rwlock1		\
	tst-rwlock2 tst-rwlock3 tst-rwlock4 tst-rwlock5 tst-rwlock6	\
	tst-rwlock7 tst-rwlock8 tst-rwlock9 tst-rwlock10 tst-rwlock11	\
	tst-rwlock12 tst-rwlock13 tst-rwlock14 tst-sched1 tst-sem1	\
	tst-sem2 tst-sem3 tst-sem4 tst-sem5 tst-sem6 tst-sem7 tst-sem8	\
	tst-sem9 tst-signal1 tst-signal2 tst-signal3 tst-signal4	\
	tst-signal5 tst-signal6 tst-spin1 tst-spin2 tst-spin3		\
	tst-stack1 tst-stack2 tst-stdio1 tst-stdio2 tst-sysconf		\
	tst-tls1 tst-tls2 tst-tls3 tst-tls4 tst-tls5 tst-tsd1 tst-tsd2	\
	tst-tsd3 tst-tsd4 tst-tsd5 tst-umask1 tst-cond-deadlock 	\
	tst-align3 tst-cancel4 tst-cancel5 tst-cancel18 tst-cancel23	\
	tst-cancel25 tst-cancelx2 tst-cancelx3 tst-cancelx4 tst-cancelx6 \
	tst-cancelx7 tst-cancelx8 tst-cancelx9 tst-cancelx10 tst-cancelx11 \
	tst-cancelx12 tst-cancelx13 tst-cancelx14 tst-cancelx15 tst-cancelx16 \
	tst-cancelx18 tst-cancelx20 tst-cancelx21 tst-cleanupx0 tst-cleanupx1 \
	tst-cleanupx2 tst-cleanupx3 tst-cleanupx4 tst-cond22 tst-cond23 \
	tst-getpid1 tst-getpid2 tst-getpid3 tst-join6 tst-tsd6 \
	tst-oddstacklimit tst-oncex3 tst-oncex4 tst-rwlock2a  \
	tst-basic7 tst-signal7 tst-vfork1x tst-vfork2x tst-sem10 tst-sem11 \
	tst-sem12 tst-initializers1-c89 tst-initializers1-c99 \
	tst-initializers1-gnu89 tst-initializers1-gnu99 \
	tst-atfork2 tst-clockid

#
# These are for the RT library and POSIX timers.
#
TESTS += tst-clock tst-clock_nanosleep tst-cpuclock1 tst-cpuclock2	\
	tst-cputimer1 tst-cputimer2 tst-cputimer3 tst-mqueue1		\
	tst-mqueue2 tst-mqueue3 tst-mqueue4 tst-mqueue5 tst-mqueue6	\
	tst-mqueue7 tst-mqueue8 tst-mqueue9 tst-timer2 tst-timer3	\
	tst-timer4 tst-timer5


ifeq ($(TARGET_ARCH),i386)
CFLAGS_tst-align := -malign-double -mpreferred-stack-boundary=4
endif
ifeq ($(TARGET_ARCH),i686)
CFLAGS_tst-align := -malign-double -mpreferred-stack-boundary=4 -msse
endif
CFLAGS_tst-cleanup4aux.o := -W
CFLAGS_tst-initializers1 := -W -Werror
CFLAGS_tst-tls3mod.so := -fPIC -DPIC -DSHARED -shared
CFLAGS_tst-tls4moda.so := -fPIC -DPIC -DSHARED -shared
CFLAGS_tst-tls4modb.so := -fPIC -DPIC -DSHARED -shared
CFLAGS_tst-tls5mod.so := -fPIC -DPIC -DSHARED -shared
CFLAGS_tst-tls5moda.so := -fPIC -DPIC -DSHARED -shared
CFLAGS_tst-tls5modb.so := -fPIC -DPIC -DSHARED -shared
CFLAGS_tst-tls5modc.so := -fPIC -DPIC -DSHARED -shared
CFLAGS_tst-tls5modd.so := -fPIC -DPIC -DSHARED -shared
CFLAGS_tst-tls5mode.so := -fPIC -DPIC -DSHARED -shared
CFLAGS_tst-tls5modf.so := -fPIC -DPIC -DSHARED -shared

CFLAGS_tst-fini1mod.so := -fPIC -DPIC -DSHARED -shared
LDFLAGS_tst-cond11 = -lrt
LDFLAGS_tst-cond19 = -lrt

LDFLAGS_tst-rwlock14 = -lrt
LDFLAGS_tst-fini1 = -Wl,-rpath=./ tst-fini1mod.so
LDFLAGS_tst-fini1mod.so = -Wl,-soname=tst-fini1mod.so
LDFLAGS_tst-unload = -ldl
LDFLAGS_tst-cancel5 := -lpthread
LDFLAGS_tst-cancel18 := -lrt
LDFLAGS_tst-cancelx18 := -lrt
LDFLAGS_tst-cancel23 := -lc -lpthread
LDFLAGS_tst-vfork1x := -lc -lpthread
LDFLAGS_tst-vfork2x := -lc -lpthread

CFLAGS_tst-cancelx2 += -fexceptions
CFLAGS_tst-cancelx3 += -fexceptions
CFLAGS_tst-cancelx4 += -fexceptions
CFLAGS_tst-cancelx6 += -fexceptions
CFLAGS_tst-cancelx7 += -fexceptions
CFLAGS_tst-cancelx8 += -fexceptions
CFLAGS_tst-cancelx9 += -fexceptions
CFLAGS_tst-cancelx10 += -fexceptions
CFLAGS_tst-cancelx11 += -fexceptions
CFLAGS_tst-cancelx12 += -fexceptions
CFLAGS_tst-cancelx13 += -fexceptions
CFLAGS_tst-cancelx14 += -fexceptions
CFLAGS_tst-cancelx15 += -fexceptions
CFLAGS_tst-cancelx16 += -fexceptions
CFLAGS_tst-cancelx18 += -fexceptions
CFLAGS_tst-cancelx20 += -fexceptions -fasynchronous-unwind-tables
CFLAGS_tst-cancelx21 += -fexceptions -fasynchronous-unwind-tables
CFLAGS_tst-cleanupx0 += -fexceptions -fasynchronous-unwind-tables
CFLAGS_tst-cleanupx1 += -fexceptions -fasynchronous-unwind-tables
CFLAGS_tst-cleanupx2 += -fexceptions
CFLAGS_tst-cleanupx3 += -fexceptions

CFLAGS_tst-oncex3 += -fexceptions
CFLAGS_tst-oncex4 += -fexceptions
CFLAGS_tst-align += $(stack-align-test-flags)
CFLAGS_tst-align3 += $(stack-align-test-flags)
CFLAGS_tst-initializers1 = -W -Wall -Werror
CFLAGS_tst-sem11 += -fexceptions -fasynchronous-unwind-tables
CFLAGS_tst-sem12 += -fexceptions -fasynchronous-unwind-tables
CFLAGS_tst-initializers1 = -W -Wall -Werror
CFLAGS_tst-initializers1-c89 = $(CFLAGS-tst-initializers1) -std=c89
CFLAGS_tst-initializers1-c99 = $(CFLAGS-tst-initializers1) -std=c99
CFLAGS_tst-initializers1-gnu89 = $(CFLAGS-tst-initializers1) -std=gnu89
CFLAGS_tst-initializers1-gnu99 = $(CFLAGS-tst-initializers1) -std=gnu99
CFLAGS_tst-cpuclock1 += -std=c99
CFLAGS_tst-cpuclock2 += -std=c99
CFLAGS_tst-cputimer1 += -std=c99
CFLAGS_tst-cputimer2 += -std=c99
CFLAGS_tst-cputimer3 += -std=c99
CFLAGS_tst-mqueue1 += -std=c99
CFLAGS_tst-mqueue7 += -std=c99
CFLAGS_tst-mqueue8 += -std=c99
CFLAGS_tst-tsd6 += -std=c99

EXTRA_LDFLAGS = $(if $(findstring -lpthread,$(LDFLAGS_$@)),,-lpthread)

LDFLAGS_tst-atfork2 := -ldl -rdynamic
LDFLAGS_tst-atfork2mod.so := -shared -static-libgcc -lpthread
LDFLAGS_tst-cleanup4 := tst-cleanup4aux.o
LDFLAGS_tst-cleanupx4 := tst-cleanup4aux.o
LDFLAGS_tst-clock2 := -lrt
LDFLAGS_tst-cond11 := -lrt
LDFLAGS_tst-cond19 := -lrt
LDFLAGS_tst-rwlock14 := -lrt
LDFLAGS_tst-tls3 := -ldl -rdynamic
LDFLAGS_tst-tls4 := -ldl
LDFLAGS_tst-tls5 :=  tst-tls5mod.so
LDFLAGS_tst-clock := -lrt
LDFLAGS_tst-clock_nanosleep := -lrt
LDFLAGS_tst-cpuclock1 := -lrt
LDFLAGS_tst-cpuclock2 := -lrt -lpthread
LDFLAGS_tst-cputimer1 := -lrt -lpthread
LDFLAGS_tst-cputimer2 := -lrt -lpthread
LDFLAGS_tst-cputimer3 := -lrt -lpthread
LDFLAGS_tst-mqueue1 := -lrt
LDFLAGS_tst-mqueue2 := -lrt
LDFLAGS_tst-mqueue3 := -lrt -lpthread
LDFLAGS_tst-mqueue4 := -lrt
LDFLAGS_tst-mqueue5 := -lrt -lpthread
LDFLAGS_tst-mqueue6 := -lrt -lpthread
LDFLAGS_tst-mqueue7 := -lrt
LDFLAGS_tst-mqueue8 := -lrt
LDFLAGS_tst-mqueue9 := -lrt
LDFLAGS_tst-timer2 := -lrt -lpthread
LDFLAGS_tst-timer3 := -lrt -lpthread
LDFLAGS_tst-timer4 := -lrt -lpthread
LDFLAGS_tst-timer5 := -lrt -lpthread
LDFLAGS_tst-dlsym1 := -ldl -rdynamic
LDFLAGS_tst-tls3mod.so := -shared -static-libgcc -lpthread
LDFLAGS_tst-tls4moda.so := -shared -static-libgcc
LDFLAGS_tst-tls4modb.so := -shared -static-libgcc
LDFLAGS_tst-tls5mod.so := -shared -static-libgcc -Wl,-soname,tst-tls5mod.so
LDFLAGS_tst-tls5moda.so := -shared -static-libgcc
LDFLAGS_tst-tls5modb.so := -shared -static-libgcc
LDFLAGS_tst-tls5modc.so := -shared -static-libgcc
LDFLAGS_tst-tls5modd.so := -shared -static-libgcc
LDFLAGS_tst-tls5mode.so := -shared -static-libgcc
LDFLAGS_tst-tls5modf.so := -shared -static-libgcc
LDFLAGS_tst-cleanupx4 := tst-cleanup4aux.o

#
# Special case
#
tst-cleanup4aux.o:
	$(Q)$(CC) $(CFLAGS) $(CFLAGS_$@) $(EXTRA_CFLAGS) -c tst-cleanup4aux.c -o $@

tst-cleanup4: tst-cleanup4aux.o
tst-tls3: tst-tls3mod.so
tst-tls4: tst-tls4moda.so tst-tls4modb.so
tst-tls5: tst-tls5mod.so

tst-cleanupx4 : tst-cleanup4aux.o
tst-fini1: tst-fini1mod.so

tst-atfork2: tst-atfork2mod.so

OPTS_tst-cancel7 = -c ./tst-cancel7
OPTS_tst-mqueue7 = -- ./tst-mqueue7
OPTS_tst-exec4 = ./tst-exec4

WRAPPER := env LD_LIBRARY_PATH="$$PWD:.:$(LD_LIBRARY_PATH)" TIMEOUTFACTOR=10
