Test.mak 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. $(showlink)
  67. $(Q)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c $@.c -o $@.o
  68. $(Q)$(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$@)
  69. ifeq ($(COMPILE_ONLY),)
  70. $(exec_test)
  71. $(diff_test)
  72. endif
  73. $(G_TARGETS):
  74. $(showlink)
  75. $(Q)$(HOSTCC) $(HOST_CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(patsubst %_glibc,%,$@)) -c $(patsubst %_glibc,%,$@).c -o $@.o
  76. $(Q)$(HOSTCC) $(HOST_LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$(patsubst %_glibc,%,$@))
  77. ifeq ($(COMPILE_ONLY),)
  78. $(exec_test)
  79. $(diff_test)
  80. $(uclibc_glibc_diff_test)
  81. endif
  82. shell_%:
  83. ifeq ($(COMPILE_ONLY),)
  84. $(showtest)
  85. $(Q)$(SHELL) $(patsubst shell_%,%.sh,$@)
  86. endif
  87. %.so: %.c
  88. $(showlink)
  89. $(Q)$(CC) \
  90. $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(patsubst %_glibc,%,$@)) \
  91. -fPIC -shared $< -o $@ -Wl,-soname,$@ \
  92. $(LDFLAGS) $(EXTRA_LIBS) $(LDFLAGS_$(patsubst %_glibc,%,$@))
  93. clean:
  94. $(showclean)
  95. $(Q)$(RM) *.a *.o *.so *~ core *.out $(CLEAN_TARGETS) $(EXTRA_CLEAN)
  96. .PHONY: all check clean test