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