Skip to content

Commit

Permalink
Report how much memory is leaking in vbo memory test
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfletch committed Feb 19, 2022
1 parent b485dde commit 8c82e72
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions tests/test_vbo_memusage.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,54 @@
import pygamegltest
import os

# We have to import at least *one* VBO implementation...
from OpenGL import GL, arrays
from OpenGL.arrays import vbo

try:
import psutil
except ImportError:
psutil = None
try:
unicode
unicode
except NameError:
unicode = str
unicode = str
long = int
import pytest
import gc

try:
import numpy as np
except ImportError:
np = None


def get_current_memory():
return psutil.Process(os.getpid()).memory_info().rss

@pytest.mark.skipif(not psutil,reason='No psutil available')
@pytest.mark.skipif(not np,reason='No Numpy available')

@pytest.mark.skipif(not psutil, reason="No psutil available")
@pytest.mark.skipif(not np, reason="No Numpy available")
@pygamegltest.pygametest()
def test_sf_2980896():
"""Test SF#2980896 report of memory leak on VBO transfer"""
data = arrays.GLfloatArray.zeros((1000,))
memory = get_current_memory()
for i in range(100):
for i in range(100):
new_vbo = vbo.VBO(data)
with new_vbo:
# data is transferred to the VBO
assert new_vbo is not None, new_vbo
new_vbo.delete()
del new_vbo
del new_vbo
gc.collect()
GL.glFinish()
if i < 1:
if i < 1:
# the *first* call can load lots of libraries, etc...
memory = get_current_memory()
else:
assert get_current_memory() - memory < 200, """Shouldn't have any (or at least much) extra RAM allocated..."""
current = get_current_memory()
assert current - memory < 200, (
"""Shouldn't have any (or at least much) extra RAM allocated, lost: %s"""
% (current - memory)
) # fails only when run in the whole suite...

0 comments on commit 8c82e72

Please # to comment.