Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix up unit tests that use the NRT stats counters.
As title.
  • Loading branch information
stuartarchibald committed Jul 20, 2022
commit 8aeb510d3ee3e799d478d7193972dd13b7496fef
16 changes: 12 additions & 4 deletions numba/tests/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,16 @@ def capture_cache_log():
yield out


class EnableNRTStatsMixin(object):
"""Mixin to enable the NRT statistics counters."""

def setUp(self):
_nrt.memsys_enable_stats()

def tearDown(self):
_nrt.memsys_disable_stats()


class MemoryLeak(object):

__enable_leak_check = True
Expand Down Expand Up @@ -804,18 +814,16 @@ def disable_leak_check(self):
self.__enable_leak_check = False


class MemoryLeakMixin(MemoryLeak):
class MemoryLeakMixin(EnableNRTStatsMixin, MemoryLeak):

def setUp(self):
_nrt.memsys_enable_stats()
super(MemoryLeakMixin, self).setUp()
self.memory_leak_setup()

def tearDown(self):
super(MemoryLeakMixin, self).tearDown()
gc.collect()
self.memory_leak_teardown()
_nrt.memsys_disable_stats()
super(MemoryLeakMixin, self).tearDown()


@contextlib.contextmanager
Expand Down
8 changes: 5 additions & 3 deletions numba/tests/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from numba import jit, njit, typeof
from numba.core import errors
from numba.tests.support import (TestCase, tag, needs_lapack, needs_blas,
_is_armv7l)
_is_armv7l, EnableNRTStatsMixin)
from .matmul_usecase import matmul_usecase
import unittest

Expand All @@ -28,7 +28,7 @@ def vdot(a, b):
return np.vdot(a, b)


class TestProduct(TestCase):
class TestProduct(EnableNRTStatsMixin, TestCase):
"""
Tests for dot products.
"""
Expand All @@ -38,6 +38,7 @@ class TestProduct(TestCase):
def setUp(self):
# Collect leftovers from previous test cases before checking for leaks
gc.collect()
super(TestProduct, self).setUp()

def sample_vector(self, n, dtype):
# Be careful to generate only exactly representable float values,
Expand Down Expand Up @@ -414,7 +415,7 @@ def kron_matrix(a, b):
return np.kron(a, b)


class TestLinalgBase(TestCase):
class TestLinalgBase(EnableNRTStatsMixin, TestCase):
"""
Provides setUp and common data/error modes for testing np.linalg functions.
"""
Expand All @@ -425,6 +426,7 @@ class TestLinalgBase(TestCase):
def setUp(self):
# Collect leftovers from previous test cases before checking for leaks
gc.collect()
super(TestLinalgBase, self).setUp()

def sample_vector(self, n, dtype):
# Be careful to generate only exactly representable float values,
Expand Down
8 changes: 4 additions & 4 deletions numba/tests/test_nrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import numba.core.typing.cffi_utils as cffi_support
from numba.core.unsafe.nrt import NRT_get_api

from numba.tests.support import (MemoryLeakMixin, TestCase, temp_directory,
from numba.tests.support import (EnableNRTStatsMixin, TestCase, temp_directory,
import_dynamic, skip_if_32bit,
run_in_subprocess)
from numba.core.registry import cpu_target
Expand Down Expand Up @@ -305,7 +305,7 @@ def release_memory():
self.assertLess(stat.size, N * 0.01)


class TestNRTIssue(MemoryLeakMixin, TestCase):
class TestNRTIssue(TestCase):
def test_issue_with_refct_op_pruning(self):
"""
GitHub Issue #1244 https://github.com/numba/numba/issues/1244
Expand Down Expand Up @@ -575,13 +575,13 @@ def foo(x):


@unittest.skipUnless(cffi_support.SUPPORTED, "cffi required")
class TestNrtExternalCFFI(MemoryLeakMixin, TestCase):
class TestNrtExternalCFFI(EnableNRTStatsMixin, TestCase):
"""Testing the use of externally compiled C code that use NRT
"""
def setUp(self):
# initialize the NRT (in case the tests are run in isolation)
super(TestNrtExternalCFFI, self).setUp()
cpu_target.target_context
super(TestNrtExternalCFFI, self).setUp()

def compile_cffi_module(self, name, source, cdef):
from cffi import FFI
Expand Down
5 changes: 3 additions & 2 deletions numba/tests/test_nrt_refct.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import unittest
from numba import njit
from numba.core.runtime import rtsys
from numba.tests.support import TestCase
from numba.tests.support import TestCase, EnableNRTStatsMixin


class TestNrtRefCt(TestCase):
class TestNrtRefCt(EnableNRTStatsMixin, TestCase):

def setUp(self):
# Clean up any NRT-backed objects hanging in a dead reference cycle
gc.collect()
super(TestNrtRefCt, self).setUp()

def test_no_return(self):
"""
Expand Down
5 changes: 3 additions & 2 deletions numba/tests/test_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from numba.core.compiler import compile_isolated, Flags
from numba import jit
from numba.core import types, errors, utils
from numba.tests.support import captured_stdout, tag, TestCase
from numba.tests.support import (captured_stdout, tag, TestCase,
EnableNRTStatsMixin)


enable_pyobj_flags = Flags()
Expand Down Expand Up @@ -43,7 +44,7 @@ def print_closure():
return jit(nopython=True)(x)


class TestPrint(TestCase):
class TestPrint(EnableNRTStatsMixin, TestCase):

def test_print_values(self):
"""
Expand Down