File: test_vbo_memusage.py

package info (click to toggle)
pyopengl 3.1.6%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,732 kB
  • sloc: python: 106,016; makefile: 8
file content (54 lines) | stat: -rw-r--r-- 1,439 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
46
47
48
49
50
51
52
53
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
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:
            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...