Test.mak 3.3 KB

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