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