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')
52 return subprocess.Popen(command, *args, **kwargs)
55 ignored_function_names = set([
57 'glXGetCurrentDisplay',
60 'glXGetProcAddressARB',
62 'glXGetVisualFromFBConfig',
64 'glXCreateNewContext',
65 'glXMakeContextCurrent',
73 app = os.path.join(options.mesa_demos, 'src', demo)
75 dirname, basename = os.path.split(app)
77 trace = os.path.abspath(demo.replace('/', '-') + '.trace')
79 env = os.environ.copy()
80 env['LD_PRELOAD'] = os.path.abspath('glxtrace.so')
81 env['TRACE_FILE'] = trace
83 args = [os.path.join('.', basename)]
84 p = popen(args, env=env, cwd=dirname, stdout=subprocess.PIPE)
87 # http://stackoverflow.com/questions/151407/how-to-get-an-x11-window-from-a-process-id
88 ref_image = demo.replace('/', '-') + '.ref.png'
89 subprocess.call('xwd -name \'%s\' | xwdtopnm | pnmtopng > %s' % (args[0], ref_image), shell=True, stdout=subprocess.PIPE)
91 os.kill(p.pid, signal.SIGTERM)
93 p = popen(['./tracedump', trace], stdout=subprocess.PIPE)
94 stdout, _ = p.communicate()
96 call_re = re.compile('^([0-9]+) (\w+)\(')
98 for orig_line in stdout.split('\n'):
99 line = ansi_strip(orig_line)
100 mo = call_re.match(line)
102 call_no = int(mo.group(1))
103 function_name = mo.group(2)
104 if function_name in ignored_function_names:
106 if function_name == 'glXSwapBuffers':
110 args = ['./glretrace']
113 args += ['-s', '/tmp/' + demo.replace('/', '-') + '.']
115 p = popen(args, stdout=subprocess.PIPE)
116 stdout, _ = p.communicate()
117 image_re = re.compile('^Wrote (.*\.png)$')
119 for line in stdout.split('\n'):
120 mo = image_re.match(line)
125 delta_image = demo.replace('/', '-') + '.diff.png'
126 p = popen(["compare", '-metric', 'AE', '-fuzz', '5%', '-extract', '250x250', ref_image, image, delta_image])
127 _, stderr = p.communicate()
131 'trivial/clear-color',
133 'trivial/clear-fbo-scissor',
134 'trivial/clear-fbo-tex',
135 'trivial/clear-random',
136 'trivial/clear-repeat',
137 'trivial/clear-scissor',
138 'trivial/clear-undefined',
140 'trivial/dlist-begin-call-end',
141 'trivial/dlist-dangling',
142 'trivial/dlist-degenerate',
143 'trivial/dlist-edgeflag',
144 'trivial/dlist-edgeflag-dangling',
145 'trivial/dlist-flat-tri',
146 'trivial/dlist-mat-tri',
147 'trivial/dlist-recursive-call',
148 'trivial/dlist-tri-flat-tri',
149 'trivial/dlist-tri-mat-tri',
150 'trivial/draw2arrays',
151 'trivial/drawarrays',
152 'trivial/drawelements',
153 'trivial/drawelements-large',
161 'trivial/line-smooth',
162 'trivial/line-stipple-wide',
163 'trivial/line-userclip',
164 'trivial/line-userclip-clip',
165 'trivial/line-userclip-nop',
166 'trivial/line-userclip-nop-clip',
170 'trivial/lineloop-clip',
171 'trivial/lineloop-elts',
173 'trivial/linestrip-clip',
174 'trivial/linestrip-flat-stipple',
175 'trivial/linestrip-stipple',
176 'trivial/linestrip-stipple-wide',
177 'trivial/long-fixed-func',
180 'trivial/point-clip',
181 'trivial/point-param',
182 'trivial/point-sprite',
183 'trivial/point-wide',
184 'trivial/point-wide-smooth',
187 'trivial/poly-flat-clip',
188 'trivial/poly-flat-unfilled-clip',
189 'trivial/poly-unfilled',
192 'trivial/quad-clip-all-vertices',
193 'trivial/quad-clip-nearplane',
194 'trivial/quad-degenerate',
196 'trivial/quad-offset-factor',
197 'trivial/quad-offset-unfilled',
198 'trivial/quad-offset-units',
199 'trivial/quad-tex-2d',
200 'trivial/quad-tex-3d',
201 'trivial/quad-tex-alpha',
202 'trivial/quad-tex-pbo',
203 'trivial/quad-tex-sub',
204 'trivial/quad-unfilled',
205 'trivial/quad-unfilled-clip',
206 'trivial/quad-unfilled-stipple',
209 'trivial/quadstrip-clip',
210 'trivial/quadstrip-cont',
211 'trivial/quadstrip-flat',
212 'trivial/readpixels',
217 'trivial/tri-alpha-tex',
218 'trivial/tri-array-interleaved',
220 'trivial/tri-blend-color',
221 'trivial/tri-blend-max',
222 'trivial/tri-blend-min',
223 'trivial/tri-blend-revsub',
224 'trivial/tri-blend-sub',
228 'trivial/tri-cull-both',
230 'trivial/tri-edgeflag',
231 'trivial/tri-edgeflag-array',
233 'trivial/tri-fbo-tex',
234 'trivial/tri-fbo-tex-mip',
236 'trivial/tri-flat-clip',
239 'trivial/tri-fp-const-imm',
241 'trivial/tri-lit-material',
242 'trivial/tri-logicop-none',
243 'trivial/tri-logicop-xor',
244 'trivial/tri-mask-tri',
245 'trivial/tri-multitex-vbo',
247 'trivial/tri-point-line-clipped',
249 'trivial/tri-repeat',
250 'trivial/tri-scissor-tri',
251 'trivial/tri-square',
252 'trivial/tri-stencil',
253 'trivial/tri-stipple',
255 'trivial/tri-tex-1d',
256 'trivial/tri-tex-3d',
258 'trivial/tri-unfilled',
259 'trivial/tri-unfilled-clip',
260 'trivial/tri-unfilled-edgeflag',
261 'trivial/tri-unfilled-fog',
262 'trivial/tri-unfilled-point',
263 'trivial/tri-unfilled-smooth',
264 'trivial/tri-unfilled-tri',
265 'trivial/tri-unfilled-tri-lit',
266 'trivial/tri-unfilled-userclip',
267 'trivial/tri-unfilled-userclip-stip',
268 'trivial/tri-userclip',
269 'trivial/tri-viewport',
274 'trivial/trifan-flat',
275 'trivial/trifan-flat-clip',
276 'trivial/trifan-flat-unfilled-clip',
277 'trivial/trifan-unfilled',
279 'trivial/tristrip-clip',
280 'trivial/tristrip-flat',
281 'trivial/vbo-drawarrays',
282 'trivial/vbo-drawelements',
283 'trivial/vbo-drawrange',
284 'trivial/vbo-noninterleaved',
287 'trivial/vp-array-hf',
288 'trivial/vp-array-int',
290 'trivial/vp-line-clip',
293 'trivial/vp-tri-cb-pos',
294 'trivial/vp-tri-cb-tex',
295 'trivial/vp-tri-imm',
296 'trivial/vp-tri-invariant',
297 'trivial/vp-tri-swap',
298 'trivial/vp-tri-tex',
299 'trivial/vp-unfilled',
304 #'demos/arbocclude2',
313 #'demos/fbo_firecube',
340 #'demos/singlebuffer',
342 #'demos/spriteblast',
356 #'fp/point-position',
359 #'fp/tri-depthwrite',
360 #'fp/tri-depthwrite2',
369 #'glsl/convolutions',
373 #'glsl/geom-sprites',
374 #'glsl/geom-stipple-lines',
375 #'glsl/geom-wide-lines',
386 #'glsl/shadow_sampler',
394 #'glsl/vert-or-frag-only',
399 #'perf/drawoverhead',
422 #'redbook/convolution',
435 #'redbook/histogram',
444 #'redbook/movelight',
445 #'redbook/multisamp',
449 #'redbook/pickdepth',
450 #'redbook/picksquare',
458 #'redbook/sccolorlight',
460 #'redbook/scenebamb',
461 #'redbook/sceneflat',
463 #'redbook/shadowmap',
468 #'redbook/surfpoints',
469 #'redbook/teaambient',
477 #'redbook/texture3d',
478 #'redbook/texturesurf',
481 #'redbook/unproject',
519 'tests/api_speed.py',
522 'tests/arbfptexture',
526 'tests/arbnpot-mipmap',
530 'tests/arbvpwarpmesh',
531 'tests/arraytexture',
539 'tests/bug_texstore_i8',
541 'tests/calibrate_rast',
548 'tests/drawbuffers2',
551 'tests/ext422square',
571 'tests/mipmap_comp_tests',
572 'tests/mipmap_limits',
573 'tests/mipmap_tunnel',
576 'tests/multitexarray',
580 'tests/packedpixels',
584 'tests/prog_parameter',
590 'tests/scissor-viewport',
592 'tests/shader-interp',
594 'tests/shadow-sample',
596 'tests/stencilreaddraw',
599 'tests/streaming_rect',
604 'tests/texcompress2',
614 'tests/unfilledclip',
633 #'xdemos/glxcontexts',
636 #'xdemos/glxgears_fbconfig',
637 #'xdemos/glxgears_pixmap',
643 #'xdemos/glxswapcontrol',
649 #'xdemos/opencloseopen',
655 #'xdemos/sharedtex_mt',
656 #'xdemos/texture_from_pixmap',
659 #'xdemos/xrotfontdemo',
660 #'xdemos/yuvrect_client',
673 # Parse command line options
674 optparser = optparse.OptionParser(
675 usage='\n\t%prog [options] ',
677 optparser.add_option(
678 '--build', metavar='PATH',
679 type='string', dest='build', default='.',
680 help='path to apitrace build')
682 optparser.add_option(
683 '--mesa-demos', metavar='PATH',
684 type='string', dest='mesa_demos', default=os.environ.get('MESA_DEMOS'),
685 help='path to mesa demos')
687 (options, args) = optparser.parse_args(sys.argv[1:])
689 optparser.error("incorrect number of arguments")
695 if __name__ == '__main__':