File: test_vbo_memusage.py

package info (click to toggle)
pyopengl 3.1.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 14,668 kB
  • sloc: python: 108,024; makefile: 4
file content (45 lines) | stat: -rw-r--r-- 1,287 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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 
except NameError:
    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')
@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): 
        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 
        gc.collect()
        GL.glFinish()
        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..."""