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(os.path.join(options.build, 'glxtrace.so'))
87 env['TRACE_FILE'] = trace
89 args = [os.path.join('.', basename)]
90 p = popen(args, env=env, cwd=dirname)
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(['xwininfo', '-root', '-tree'])
96 subprocess.call("xwd -name '%s' | xwdtopnm | pnmtopng > '%s'" % (args[0], ref_image), shell=True)
98 os.kill(p.pid, signal.SIGTERM)
100 p = popen([os.path.join(options.build, 'tracedump'), trace], stdout=subprocess.PIPE)
101 stdout, _ = p.communicate()
103 call_re = re.compile('^([0-9]+) (\w+)\(')
104 double_buffer = False
105 for orig_line in stdout.split('\n'):
106 line = ansi_strip(orig_line)
107 mo = call_re.match(line)
109 call_no = int(mo.group(1))
110 function_name = mo.group(2)
111 if function_name in ignored_function_names:
113 if function_name == 'glXSwapBuffers':
117 args = [os.path.join(options.build, 'glretrace')]
122 args += ['-s', '/tmp/' + demo.replace('/', '-') + '.']
124 p = popen(args, stdout=subprocess.PIPE)
125 stdout, _ = p.communicate()
126 image_re = re.compile('^Wrote (.*\.png)$')
128 for line in stdout.split('\n'):
129 mo = image_re.match(line)
134 delta_image = demo.replace('/', '-') + '.diff.png'
135 p = popen(["compare", '-alpha', 'opaque', '-metric', 'AE', '-fuzz', '5%', ref_image, image, delta_image])
136 _, stderr = p.communicate()
140 'trivial/clear-color',
142 'trivial/clear-fbo-scissor',
143 'trivial/clear-fbo-tex',
144 'trivial/clear-random',
145 'trivial/clear-repeat',
146 'trivial/clear-scissor',
147 'trivial/clear-undefined',
149 'trivial/dlist-begin-call-end',
150 'trivial/dlist-dangling',
151 'trivial/dlist-degenerate',
152 'trivial/dlist-edgeflag',
153 'trivial/dlist-edgeflag-dangling',
154 'trivial/dlist-flat-tri',
155 'trivial/dlist-mat-tri',
156 'trivial/dlist-recursive-call',
157 'trivial/dlist-tri-flat-tri',
158 'trivial/dlist-tri-mat-tri',
159 'trivial/draw2arrays',
160 'trivial/drawarrays',
161 'trivial/drawelements',
162 'trivial/drawelements-large',
170 'trivial/line-smooth',
171 'trivial/line-stipple-wide',
172 'trivial/line-userclip',
173 'trivial/line-userclip-clip',
174 'trivial/line-userclip-nop',
175 'trivial/line-userclip-nop-clip',
179 'trivial/lineloop-clip',
180 'trivial/lineloop-elts',
182 'trivial/linestrip-clip',
183 'trivial/linestrip-flat-stipple',
184 'trivial/linestrip-stipple',
185 'trivial/linestrip-stipple-wide',
186 'trivial/long-fixed-func',
189 'trivial/point-clip',
190 'trivial/point-param',
191 'trivial/point-sprite',
192 'trivial/point-wide',
193 'trivial/point-wide-smooth',
196 'trivial/poly-flat-clip',
197 'trivial/poly-flat-unfilled-clip',
198 'trivial/poly-unfilled',
201 'trivial/quad-clip-all-vertices',
202 'trivial/quad-clip-nearplane',
203 'trivial/quad-degenerate',
205 'trivial/quad-offset-factor',
206 'trivial/quad-offset-unfilled',
207 'trivial/quad-offset-units',
208 'trivial/quad-tex-2d',
209 'trivial/quad-tex-3d',
210 'trivial/quad-tex-alpha',
211 'trivial/quad-tex-pbo',
212 'trivial/quad-tex-sub',
213 'trivial/quad-unfilled',
214 'trivial/quad-unfilled-clip',
215 'trivial/quad-unfilled-stipple',
218 'trivial/quadstrip-clip',
219 'trivial/quadstrip-cont',
220 'trivial/quadstrip-flat',
221 'trivial/readpixels',
226 'trivial/tri-alpha-tex',
227 'trivial/tri-array-interleaved',
229 'trivial/tri-blend-color',
230 'trivial/tri-blend-max',
231 'trivial/tri-blend-min',
232 'trivial/tri-blend-revsub',
233 'trivial/tri-blend-sub',
237 'trivial/tri-cull-both',
239 'trivial/tri-edgeflag',
240 'trivial/tri-edgeflag-array',
242 'trivial/tri-fbo-tex',
243 'trivial/tri-fbo-tex-mip',
245 'trivial/tri-flat-clip',
248 'trivial/tri-fp-const-imm',
250 'trivial/tri-lit-material',
251 'trivial/tri-logicop-none',
252 'trivial/tri-logicop-xor',
253 'trivial/tri-mask-tri',
254 'trivial/tri-multitex-vbo',
256 'trivial/tri-point-line-clipped',
258 'trivial/tri-repeat',
259 'trivial/tri-scissor-tri',
260 'trivial/tri-square',
261 'trivial/tri-stencil',
262 'trivial/tri-stipple',
264 'trivial/tri-tex-1d',
265 'trivial/tri-tex-3d',
267 'trivial/tri-unfilled',
268 'trivial/tri-unfilled-clip',
269 'trivial/tri-unfilled-edgeflag',
270 'trivial/tri-unfilled-fog',
271 'trivial/tri-unfilled-point',
272 'trivial/tri-unfilled-smooth',
273 'trivial/tri-unfilled-tri',
274 'trivial/tri-unfilled-tri-lit',
275 'trivial/tri-unfilled-userclip',
276 'trivial/tri-unfilled-userclip-stip',
277 'trivial/tri-userclip',
278 'trivial/tri-viewport',
283 'trivial/trifan-flat',
284 'trivial/trifan-flat-clip',
285 'trivial/trifan-flat-unfilled-clip',
286 'trivial/trifan-unfilled',
288 'trivial/tristrip-clip',
289 'trivial/tristrip-flat',
290 'trivial/vbo-drawarrays',
291 'trivial/vbo-drawelements',
292 'trivial/vbo-drawrange',
293 'trivial/vbo-noninterleaved',
296 'trivial/vp-array-hf',
297 'trivial/vp-array-int',
299 'trivial/vp-line-clip',
302 'trivial/vp-tri-cb-pos',
303 'trivial/vp-tri-cb-tex',
304 'trivial/vp-tri-imm',
305 'trivial/vp-tri-invariant',
306 'trivial/vp-tri-swap',
307 'trivial/vp-tri-tex',
308 'trivial/vp-unfilled',
313 #'demos/arbocclude2',
322 #'demos/fbo_firecube',
349 #'demos/singlebuffer',
351 #'demos/spriteblast',
365 #'fp/point-position',
368 #'fp/tri-depthwrite',
369 #'fp/tri-depthwrite2',
378 #'glsl/convolutions',
382 #'glsl/geom-sprites',
383 #'glsl/geom-stipple-lines',
384 #'glsl/geom-wide-lines',
395 #'glsl/shadow_sampler',
403 #'glsl/vert-or-frag-only',
408 #'perf/drawoverhead',
431 #'redbook/convolution',
444 #'redbook/histogram',
453 #'redbook/movelight',
454 #'redbook/multisamp',
458 #'redbook/pickdepth',
459 #'redbook/picksquare',
467 #'redbook/sccolorlight',
469 #'redbook/scenebamb',
470 #'redbook/sceneflat',
472 #'redbook/shadowmap',
477 #'redbook/surfpoints',
478 #'redbook/teaambient',
486 #'redbook/texture3d',
487 #'redbook/texturesurf',
490 #'redbook/unproject',
530 'tests/arbfptexture',
534 'tests/arbnpot-mipmap',
538 'tests/arbvpwarpmesh',
539 'tests/arraytexture',
547 'tests/bug_texstore_i8',
549 'tests/calibrate_rast',
556 'tests/drawbuffers2',
559 'tests/ext422square',
579 'tests/mipmap_comp_tests',
580 'tests/mipmap_limits',
581 'tests/mipmap_tunnel',
584 'tests/multitexarray',
588 'tests/packedpixels',
592 'tests/prog_parameter',
598 'tests/scissor-viewport',
600 'tests/shader-interp',
602 'tests/shadow-sample',
604 'tests/stencilreaddraw',
607 'tests/streaming_rect',
612 'tests/texcompress2',
622 'tests/unfilledclip',
641 #'xdemos/glxcontexts',
644 #'xdemos/glxgears_fbconfig',
645 #'xdemos/glxgears_pixmap',
651 #'xdemos/glxswapcontrol',
657 #'xdemos/opencloseopen',
663 #'xdemos/sharedtex_mt',
664 #'xdemos/texture_from_pixmap',
667 #'xdemos/xrotfontdemo',
668 #'xdemos/yuvrect_client',
681 # Parse command line options
682 optparser = optparse.OptionParser(
683 usage='\n\t%prog [options] [demo] ...',
685 optparser.add_option(
686 '--build', metavar='PATH',
687 type='string', dest='build', default='.',
688 help='path to apitrace build [default=%default]')
689 optparser.add_option(
690 '--mesa-demos', metavar='PATH',
691 type='string', dest='mesa_demos', default=os.environ.get('MESA_DEMOS'),
692 help='path to Mesa demos [default=%default]')
694 (options, args) = optparser.parse_args(sys.argv[1:])
696 if not options.mesa_demos:
697 optparser.error('path to Mesa demos not specified')
707 if __name__ == '__main__':