Test.mak 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. include ../Rules.mak
  13. U_TARGETS := $(TESTS)
  14. G_TARGETS := $(patsubst %,%_glibc,$(U_TARGETS))
  15. U_TARGETS += $(U_TESTS)
  16. G_TARGETS += $(G_TESTS)
  17. TARGETS =
  18. ifeq ($(GLIBC_ONLY),)
  19. TARGETS += $(U_TARGETS)
  20. endif
  21. ifeq ($(UCLIBC_ONLY),)
  22. TARGETS += $(G_TARGETS)
  23. endif
  24. CLEAN_TARGETS := $(U_TARGETS) $(G_TARGETS)
  25. test check all: $(TARGETS)
  26. # dummy rule to prevent the "Nothing to be done for `all'." message
  27. ifeq ($(Q),@)
  28. @true
  29. endif
  30. $(TARGETS): Makefile $(TESTDIR)Makefile $(TESTDIR)Rules.mak $(TESTDIR)Test.mak
  31. $(U_TARGETS): $(patsubst %,%.c,$(U_TARGETS))
  32. $(G_TARGETS): $(patsubst %_glibc,%.c,$(G_TARGETS))
  33. define diff_test
  34. $(Q)\
  35. for x in "$@.out" "$(patsubst %_glibc,%,$@).out" ; do \
  36. test -e "$$x.good" && $(do_showdiff) "$@.out" "$$x.good" && exec diff -u "$@.out" "$$x.good" ; \
  37. done ; \
  38. true
  39. endef
  40. define uclibc_glibc_diff_test
  41. $(Q)\
  42. test -z "$(DODIFF_$(patsubst %_glibc,%,$@))" && exec true ; \
  43. uclibc_out="$@.out" ; \
  44. glibc_out="$(patsubst %_glibc,%,$@).out" ; \
  45. $(do_showdiff) $$uclibc_out $$glibc_out ; \
  46. exec diff -u "$$uclibc_out" "$$glibc_out"
  47. endef
  48. define exec_test
  49. $(showtest)
  50. $(Q)\
  51. $(WRAPPER) $(WRAPPER_$(patsubst %_glibc,%,$@)) \
  52. ./$@ $(OPTS) $(OPTS_$(patsubst %_glibc,%,$@)) &> "$@.out" ; \
  53. ret=$$? ; \
  54. expected_ret="$(RET_$(patsubst %_glibc,%,$@))" ; \
  55. test -z "$$expected_ret" && export expected_ret=0 ; \
  56. if ! test $$ret -eq $$expected_ret ; then \
  57. $(RM) $@ ; \
  58. cat "$@.out" ; \
  59. exec false ; \
  60. fi
  61. $(SCAT) "$@.out"
  62. endef
  63. $(U_TARGETS):
  64. $(showlink)
  65. $(Q)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c $@.c -o $@.o
  66. $(Q)$(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$@)
  67. ifeq ($(COMPILE_ONLY),)
  68. $(exec_test)
  69. $(diff_test)
  70. endif
  71. $(G_TARGETS):
  72. $(showlink)
  73. $(Q)$(HOSTCC) $(HOST_CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(patsubst %_glibc,%,$@)) -c $(patsubst %_glibc,%,$@).c -o $@.o
  74. $(Q)$(HOSTCC) $(HOST_LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$(patsubst %_glibc,%,$@))
  75. ifeq ($(COMPILE_ONLY),)
  76. $(exec_test)
  77. $(diff_test)
  78. $(uclibc_glibc_diff_test)
  79. endif
  80. %.so: %.c
  81. $(showlink)
  82. $(Q)$(CC) \
  83. $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(patsubst %_glibc,%,$@)) \
  84. -fPIC -shared $< -o $@ -Wl,-soname,$@ \
  85. $(LDFLAGS) $(EXTRA_LIBS) $(LDFLAGS_$(patsubst %_glibc,%,$@))
  86. clean:
  87. $(showclean)
  88. $(Q)$(RM) *.a *.o *.so *~ core *.out $(CLEAN_TARGETS) $(EXTRA_CLEAN)