Test.mak 3.5 KB

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