Test.mak 3.2 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. RUN_TARGETS := $(patsubst %,%.exe,$(TARGETS))
  31. TARGETS += $(SHELL_TESTS)
  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" 2>&1 ; \
  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. exit 1 ; \
  61. fi
  62. $(SCAT) "$(binary_name).out"
  63. endef
  64. test check all: run
  65. run: $(RUN_TARGETS) compile
  66. $(RUN_TARGETS): $(TARGETS)
  67. $(exec_test)
  68. $(diff_test)
  69. ifeq ($(UCLIBC_ONLY),)
  70. $(uclibc_glibc_diff_test)
  71. endif
  72. compile: $(COMPILE_TARGETS)
  73. G_TARGET_SRCS := $(patsubst %,%.c,$(G_TARGETS))
  74. U_TARGET_SRCS := $(patsubst %,%.c,$(U_TARGETS))
  75. $(MAKE_SRCS): Makefile $(TESTDIR)Makefile $(TESTDIR)Rules.mak $(TESTDIR)Test.mak
  76. $(U_TARGETS): $(U_TARGET_SRCS) $(MAKE_SRCS)
  77. $(showlink)
  78. $(Q)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c $@.c -o $@.o
  79. $(Q)$(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$@)
  80. $(G_TARGETS): $(U_TARGET_SRCS) $(MAKE_SRCS)
  81. $(showlink)
  82. $(Q)$(HOSTCC) $(HOST_CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(patsubst %_glibc,%,$@)) -c $(patsubst %_glibc,%,$@).c -o $@.o
  83. $(Q)$(HOSTCC) $(HOST_LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$(patsubst %_glibc,%,$@))
  84. shell_%:
  85. $(showtest)
  86. $(Q)$(SHELL) $(patsubst shell_%,%.sh,$(binary_name))
  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 *.gdb $(CLEAN_TARGETS) $(EXTRA_CLEAN)
  96. $(Q)$(RM_R) $(EXTRA_DIRS)
  97. .PHONY: all check clean test run compile