Test.mak 2.8 KB

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