Test.mak 3.9 KB

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