1#===- test/Makefile ----------------------------------------*- Makefile -*--===#
2#
3#                     The LLVM Compiler Infrastructure
4#
5# This file is distributed under the University of Illinois Open Source
6# License. See LICENSE.TXT for details.
7#
8#===------------------------------------------------------------------------===#
9
10LEVEL = ..
11DIRS  =
12
13all:: check-local
14
15# 'lit' is the default test runner.
16check-local:: check-local-lit
17
18# Include other test rules
19include Makefile.tests
20
21#===------------------------------------------------------------------------===#
22# DejaGNU testing support
23#===------------------------------------------------------------------------===#
24
25ifneq ($(GREP_OPTIONS),)
26$(warning GREP_OPTIONS environment variable may interfere with test results)
27endif
28
29ifdef VERBOSE
30RUNTESTFLAGS := $(VERBOSE)
31LIT_ARGS := -v
32else
33LIT_ARGS := -s -v
34endif
35
36# -jN causes crash on Cygwin's python.
37ifneq (,$(filter $(HOST_OS),Cygwin))
38  LIT_ARGS += -j1
39endif
40
41ifdef TESTSUITE
42LIT_TESTSUITE := $(TESTSUITE)
43CLEANED_TESTSUITE := $(patsubst %/,%,$(TESTSUITE))
44CLEANED_TESTSUITE := $(patsubst test/%,%,$(CLEANED_TESTSUITE))
45RUNTESTFLAGS += --tool $(CLEANED_TESTSUITE)
46else
47LIT_TESTSUITE := .
48endif
49
50ifdef VG
51VALGRIND := valgrind --tool=memcheck --quiet --trace-children=yes --error-exitcode=3 --leak-check=full $(VALGRIND_EXTRA_ARGS)
52endif
53
54# Check what to run for -all.
55LIT_ALL_TESTSUITES := $(LIT_TESTSUITE)
56
57extra-lit-site-cfgs::
58.PHONY: extra-lit-site-cfgs
59
60ifneq ($(strip $(filter check-local-all,$(MAKECMDGOALS))),)
61ifndef TESTSUITE
62ifeq ($(shell test -d $(PROJ_SRC_DIR)/../tools/clang && echo OK), OK)
63LIT_ALL_TESTSUITES += $(PROJ_OBJ_DIR)/../tools/clang/test
64
65# Force creation of Clang's lit.site.cfg.
66clang-lit-site-cfg: FORCE
67	$(MAKE) -C $(PROJ_OBJ_DIR)/../tools/clang/test lit.site.cfg Unit/lit.site.cfg
68extra-lit-site-cfgs:: clang-lit-site-cfg
69endif
70endif
71endif
72
73IGNORE_TESTS :=
74
75ifndef RUNLLVM2CPP
76IGNORE_TESTS += llvm2cpp.exp
77endif
78
79ifdef IGNORE_TESTS
80RUNTESTFLAGS += --ignore "$(strip $(IGNORE_TESTS))"
81endif
82
83# ulimits like these are redundantly enforced by the buildbots, so
84# just removing them here won't work.
85# Both AuroraUX & Solaris do not have the -m flag for ulimit
86ifeq ($(HOST_OS),SunOS)
87ULIMIT=ulimit -t 600 ; ulimit -d 512000 ; ulimit -v 512000 ;
88else # !SunOS
89ifeq ($(HOST_OS),AuroraUX)
90ULIMIT=ulimit -t 600 ; ulimit -d 512000 ; ulimit -v 512000 ;
91else # !AuroraUX
92# Fedora 13 x86-64 python fails with -v 76800
93ULIMIT=ulimit -t 600 ; ulimit -d 512000 ; ulimit -m 512000 ; ulimit -v 1024000 ;
94endif # AuroraUX
95endif # SunOS
96
97ifneq ($(RUNTEST),)
98check-local-dg:: site.exp
99	( $(ULIMIT) \
100	  PATH="$(LLVMToolDir):$(LLVM_SRC_ROOT)/test/Scripts:$(LLVMGCCDIR)/bin:$(PATH)" \
101	  $(RUNTEST) $(RUNTESTFLAGS) )
102else
103check-local-dg:: site.exp
104	@echo "*** dejagnu not found.  Make sure 'runtest' is in your PATH, then reconfigure LLVM."
105endif
106
107check-local-lit:: lit.site.cfg Unit/lit.site.cfg
108	( $(ULIMIT) \
109	  $(LLVM_SRC_ROOT)/utils/lit/lit.py $(LIT_ARGS) $(LIT_TESTSUITE) )
110
111check-local-all:: lit.site.cfg Unit/lit.site.cfg extra-lit-site-cfgs
112	( $(ULIMIT) \
113	  $(LLVM_SRC_ROOT)/utils/lit/lit.py $(LIT_ARGS) $(LIT_ALL_TESTSUITES) )
114
115clean::
116	$(RM) -rf `find $(LLVM_OBJ_ROOT)/test -name Output -type d -print`
117
118# dsymutil is used on the Darwin to manipulate DWARF debugging information.
119ifeq ($(TARGET_OS),Darwin)
120DSYMUTIL=dsymutil
121else
122DSYMUTIL=true
123endif
124ifdef TargetCommonOpts
125BUGPOINT_TOPTS="-gcc-tool-args $(TargetCommonOpts)"
126else
127BUGPOINT_TOPTS=""
128endif
129
130ifneq ($(OCAMLOPT),)
131CC_FOR_OCAMLOPT := $(shell $(OCAMLOPT) -config | grep native_c_compiler | sed -e 's/native_c_compiler: //')
132CXX_FOR_OCAMLOPT := $(subst gcc,g++,$(CC_FOR_OCAMLOPT))
133endif
134
135FORCE:
136
137site.exp: FORCE
138	@echo 'Making a new site.exp file...'
139	@echo '## Autogenerated by LLVM configuration.' > site.tmp
140	@echo '# Do not edit!' >> site.tmp
141	@echo 'set target_triplet "$(TARGET_TRIPLE)"' >> site.tmp
142	@echo 'set TARGETS_TO_BUILD "$(TARGETS_TO_BUILD)"' >> site.tmp
143	@echo 'set llvmgcc_langs "$(LLVMGCC_LANGS)"' >> site.tmp
144	@echo 'set llvmtoolsdir "$(ToolDir)"' >>site.tmp
145	@echo 'set llvmlibsdir "$(LibDir)"' >>site.tmp
146	@echo 'set llvmshlibdir "$(SharedLibDir)"' >>site.tmp
147	@echo 'set llvm_bindings "$(BINDINGS_TO_BUILD)"' >> site.tmp
148	@echo 'set srcroot "$(LLVM_SRC_ROOT)"' >>site.tmp
149	@echo 'set objroot "$(LLVM_OBJ_ROOT)"' >>site.tmp
150	@echo 'set srcdir "$(LLVM_SRC_ROOT)/test"' >>site.tmp
151	@echo 'set objdir "$(LLVM_OBJ_ROOT)/test"' >>site.tmp
152	@echo 'set gccpath "$(CC)"' >>site.tmp
153	@echo 'set gxxpath "$(CXX)"' >>site.tmp
154	@echo 'set compile_c "' $(CC) $(CPP.Flags) $(TargetCommonOpts) $(CompileCommonOpts) -c '"' >>site.tmp
155	@echo 'set compile_cxx "' $(CXX) $(CPP.Flags) $(CXX.Flags) $(TargetCommonOpts) $(CompileCommonOpts) -c -x c++ '"' >> site.tmp
156	@echo 'set link "' $(CXX) $(CPP.Flags) $(CXX.Flags) $(TargetCommonOpts) $(CompileCommonOpts) $(LD.Flags) '"' >>site.tmp
157	@echo 'set llvmgcc "$(LLVMGCC) $(TargetCommonOpts) $(EXTRA_OPTIONS)"' >> site.tmp
158	@echo 'set llvmgxx "$(LLVMGCC) $(TargetCommonOpts) $(EXTRA_OPTIONS)"' >> site.tmp
159	@echo 'set bugpoint_topts $(BUGPOINT_TOPTS)' >> site.tmp
160	@echo 'set shlibext "$(SHLIBEXT)"' >> site.tmp
161	@echo 'set ocamlopt "$(OCAMLOPT) -cc \"$(CXX_FOR_OCAMLOPT)\" -I $(LibDir)/ocaml"' >> site.tmp
162	@echo 'set valgrind "$(VALGRIND)"' >> site.tmp
163	@echo 'set grep "$(GREP)"' >>site.tmp
164	@echo 'set gas "$(GAS)"' >>site.tmp
165	@echo 'set llvmdsymutil "$(DSYMUTIL)"' >>site.tmp
166	@echo 'set emitir "$(LLVMCC_EMITIR_FLAG)"' >>site.tmp
167	@echo '## All variables above are generated by configure. Do Not Edit ## ' >>site.tmp
168	@test ! -f site.exp || \
169	sed '1,/^## All variables above are.*##/ d' site.exp >> site.tmp
170	@-rm -f site.bak
171	@test ! -f site.exp || mv site.exp site.bak
172	@mv site.tmp site.exp
173
174ifeq ($(DISABLE_ASSERTIONS),1)
175ENABLE_ASSERTIONS=0
176else
177ENABLE_ASSERTIONS=1
178endif
179
180lit.site.cfg: site.exp
181	@echo "Making LLVM 'lit.site.cfg' file..."
182	@$(ECHOPATH) s=@LLVM_SOURCE_DIR@=$(LLVM_SRC_ROOT)=g > lit.tmp
183	@$(ECHOPATH) s=@LLVM_BINARY_DIR@=$(LLVM_OBJ_ROOT)=g >> lit.tmp
184	@$(ECHOPATH) s=@LLVM_TOOLS_DIR@=$(ToolDir)=g >> lit.tmp
185	@$(ECHOPATH) s=@LLVMGCCDIR@=$(LLVMGCCDIR)=g >> lit.tmp
186	@$(ECHOPATH) s=@PYTHON_EXECUTABLE@=python=g >> lit.tmp
187	@$(ECHOPATH) s=@ENABLE_SHARED@=$(ENABLE_SHARED)=g >> lit.tmp
188	@$(ECHOPATH) s=@ENABLE_ASSERTIONS@=$(ENABLE_ASSERTIONS)=g >> lit.tmp
189	@sed -f lit.tmp $(PROJ_SRC_DIR)/lit.site.cfg.in > $@
190	@-rm -f lit.tmp
191
192Unit/lit.site.cfg: $(PROJ_OBJ_DIR)/Unit/.dir FORCE
193	@echo "Making LLVM unittest 'lit.site.cfg' file..."
194	@$(ECHOPATH) s=@LLVM_SOURCE_DIR@=$(LLVM_SRC_ROOT)=g > unit.tmp
195	@$(ECHOPATH) s=@LLVM_BINARY_DIR@=$(LLVM_OBJ_ROOT)=g >> unit.tmp
196	@$(ECHOPATH) s=@LLVM_TOOLS_DIR@=$(ToolDir)=g >> unit.tmp
197	@$(ECHOPATH) s=@LLVMGCCDIR@=$(LLVMGCCDIR)=g >> unit.tmp
198	@$(ECHOPATH) s=@LLVM_BUILD_MODE@=$(BuildMode)=g >> unit.tmp
199	@$(ECHOPATH) s=@ENABLE_SHARED@=$(ENABLE_SHARED)=g >> unit.tmp
200	@$(ECHOPATH) s=@SHLIBDIR@=$(SharedLibDir)=g >> unit.tmp
201	@$(ECHOPATH) s=@SHLIBPATH_VAR@=$(SHLIBPATH_VAR)=g >> unit.tmp
202	@sed -f unit.tmp $(PROJ_SRC_DIR)/Unit/lit.site.cfg.in > $@
203	@-rm -f unit.tmp
204