]> git.cworth.org Git - apitrace-tests/blob - mesademos.py
Store results in current dir.
[apitrace-tests] / mesademos.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 '''Apitrace test suite based on Mesa demos.'''
29
30
31
32 import os.path
33 import optparse
34 import sys
35 import subprocess
36 import time
37 import re
38 import signal
39
40
41 ansi_re = re.compile('\x1b\[[0-9]{1,2}(;[0-9]{1,2}){0,2}m')
42
43
44 def ansi_strip(s):
45     # http://www.theeggeadventure.com/wikimedia/index.php/Linux_Tips#Use_sed_to_remove_ANSI_colors
46     return ansi_re.sub('', s)
47
48
49 def popen(command, *args, **kwargs):
50     sys.stdout.write(' '.join(command) + '\n')
51     sys.stdout.flush()
52     return subprocess.Popen(command, *args, **kwargs)
53
54
55 ignored_function_names = set([
56     'glGetString',
57     'glXGetCurrentDisplay',
58     'glXGetClientString',
59     'glXGetProcAddress',
60     'glXGetProcAddressARB',
61     'glXQueryVersion',
62     'glXGetVisualFromFBConfig',
63     'glXChooseFBConfig',
64     'glXCreateNewContext',
65     'glXMakeContextCurrent',
66     'glXQueryExtension',
67     'glXIsDirect',
68 ])
69
70
71 def runtest(demo):
72
73     app = os.path.join(options.mesa_demos, 'src', demo)
74
75     dirname, basename = os.path.split(app)
76     
77     trace = os.path.abspath(demo.replace('/', '-') + '.trace')
78
79     env = os.environ.copy()
80     env['LD_PRELOAD'] = os.path.abspath('glxtrace.so')
81     env['TRACE_FILE'] = trace
82     
83     args = [os.path.join('.', basename)]
84     p = popen(args, env=env, cwd=dirname, stdout=subprocess.PIPE)
85     time.sleep(0.5)
86
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)
90
91     os.kill(p.pid, signal.SIGTERM)
92
93     p = popen(['./tracedump', trace], stdout=subprocess.PIPE)
94     stdout, _ = p.communicate()
95
96     call_re = re.compile('^([0-9]+) (\w+)\(')
97     double_buffer = False
98     for orig_line in stdout.split('\n'):
99         line = ansi_strip(orig_line)
100         mo = call_re.match(line)
101         if mo:
102             call_no = int(mo.group(1))
103             function_name = mo.group(2)
104             if function_name in ignored_function_names:
105                 continue
106             if function_name == 'glXSwapBuffers':
107                 double_buffer = True
108         #print orig_line
109
110     args = ['./glretrace']
111     if double_buffer:
112         args += ['-db']
113     args += ['-s', '/tmp/' + demo.replace('/', '-') + '.']
114     args += [trace]
115     p = popen(args, stdout=subprocess.PIPE)
116     stdout, _ = p.communicate()
117     image_re = re.compile('^Wrote (.*\.png)$')
118     image = None
119     for line in stdout.split('\n'):
120         mo = image_re.match(line)
121         if mo:
122             image = mo.group(1)
123     
124     if image:
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()
128
129
130 tests = [
131     'trivial/clear-color',
132     'trivial/clear-fbo',
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',
139     'trivial/createwin',
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',
154     'trivial/drawrange',
155     'trivial/flat-clip',
156     'trivial/fs-tri',
157     'trivial/line',
158     'trivial/line-clip',
159     'trivial/line-cull',
160     'trivial/line-flat',
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',
167     'trivial/line-wide',
168     'trivial/line-xor',
169     'trivial/lineloop',
170     'trivial/lineloop-clip',
171     'trivial/lineloop-elts',
172     'trivial/linestrip',
173     'trivial/linestrip-clip',
174     'trivial/linestrip-flat-stipple',
175     'trivial/linestrip-stipple',
176     'trivial/linestrip-stipple-wide',
177     'trivial/long-fixed-func',
178     'trivial/pgon-mode',
179     'trivial/point',
180     'trivial/point-clip',
181     'trivial/point-param',
182     'trivial/point-sprite',
183     'trivial/point-wide',
184     'trivial/point-wide-smooth',
185     'trivial/poly',
186     'trivial/poly-flat',
187     'trivial/poly-flat-clip',
188     'trivial/poly-flat-unfilled-clip',
189     'trivial/poly-unfilled',
190     'trivial/quad',
191     'trivial/quad-clip',
192     'trivial/quad-clip-all-vertices',
193     'trivial/quad-clip-nearplane',
194     'trivial/quad-degenerate',
195     'trivial/quad-flat',
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',
207     'trivial/quads',
208     'trivial/quadstrip',
209     'trivial/quadstrip-clip',
210     'trivial/quadstrip-cont',
211     'trivial/quadstrip-flat',
212     'trivial/readpixels',
213     'trivial/sub-tex',
214     'trivial/tex-quads',
215     'trivial/tri',
216     'trivial/tri-alpha',
217     'trivial/tri-alpha-tex',
218     'trivial/tri-array-interleaved',
219     'trivial/tri-blend',
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',
225     'trivial/tri-clear',
226     'trivial/tri-clip',
227     'trivial/tri-cull',
228     'trivial/tri-cull-both',
229     'trivial/tri-dlist',
230     'trivial/tri-edgeflag',
231     'trivial/tri-edgeflag-array',
232     'trivial/tri-fbo',
233     'trivial/tri-fbo-tex',
234     'trivial/tri-fbo-tex-mip',
235     'trivial/tri-flat',
236     'trivial/tri-flat-clip',
237     'trivial/tri-fog',
238     'trivial/tri-fp',
239     'trivial/tri-fp-const-imm',
240     'trivial/tri-lit',
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',
246     'trivial/tri-orig',
247     'trivial/tri-point-line-clipped',
248     'trivial/tri-query',
249     'trivial/tri-repeat',
250     'trivial/tri-scissor-tri',
251     'trivial/tri-square',
252     'trivial/tri-stencil',
253     'trivial/tri-stipple',
254     'trivial/tri-tex',
255     'trivial/tri-tex-1d',
256     'trivial/tri-tex-3d',
257     'trivial/tri-tri',
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',
270     'trivial/tri-z',
271     'trivial/tri-z-9',
272     'trivial/tri-z-eq',
273     'trivial/trifan',
274     'trivial/trifan-flat',
275     'trivial/trifan-flat-clip',
276     'trivial/trifan-flat-unfilled-clip',
277     'trivial/trifan-unfilled',
278     'trivial/tristrip',
279     'trivial/tristrip-clip',
280     'trivial/tristrip-flat',
281     'trivial/vbo-drawarrays',
282     'trivial/vbo-drawelements',
283     'trivial/vbo-drawrange',
284     'trivial/vbo-noninterleaved',
285     'trivial/vbo-tri',
286     'trivial/vp-array',
287     'trivial/vp-array-hf',
288     'trivial/vp-array-int',
289     'trivial/vp-clip',
290     'trivial/vp-line-clip',
291     'trivial/vp-tri',
292     'trivial/vp-tri-cb',
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',
300
301     #'demos/arbfplight',
302     #'demos/arbfslight',
303     #'demos/arbocclude',
304     #'demos/arbocclude2',
305     #'demos/bounce',
306     #'demos/clearspd',
307     #'demos/copypix',
308     #'demos/cubemap',
309     #'demos/dinoshade',
310     #'demos/dissolve',
311     #'demos/drawpix',
312     #'demos/engine',
313     #'demos/fbo_firecube',
314     #'demos/fbotexture',
315     #'demos/fire',
316     #'demos/fogcoord',
317     #'demos/fplight',
318     #'demos/fslight',
319     #'demos/gamma',
320     #'demos/gearbox',
321     #'demos/gears',
322     #'demos/geartrain',
323     #'demos/glinfo',
324     #'demos/gloss',
325     #'demos/gltestperf',
326     #'demos/ipers',
327     #'demos/isosurf',
328     #'demos/lodbias',
329     #'demos/morph3d',
330     #'demos/multiarb',
331     #'demos/paltex',
332     #'demos/pointblast',
333     #'demos/projtex',
334     #'demos/rain',
335     #'demos/ray',
336     #'demos/readpix',
337     #'demos/reflect',
338     #'demos/renormal',
339     #'demos/shadowtex',
340     #'demos/singlebuffer',
341     #'demos/spectex',
342     #'demos/spriteblast',
343     #'demos/stex3d',
344     #'demos/teapot',
345     #'demos/terrain',
346     #'demos/tessdemo',
347     #'demos/texcyl',
348     #'demos/texenv',
349     #'demos/textures',
350     #'demos/trispd',
351     #'demos/tunnel',
352     #'demos/tunnel2',
353     #'demos/vao_demo',
354     #'demos/winpos',
355     #'fp/fp-tri',
356     #'fp/point-position',
357     #'fp/tri-depth',
358     #'fp/tri-depth2',
359     #'fp/tri-depthwrite',
360     #'fp/tri-depthwrite2',
361     #'fp/tri-param',
362     #'fp/tri-tex',
363     #'fpglsl/fp-tri',
364     #'glsl/array',
365     #'glsl/bezier',
366     #'glsl/bitmap',
367     #'glsl/brick',
368     #'glsl/bump',
369     #'glsl/convolutions',
370     #'glsl/deriv',
371     #'glsl/fragcoord',
372     #'glsl/fsraytrace',
373     #'glsl/geom-sprites',
374     #'glsl/geom-stipple-lines',
375     #'glsl/geom-wide-lines',
376     #'glsl/identity',
377     #'glsl/linktest',
378     #'glsl/mandelbrot',
379     #'glsl/multinoise',
380     #'glsl/multitex',
381     #'glsl/noise',
382     #'glsl/noise2',
383     #'glsl/pointcoord',
384     #'glsl/points',
385     #'glsl/samplers',
386     #'glsl/shadow_sampler',
387     #'glsl/shtest',
388     #'glsl/skinning',
389     #'glsl/texaaline',
390     #'glsl/texdemo1',
391     #'glsl/toyball',
392     #'glsl/trirast',
393     #'glsl/twoside',
394     #'glsl/vert-or-frag-only',
395     #'glsl/vert-tex',
396     #'glsl/vsraytrace',
397     #'gs/gs-tri',
398     #'perf/copytex',
399     #'perf/drawoverhead',
400     #'perf/fbobind',
401     #'perf/fill',
402     #'perf/genmipmap',
403     #'perf/readpixels',
404     #'perf/swapbuffers',
405     #'perf/teximage',
406     #'perf/vbo',
407     #'perf/vertexrate',
408     #'redbook/aaindex',
409     #'redbook/aapoly',
410     #'redbook/aargb',
411     #'redbook/accanti',
412     #'redbook/accpersp',
413     #'redbook/alpha',
414     #'redbook/alpha3D',
415     #'redbook/anti',
416     #'redbook/bezcurve',
417     #'redbook/bezmesh',
418     #'redbook/checker',
419     #'redbook/clip',
420     #'redbook/colormat',
421     #'redbook/combiner',
422     #'redbook/convolution',
423     #'redbook/cube',
424     #'redbook/cubemap',
425     #'redbook/depthcue',
426     #'redbook/dof',
427     #'redbook/double',
428     #'redbook/drawf',
429     #'redbook/feedback',
430     #'redbook/fog',
431     #'redbook/fogcoord',
432     #'redbook/fogindex',
433     #'redbook/font',
434     #'redbook/hello',
435     #'redbook/histogram',
436     #'redbook/image',
437     #'redbook/light',
438     #'redbook/lines',
439     #'redbook/list',
440     #'redbook/material',
441     #'redbook/minmax',
442     #'redbook/mipmap',
443     #'redbook/model',
444     #'redbook/movelight',
445     #'redbook/multisamp',
446     #'redbook/multitex',
447     #'redbook/mvarray',
448     #'redbook/nurbs',
449     #'redbook/pickdepth',
450     #'redbook/picksquare',
451     #'redbook/plane',
452     #'redbook/planet',
453     #'redbook/pointp',
454     #'redbook/polyoff',
455     #'redbook/polys',
456     #'redbook/quadric',
457     #'redbook/robot',
458     #'redbook/sccolorlight',
459     #'redbook/scene',
460     #'redbook/scenebamb',
461     #'redbook/sceneflat',
462     #'redbook/select',
463     #'redbook/shadowmap',
464     #'redbook/smooth',
465     #'redbook/stencil',
466     #'redbook/stroke',
467     #'redbook/surface',
468     #'redbook/surfpoints',
469     #'redbook/teaambient',
470     #'redbook/teapots',
471     #'redbook/tess',
472     #'redbook/tesswind',
473     #'redbook/texbind',
474     #'redbook/texgen',
475     #'redbook/texprox',
476     #'redbook/texsub',
477     #'redbook/texture3d',
478     #'redbook/texturesurf',
479     #'redbook/torus',
480     #'redbook/trim',
481     #'redbook/unproject',
482     #'redbook/varray',
483     #'redbook/wrap',
484     #'samples/accum',
485     #'samples/bitmap1',
486     #'samples/bitmap2',
487     #'samples/blendeq',
488     #'samples/blendxor',
489     #'samples/copy',
490     #'samples/cursor',
491     #'samples/depth',
492     #'samples/eval',
493     #'samples/fog',
494     #'samples/font',
495     #'samples/line',
496     #'samples/logo',
497     #'samples/nurb',
498     #'samples/oglinfo',
499     #'samples/olympic',
500     #'samples/overlay',
501     #'samples/point',
502     #'samples/prim',
503     #'samples/quad',
504     #'samples/rgbtoppm',
505     #'samples/select',
506     #'samples/shape',
507     #'samples/sphere',
508     #'samples/star',
509     #'samples/stencil',
510     #'samples/stretch',
511     #'samples/texture',
512     #'samples/tri',
513     #'samples/wave',
514     #'slang/cltest',
515     #'slang/sotest',
516     #'slang/vstest',
517     'tests/afsmultiarb',
518     'tests/antialias',
519     'tests/api_speed.py',
520     'tests/arbfpspec',
521     'tests/arbfptest1',
522     'tests/arbfptexture',
523     'tests/arbfptrig',
524     'tests/arbgpuprog',
525     'tests/arbnpot',
526     'tests/arbnpot-mipmap',
527     'tests/arbvptest1',
528     'tests/arbvptest3',
529     'tests/arbvptorus',
530     'tests/arbvpwarpmesh',
531     'tests/arraytexture',
532     'tests/auxbuffer',
533     'tests/blendxor',
534     'tests/blitfb',
535     'tests/bufferobj',
536     'tests/bug_3050',
537     'tests/bug_3101',
538     'tests/bug_3195',
539     'tests/bug_texstore_i8',
540     'tests/bumpmap',
541     'tests/calibrate_rast',
542     'tests/condrender',
543     'tests/copypixrate',
544     'tests/cva',
545     'tests/cva_huge',
546     'tests/cylwrap',
547     'tests/drawbuffers',
548     'tests/drawbuffers2',
549     'tests/drawstencil',
550     'tests/exactrast',
551     'tests/ext422square',
552     'tests/fbotest1',
553     'tests/fbotest2',
554     'tests/fbotest3',
555     'tests/fillrate',
556     'tests/floattex',
557     'tests/fogcoord',
558     'tests/fptest1',
559     'tests/fptexture',
560     'tests/getteximage',
561     'tests/glutfx',
562     'tests/interleave',
563     'tests/invert',
564     'tests/jkrahntest',
565     'tests/lineclip',
566     'tests/manytex',
567     'tests/mapbufrange',
568     'tests/minmag',
569     'tests/mipgen',
570     'tests/mipmap_comp',
571     'tests/mipmap_comp_tests',
572     'tests/mipmap_limits',
573     'tests/mipmap_tunnel',
574     'tests/mipmap_view',
575     'tests/multipal',
576     'tests/multitexarray',
577     'tests/multiwindow',
578     'tests/no_s3tc',
579     'tests/occlude',
580     'tests/packedpixels',
581     'tests/pbo',
582     'tests/persp_hint',
583     'tests/prim',
584     'tests/prog_parameter',
585     'tests/quads',
586     'tests/random',
587     'tests/readrate',
588     'tests/rubberband',
589     'tests/scissor',
590     'tests/scissor-viewport',
591     'tests/seccolor',
592     'tests/shader-interp',
593     'tests/shader_api',
594     'tests/shadow-sample',
595     'tests/sharedtex',
596     'tests/stencilreaddraw',
597     'tests/stencilwrap',
598     'tests/step',
599     'tests/streaming_rect',
600     'tests/subtex',
601     'tests/subtexrate',
602     'tests/tex1d',
603     'tests/texcmp',
604     'tests/texcompress2',
605     'tests/texcompsub',
606     'tests/texdown',
607     'tests/texfilt',
608     'tests/texgenmix',
609     'tests/texleak',
610     'tests/texline',
611     'tests/texobj',
612     'tests/texobjshare',
613     'tests/texrect',
614     'tests/unfilledclip',
615     'tests/vparray',
616     'tests/vpeval',
617     'tests/vptest1',
618     'tests/vptest2',
619     'tests/vptest3',
620     'tests/vptorus',
621     'tests/vpwarpmesh',
622     'tests/yuvrect',
623     'tests/yuvsquare',
624     'tests/zbitmap',
625     'tests/zcomp',
626     'tests/zdrawpix',
627     'tests/zreaddraw',
628     #'vp/vp-tris',
629     #'vpglsl/vp-tris',
630     #'xdemos/corender',
631     #'xdemos/glsync',
632     #'xdemos/glthreads',
633     #'xdemos/glxcontexts',
634     #'xdemos/glxdemo',
635     #'xdemos/glxgears',
636     #'xdemos/glxgears_fbconfig',
637     #'xdemos/glxgears_pixmap',
638     #'xdemos/glxheads',
639     #'xdemos/glxinfo',
640     #'xdemos/glxpbdemo',
641     #'xdemos/glxpixmap',
642     #'xdemos/glxsnoop',
643     #'xdemos/glxswapcontrol',
644     #'xdemos/manywin',
645     #'xdemos/msctest',
646     #'xdemos/multictx',
647     #'xdemos/offset',
648     #'xdemos/omlsync',
649     #'xdemos/opencloseopen',
650     #'xdemos/overlay',
651     #'xdemos/pbdemo',
652     #'xdemos/pbinfo',
653     #'xdemos/shape',
654     #'xdemos/sharedtex',
655     #'xdemos/sharedtex_mt',
656     #'xdemos/texture_from_pixmap',
657     #'xdemos/wincopy',
658     #'xdemos/xfont',
659     #'xdemos/xrotfontdemo',
660     #'xdemos/yuvrect_client',
661 ]
662
663
664 tests = [
665     'trivial/tri',
666     'trivial/tri-tex',
667 ]
668
669
670 def main():
671     global options
672
673     # Parse command line options
674     optparser = optparse.OptionParser(
675         usage='\n\t%prog [options] ',
676         version='%%prog')
677     optparser.add_option(
678         '--build', metavar='PATH',
679         type='string', dest='build', default='.',
680         help='path to apitrace build')
681
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')
686
687     (options, args) = optparser.parse_args(sys.argv[1:])
688     if args:
689         optparser.error("incorrect number of arguments")
690
691     for test in tests:
692        runtest(test)
693
694
695 if __name__ == '__main__':
696     main()