Skip to content

Commit

Permalink
TESTSUITE Add pytest compatible runner to run process-isolated check-…
Browse files Browse the repository at this point in the history
…scripts
  • Loading branch information
mcfletch committed Dec 30, 2024
1 parent 8ff9cfa commit 61c66e7
Show file tree
Hide file tree
Showing 23 changed files with 605 additions and 261 deletions.
32 changes: 21 additions & 11 deletions tests/check_crash_on_glutinit.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions tests/check_egl_es1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
1 change: 1 addition & 0 deletions tests/check_egl_es2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
1 change: 1 addition & 0 deletions tests/check_egl_opengl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
20 changes: 12 additions & 8 deletions tests/check_egl_platform_ext.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
"""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
from OpenGL.EGL.EXT import platform_base
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()
17 changes: 11 additions & 6 deletions tests/check_egl_pygame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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':
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 3 additions & 0 deletions tests/check_gles_imports.py
Original file line number Diff line number Diff line change
@@ -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')
113 changes: 68 additions & 45 deletions tests/check_glut_debug.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Loading

0 comments on commit 61c66e7

Please sign in to comment.