Add a VALGRIND_EXTRA_ARGS makefile variable, with the obvious semantics.
[oota-llvm.git] / test / Makefile
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
10 LEVEL = ..
11 DIRS  =
12
13 #
14 # Make Dejagnu the default for testing
15 #
16 all:: check-local
17
18 # Include other test rules
19 include Makefile.tests
20
21 #===------------------------------------------------------------------------===#
22 # DejaGNU testing support
23 #===------------------------------------------------------------------------===#
24
25 ifneq ($(GREP_OPTIONS),)
26 $(warning GREP_OPTIONS environment variable may interfere with test results)
27 endif
28
29 ifdef VERBOSE
30 RUNTESTFLAGS := $(VERBOSE)
31 LIT_ARGS := -v
32 else
33 LIT_ARGS := -s -v
34 endif
35
36 ifdef TESTSUITE
37 LIT_TESTSUITE := $(TESTSUITE)
38 CLEANED_TESTSUITE := $(patsubst %/,%,$(TESTSUITE))
39 CLEANED_TESTSUITE := $(patsubst test/%,%,$(CLEANED_TESTSUITE))
40 RUNTESTFLAGS += --tool $(CLEANED_TESTSUITE)
41 else
42 LIT_TESTSUITE := .
43 endif
44
45 ifdef VG
46 VALGRIND := valgrind --tool=memcheck --quiet --trace-children=yes --error-exitcode=3 --leak-check=full $(VALGRIND_EXTRA_ARGS)
47 endif
48
49 IGNORE_TESTS :=
50
51 ifndef RUNLLVM2CPP
52 IGNORE_TESTS += llvm2cpp.exp
53 endif
54
55 ifdef IGNORE_TESTS
56 RUNTESTFLAGS += --ignore "$(strip $(IGNORE_TESTS))"
57 endif
58
59 # Both AuroraUX & Solaris do not have the -m flag for ulimit
60 ifeq ($(HOST_OS),SunOS)
61 ULIMIT=ulimit -t 600 ; ulimit -d 512000 ; ulimit -v 512000 ;
62 else
63 ULIMIT=ulimit -t 600 ; ulimit -d 512000 ; ulimit -m 512000 ; ulimit -v 512000 ;
64 endif
65
66 ifneq ($(RUNTEST),)
67 check-local:: site.exp
68         ( $(ULIMIT) \
69           PATH="$(LLVMToolDir):$(LLVM_SRC_ROOT)/test/Scripts:$(LLVMGCCDIR)/bin:$(PATH)" \
70           $(RUNTEST) $(RUNTESTFLAGS) )
71 else
72 check-local:: site.exp
73         @echo "*** dejagnu not found.  Make sure 'runtest' is in your PATH, then reconfigure LLVM."
74 endif
75
76 check-local-lit:: lit.site.cfg Unit/lit.site.cfg
77         ( $(ULIMIT) \
78           $(LLVM_SRC_ROOT)/utils/lit/lit.py \
79                 --path "$(LLVMToolDir)" \
80                 --path "$(LLVM_SRC_ROOT)/test/Scripts" \
81                 --path "$(LLVMGCCDIR)/bin" \
82                 $(LIT_ARGS) $(LIT_TESTSUITE) )
83
84 ifdef TESTONE
85 CLEANED_TESTONE := $(patsubst %/,%,$(TESTONE))
86 CLEANED_TESTONE := $(patsubst test/%,%,$(CLEANED_TESTONE))
87 SUBDIR := $(shell dirname $(CLEANED_TESTONE))
88 TESTPATH := $(LLVM_SRC_ROOT)/test/$(CLEANED_TESTONE)
89 check-one: site.exp $(TCLSH)
90         $(Verb)( echo "source $(LLVM_OBJ_ROOT)/test/site.exp" ; \
91           echo "set subdir $(SUBDIR)" ; \
92           echo "proc pass  { msg } { puts \"PASS: \$$msg\" } "; \
93           echo "proc fail  { msg } { puts \"FAIL: \$$msg\" }" ; \
94           echo "proc xfail { msg } { puts \"XFAIL: \$$msg\" }" ; \
95           echo "proc xpass { msg } { puts \"XPASS: \$$msg\" }" ; \
96           echo "proc verbose args { }" ; \
97           echo "source $(LLVM_SRC_ROOT)/test/lib/llvm.exp" ; \
98           echo "RunLLVMTests $(TESTPATH)" ) | \
99         ( $(ULIMIT) \
100           PATH="$(LLVMToolDir):$(LLVM_SRC_ROOT)/test/Scripts:$(PATH)" \
101           $(TCLSH) )
102 endif
103
104 clean::
105         $(RM) -rf `find $(LLVM_OBJ_ROOT)/test -name Output -type d -print`
106
107 # dsymutil is used on the Darwin to manipulate DWARF debugging information.
108 ifeq ($(TARGET_OS),Darwin)
109 DSYMUTIL=dsymutil
110 else
111 DSYMUTIL=true
112 endif
113 ifdef TargetCommonOpts
114 BUGPOINT_TOPTS="-gcc-tool-args $(TargetCommonOpts)"
115 else
116 BUGPOINT_TOPTS=""
117 endif
118
119 ifneq ($(OCAMLOPT),)
120 CC_FOR_OCAMLOPT := $(shell $(OCAMLOPT) -config | grep native_c_compiler | sed -e 's/native_c_compiler: //')
121 CXX_FOR_OCAMLOPT := $(subst gcc,g++,$(CC_FOR_OCAMLOPT))
122 endif
123
124 FORCE:
125
126 site.exp: FORCE
127         @echo 'Making a new site.exp file...'
128         @echo '## these variables are automatically generated by make ##' >site.tmp
129         @echo '# Do not edit here.  If you wish to override these values' >>site.tmp
130         @echo '# edit the last section' >>site.tmp
131         @echo 'set target_triplet "$(TARGET_TRIPLE)"' >> site.tmp
132         @echo 'set TARGETS_TO_BUILD "$(TARGETS_TO_BUILD)"' >> site.tmp
133         @echo 'set llvmgcc_langs "$(LLVMGCC_LANGS)"' >> site.tmp
134         @echo 'set llvmgcc_version "$(LLVMGCC_VERSION)"' >> site.tmp
135         @echo 'set llvmtoolsdir "$(ToolDir)"' >>site.tmp
136         @echo 'set llvmlibsdir "$(LibDir)"' >>site.tmp
137         @echo 'set llvm_bindings "$(BINDINGS_TO_BUILD)"' >> site.tmp
138         @echo 'set srcroot "$(LLVM_SRC_ROOT)"' >>site.tmp
139         @echo 'set objroot "$(LLVM_OBJ_ROOT)"' >>site.tmp
140         @echo 'set srcdir "$(LLVM_SRC_ROOT)/test"' >>site.tmp
141         @echo 'set objdir "$(LLVM_OBJ_ROOT)/test"' >>site.tmp
142         @echo 'set gccpath "$(CC)"' >>site.tmp
143         @echo 'set gxxpath "$(CXX)"' >>site.tmp
144         @echo 'set compile_c "' $(CC) $(CPP.Flags) $(TargetCommonOpts) $(CompileCommonOpts) -c '"' >>site.tmp
145         @echo 'set compile_cxx "' $(CXX) $(CPP.Flags) $(CXX.Flags) $(TargetCommonOpts) $(CompileCommonOpts) -c '"' >> site.tmp
146         @echo 'set link "' $(CXX) $(CPP.Flags) $(CXX.Flags) $(TargetCommonOpts) $(CompileCommonOpts) $(LD.Flags) '"' >>site.tmp
147         @echo 'set llvmgcc "$(LLVMGCC) $(TargetCommonOpts) $(EXTRA_OPTIONS)"' >> site.tmp
148         @echo 'set llvmgxx "$(LLVMGCC) $(TargetCommonOpts) $(EXTRA_OPTIONS)"' >> site.tmp
149         @echo 'set llvmgccmajvers "$(LLVMGCC_MAJVERS)"' >> site.tmp
150         @echo 'set bugpoint_topts $(BUGPOINT_TOPTS)' >> site.tmp
151         @echo 'set shlibext "$(SHLIBEXT)"' >> site.tmp
152         @echo 'set ocamlopt "$(OCAMLOPT) -cc \"$(CXX_FOR_OCAMLOPT)\" -I $(LibDir)/ocaml"' >> site.tmp
153         @echo 'set valgrind "$(VALGRIND)"' >> site.tmp
154         @echo 'set grep "$(GREP)"' >>site.tmp
155         @echo 'set gas "$(GAS)"' >>site.tmp
156         @echo 'set llvmdsymutil "$(DSYMUTIL)"' >>site.tmp
157         @echo '## All variables above are generated by configure. Do Not Edit ## ' >>site.tmp
158         @test ! -f site.exp || \
159         sed '1,/^## All variables above are.*##/ d' site.exp >> site.tmp
160         @-rm -f site.bak
161         @test ! -f site.exp || mv site.exp site.bak
162         @mv site.tmp site.exp
163
164 lit.site.cfg: site.exp
165         @echo "Making 'lit.site.cfg' file..."
166         @echo "## Autogenerated by Makefile ##" > $@
167         @echo "# Do not edit!" >> $@
168         @echo >> $@
169         @echo "# Preserve some key paths for use by main LLVM test suite config." >> $@
170         @echo "config.llvm_obj_root = \"\"\"$(LLVM_OBJ_ROOT)\"\"\"" >> $@
171         @echo >> $@
172         @echo "# Let the main config do the real work." >> $@
173         @echo "lit.load_config(config, \"\"\"$(LLVM_SRC_ROOT)/test/lit.cfg\"\"\")" >> $@
174
175 Unit/lit.site.cfg: Unit/.dir FORCE
176         @echo "Making unittest 'lit.site.cfg' file..."
177         @echo "## Autogenerated by Makefile ##" > $@
178         @echo "# Do not edit!" >> $@
179         @echo >> $@
180         @echo "# Preserve some key paths for use by main LLVM test suite config." >> $@
181         @echo "config.llvm_obj_root = \"\"\"$(LLVM_OBJ_ROOT)\"\"\"" >> $@
182         @echo >> $@
183         @echo "# Remember the build mode." >> $@
184         @echo "config.llvm_build_mode = \"\"\"$(BuildMode)\"\"\"" >> $@
185         @echo >> $@
186         @echo "# Let the main config do the real work." >> $@
187         @echo "lit.load_config(config, \"\"\"$(LLVM_SRC_ROOT)/test/Unit/lit.cfg\"\"\")" >> $@
188