Test.mak 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. echo "ret == $$ret ; expected_ret == $$expected_ret" ; \
  60. cat "$(binary_name).out" ; \
  61. exit 1 ; \
  62. fi
  63. $(SCAT) "$(binary_name).out"
  64. endef
  65. test check all: run
  66. run: $(RUN_TARGETS) compile
  67. $(RUN_TARGETS): $(TARGETS)
  68. ifeq ($(shell echo "$(SHELL_TESTS)"|grep "$(binary_name)"),)
  69. $(exec_test)
  70. $(diff_test)
  71. ifeq ($(UCLIBC_ONLY),)
  72. $(uclibc_glibc_diff_test)
  73. endif
  74. endif
  75. compile: $(COMPILE_TARGETS)
  76. G_TARGET_SRCS := $(patsubst %,%.c,$(G_TARGETS))
  77. U_TARGET_SRCS := $(patsubst %,%.c,$(U_TARGETS))
  78. $(MAKE_SRCS): Makefile $(TESTDIR)Makefile $(TESTDIR)Rules.mak $(TESTDIR)Test.mak
  79. $(U_TARGETS): $(U_TARGET_SRCS) $(MAKE_SRCS)
  80. $(showlink)
  81. $(Q)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c $@.c -o $@.o
  82. $(Q)$(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$@)
  83. $(G_TARGETS): $(U_TARGET_SRCS) $(MAKE_SRCS)
  84. $(showlink)
  85. $(Q)$(HOSTCC) $(HOST_CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(patsubst %_glibc,%,$@)) -c $(patsubst %_glibc,%,$@).c -o $@.o
  86. $(Q)$(HOSTCC) $(HOST_LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$(patsubst %_glibc,%,$@))
  87. shell_%:
  88. $(showtest)
  89. $(Q)$(SHELL) $(patsubst shell_%,%.sh,$(binary_name))
  90. %.so: %.c
  91. $(showlink)
  92. $(Q)$(CC) \
  93. $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(patsubst %_glibc,%,$@)) \
  94. -fPIC -shared $< -o $@ -Wl,-soname,$@ \
  95. $(LDFLAGS) $(EXTRA_LIBS) $(LDFLAGS_$(patsubst %_glibc,%,$@))
  96. clean:
  97. $(showclean)
  98. $(Q)$(RM) *.a *.o *.so *~ core *.out *.gdb $(CLEAN_TARGETS) $(EXTRA_CLEAN)
  99. .PHONY: all check clean test run compile