diff --git a/tests/check_crash_on_glutinit.py b/tests/check_crash_on_glutinit.py index 938e5ea3..205cfe1a 100644 --- a/tests/check_crash_on_glutinit.py +++ b/tests/check_crash_on_glutinit.py @@ -1,13 +1,23 @@ +from OpenGL.GLUT import * +from OpenGL.GL import * + + +def main(): + if glutInit: + glutInit(' ') + glutInitDisplayMode(GLUT_SINGLE) + window = glutCreateWindow("hello") + glutDisplayFunc(lambda *args: 1) + # glutMainLoop() + try: + if fgDeinitialize: + fgDeinitialize(False) + except NameError as err: + pass # Older PyOpenGL, you may see a seg-fault here... + print('OK') + else: + print('SKIP') + if __name__ == "__main__": - from OpenGL.GLUT import * - from OpenGL.GL import * - glutInit( ' ' ) - glutInitDisplayMode( GLUT_SINGLE ) - window = glutCreateWindow("hello") - glutDisplayFunc( lambda *args: 1 ) - #glutMainLoop() - try: - if fgDeinitialize: fgDeinitialize(False) - except NameError as err: - pass # Older PyOpenGL, you may see a seg-fault here... + main() diff --git a/tests/check_egl_es1.py b/tests/check_egl_es1.py index 51482bb9..62fd27f2 100755 --- a/tests/check_egl_es1.py +++ b/tests/check_egl_es1.py @@ -12,6 +12,7 @@ def test_es1(): GL.glEnableClientState(GL.GL_VERTEX_ARRAY) GL.glVertexPointer(3, GL.GL_FLOAT, 0, vertices) GL.glDrawArrays(GL.GL_TRIANGLES, 0, 3) + print('OK') if __name__ == "__main__": diff --git a/tests/check_egl_es2.py b/tests/check_egl_es2.py index a7fd7cb5..8a431b97 100755 --- a/tests/check_egl_es2.py +++ b/tests/check_egl_es2.py @@ -49,6 +49,7 @@ def test_gl(): stride = 3 * 4 glVertexAttribPointer(position_location, 3, GL_FLOAT, False, stride, vbo) glDrawArrays(GL_TRIANGLES, 0, 3) + print('OK') if __name__ == "__main__": diff --git a/tests/check_egl_opengl.py b/tests/check_egl_opengl.py index a2556dfc..3cf65b46 100755 --- a/tests/check_egl_opengl.py +++ b/tests/check_egl_opengl.py @@ -8,6 +8,7 @@ def test_gl(): GL.glClearColor(1, 0, 0, 0) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) + print('OK') if __name__ == "__main__": diff --git a/tests/check_egl_platform_ext.py b/tests/check_egl_platform_ext.py index 178ecf61..243d8c31 100644 --- a/tests/check_egl_platform_ext.py +++ b/tests/check_egl_platform_ext.py @@ -1,6 +1,8 @@ """This checking script from https://github.com/mcfletch/pyopengl/issues/6""" + import OpenGL import OpenGL.platform.egl + OpenGL.platform.PLATFORM = p = OpenGL.platform.egl.EGLPlatform() from OpenGL import EGL from OpenGL.EGL.VERSION import EGL_1_5 @@ -8,30 +10,32 @@ from OpenGL.EGL.MESA import platform_gbm import ctypes, glob + def main(): cards = sorted(glob.glob("/dev/dri/renderD*")) if not cards: + print('SKIP') raise RuntimeError("Need a /dev/dri/renderD* device to do rendering") if len(cards) > 1: - print("Note, using first card: %s"%(cards[0])) + print("Note, using first card: %s" % (cards[0])) with open(cards[0], "w") as f: - gbm = ctypes.CDLL("libgbm.so.1") # On Ubuntu, package libgbm1 + gbm = ctypes.CDLL("libgbm.so.1") # On Ubuntu, package libgbm1 dev = gbm.gbm_create_device(f.fileno()) dpy = platform_base.eglGetPlatformDisplayEXT( - platform_gbm.EGL_PLATFORM_GBM_MESA, - ctypes.c_void_p(dev), - ctypes.c_void_p(0) + platform_gbm.EGL_PLATFORM_GBM_MESA, ctypes.c_void_p(dev), ctypes.c_void_p(0) ) print(dpy) if EGL_1_5.eglGetPlatformDisplay: dpy = EGL_1_5.eglGetPlatformDisplay( - platform_gbm.EGL_PLATFORM_GBM_MESA, - ctypes.c_void_p(dev), - ctypes.c_void_p(0) + platform_gbm.EGL_PLATFORM_GBM_MESA, + ctypes.c_void_p(dev), + ctypes.c_void_p(0), ) print(dpy) else: print("No EGL_1_5 implementation") + print('OK') + if __name__ == "__main__": main() diff --git a/tests/check_egl_pygame.py b/tests/check_egl_pygame.py index 649e99e6..849ad8a0 100644 --- a/tests/check_egl_pygame.py +++ b/tests/check_egl_pygame.py @@ -88,8 +88,8 @@ def mainloop(displayfunc): if event.type == pygame.QUIT: return if not displayfunc(): - break - print("rendered") + return False + return True def main(displayfunc, api): @@ -110,9 +110,6 @@ def main(displayfunc, api): configs = (EGLConfig * num_configs.value)() eglGetConfigs(display, configs, num_configs.value, num_configs) - for number, config_id in enumerate(configs): - # print config_id - log.info("Config #%d\n%s", number, describe_config(display, config_id)) bit = EGL_OPENGL_API if api == 'gles': @@ -131,6 +128,11 @@ def main(displayfunc, api): attributes = (EGLint * len(attributes))(*attributes) eglChooseConfig(display, attributes, configs, len(configs), num_configs) + for number, config_id in enumerate(configs): + # print config_id + log.info("Config #%d\n%s", number, describe_config(display, config_id)) + break + log.info("Attempting to bind and create contexts/apis for %s", api) try: eglBindAPI(0x3333) # junk value @@ -165,11 +167,13 @@ def _displayfunc(): try: displayfunc(display, surface, ctx) except Exception: + log.exception("Failure during display function") return False else: return True - mainloop(_displayfunc) + if not mainloop(_displayfunc): + raise RuntimeError("Display func crashed") pbufAttribs = (EGLint * 5)(*[EGL_WIDTH, 500, EGL_HEIGHT, 500, EGL_NONE]) pbuffer = eglCreatePbufferSurface(display, configs[0], pbufAttribs) @@ -181,6 +185,7 @@ def _displayfunc(): "Available EGL extensions:\n %s", "\n ".join([as_str(ext) for ext in EGLQuerier.getExtensions().split()]), ) + print('OK') def displayfunc_gl(display, surface, ctx): diff --git a/tests/test_err_check_extension_check.py b/tests/check_freeglut_deinit.py similarity index 58% rename from tests/test_err_check_extension_check.py rename to tests/check_freeglut_deinit.py index eeab942e..1387ac16 100644 --- a/tests/test_err_check_extension_check.py +++ b/tests/check_freeglut_deinit.py @@ -1,25 +1,36 @@ import OpenGL + OpenGL.ERROR_CHECKING = False OpenGL.USE_ACCELERATE = False from OpenGL.GLUT import * -def reshape(width, height): pass -def display(): glutSwapBuffers() + +def reshape(width, height): + pass + + +def display(): + glutSwapBuffers() + def main(): glutInit([]) - glutInitDisplayMode(GLUT_RGBA|GLUT_3_2_CORE_PROFILE) + glutInitDisplayMode(GLUT_RGBA | GLUT_3_2_CORE_PROFILE) glutCreateWindow(b"test") glutReshapeFunc(reshape) glutDisplayFunc(display) from OpenGL.GL import glGenVertexArrays, glVertex3f + assert bool(glGenVertexArrays) try: - if fgDeinitialize: fgDeinitialize(False) + if fgDeinitialize: + fgDeinitialize(False) except NameError as err: - pass # Older PyOpenGL, you may see a seg-fault here... + pass # Older PyOpenGL, you may see a seg-fault here... + print('OK') + if __name__ == "__main__": main() diff --git a/tests/check_gles_imports.py b/tests/check_gles_imports.py index 2a7bfe57..41ced1b6 100644 --- a/tests/check_gles_imports.py +++ b/tests/check_gles_imports.py @@ -1,8 +1,11 @@ #! /usr/bin/env python """Attempt to import GLES libraries""" import os + if not 'PYOPENGL_PLATFORM' in os.environ: os.environ['PYOPENGL_PLATFORM'] = 'egl' from OpenGL.GLES1 import * from OpenGL.GLES2 import * from OpenGL.GLES3 import * + +print('OK') diff --git a/tests/check_glut_debug.py b/tests/check_glut_debug.py index be2ba9e6..c0c31116 100644 --- a/tests/check_glut_debug.py +++ b/tests/check_glut_debug.py @@ -1,13 +1,16 @@ """Test GLUT forward-compatible mode...""" + from __future__ import print_function import OpenGL + OpenGL.FORWARD_COMPATIBLE_ONLY = True OpenGL.ERROR_CHECKING = True -#OpenGL.USE_ACCELERATE = False +# OpenGL.USE_ACCELERATE = False from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import time + start = time.time() from OpenGL.GL.AMD.debug_output import glGetDebugMessageLogAMD @@ -24,93 +27,113 @@ window = None + def display(): try: - glutSetWindow(window); - glClearColor (0.0, 0.0, (time.time()%1.0)/1.0, 0.0) - glClear (GL_COLOR_BUFFER_BIT) + glutSetWindow(window) + glClearColor(0.0, 0.0, (time.time() % 1.0) / 1.0, 0.0) + glClear(GL_COLOR_BUFFER_BIT) try: - glGetString( GL_EXTENSIONS ) + glGetString(GL_EXTENSIONS) except GLError: - pass + pass else: print('Egads, glGetString should not have worked!') - assert bool( glGenVertexArrays ), "Should have vertex array support in 3.2" + assert bool(glGenVertexArrays), "Should have vertex array support in 3.2" for message in get_debug_messages(): print(message) - glFlush () + glFlush() glutSwapBuffers() except Exception: - glutDestroyWindow( window ) + glutDestroyWindow(window) raise + def get_debug_messages(): messages = [] - count = glGetIntegerv( GL_DEBUG_LOGGED_MESSAGES ) - max_size = int(glGetIntegerv( GL_MAX_DEBUG_MESSAGE_LENGTH )) + count = glGetIntegerv(GL_DEBUG_LOGGED_MESSAGES) + max_size = int(glGetIntegerv(GL_MAX_DEBUG_MESSAGE_LENGTH)) source = GLenum() type = GLenum() id = GLenum() severity = GLenum() length = GLsizei() - buffer = ctypes.create_string_buffer( max_size ) + buffer = ctypes.create_string_buffer(max_size) for i in range(count): - result = glGetDebugMessageLog( 1, max_size, source, type, id, severity, length, buffer ) + result = glGetDebugMessageLog( + 1, max_size, source, type, id, severity, length, buffer + ) if result: - messages.append( { - 'message':buffer[:length.value], - 'type': type.value, - 'id': id.value, - 'severity': severity.value, - 'source': source.value, - }) + messages.append( + { + 'message': buffer[: length.value], + 'type': type.value, + 'id': id.value, + 'severity': severity.value, + 'source': source.value, + } + ) return messages assert len(messages), messages - -size = (250,250) +size = (250, 250) + -def reshape( *args ): - global size +def reshape(*args): + global size size = args - glViewport( *( (0,0)+args) ) + glViewport(*((0, 0) + args)) display() -def printFunction( name ): - def onevent( *args ): - print('%s -> %s'%(name, ", ".join( [str(a) for a in args ]))) + +def printFunction(name): + def onevent(*args): + print('%s -> %s' % (name, ", ".join([str(a) for a in args]))) + return onevent +def idle(*args, **named): + sys.stdout.write("OK\n") + sys.stdout.flush() + global window + glutDestroyWindow(window) + try: + if fgDeinitialize: + fgDeinitialize(False) + except NameError: + pass # Older PyOpenGL, you may see a seg-fault here... + + os._exit(0) + if __name__ == "__main__": import sys + newArgv = glutInit(sys.argv) glutInitContextVersion(3, 1) - glutInitContextFlags(GLUT_FORWARD_COMPATIBLE|GLUT_DEBUG) + glutInitContextFlags(GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG) glutInitContextProfile(GLUT_CORE_PROFILE) - glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ) + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) - glutSetOption( - GLUT_ACTION_ON_WINDOW_CLOSE, - GLUT_ACTION_GLUTMAINLOOP_RETURNS - ); + glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS) glutInitWindowSize(250, 250) glutInitWindowPosition(100, 100) window = glutCreateWindow("hello") print('window', repr(window)) glutDisplayFunc(display) glutReshapeFunc(reshape) - glutMouseFunc(printFunction( 'Mouse' )) - glutEntryFunc(printFunction( 'Entry' )) - glutKeyboardFunc( printFunction( 'Keyboard' )) - glutKeyboardUpFunc( printFunction( 'KeyboardUp' )) - glutMotionFunc( printFunction( 'Motion' )) - glutPassiveMotionFunc( printFunction( 'PassiveMotion' )) - glutVisibilityFunc( printFunction( 'Visibility' )) - glutWindowStatusFunc( printFunction( 'WindowStatus' )) - glutSpecialFunc( printFunction( 'Special' )) - glutSpecialUpFunc( printFunction( 'SpecialUp' )) - + glutMouseFunc(printFunction('Mouse')) + glutEntryFunc(printFunction('Entry')) + glutKeyboardFunc(printFunction('Keyboard')) + glutKeyboardUpFunc(printFunction('KeyboardUp')) + glutMotionFunc(printFunction('Motion')) + glutIdleFunc(idle) + glutPassiveMotionFunc(printFunction('PassiveMotion')) + glutVisibilityFunc(printFunction('Visibility')) + glutWindowStatusFunc(printFunction('WindowStatus')) + glutSpecialFunc(printFunction('Special')) + glutSpecialUpFunc(printFunction('SpecialUp')) + glutMainLoop() diff --git a/tests/check_glut_fc.py b/tests/check_glut_fc.py index 9ed0cdb1..e7623cc1 100644 --- a/tests/check_glut_fc.py +++ b/tests/check_glut_fc.py @@ -1,113 +1,123 @@ """Test GLUT forward-compatible mode...""" + from __future__ import print_function import OpenGL + OpenGL.FORWARD_COMPATIBLE_ONLY = True OpenGL.ERROR_CHECKING = True -#OpenGL.USE_ACCELERATE = False +# OpenGL.USE_ACCELERATE = False from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * -#from OpenGL.GL import shaders -import time + +# from OpenGL.GL import shaders +import time, sys, os + start = time.time() window = None + def display(): try: - glutSetWindow(window); - glClearColor (0.0, 0.0, (time.time()%1.0)/1.0, 0.0) - glClear (GL_COLOR_BUFFER_BIT) + glutSetWindow(window) + glClearColor(0.0, 0.0, (time.time() % 1.0) / 1.0, 0.0) + glClear(GL_COLOR_BUFFER_BIT) try: - glGetString( GL_EXTENSIONS ) + glGetString(GL_EXTENSIONS) except GLError: - pass + pass else: print('Egads, glGetString should not have worked!') - assert bool( glGenVertexArrays ), "Should have vertex array support in 3.2" - glFlush () + assert bool(glGenVertexArrays), "Should have vertex array support in 3.2" + glFlush() glutSwapBuffers() except Exception: - glutDestroyWindow( window ) + glutDestroyWindow(window) raise -size = (250,250) -def reshape( *args ): - global size +size = (250, 250) + + +def reshape(*args): + global size size = args - glViewport( *( (0,0)+args) ) + glViewport(*((0, 0) + args)) display() -def ontimer( *args ): -# print 'timer', args, '@time', time.time()-start - glutTimerFunc( 1000, ontimer, 24 ) + +def ontimer(*args): + # print 'timer', args, '@time', time.time()-start + glutTimerFunc(1000, ontimer, 24) + def idle(): - delta = time.time()-start - if delta < 10: - global size - x,y = size + delta = time.time() - start + if delta < 2: + global size + x, y = size if delta < 5: change = +1 else: change = -1 - x = x-change - y = y+change + x = x - change + y = y + change if x < 1: x = 1 if y < 1: y = 1 - glutReshapeWindow( x, y ) - size = (x,y) + glutReshapeWindow(x, y) + size = (x, y) glutSetWindow(window) glutPostRedisplay() else: - glutDestroyWindow( window ) - print('window destroyed') + glutDestroyWindow(window) + sys.stdout.write('OK\n') + sys.stdout.flush() try: - if fgDeinitialize: fgDeinitialize(False) + if fgDeinitialize: + fgDeinitialize(False) except NameError: - pass # Older PyOpenGL, you may see a seg-fault here... - import sys - sys.exit( 0 ) + pass # Older PyOpenGL, you may see a seg-fault here... + + os._exit(0) -def printFunction( name ): - def onevent( *args ): - print('%s -> %s'%(name, ", ".join( [str(a) for a in args ]))) - return onevent +def printFunction(name): + def onevent(*args): + print('%s -> %s' % (name, ", ".join([str(a) for a in args]))) + + return onevent if __name__ == "__main__": import sys + newArgv = glutInit(sys.argv) glutInitContextVersion(3, 1) glutInitContextFlags(GLUT_FORWARD_COMPATIBLE) glutInitContextProfile(GLUT_CORE_PROFILE) - glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ) + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) - glutSetOption( - GLUT_ACTION_ON_WINDOW_CLOSE, - GLUT_ACTION_GLUTMAINLOOP_RETURNS - ); + glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS) glutInitWindowSize(250, 250) glutInitWindowPosition(100, 100) window = glutCreateWindow("hello") print('window', repr(window)) glutDisplayFunc(display) glutReshapeFunc(reshape) - glutMouseFunc(printFunction( 'Mouse' )) - glutEntryFunc(printFunction( 'Entry' )) - glutKeyboardFunc( printFunction( 'Keyboard' )) - glutKeyboardUpFunc( printFunction( 'KeyboardUp' )) - glutMotionFunc( printFunction( 'Motion' )) - glutPassiveMotionFunc( printFunction( 'PassiveMotion' )) - glutVisibilityFunc( printFunction( 'Visibility' )) - glutWindowStatusFunc( printFunction( 'WindowStatus' )) - glutSpecialFunc( printFunction( 'Special' )) - glutSpecialUpFunc( printFunction( 'SpecialUp' )) - glutTimerFunc( 1000, ontimer, 23 ) - - glutIdleFunc( idle ) + glutMouseFunc(printFunction('Mouse')) + glutEntryFunc(printFunction('Entry')) + glutKeyboardFunc(printFunction('Keyboard')) + glutKeyboardUpFunc(printFunction('KeyboardUp')) + glutMotionFunc(printFunction('Motion')) + glutPassiveMotionFunc(printFunction('PassiveMotion')) + glutVisibilityFunc(printFunction('Visibility')) + glutWindowStatusFunc(printFunction('WindowStatus')) + glutSpecialFunc(printFunction('Special')) + glutSpecialUpFunc(printFunction('SpecialUp')) + glutTimerFunc(1000, ontimer, 23) + + glutIdleFunc(idle) glutMainLoop() diff --git a/tests/check_glut_load.py b/tests/check_glut_load.py index e9d3ad0a..5bc23473 100644 --- a/tests/check_glut_load.py +++ b/tests/check_glut_load.py @@ -1,17 +1,22 @@ from __future__ import print_function -import ctypes +import ctypes, sys + try: from ctypes.util import find_library except ImportError as err: - from ctypes.util import findLib - def find_library( string ): - return findLib( string )[0] + from ctypes.util import findLib + + def find_library(string): + return findLib(string)[0] + -GL = OpenGL = ctypes.CDLL( find_library('GL'), mode=ctypes.RTLD_GLOBAL ) -GLU = ctypes.CDLL( find_library('GLU'), mode=ctypes.RTLD_GLOBAL ) +GL = OpenGL = ctypes.CDLL(find_library('GL'), mode=ctypes.RTLD_GLOBAL) +GLU = ctypes.CDLL(find_library('GLU'), mode=ctypes.RTLD_GLOBAL) # glut shouldn't need to be global IIUC -GLUT = ctypes.CDLL( find_library('glut'), mode=ctypes.RTLD_GLOBAL ) +GLUT = ctypes.CDLL(find_library('glut'), mode=ctypes.RTLD_GLOBAL) print('GL', GL) print('GLU', GLU) print('GLUT', GLUT) print(GLUT.glutSolidTeapot) +sys.stdout.write('OK\n') +sys.stdout.flush() diff --git a/tests/check_glutinit.py b/tests/check_glutinit.py index 3bf0af01..b9713daa 100644 --- a/tests/check_glutinit.py +++ b/tests/check_glutinit.py @@ -2,16 +2,21 @@ from OpenGL.GL import * from OpenGL.GLUT import * from OpenGL.GLU import * -import time +import time, sys -resX,resY = (400,300 ) +resX, resY = (400, 300) -def display( ): - glutSetWindow(window); - glClearColor (0.0, 0.0, (time.time()%1.0)/1.0, 0.0) - glClear (GL_COLOR_BUFFER_BIT) - glFlush () + +def display(): + glutSetWindow(window) + glClearColor(0.0, 0.0, (time.time() % 1.0) / 1.0, 0.0) + glClear(GL_COLOR_BUFFER_BIT) + glFlush() glutSwapBuffers() + sys.stdout.write('OK\n') + sys.stdout.flush() + if glutLeaveMainLoop: + glutLeaveMainLoop() if __name__ == "__main__": @@ -23,8 +28,7 @@ def display( ): glutInitWindowPosition(0, 0) window = glutCreateWindow("hello") glutDisplayFunc(display) - for name in (GL_VENDOR,GL_RENDERER,GL_SHADING_LANGUAGE_VERSION,GL_EXTENSIONS): - print(( '%s = %r'%( name,glGetString(name)))) - + for name in (GL_VENDOR, GL_RENDERER, GL_SHADING_LANGUAGE_VERSION, GL_EXTENSIONS): + print(('%s = %r' % (name, glGetString(name)))) + glutMainLoop() - diff --git a/tests/check_glutinit_0args.py b/tests/check_glutinit_0args.py index d7ebfe11..083259a6 100644 --- a/tests/check_glutinit_0args.py +++ b/tests/check_glutinit_0args.py @@ -10,8 +10,9 @@ raise else: print('accepted 0 arguments, as desired') + print('OK') try: - if fgDeinitialize: fgDeinitialize(False) + if fgDeinitialize: + fgDeinitialize(False) except NameError as err: - pass # Older PyOpenGL, you may see a seg-fault here... - + pass # Older PyOpenGL, you may see a seg-fault here... diff --git a/tests/check_glutinit_simplest.py b/tests/check_glutinit_simplest.py index 660fcca4..539b523c 100644 --- a/tests/check_glutinit_simplest.py +++ b/tests/check_glutinit_simplest.py @@ -1,7 +1,10 @@ from OpenGL.GLUT import * + glutInit() glutInitDisplayMode(GLUT_RGB) +print('OK') try: - if fgDeinitialize: fgDeinitialize(False) + if fgDeinitialize: + fgDeinitialize(False) except NameError as err: - pass # Older PyOpenGL, you may see a seg-fault here... + pass # Older PyOpenGL, you may see a seg-fault here... diff --git a/tests/check_glutinit_single.py b/tests/check_glutinit_single.py index 520a6990..3935d7ef 100644 --- a/tests/check_glutinit_single.py +++ b/tests/check_glutinit_single.py @@ -1,9 +1,12 @@ from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * + glutInit(['']) -glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB) +glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) +print('OK') try: - if fgDeinitialize: fgDeinitialize(False) + if fgDeinitialize: + fgDeinitialize(False) except NameError as err: - pass # Older PyOpenGL, you may see a seg-fault here... + pass # Older PyOpenGL, you may see a seg-fault here... diff --git a/tests/check_glutwindow.py b/tests/check_glutwindow.py index 2eea5c86..e69e0975 100644 --- a/tests/check_glutwindow.py +++ b/tests/check_glutwindow.py @@ -1,122 +1,134 @@ """Test simple functions (i.e. no pointers involved)""" + from __future__ import print_function +import sys from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * from OpenGL._bytes import as_8_bit import time + start = time.time() window = None -def drawText( value, x,y, windowHeight, windowWidth, step = 18 ): - """Draw the given text at given 2D position in window - """ - glMatrixMode(GL_PROJECTION); + +def drawText(value, x, y, windowHeight, windowWidth, step=18): + """Draw the given text at given 2D position in window""" + glMatrixMode(GL_PROJECTION) # For some reason the GL_PROJECTION_MATRIX is overflowing with a single push! # glPushMatrix() - matrix = glGetDouble( GL_PROJECTION_MATRIX ) - - glLoadIdentity(); + matrix = glGetDouble(GL_PROJECTION_MATRIX) + + glLoadIdentity() glOrtho(0.0, windowHeight or 32, 0.0, windowWidth or 32, -1.0, 1.0) - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - glRasterPos2i(x, y); + glMatrixMode(GL_MODELVIEW) + glPushMatrix() + glLoadIdentity() + glRasterPos2i(x, y) lines = 0 for character in value: if character == '\n': - glRasterPos2i(x, y-(lines*18)) + glRasterPos2i(x, y - (lines * 18)) else: - glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(character)); - glPopMatrix(); - glMatrixMode(GL_PROJECTION); + glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(character)) + glPopMatrix() + glMatrixMode(GL_PROJECTION) # For some reason the GL_PROJECTION_MATRIX is overflowing with a single push! # glPopMatrix(); - glLoadMatrixd( matrix ) # should have un-decorated alias for this... - - glMatrixMode(GL_MODELVIEW); + glLoadMatrixd(matrix) # should have un-decorated alias for this... + + glMatrixMode(GL_MODELVIEW) + def display(): - glutSetWindow(window); - glClearColor (0.0, 0.0, (time.time()%1.0)/1.0, 0.0) - glClear (GL_COLOR_BUFFER_BIT) - drawText( 'hello', 20,20, size[0],size[1] ) - #glutBitmapCharacter( GLUT_BITMAP_8_BY_13, ord('a')) - glutSolidTeapot( .2 ) - glFlush () + glutSetWindow(window) + glClearColor(0.0, 0.0, (time.time() % 1.0) / 1.0, 0.0) + glClear(GL_COLOR_BUFFER_BIT) + drawText('hello', 20, 20, size[0], size[1]) + # glutBitmapCharacter( GLUT_BITMAP_8_BY_13, ord('a')) + glutSolidTeapot(0.2) + glFlush() glutSwapBuffers() -size = (250,250) -def reshape( *args ): - global size +size = (250, 250) + + +def reshape(*args): + global size size = args - glViewport( *( (0,0)+args) ) + glViewport(*((0, 0) + args)) display() -def ontimer( *args ): - print(('timer', args, '@time', time.time()-start)) - glutTimerFunc( 1000, ontimer, 24 ) + +def ontimer(*args): + print(('timer', args, '@time', time.time() - start)) + glutTimerFunc(1000, ontimer, 24) + def idle(): - delta = time.time()-start - if delta < 10: - global size - x,y = size + delta = time.time() - start + if delta < 2: + global size + x, y = size if delta < 5: change = +1 else: change = -1 - x = x-change - y = y+change + x = x - change + y = y + change if x < 1: x = 1 if y < 1: y = 1 - glutReshapeWindow( x, y ) - size = (x,y) + glutReshapeWindow(x, y) + size = (x, y) glutSetWindow(window) glutPostRedisplay() else: - glutDestroyWindow( window ) - print('window destroyed') + sys.stdout.write("OK\n") + sys.stdout.flush() + glutDestroyWindow(window) try: - if fgDeinitialize: fgDeinitialize(False) + if fgDeinitialize: + fgDeinitialize(False) except NameError: - pass # Older PyOpenGL, you may see a seg-fault here... - import sys - sys.exit( 0 ) + pass # Older PyOpenGL, you may see a seg-fault here... + + os._exit(0) -def printFunction( name ): - def onevent( *args ): - print(('%s -> %s'%(name, ", ".join( [str(a) for a in args ])))) - return onevent +def printFunction(name): + def onevent(*args): + print(('%s -> %s' % (name, ", ".join([str(a) for a in args])))) + + return onevent if __name__ == "__main__": import sys + newArgv = glutInit(sys.argv) print(('newArguments', newArgv)) - glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB ) + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) glutInitWindowSize(250, 250) glutInitWindowPosition(100, 100) window = glutCreateWindow(as_8_bit("hello")) print(('window', repr(window))) glutDisplayFunc(display) glutReshapeFunc(reshape) - glutMouseFunc(printFunction( 'Mouse' )) - glutEntryFunc(printFunction( 'Entry' )) - glutKeyboardFunc( printFunction( 'Keyboard' )) - glutKeyboardUpFunc( printFunction( 'KeyboardUp' )) - glutMotionFunc( printFunction( 'Motion' )) - glutPassiveMotionFunc( printFunction( 'PassiveMotion' )) - glutVisibilityFunc( printFunction( 'Visibility' )) - glutWindowStatusFunc( printFunction( 'WindowStatus' )) - glutSpecialFunc( printFunction( 'Special' )) - glutSpecialUpFunc( printFunction( 'SpecialUp' )) - glutTimerFunc( 1000, ontimer, 23 ) - - glutIdleFunc( idle ) + glutMouseFunc(printFunction('Mouse')) + glutEntryFunc(printFunction('Entry')) + glutKeyboardFunc(printFunction('Keyboard')) + glutKeyboardUpFunc(printFunction('KeyboardUp')) + glutMotionFunc(printFunction('Motion')) + glutPassiveMotionFunc(printFunction('PassiveMotion')) + glutVisibilityFunc(printFunction('Visibility')) + glutWindowStatusFunc(printFunction('WindowStatus')) + glutSpecialFunc(printFunction('Special')) + glutSpecialUpFunc(printFunction('SpecialUp')) + glutTimerFunc(1000, ontimer, 23) + + glutIdleFunc(idle) glutMainLoop() diff --git a/tests/check_import_err.py b/tests/check_import_err.py index 0baff3db..77b27dce 100644 --- a/tests/check_import_err.py +++ b/tests/check_import_err.py @@ -1,5 +1,10 @@ """Check github #43 import error on win32 nt""" + +import sys import logging logging.basicConfig(level=logging.DEBUG) from OpenGL.GLU import * + +sys.stdout.write('OK\n') +sys.stdout.flush() diff --git a/tests/checkinitframebufferarb.py b/tests/check_init_framebufferarb.py similarity index 84% rename from tests/checkinitframebufferarb.py rename to tests/check_init_framebufferarb.py index 70842eae..5922d512 100644 --- a/tests/checkinitframebufferarb.py +++ b/tests/check_init_framebufferarb.py @@ -14,8 +14,12 @@ def main(): pg.display.set_mode((50, 50), DOUBLEBUF | OPENGL) pg.display.init() OpenGL.GL.glGetString(OpenGL.GL.GL_VERSION) + if not glInitFramebufferObjectARB: + print("SKIP") + return print(glInitFramebufferObjectARB()) print(OpenGL.__version__) + print('OK') if __name__ == "__main__": diff --git a/tests/check_leak_on_discontiguous_array.py b/tests/check_leak_on_discontiguous_array.py index ce6f6282..09dadde7 100644 --- a/tests/check_leak_on_discontiguous_array.py +++ b/tests/check_leak_on_discontiguous_array.py @@ -1,17 +1,20 @@ """Test for github issue #47""" -from __future__ import print_function + +import sys import OpenGL -OpenGL.SIZE_1_ARRAY_UNPACK = False # just for convenience -OpenGL.ERROR_ON_COPY = False # we are checking a leak in the copying + +OpenGL.SIZE_1_ARRAY_UNPACK = False # just for convenience +OpenGL.ERROR_ON_COPY = False # we are checking a leak in the copying import pygamegltest import numpy as np from OpenGL.GL import * from OpenGL.GL import shaders from sys import getrefcount + @pygamegltest.pygametest(name="Texture image 2d leak check") def main(): - data = np.zeros([256,256,3],dtype='b') + data = np.zeros([256, 256, 3], dtype='b') glEnable(GL_TEXTURE_2D) textures = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, textures[0]) @@ -20,12 +23,20 @@ def main(): rc1 = getrefcount(reversed_data) for i in range(100): glTexImage2D( - GL_TEXTURE_2D, - 0, - GL_RGB, - 256, 256, 0, GL_RGB,GL_UNSIGNED_BYTE, reversed_data) + GL_TEXTURE_2D, + 0, + GL_RGB, + 256, + 256, + 0, + GL_RGB, + GL_UNSIGNED_BYTE, + reversed_data, + ) rc2 = getrefcount(reversed_data) assert rc1 == rc2, (rc1, rc2) + sys.stdout.write('OK\n') + sys.stdout.flush() if __name__ == "__main__": diff --git a/tests/check_silence_numpy_warning.py b/tests/check_silence_numpy_warning.py new file mode 100644 index 00000000..ef612a4d --- /dev/null +++ b/tests/check_silence_numpy_warning.py @@ -0,0 +1,17 @@ +import logging + +logging.basicConfig(level=logging.INFO) +logging.getLogger('OpenGL.plugins').setLevel(logging.ERROR) + + +def fail_handler(*args, **named): + raise RuntimeError("Should not have called this handler!") + + +logging.getLogger('OpenGL.plugins').addHandler(fail_handler) +from OpenGL.arrays import arraydatatype + +dt = arraydatatype.GLuintArray +d = dt.zeros((3,)) + +print('OK') diff --git a/tests/egl_ext_enumerate.py b/tests/egl_ext_enumerate.py index 6d70ee2c..85188529 100644 --- a/tests/egl_ext_enumerate.py +++ b/tests/egl_ext_enumerate.py @@ -3,13 +3,17 @@ from OpenGL.EGL.EXT import device_query, device_enumeration from OpenGL.GL import GLint + def main(): - with egl_context(output=None) as context: - display,context,surface = context - print("Vendor: %s"%(EGL.eglQueryString(display, EGL.EGL_VENDOR))) - print("Version: %s"%(EGL.eglQueryString(display, EGL.EGL_VERSION))) - print("Extensions: %s"%(EGL.eglQueryString(display, EGL.EGL_EXTENSIONS),)) - print("Client Extensions: %s"%(EGL.eglQueryString(display, EGL.EGL_CLIENT_APIS),)) + with egl_context(output=None, pbuffer=True) as context: + display, context, surface = context + print("Vendor: %s" % (EGL.eglQueryString(display, EGL.EGL_VENDOR))) + print("Version: %s" % (EGL.eglQueryString(display, EGL.EGL_VERSION))) + print("Extensions: %s" % (EGL.eglQueryString(display, EGL.EGL_EXTENSIONS),)) + print( + "Client Extensions: %s" + % (EGL.eglQueryString(display, EGL.EGL_CLIENT_APIS),) + ) if device_enumeration.eglQueryDevicesEXT: devices = (device_query.EGLDeviceEXT * 5)() count = GLint() @@ -18,12 +22,15 @@ def main(): devices, count, ) - for device in devices[:int(count)]: + for device in devices[: count.value]: print(device) else: print('No device_query extension available') + print('OK') + if __name__ == "__main__": import logging + logging.basicConfig(level=logging.DEBUG) - main() \ No newline at end of file + main() diff --git a/tests/feedbackvarying.py b/tests/feedbackvarying.py index 25dc33c7..1228b95d 100644 --- a/tests/feedbackvarying.py +++ b/tests/feedbackvarying.py @@ -1,8 +1,10 @@ """Transliteration of https://open.gl/feedback into Python""" + from __future__ import print_function import pygamegltest from OpenGL.GL import * from OpenGL.GL import shaders + vertex_shader = """#version 150 core in float inValue; out float outValue; @@ -12,56 +14,61 @@ } """ + @pygamegltest.pygametest(name="Geometry Shader Test") def main(): program = shaders.compileProgram( - shaders.compileShader([vertex_shader], GL_VERTEX_SHADER), + shaders.compileShader([vertex_shader], GL_VERTEX_SHADER), ) - buff = ctypes.c_char_p( b"outValue" ) + buff = ctypes.c_char_p(b"outValue") c_text = ctypes.cast(ctypes.pointer(buff), ctypes.POINTER(ctypes.POINTER(GLchar))) # modifies the state in the linking of the program - glTransformFeedbackVaryings(program, 1, c_text, GL_INTERLEAVED_ATTRIBS); - + glTransformFeedbackVaryings(program, 1, c_text, GL_INTERLEAVED_ATTRIBS) + # so have to re-link glLinkProgram(program) - glUseProgram(program); + glUseProgram(program) - vao = glGenVertexArrays(1); - glBindVertexArray(vao); + vao = glGenVertexArrays(1) + glBindVertexArray(vao) data = (GLfloat * 5)(1.0, 2.0, 3.0, 4.0, 5.0) - - vbo = glGenBuffers(1); - glBindBuffer(GL_ARRAY_BUFFER, vbo); - glBufferData(GL_ARRAY_BUFFER, ctypes.sizeof(data), data, GL_STATIC_DRAW); - inputAttrib = glGetAttribLocation(program, "inValue"); - glEnableVertexAttribArray(inputAttrib); + vbo = glGenBuffers(1) + glBindBuffer(GL_ARRAY_BUFFER, vbo) + glBufferData(GL_ARRAY_BUFFER, ctypes.sizeof(data), data, GL_STATIC_DRAW) + + inputAttrib = glGetAttribLocation(program, "inValue") + glEnableVertexAttribArray(inputAttrib) # Note the need to cast 0 to a GLvoidp here! - glVertexAttribPointer(inputAttrib, 1, GL_FLOAT, GL_FALSE, 0, GLvoidp(0)); + glVertexAttribPointer(inputAttrib, 1, GL_FLOAT, GL_FALSE, 0, GLvoidp(0)) - tbo = glGenBuffers(1); - glBindBuffer(GL_ARRAY_BUFFER, tbo); - glBufferData(GL_ARRAY_BUFFER, ctypes.sizeof(data), None, GL_STATIC_READ); + tbo = glGenBuffers(1) + glBindBuffer(GL_ARRAY_BUFFER, tbo) + glBufferData(GL_ARRAY_BUFFER, ctypes.sizeof(data), None, GL_STATIC_READ) - glEnable(GL_RASTERIZER_DISCARD); + glEnable(GL_RASTERIZER_DISCARD) - glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tbo); + glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tbo) - glBeginTransformFeedback(GL_POINTS); - glDrawArrays(GL_POINTS, 0, len(data)); - glEndTransformFeedback(); + glBeginTransformFeedback(GL_POINTS) + glDrawArrays(GL_POINTS, 0, len(data)) + glEndTransformFeedback() - glDisable(GL_RASTERIZER_DISCARD); + glDisable(GL_RASTERIZER_DISCARD) - glFlush(); + glFlush() - feedback = (GLfloat*len(data))() - glGetBufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, ctypes.sizeof(feedback), feedback); + feedback = (GLfloat * len(data))() + glGetBufferSubData( + GL_TRANSFORM_FEEDBACK_BUFFER, 0, ctypes.sizeof(feedback), feedback + ) for value in feedback: print(value) + print('OK') + if __name__ == "__main__": main() diff --git a/tests/test_checks.py b/tests/test_checks.py new file mode 100644 index 00000000..89a9171a --- /dev/null +++ b/tests/test_checks.py @@ -0,0 +1,196 @@ +"""Test cases that run stand-alone check-scripts""" + +import os, sys, subprocess, logging +import pytest +from functools import wraps +from OpenGL.GLUT import glutInit + +HERE = os.path.dirname(os.path.abspath(__file__)) +log = logging.getLogger(__name__) + + +def glx_only(func): + @wraps(func) + def glx_only_test(*args, **named): + if not sys.platform in ('linux', 'linux2'): + pytest.skip("Linux-only") + return func(*args, **named) + + return glx_only_test + + +def glut_only(func): + @wraps(func) + def glut_only_test(*args, **named): + if not glutInit: + pytest.skip("No GLUT installed") + return func(*args, **named) + + return glut_only_test + + +def check_test(func): + filename = func.__name__[5:] + '.py' + file = os.path.join(HERE, filename) + + @wraps(func) + def test_x(): + log.info("Starting test: %s", filename) + pipe = subprocess.Popen( + [ + sys.executable, + file, + ], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + try: + stdout, stderr = pipe.communicate() + except subprocess.TimeoutExpired: + log.warning("TIMEOUT on %s", filename) + pipe.kill() + raise + except subprocess.CalledProcessError as err: + log.warning("ERROR reported by process: %s", err) + raise + output = stdout.decode('utf-8', errors='ignore') + lines = [x.strip() for x in output.strip().splitlines()] + if not lines: + log.error( + "Test did not produce output: %s", + stderr.decode('utf-8', errors='ignore'), + ) + raise RuntimeError('Test script failure') + if 'SKIP' in lines: + raise pytest.skip("Skipped by executable") + elif 'OK' in lines: + return + else: + log.error( + "Failing check script output: %s", + stderr.decode('utf-8', errors='ignore'), + ) + print(output) + raise RuntimeError("Test Failed") + + return test_x + + +@glut_only +@check_test +def test_check_crash_on_glutinit(): + """Checks that basic glut init works""" + + +@check_test +def test_check_egl_es1(): + """Checks egl with es1 under pygame""" + + +@check_test +def test_check_egl_es2(): + """Checks egl with es2 under pygame""" + + +@check_test +def test_check_egl_opengl(): + """Checks egl with opengl under pygame""" + + +@check_test +def test_check_egl_platform_ext(): + """Checks egl display platform directly from render devices""" + + +@glut_only +@check_test +def test_check_glutwindow(): + """Checks GLUT window manipulation functions""" + + +@check_test +def test_check_egl_pygame(): + """Checks egl running over a pygame context""" + + +@glut_only +@check_test +def test_check_freeglut_deinit(): + """Checks free-glut deinitialise""" + + +@check_test +def test_check_import_err(): + """Checks that the GLU module can be imported""" + + +@check_test +def test_check_leak_on_discontiguous_array(): + """Checks that discontiguous array copy doesn't leak the copy""" + + +@check_test +def test_check_init_framebufferarb(): + """Checks that framebufferarb init function is non-null""" + + +@check_test +def test_check_gles_imports(): + """Checks that we can import GLES without crashing""" + + +@glut_only +@check_test +def test_check_glut_debug(): + """Tests GLUT debug function""" + + +@glut_only +@check_test +def test_check_glut_fc(): + """Tests GLUT forward-compatible-only""" + + +@glut_only +@check_test +def test_check_glut_load(): + """Tests GLUT forward-compatible-only""" + + +@glut_only +@check_test +def test_check_glutinit(): + """Tests GLUT init""" + + +@glut_only +@check_test +def test_check_glutinit_0args(): + """Tests GLUT init with no arguments""" + + +@glut_only +@check_test +def test_check_glutinit_single(): + """Tests GLUT init with single argument""" + + +@glut_only +@check_test +def test_check_glutinit_simplest(): + """Tests GLUT init in simplest possible case""" + + +@check_test +def test_check_silence_numpy_warning(): + """Tests GLUT init in simplest possible case""" + + +@check_test +def test_egl_ext_enumerate(): + """Tests that EGL can retrieve extension list""" + + +@check_test +def test_feedbackvarying(): + """Tests that feedback varying buffer operations work"""