Test.mak 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. $(SIMULATOR) $(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. $(addsuffix .exe,$(U_TARGETS)): SIMULATOR:=$(SIMULATOR_uclibc)
  80. $(addsuffix .exe,$(G_TARGETS)): SIMULATOR:=$(SIMULATOR_glibc)
  81. $(RUN_TARGETS):
  82. $(exec_test)
  83. $(diff_test)
  84. ifeq ($(UCLIBC_ONLY),)
  85. $(uclibc_glibc_diff_test)
  86. endif
  87. compile: $(COMPILE_TARGETS)
  88. G_TARGET_SRCS := $(addsuffix .c,$(G_TARGETS))
  89. U_TARGET_SRCS := $(addsuffix .c,$(U_TARGETS))
  90. $(MAKE_SRCS): Makefile $(TESTDIR)Makefile $(TESTDIR)Rules.mak $(TESTDIR)Test.mak
  91. $(U_TARGETS): $(U_TARGET_SRCS) $(MAKE_SRCS)
  92. $(showlink)
  93. $(Q)$(CC) $(filter-out $(CFLAGS-OMIT-$@),$(CFLAGS)) $(EXTRA_CFLAGS) $(CFLAGS_$(notdir $(CURDIR))) $(CFLAGS_$@) -c $@.c -o $@.o
  94. $(Q)$(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$@)
  95. $(G_TARGETS): $(U_TARGET_SRCS) $(MAKE_SRCS)
  96. $(showlink)
  97. $(Q)$(HOSTCC) $(filter-out $(HOST_CFLAGS-OMIT-$(patsubst %_glibc,%,$@)),$(HOST_CFLAGS)) \
  98. $(CFLAGS_$(notdir $(CURDIR))) $(CFLAGS_$(patsubst %_glibc,%,$@)) \
  99. -c $(patsubst %_glibc,%,$@).c -o $@.o
  100. $(Q)$(HOSTCC) $(HOST_LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$(patsubst %_glibc,%,$@)) $(LDFLAGS_$@)
  101. shell_%:
  102. $(showtest)
  103. $(Q)$(if $(PRE_RUN_$(@)),$(PRE_RUN_$(@)))
  104. $(Q)$(SHELL) $(patsubst shell_%,%.sh,$(binary_name))
  105. $(Q)$(if $(POST_RUN_$(@)),$(POST_RUN_$(@)))
  106. %.so: %.c
  107. $(showlink)
  108. $(Q)$(CC) \
  109. $(filter-out $(CFLAGS-OMIT-$<),$(CFLAGS)) $(EXTRA_CFLAGS) \
  110. $(CFLAGS_$(patsubst %_glibc,%,$@)) \
  111. -fPIC -shared $< -o $@ -Wl,-soname,$@ \
  112. $(filter-out $(LDFLAGS-OMIT-$<),$(LDFLAGS)) $(EXTRA_LIBS) \
  113. $(LDFLAGS_$(patsubst %_glibc,%,$@))
  114. clean:
  115. $(showclean)
  116. $(Q)$(RM) *.a *.o *.so *~ core *.out *.gdb $(CLEAN_TARGETS) $(EXTRA_CLEAN)
  117. $(Q)$(RM_R) $(EXTRA_DIRS)
  118. .PHONY: all check clean test run compile