Add support for XFAILing valgrind runs with memory leak checking independently
[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             self.valgrindArgs.extend(self.valgrindUserArgs)
51
52
53     def load_config(self, config, path):
54         """load_config(config, path) - Load a config object from an alternate
55         path."""
56         from TestingConfig import TestingConfig
57         return TestingConfig.frompath(path, config.parent, self,
58                                       mustExist = True,
59                                       config = config)
60
61     def getBashPath(self):
62         """getBashPath - Get the path to 'bash'"""
63         import os, Util
64
65         if self.bashPath is not None:
66             return self.bashPath
67
68         self.bashPath = Util.which('bash', os.pathsep.join(self.path))
69         if self.bashPath is None:
70             # Check some known paths.
71             for path in ('/bin/bash', '/usr/bin/bash'):
72                 if os.path.exists(path):
73                     self.bashPath = path
74                     break
75
76         if self.bashPath is None:
77             self.warning("Unable to find 'bash', running Tcl tests internally.")
78             self.bashPath = ''
79
80         return self.bashPath
81
82     def _write_message(self, kind, message):
83         import inspect, os, sys
84
85         # Get the file/line where this message was generated.
86         f = inspect.currentframe()
87         # Step out of _write_message, and then out of wrapper.
88         f = f.f_back.f_back
89         file,line,_,_,_ = inspect.getframeinfo(f)
90         location = '%s:%d' % (os.path.basename(file), line)
91
92         print >>sys.stderr, '%s: %s: %s: %s' % (self.progname, location,
93                                                 kind, message)
94
95     def note(self, message):
96         self._write_message('note', message)
97
98     def warning(self, message):
99         self._write_message('warning', message)
100         self.numWarnings += 1
101
102     def error(self, message):
103         self._write_message('error', message)
104         self.numErrors += 1
105
106     def fatal(self, message):
107         import sys
108         self._write_message('fatal', message)
109         sys.exit(2)