]> git.cworth.org Git - apitrace-tests/blob - testsuite.py
Generalize the tests for other example suites.
[apitrace-tests] / testsuite.py
1 #!/usr/bin/env python
2 ##########################################################################
3 #
4 # Copyright 2011 Jose Fonseca
5 # All Rights Reserved.
6 #
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
8 # of this software and associated documentation files (the "Software"), to deal
9 # in the Software without restriction, including without limitation the rights
10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 # copies of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
13 #
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 # THE SOFTWARE.
24 #
25 ##########################################################################/
26
27
28 import fnmatch
29 import optparse
30 import os.path
31 import sys
32
33 from test import Report, TestCase
34
35
36 def runtest(report, demo):
37     app = os.path.join(options.mesa_demos, 'src', demo)
38     dirname, basename = os.path.split(app)
39     name = demo.replace('/', '-')
40     args = [os.path.join('.', basename)]
41
42     test = TestCase(
43         name = name,
44         args = args,
45         cwd = dirname,
46         build = options.build,
47         results = options.results,
48     )
49     test.run(report)
50
51
52 def parse_spec(filename):
53     testlist = []
54     for line in open(filename, 'rt'):
55         if line.lstrip().startswith('#') or not line.strip():
56             # comment / empty
57             continue
58         fields = line.split()
59
60         name = fields.pop(0)
61         cwd = fields.pop(0)
62         args = fields
63
64         if cwd:
65             if options.cwd is not None:
66                 cwd = os.path.join(options.cwd, cwd)
67             if not os.path.dirname(args[0]):
68                 args[0] = os.path.join('.', args[0])
69         else:
70             cwd = None
71
72         test = TestCase(
73             name = name,
74             args = args,
75             cwd = cwd,
76             build = options.build,
77             results = options.results,
78         )
79
80         testlist.append(test)
81     return testlist
82
83
84 def main():
85     global options
86
87     # Parse command line options
88     optparser = optparse.OptionParser(
89         usage='\n\t%prog [options] testspec [glob] ...',
90         version='%%prog')
91     optparser.add_option(
92         '-B', '--build', metavar='PATH',
93         type='string', dest='build', default=None,
94         help='path to apitrace build')
95     optparser.add_option(
96         '-C', '--directory', metavar='PATH',
97         type='string', dest='cwd', default=None,
98         help='change to directory')
99     optparser.add_option(
100         '-R', '--results', metavar='PATH',
101         type='string', dest='results', default='results',
102         help='results directory [default=%default]')
103
104     (options, args) = optparser.parse_args(sys.argv[1:])
105     if not args:
106         optparser.error('a test spec must be specified')
107
108     spec = args.pop(0)
109     testlist = parse_spec(spec)
110
111     if args:
112         new_testlist = []
113         for test in testlist:
114             for pattern in args:
115                 if fnmatch.fnmatchcase(test.name, pattern):
116                     new_testlist.append(test)
117         testlist = new_testlist
118
119     report = Report(options.results)
120     for test in testlist:
121         test.run(report)
122
123
124 if __name__ == '__main__':
125     main()