]> git.cworth.org Git - apitrace-tests/blob - mesademos.py
Allow to specify the mesa demo on command line.
[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/arbfpspec',
520     'tests/arbfptest1',
521     'tests/arbfptexture',
522     'tests/arbfptrig',
523     'tests/arbgpuprog',
524     'tests/arbnpot',
525     'tests/arbnpot-mipmap',
526     'tests/arbvptest1',
527     'tests/arbvptest3',
528     'tests/arbvptorus',
529     'tests/arbvpwarpmesh',
530     'tests/arraytexture',
531     'tests/auxbuffer',
532     'tests/blendxor',
533     'tests/blitfb',
534     'tests/bufferobj',
535     'tests/bug_3050',
536     'tests/bug_3101',
537     'tests/bug_3195',
538     'tests/bug_texstore_i8',
539     'tests/bumpmap',
540     'tests/calibrate_rast',
541     'tests/condrender',
542     'tests/copypixrate',
543     'tests/cva',
544     'tests/cva_huge',
545     'tests/cylwrap',
546     'tests/drawbuffers',
547     'tests/drawbuffers2',
548     'tests/drawstencil',
549     'tests/exactrast',
550     'tests/ext422square',
551     'tests/fbotest1',
552     'tests/fbotest2',
553     'tests/fbotest3',
554     'tests/fillrate',
555     'tests/floattex',
556     'tests/fogcoord',
557     'tests/fptest1',
558     'tests/fptexture',
559     'tests/getteximage',
560     'tests/glutfx',
561     'tests/interleave',
562     'tests/invert',
563     'tests/jkrahntest',
564     'tests/lineclip',
565     'tests/manytex',
566     'tests/mapbufrange',
567     'tests/minmag',
568     'tests/mipgen',
569     'tests/mipmap_comp',
570     'tests/mipmap_comp_tests',
571     'tests/mipmap_limits',
572     'tests/mipmap_tunnel',
573     'tests/mipmap_view',
574     'tests/multipal',
575     'tests/multitexarray',
576     'tests/multiwindow',
577     'tests/no_s3tc',
578     'tests/occlude',
579     'tests/packedpixels',
580     'tests/pbo',
581     'tests/persp_hint',
582     'tests/prim',
583     'tests/prog_parameter',
584     'tests/quads',
585     'tests/random',
586     'tests/readrate',
587     'tests/rubberband',
588     'tests/scissor',
589     'tests/scissor-viewport',
590     'tests/seccolor',
591     'tests/shader-interp',
592     'tests/shader_api',
593     'tests/shadow-sample',
594     'tests/sharedtex',
595     'tests/stencilreaddraw',
596     'tests/stencilwrap',
597     'tests/step',
598     'tests/streaming_rect',
599     'tests/subtex',
600     'tests/subtexrate',
601     'tests/tex1d',
602     'tests/texcmp',
603     'tests/texcompress2',
604     'tests/texcompsub',
605     'tests/texdown',
606     'tests/texfilt',
607     'tests/texgenmix',
608     'tests/texleak',
609     'tests/texline',
610     'tests/texobj',
611     'tests/texobjshare',
612     'tests/texrect',
613     'tests/unfilledclip',
614     'tests/vparray',
615     'tests/vpeval',
616     'tests/vptest1',
617     'tests/vptest2',
618     'tests/vptest3',
619     'tests/vptorus',
620     'tests/vpwarpmesh',
621     'tests/yuvrect',
622     'tests/yuvsquare',
623     'tests/zbitmap',
624     'tests/zcomp',
625     'tests/zdrawpix',
626     'tests/zreaddraw',
627     #'vp/vp-tris',
628     #'vpglsl/vp-tris',
629     #'xdemos/corender',
630     #'xdemos/glsync',
631     #'xdemos/glthreads',
632     #'xdemos/glxcontexts',
633     #'xdemos/glxdemo',
634     #'xdemos/glxgears',
635     #'xdemos/glxgears_fbconfig',
636     #'xdemos/glxgears_pixmap',
637     #'xdemos/glxheads',
638     #'xdemos/glxinfo',
639     #'xdemos/glxpbdemo',
640     #'xdemos/glxpixmap',
641     #'xdemos/glxsnoop',
642     #'xdemos/glxswapcontrol',
643     #'xdemos/manywin',
644     #'xdemos/msctest',
645     #'xdemos/multictx',
646     #'xdemos/offset',
647     #'xdemos/omlsync',
648     #'xdemos/opencloseopen',
649     #'xdemos/overlay',
650     #'xdemos/pbdemo',
651     #'xdemos/pbinfo',
652     #'xdemos/shape',
653     #'xdemos/sharedtex',
654     #'xdemos/sharedtex_mt',
655     #'xdemos/texture_from_pixmap',
656     #'xdemos/wincopy',
657     #'xdemos/xfont',
658     #'xdemos/xrotfontdemo',
659     #'xdemos/yuvrect_client',
660 ]
661
662
663 tests = [
664     'trivial/tri',
665     'trivial/tri-tex',
666 ]
667
668
669 def main():
670     global options
671
672     # Parse command line options
673     optparser = optparse.OptionParser(
674         usage='\n\t%prog [options] [demo] ...',
675         version='%%prog')
676     optparser.add_option(
677         '--build', metavar='PATH',
678         type='string', dest='build', default='.',
679         help='path to apitrace build')
680
681     optparser.add_option(
682         '--mesa-demos', metavar='PATH',
683         type='string', dest='mesa_demos', default=os.environ.get('MESA_DEMOS'),
684         help='path to mesa demos')
685
686     (options, args) = optparser.parse_args(sys.argv[1:])
687     if args:
688         tests = args
689
690     for test in tests:
691        runtest(test)
692
693
694 if __name__ == '__main__':
695     main()