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):
51 sys.stdout.write('cd %s && ' % kwargs['cwd'])
53 for name, value in kwargs['env'].iteritems():
54 if value != os.environ.get(name, None):
55 sys.stdout.write('%s=%s ' % (name, value))
56 sys.stdout.write(' '.join(command) + '\n')
58 return subprocess.Popen(command, *args, **kwargs)
61 ignored_function_names = set([
63 'glXGetCurrentDisplay',
66 'glXGetProcAddressARB',
68 'glXGetVisualFromFBConfig',
70 'glXCreateNewContext',
71 'glXMakeContextCurrent',
79 app = os.path.join(options.mesa_demos, 'src', demo)
81 dirname, basename = os.path.split(app)
83 trace = os.path.abspath(demo.replace('/', '-') + '.trace')
85 env = os.environ.copy()
86 env['LD_PRELOAD'] = os.path.abspath('glxtrace.so')
87 env['TRACE_FILE'] = trace
89 args = [os.path.join('.', basename)]
90 p = popen(args, env=env, cwd=dirname, stdout=subprocess.PIPE)
93 # http://stackoverflow.com/questions/151407/how-to-get-an-x11-window-from-a-process-id
94 ref_image = demo.replace('/', '-') + '.ref.png'
95 subprocess.call('xwd -name \'%s\' | xwdtopnm | pnmtopng > %s' % (args[0], ref_image), shell=True, stdout=subprocess.PIPE)
97 os.kill(p.pid, signal.SIGTERM)
99 p = popen(['./tracedump', trace], stdout=subprocess.PIPE)
100 stdout, _ = p.communicate()
102 call_re = re.compile('^([0-9]+) (\w+)\(')
103 double_buffer = False
104 for orig_line in stdout.split('\n'):
105 line = ansi_strip(orig_line)
106 mo = call_re.match(line)
108 call_no = int(mo.group(1))
109 function_name = mo.group(2)
110 if function_name in ignored_function_names:
112 if function_name == 'glXSwapBuffers':
116 args = ['./glretrace']
119 args += ['-s', '/tmp/' + demo.replace('/', '-') + '.']
121 p = popen(args, stdout=subprocess.PIPE)
122 stdout, _ = p.communicate()
123 image_re = re.compile('^Wrote (.*\.png)$')
125 for line in stdout.split('\n'):
126 mo = image_re.match(line)
131 delta_image = demo.replace('/', '-') + '.diff.png'
132 p = popen(["compare", '-alpha', 'opaque', '-metric', 'AE', '-fuzz', '5%', ref_image, image, delta_image])
133 _, stderr = p.communicate()
137 'trivial/clear-color',
139 'trivial/clear-fbo-scissor',
140 'trivial/clear-fbo-tex',
141 'trivial/clear-random',
142 'trivial/clear-repeat',
143 'trivial/clear-scissor',
144 'trivial/clear-undefined',
146 'trivial/dlist-begin-call-end',
147 'trivial/dlist-dangling',
148 'trivial/dlist-degenerate',
149 'trivial/dlist-edgeflag',
150 'trivial/dlist-edgeflag-dangling',
151 'trivial/dlist-flat-tri',
152 'trivial/dlist-mat-tri',
153 'trivial/dlist-recursive-call',
154 'trivial/dlist-tri-flat-tri',
155 'trivial/dlist-tri-mat-tri',
156 'trivial/draw2arrays',
157 'trivial/drawarrays',
158 'trivial/drawelements',
159 'trivial/drawelements-large',
167 'trivial/line-smooth',
168 'trivial/line-stipple-wide',
169 'trivial/line-userclip',
170 'trivial/line-userclip-clip',
171 'trivial/line-userclip-nop',
172 'trivial/line-userclip-nop-clip',
176 'trivial/lineloop-clip',
177 'trivial/lineloop-elts',
179 'trivial/linestrip-clip',
180 'trivial/linestrip-flat-stipple',
181 'trivial/linestrip-stipple',
182 'trivial/linestrip-stipple-wide',
183 'trivial/long-fixed-func',
186 'trivial/point-clip',
187 'trivial/point-param',
188 'trivial/point-sprite',
189 'trivial/point-wide',
190 'trivial/point-wide-smooth',
193 'trivial/poly-flat-clip',
194 'trivial/poly-flat-unfilled-clip',
195 'trivial/poly-unfilled',
198 'trivial/quad-clip-all-vertices',
199 'trivial/quad-clip-nearplane',
200 'trivial/quad-degenerate',
202 'trivial/quad-offset-factor',
203 'trivial/quad-offset-unfilled',
204 'trivial/quad-offset-units',
205 'trivial/quad-tex-2d',
206 'trivial/quad-tex-3d',
207 'trivial/quad-tex-alpha',
208 'trivial/quad-tex-pbo',
209 'trivial/quad-tex-sub',
210 'trivial/quad-unfilled',
211 'trivial/quad-unfilled-clip',
212 'trivial/quad-unfilled-stipple',
215 'trivial/quadstrip-clip',
216 'trivial/quadstrip-cont',
217 'trivial/quadstrip-flat',
218 'trivial/readpixels',
223 'trivial/tri-alpha-tex',
224 'trivial/tri-array-interleaved',
226 'trivial/tri-blend-color',
227 'trivial/tri-blend-max',
228 'trivial/tri-blend-min',
229 'trivial/tri-blend-revsub',
230 'trivial/tri-blend-sub',
234 'trivial/tri-cull-both',
236 'trivial/tri-edgeflag',
237 'trivial/tri-edgeflag-array',
239 'trivial/tri-fbo-tex',
240 'trivial/tri-fbo-tex-mip',
242 'trivial/tri-flat-clip',
245 'trivial/tri-fp-const-imm',
247 'trivial/tri-lit-material',
248 'trivial/tri-logicop-none',
249 'trivial/tri-logicop-xor',
250 'trivial/tri-mask-tri',
251 'trivial/tri-multitex-vbo',
253 'trivial/tri-point-line-clipped',
255 'trivial/tri-repeat',
256 'trivial/tri-scissor-tri',
257 'trivial/tri-square',
258 'trivial/tri-stencil',
259 'trivial/tri-stipple',
261 'trivial/tri-tex-1d',
262 'trivial/tri-tex-3d',
264 'trivial/tri-unfilled',
265 'trivial/tri-unfilled-clip',
266 'trivial/tri-unfilled-edgeflag',
267 'trivial/tri-unfilled-fog',
268 'trivial/tri-unfilled-point',
269 'trivial/tri-unfilled-smooth',
270 'trivial/tri-unfilled-tri',
271 'trivial/tri-unfilled-tri-lit',
272 'trivial/tri-unfilled-userclip',
273 'trivial/tri-unfilled-userclip-stip',
274 'trivial/tri-userclip',
275 'trivial/tri-viewport',
280 'trivial/trifan-flat',
281 'trivial/trifan-flat-clip',
282 'trivial/trifan-flat-unfilled-clip',
283 'trivial/trifan-unfilled',
285 'trivial/tristrip-clip',
286 'trivial/tristrip-flat',
287 'trivial/vbo-drawarrays',
288 'trivial/vbo-drawelements',
289 'trivial/vbo-drawrange',
290 'trivial/vbo-noninterleaved',
293 'trivial/vp-array-hf',
294 'trivial/vp-array-int',
296 'trivial/vp-line-clip',
299 'trivial/vp-tri-cb-pos',
300 'trivial/vp-tri-cb-tex',
301 'trivial/vp-tri-imm',
302 'trivial/vp-tri-invariant',
303 'trivial/vp-tri-swap',
304 'trivial/vp-tri-tex',
305 'trivial/vp-unfilled',
310 #'demos/arbocclude2',
319 #'demos/fbo_firecube',
346 #'demos/singlebuffer',
348 #'demos/spriteblast',
362 #'fp/point-position',
365 #'fp/tri-depthwrite',
366 #'fp/tri-depthwrite2',
375 #'glsl/convolutions',
379 #'glsl/geom-sprites',
380 #'glsl/geom-stipple-lines',
381 #'glsl/geom-wide-lines',
392 #'glsl/shadow_sampler',
400 #'glsl/vert-or-frag-only',
405 #'perf/drawoverhead',
428 #'redbook/convolution',
441 #'redbook/histogram',
450 #'redbook/movelight',
451 #'redbook/multisamp',
455 #'redbook/pickdepth',
456 #'redbook/picksquare',
464 #'redbook/sccolorlight',
466 #'redbook/scenebamb',
467 #'redbook/sceneflat',
469 #'redbook/shadowmap',
474 #'redbook/surfpoints',
475 #'redbook/teaambient',
483 #'redbook/texture3d',
484 #'redbook/texturesurf',
487 #'redbook/unproject',
527 'tests/arbfptexture',
531 'tests/arbnpot-mipmap',
535 'tests/arbvpwarpmesh',
536 'tests/arraytexture',
544 'tests/bug_texstore_i8',
546 'tests/calibrate_rast',
553 'tests/drawbuffers2',
556 'tests/ext422square',
576 'tests/mipmap_comp_tests',
577 'tests/mipmap_limits',
578 'tests/mipmap_tunnel',
581 'tests/multitexarray',
585 'tests/packedpixels',
589 'tests/prog_parameter',
595 'tests/scissor-viewport',
597 'tests/shader-interp',
599 'tests/shadow-sample',
601 'tests/stencilreaddraw',
604 'tests/streaming_rect',
609 'tests/texcompress2',
619 'tests/unfilledclip',
638 #'xdemos/glxcontexts',
641 #'xdemos/glxgears_fbconfig',
642 #'xdemos/glxgears_pixmap',
648 #'xdemos/glxswapcontrol',
654 #'xdemos/opencloseopen',
660 #'xdemos/sharedtex_mt',
661 #'xdemos/texture_from_pixmap',
664 #'xdemos/xrotfontdemo',
665 #'xdemos/yuvrect_client',
678 # Parse command line options
679 optparser = optparse.OptionParser(
680 usage='\n\t%prog [options] [demo] ...',
682 optparser.add_option(
683 '--build', metavar='PATH',
684 type='string', dest='build', default='.',
685 help='path to apitrace build')
687 optparser.add_option(
688 '--mesa-demos', metavar='PATH',
689 type='string', dest='mesa_demos', default=os.environ.get('MESA_DEMOS'),
690 help='path to mesa demos')
692 (options, args) = optparser.parse_args(sys.argv[1:])
700 if __name__ == '__main__':