Test.mak 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # Common makefile rules for tests
  2. #
  3. # Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  4. #
  5. # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. ifeq ($(TESTS),)
  7. TESTS := $(patsubst %.c,%,$(wildcard *.c))
  8. endif
  9. ifneq ($(TESTS_DISABLED),)
  10. TESTS := $(filter-out $(TESTS_DISABLED),$(TESTS))
  11. endif
  12. ifeq ($(SHELL_TESTS),)
  13. SHELL_TESTS := $(patsubst %.sh,shell_%,$(wildcard *.sh))
  14. endif
  15. ifneq ($(filter-out test,$(TESTS)),$(TESTS))
  16. $(error Sanity check: cannot have a test named "test.c")
  17. endif
  18. top_builddir = ../../
  19. include ../Rules.mak
  20. U_TARGETS := $(TESTS)
  21. G_TARGETS := $(patsubst %,%_glibc,$(U_TARGETS))
  22. U_TARGETS += $(U_TESTS)
  23. G_TARGETS += $(G_TESTS)
  24. TARGETS := $(SHELL_TESTS)
  25. ifeq ($(GLIBC_ONLY),)
  26. TARGETS += $(U_TARGETS)
  27. endif
  28. ifeq ($(UCLIBC_ONLY),)
  29. TARGETS += $(G_TARGETS)
  30. endif
  31. CLEAN_TARGETS := $(U_TARGETS) $(G_TARGETS)
  32. test check all: $(TARGETS)
  33. $(TARGETS): Makefile $(TESTDIR)Makefile $(TESTDIR)Rules.mak $(TESTDIR)Test.mak
  34. $(U_TARGETS): $(patsubst %,%.c,$(U_TARGETS))
  35. $(G_TARGETS): $(patsubst %_glibc,%.c,$(G_TARGETS))
  36. define diff_test
  37. $(Q)\
  38. for x in "$@.out" "$(patsubst %_glibc,%,$@).out" ; do \
  39. test -e "$$x.good" && $(do_showdiff) "$@.out" "$$x.good" && exec diff -u "$@.out" "$$x.good" ; \
  40. done ; \
  41. true
  42. endef
  43. define uclibc_glibc_diff_test
  44. $(Q)\
  45. test -z "$(DODIFF_$(patsubst %_glibc,%,$@))" && exec true ; \
  46. uclibc_out="$@.out" ; \
  47. glibc_out="$(patsubst %_glibc,%,$@).out" ; \
  48. $(do_showdiff) $$uclibc_out $$glibc_out ; \
  49. exec diff -u "$$uclibc_out" "$$glibc_out"
  50. endef
  51. define exec_test
  52. $(showtest)
  53. $(Q)\
  54. $(WRAPPER) $(WRAPPER_$(patsubst %_glibc,%,$@)) \
  55. ./$@ $(OPTS) $(OPTS_$(patsubst %_glibc,%,$@)) &> "$@.out" ; \
  56. ret=$$? ; \
  57. expected_ret="$(RET_$(patsubst %_glibc,%,$@))" ; \
  58. test -z "$$expected_ret" && export expected_ret=0 ; \
  59. if ! test $$ret -eq $$expected_ret ; then \
  60. $(RM) $@ ; \
  61. cat "$@.out" ; \
  62. exec false ; \
  63. fi
  64. $(SCAT) "$@.out"
  65. endef
  66. $(U_TARGETS):
  67. ifeq ($(CHECK_ONLY),)
  68. $(showlink)
  69. $(Q)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c $@.c -o $@.o
  70. $(Q)$(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$@)
  71. endif
  72. ifeq ($(COMPILE_ONLY),)
  73. $(exec_test)
  74. $(diff_test)
  75. endif
  76. $(G_TARGETS):
  77. $(showlink)
  78. $(Q)$(HOSTCC) $(HOST_CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(patsubst %_glibc,%,$@)) -c $(patsubst %_glibc,%,$@).c -o $@.o
  79. $(Q)$(HOSTCC) $(HOST_LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$(patsubst %_glibc,%,$@))
  80. ifeq ($(COMPILE_ONLY),)
  81. $(exec_test)
  82. $(diff_test)
  83. $(uclibc_glibc_diff_test)
  84. endif
  85. shell_%:
  86. ifeq ($(COMPILE_ONLY),)
  87. $(showtest)
  88. $(Q)$(SHELL) $(patsubst shell_%,%.sh,$@)
  89. endif
  90. %.so: %.c
  91. $(showlink)
  92. $(Q)$(CC) \
  93. $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(patsubst %_glibc,%,$@)) \
  94. -fPIC -shared $< -o $@ -Wl,-soname,$@ \
  95. $(LDFLAGS) $(EXTRA_LIBS) $(LDFLAGS_$(patsubst %_glibc,%,$@))
  96. clean:
  97. $(showclean)
  98. $(Q)$(RM) *.a *.o *.so *~ core *.out *.gdb $(CLEAN_TARGETS) $(EXTRA_CLEAN)
  99. .PHONY: all check clean test