Test.mak 3.1 KB

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