When we don't pass --vg-leak to lit, pass --leak-check=no to valgrind.
[oota-llvm.git] / utils / lit / lit / LitConfig.py
1 class LitConfig:
2     """LitConfig - Configuration data for a 'lit' test runner instance, shared
3     across all tests.
4
5     The LitConfig object is also used to communicate with client configuration
6     files, it is always passed in as the global variable 'lit' so that
7     configuration files can access common functionality and internal components
8     easily.
9     """
10
11     # Provide access to built-in formats.
12     import LitFormats as formats
13
14     # Provide access to built-in utility functions.
15     import Util as util
16
17     def __init__(self, progname, path, quiet,
18                  useValgrind, valgrindLeakCheck, valgrindArgs,
19                  useTclAsSh,
20                  noExecute, debug, isWindows,
21                  params):
22         # The name of the test runner.
23         self.progname = progname
24         # The items to add to the PATH environment variable.
25         self.path = list(map(str, path))
26         self.quiet = bool(quiet)
27         self.useValgrind = bool(useValgrind)
28         self.valgrindLeakCheck = bool(valgrindLeakCheck)
29         self.valgrindUserArgs = list(valgrindArgs)
30         self.useTclAsSh = bool(useTclAsSh)
31         self.noExecute = noExecute
32         self.debug = debug
33         self.isWindows = bool(isWindows)
34         self.params = dict(params)
35         self.bashPath = None
36
37         self.numErrors = 0
38         self.numWarnings = 0
39
40         self.valgrindArgs = []
41         self.valgrindTriple = ""
42         if self.useValgrind:
43             self.valgrindTriple = "-vg"
44             self.valgrindArgs = ['valgrind', '-q', '--run-libc-freeres=no',
45                                  '--tool=memcheck', '--trace-children=yes',
46                                  '--error-exitcode=123']
47             if self.valgrindLeakCheck:
48                 self.valgrindTriple += "_leak"
49                 self.valgrindArgs.append('--leak-check=full')
50             else:
51                 # The default is 'summary'.
52                 self.valgrindArgs.append('--leak-check=no')
53             self.valgrindArgs.extend(self.valgrindUserArgs)
54
55
56     def load_config(self, config, path):
57         """load_config(config, path) - Load a config object from an alternate
58         path."""
59         from TestingConfig import TestingConfig
60         return TestingConfig.frompath(path, config.parent, self,
61                                       mustExist = True,
62                                       config = config)
63
64     def getBashPath(self):
65         """getBashPath - Get the path to 'bash'"""
66         import os, Util
67
68         if self.bashPath is not None:
69             return self.bashPath
70
71         self.bashPath = Util.which('bash', os.pathsep.join(self.path))
72         if self.bashPath is None:
73             # Check some known paths.
74             for path in ('/bin/bash', '/usr/bin/bash'):
75                 if os.path.exists(path):
76                     self.bashPath = path
77                     break
78
79         if self.bashPath is None:
80             self.warning("Unable to find 'bash', running Tcl tests internally.")
81             self.bashPath = ''
82
83         return self.bashPath
84
85     def _write_message(self, kind, message):
86         import inspect, os, sys
87
88         # Get the file/line where this message was generated.
89         f = inspect.currentframe()
90         # Step out of _write_message, and then out of wrapper.
91         f = f.f_back.f_back
92         file,line,_,_,_ = inspect.getframeinfo(f)
93         location = '%s:%d' % (os.path.basename(file), line)
94
95         print >>sys.stderr, '%s: %s: %s: %s' % (self.progname, location,
96                                                 kind, message)
97
98     def note(self, message):
99         self._write_message('note', message)
100
101     def warning(self, message):
102         self._write_message('warning', message)
103         self.numWarnings += 1
104
105     def error(self, message):
106         self._write_message('error', message)
107         self.numErrors += 1
108
109     def fatal(self, message):
110         import sys
111         self._write_message('fatal', message)
112         sys.exit(2)