Test.mak 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. @true
  34. $(TARGETS): Makefile $(TESTDIR)Makefile $(TESTDIR)Rules.mak $(TESTDIR)Test.mak
  35. $(U_TARGETS): $(patsubst %,%.c,$(U_TARGETS))
  36. $(G_TARGETS): $(patsubst %_glibc,%.c,$(G_TARGETS))
  37. define diff_test
  38. $(Q)\
  39. for x in "$@.out" "$(patsubst %_glibc,%,$@).out" ; do \
  40. test -e "$$x.good" && $(do_showdiff) "$@.out" "$$x.good" && exec diff -u "$@.out" "$$x.good" ; \
  41. done ; \
  42. true
  43. endef
  44. define uclibc_glibc_diff_test
  45. $(Q)\
  46. test -z "$(DODIFF_$(patsubst %_glibc,%,$@))" && exec true ; \
  47. uclibc_out="$@.out" ; \
  48. glibc_out="$(patsubst %_glibc,%,$@).out" ; \
  49. $(do_showdiff) $$uclibc_out $$glibc_out ; \
  50. exec diff -u "$$uclibc_out" "$$glibc_out"
  51. endef
  52. define exec_test
  53. $(showtest)
  54. $(Q)\
  55. $(WRAPPER) $(WRAPPER_$(patsubst %_glibc,%,$@)) \
  56. ./$@ $(OPTS) $(OPTS_$(patsubst %_glibc,%,$@)) &> "$@.out" ; \
  57. ret=$$? ; \
  58. expected_ret="$(RET_$(patsubst %_glibc,%,$@))" ; \
  59. test -z "$$expected_ret" && export expected_ret=0 ; \
  60. if ! test $$ret -eq $$expected_ret ; then \
  61. $(RM) $@ ; \
  62. echo "ret == $$ret ; expected_ret == $$expected_ret" ; \
  63. cat "$@.out" ; \
  64. exit 1 ; \
  65. fi
  66. $(SCAT) "$@.out"
  67. endef
  68. $(U_TARGETS):
  69. ifeq ($(CHECK_ONLY),)
  70. $(showlink)
  71. $(Q)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c $@.c -o $@.o
  72. $(Q)$(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$@)
  73. endif
  74. ifeq ($(COMPILE_ONLY),)
  75. $(exec_test)
  76. $(diff_test)
  77. endif
  78. $(G_TARGETS):
  79. $(showlink)
  80. $(Q)$(HOSTCC) $(HOST_CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(patsubst %_glibc,%,$@)) -c $(patsubst %_glibc,%,$@).c -o $@.o
  81. $(Q)$(HOSTCC) $(HOST_LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$(patsubst %_glibc,%,$@))
  82. ifeq ($(COMPILE_ONLY),)
  83. $(exec_test)
  84. $(diff_test)
  85. $(uclibc_glibc_diff_test)
  86. endif
  87. shell_%:
  88. ifeq ($(COMPILE_ONLY),)
  89. $(showtest)
  90. $(Q)$(SHELL) $(patsubst shell_%,%.sh,$@)
  91. endif
  92. %.so: %.c
  93. $(showlink)
  94. $(Q)$(CC) \
  95. $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(patsubst %_glibc,%,$@)) \
  96. -fPIC -shared $< -o $@ -Wl,-soname,$@ \
  97. $(LDFLAGS) $(EXTRA_LIBS) $(LDFLAGS_$(patsubst %_glibc,%,$@))
  98. clean:
  99. $(showclean)
  100. $(Q)$(RM) *.a *.o *.so *~ core *.out *.gdb $(CLEAN_TARGETS) $(EXTRA_CLEAN)
  101. .PHONY: all check clean test