2 ##########################################################################
4 # Copyright 2011 Jose Fonseca
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:
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
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
25 ##########################################################################/
28 '''Apitrace test suite based on Mesa demos.'''
41 ansi_re = re.compile('\x1b\[[0-9]{1,2}(;[0-9]{1,2}){0,2}m')
45 # http://www.theeggeadventure.com/wikimedia/index.php/Linux_Tips#Use_sed_to_remove_ANSI_colors
46 return ansi_re.sub('', s)
49 def popen(command, *args, **kwargs):
50 sys.stdout.write(' '.join(command) + '\n')
51 return subprocess.Popen(command, *args, **kwargs)
54 ignored_function_names = set([
56 'glXGetCurrentDisplay',
59 'glXGetProcAddressARB',
61 'glXGetVisualFromFBConfig',
63 'glXCreateNewContext',
64 'glXMakeContextCurrent',
72 app = os.path.join(options.mesa_demos, demo)
74 dirname, basename = os.path.split(app)
76 env = os.environ.copy()
77 env['LD_PRELOAD'] = os.path.abspath('glxtrace.so')
78 env['TRACE_FILE'] = '/tmp/trace'
80 args = [os.path.join('.', basename)]
81 p = popen(args, env=env, cwd=dirname, stdout=subprocess.PIPE)
84 # http://stackoverflow.com/questions/151407/how-to-get-an-x11-window-from-a-process-id
85 subprocess.call('xwd -name \'%s\' | xwdtopnm | pnmtopng > %s' % (args[0], '/tmp/ref.png'), shell=True, stdout=subprocess.PIPE)
87 os.kill(p.pid, signal.SIGTERM)
89 p = popen(['./tracedump', '/tmp/trace'], stdout=subprocess.PIPE)
90 stdout, _ = p.communicate()
92 call_re = re.compile('^([0-9]+) (\w+)\(')
94 for orig_line in stdout.split('\n'):
95 line = ansi_strip(orig_line)
96 mo = call_re.match(line)
98 call_no = int(mo.group(1))
99 function_name = mo.group(2)
100 if function_name in ignored_function_names:
102 if function_name == 'glXSwapBuffers':
106 args = ['./glretrace']
109 args += ['-s', '/tmp/test_']
110 args += ['/tmp/trace']
111 p = popen(args, stdout=subprocess.PIPE)
112 stdout, _ = p.communicate()
113 image_re = re.compile('^Wrote (.*\.png)$')
115 for line in stdout.split('\n'):
116 mo = image_re.match(line)
121 p = popen(["compare", '-metric', 'AE', '-fuzz', '5%', '-extract', '250x250', '/tmp/ref.png', image, '/tmp/delta.png'])
122 _, stderr = p.communicate()
126 'trivial/clear-color',
128 'trivial/clear-fbo-scissor',
129 'trivial/clear-fbo-tex',
130 'trivial/clear-random',
131 'trivial/clear-repeat',
132 'trivial/clear-scissor',
133 'trivial/clear-undefined',
135 'trivial/dlist-begin-call-end',
136 'trivial/dlist-dangling',
137 'trivial/dlist-degenerate',
138 'trivial/dlist-edgeflag',
139 'trivial/dlist-edgeflag-dangling',
140 'trivial/dlist-flat-tri',
141 'trivial/dlist-mat-tri',
142 'trivial/dlist-recursive-call',
143 'trivial/dlist-tri-flat-tri',
144 'trivial/dlist-tri-mat-tri',
145 'trivial/draw2arrays',
146 'trivial/drawarrays',
147 'trivial/drawelements',
148 'trivial/drawelements-large',
156 'trivial/line-smooth',
157 'trivial/line-stipple-wide',
158 'trivial/line-userclip',
159 'trivial/line-userclip-clip',
160 'trivial/line-userclip-nop',
161 'trivial/line-userclip-nop-clip',
165 'trivial/lineloop-clip',
166 'trivial/lineloop-elts',
168 'trivial/linestrip-clip',
169 'trivial/linestrip-flat-stipple',
170 'trivial/linestrip-stipple',
171 'trivial/linestrip-stipple-wide',
172 'trivial/long-fixed-func',
175 'trivial/point-clip',
176 'trivial/point-param',
177 'trivial/point-sprite',
178 'trivial/point-wide',
179 'trivial/point-wide-smooth',
182 'trivial/poly-flat-clip',
183 'trivial/poly-flat-unfilled-clip',
184 'trivial/poly-unfilled',
187 'trivial/quad-clip-all-vertices',
188 'trivial/quad-clip-nearplane',
189 'trivial/quad-degenerate',
191 'trivial/quad-offset-factor',
192 'trivial/quad-offset-unfilled',
193 'trivial/quad-offset-units',
194 'trivial/quad-tex-2d',
195 'trivial/quad-tex-3d',
196 'trivial/quad-tex-alpha',
197 'trivial/quad-tex-pbo',
198 'trivial/quad-tex-sub',
199 'trivial/quad-unfilled',
200 'trivial/quad-unfilled-clip',
201 'trivial/quad-unfilled-stipple',
204 'trivial/quadstrip-clip',
205 'trivial/quadstrip-cont',
206 'trivial/quadstrip-flat',
207 'trivial/readpixels',
212 'trivial/tri-alpha-tex',
213 'trivial/tri-array-interleaved',
215 'trivial/tri-blend-color',
216 'trivial/tri-blend-max',
217 'trivial/tri-blend-min',
218 'trivial/tri-blend-revsub',
219 'trivial/tri-blend-sub',
223 'trivial/tri-cull-both',
225 'trivial/tri-edgeflag',
226 'trivial/tri-edgeflag-array',
228 'trivial/tri-fbo-tex',
229 'trivial/tri-fbo-tex-mip',
231 'trivial/tri-flat-clip',
234 'trivial/tri-fp-const-imm',
236 'trivial/tri-lit-material',
237 'trivial/tri-logicop-none',
238 'trivial/tri-logicop-xor',
239 'trivial/tri-mask-tri',
240 'trivial/tri-multitex-vbo',
242 'trivial/tri-point-line-clipped',
244 'trivial/tri-repeat',
245 'trivial/tri-scissor-tri',
246 'trivial/tri-square',
247 'trivial/tri-stencil',
248 'trivial/tri-stipple',
250 'trivial/tri-tex-1d',
251 'trivial/tri-tex-3d',
253 'trivial/tri-unfilled',
254 'trivial/tri-unfilled-clip',
255 'trivial/tri-unfilled-edgeflag',
256 'trivial/tri-unfilled-fog',
257 'trivial/tri-unfilled-point',
258 'trivial/tri-unfilled-smooth',
259 'trivial/tri-unfilled-tri',
260 'trivial/tri-unfilled-tri-lit',
261 'trivial/tri-unfilled-userclip',
262 'trivial/tri-unfilled-userclip-stip',
263 'trivial/tri-userclip',
264 'trivial/tri-viewport',
269 'trivial/trifan-flat',
270 'trivial/trifan-flat-clip',
271 'trivial/trifan-flat-unfilled-clip',
272 'trivial/trifan-unfilled',
274 'trivial/tristrip-clip',
275 'trivial/tristrip-flat',
276 'trivial/vbo-drawarrays',
277 'trivial/vbo-drawelements',
278 'trivial/vbo-drawrange',
279 'trivial/vbo-noninterleaved',
282 'trivial/vp-array-hf',
283 'trivial/vp-array-int',
285 'trivial/vp-line-clip',
288 'trivial/vp-tri-cb-pos',
289 'trivial/vp-tri-cb-tex',
290 'trivial/vp-tri-imm',
291 'trivial/vp-tri-invariant',
292 'trivial/vp-tri-swap',
293 'trivial/vp-tri-tex',
294 'trivial/vp-unfilled',
299 #'demos/arbocclude2',
308 #'demos/fbo_firecube',
335 #'demos/singlebuffer',
337 #'demos/spriteblast',
351 #'fp/point-position',
354 #'fp/tri-depthwrite',
355 #'fp/tri-depthwrite2',
364 #'glsl/convolutions',
368 #'glsl/geom-sprites',
369 #'glsl/geom-stipple-lines',
370 #'glsl/geom-wide-lines',
381 #'glsl/shadow_sampler',
389 #'glsl/vert-or-frag-only',
394 #'perf/drawoverhead',
417 #'redbook/convolution',
430 #'redbook/histogram',
439 #'redbook/movelight',
440 #'redbook/multisamp',
444 #'redbook/pickdepth',
445 #'redbook/picksquare',
453 #'redbook/sccolorlight',
455 #'redbook/scenebamb',
456 #'redbook/sceneflat',
458 #'redbook/shadowmap',
463 #'redbook/surfpoints',
464 #'redbook/teaambient',
472 #'redbook/texture3d',
473 #'redbook/texturesurf',
476 #'redbook/unproject',
514 'tests/api_speed.py',
517 'tests/arbfptexture',
521 'tests/arbnpot-mipmap',
525 'tests/arbvpwarpmesh',
526 'tests/arraytexture',
534 'tests/bug_texstore_i8',
536 'tests/calibrate_rast',
543 'tests/drawbuffers2',
546 'tests/ext422square',
566 'tests/mipmap_comp_tests',
567 'tests/mipmap_limits',
568 'tests/mipmap_tunnel',
571 'tests/multitexarray',
575 'tests/packedpixels',
579 'tests/prog_parameter',
585 'tests/scissor-viewport',
587 'tests/shader-interp',
589 'tests/shadow-sample',
591 'tests/stencilreaddraw',
594 'tests/streaming_rect',
599 'tests/texcompress2',
609 'tests/unfilledclip',
628 #'xdemos/glxcontexts',
631 #'xdemos/glxgears_fbconfig',
632 #'xdemos/glxgears_pixmap',
638 #'xdemos/glxswapcontrol',
644 #'xdemos/opencloseopen',
650 #'xdemos/sharedtex_mt',
651 #'xdemos/texture_from_pixmap',
654 #'xdemos/xrotfontdemo',
655 #'xdemos/yuvrect_client',
668 # Parse command line options
669 optparser = optparse.OptionParser(
670 usage='\n\t%prog [options] ',
672 optparser.add_option(
673 '--build', metavar='PATH',
674 type='string', dest='build', default='.',
675 help='path to apitrace build')
677 optparser.add_option(
678 '--mesa-demos', metavar='PATH',
679 type='string', dest='mesa_demos', default=os.environ.get('MESA_DEMOS'),
680 help='path to mesa demos')
682 (options, args) = optparser.parse_args(sys.argv[1:])
684 optparser.error("incorrect number of arguments")
687 runtest('src/' + test)
690 if __name__ == '__main__':