Test.mak 4.6 KB

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