Test.mak 4.0 KB

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