From ec7b73f80ed7d7fbcae90b88300ca5eb5ff07f23 Mon Sep 17 00:00:00 2001 From: Thomas Hisch Date: Fri, 29 Dec 2017 12:48:59 +0100 Subject: [PATCH] Add memory leak test Related: #10157 --- .travis.yml | 2 ++ numpy/tests/test_memory.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 numpy/tests/test_memory.py diff --git a/.travis.yml b/.travis.yml index 2046ce975145..2d83cce741ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ addons: - gfortran - libatlas-dev - libatlas-base-dev + - valgrind # Speedup builds, particularly when USE_CHROOT=1 - eatmydata @@ -45,6 +46,7 @@ matrix: apt: packages: - debootstrap + - valgrind - python: 3.4 env: USE_DEBUG=1 dist: trusty diff --git a/numpy/tests/test_memory.py b/numpy/tests/test_memory.py new file mode 100644 index 000000000000..51f3589da114 --- /dev/null +++ b/numpy/tests/test_memory.py @@ -0,0 +1,21 @@ +from __future__ import division, absolute_import, print_function + +import sys +import subprocess +import itertools + + +class TestMemory(object): + def test_memory_leak(self): + # see #10157 + output = subprocess.check_output([ + 'valgrind', + sys.executable, + '-c', 'import numpy'], stderr=subprocess.STDOUT) + + leak_summary = '\n'.join( + itertools.dropwhile(lambda x: not x.endswith('LEAK SUMMARY:'), + output.decode().splitlines())) + + if 'definitely lost: 0 bytes in' not in leak_summary: + raise ValueError(leak_summary)