diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-05-05 11:16:25 -0700 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2020-05-05 11:16:25 -0700 |
commit | 8ad353bc515d7765e7dc3dfaaa8f9f6db4f85aba (patch) | |
tree | bc7f0d5834fc43ace1f4b6113859e73f2da353e4 | |
parent | 15b35646d95b617b04a2e556f1b0902d3f64c3cb (diff) | |
download | psutil-8ad353bc515d7765e7dc3dfaaa8f9f6db4f85aba.tar.gz |
fix some memleak tests on win
-rw-r--r-- | psutil/arch/windows/net.c | 2 | ||||
-rwxr-xr-x | psutil/tests/test_memory_leaks.py | 22 | ||||
-rwxr-xr-x | scripts/internal/winmake.py | 4 | ||||
-rwxr-xr-x | setup.py | 10 |
4 files changed, 29 insertions, 9 deletions
diff --git a/psutil/arch/windows/net.c b/psutil/arch/windows/net.c index 56c6b6f1..0891bdba 100644 --- a/psutil/arch/windows/net.c +++ b/psutil/arch/windows/net.c @@ -17,6 +17,8 @@ static PIP_ADAPTER_ADDRESSES psutil_get_nic_addresses() { + // Note: GetAdaptersAddresses() increase the handle count on first + // call (and not anymore later on). // allocate a 15 KB buffer to start with int outBufLen = 15000; DWORD dwRetVal = 0; diff --git a/psutil/tests/test_memory_leaks.py b/psutil/tests/test_memory_leaks.py index 61049a91..5fb1cba4 100755 --- a/psutil/tests/test_memory_leaks.py +++ b/psutil/tests/test_memory_leaks.py @@ -138,6 +138,8 @@ class TestProcessObjectLeaks(TestMemoryLeak): @unittest.skipIf(POSIX, "worthless on POSIX") def test_username(self): + # always open 1 handle on Windows (only once) + psutil.Process().username() self.execute(self.proc.username) @skip_if_linux() @@ -250,7 +252,7 @@ class TestProcessObjectLeaks(TestMemoryLeak): @unittest.skipIf(not WINDOWS, "WINDOWS only") def test_proc_info(self): - self.execute(cext.proc_info, os.getpid()) + self.execute(lambda: cext.proc_info(os.getpid())) class TestTerminatedProcessLeaks(TestProcessObjectLeaks): @@ -359,6 +361,7 @@ class TestModuleFunctionsLeaks(TestMemoryLeak): @unittest.skipIf(not WINDOWS, "WINDOWS only") def test_getloadavg(self): + psutil.getloadavg() self.execute(psutil.getloadavg) # --- mem @@ -400,26 +403,41 @@ class TestModuleFunctionsLeaks(TestMemoryLeak): # --- net + # XXX @unittest.skipIf(TRAVIS and MACOS, "false positive on TRAVIS + MACOS") @unittest.skipIf(CIRRUS and FREEBSD, "false positive on CIRRUS + FREEBSD") @skip_if_linux() @unittest.skipIf(not HAS_NET_IO_COUNTERS, 'not supported') def test_net_io_counters(self): + if WINDOWS: + # GetAdaptersAddresses() increases the handle count on first + # call (only). + psutil.net_io_counters() self.execute(lambda: psutil.net_io_counters(nowrap=False)) @skip_if_linux() @unittest.skipIf(MACOS and os.getuid() != 0, "need root access") def test_net_connections(self): + # always opens and handle on Windows() (once) + psutil.net_connections(kind='all') with create_sockets(): - self.execute(psutil.net_connections, times=100) + self.execute(lambda: psutil.net_connections(kind='all'), times=100) def test_net_if_addrs(self): + if WINDOWS: + # GetAdaptersAddresses() increases the handle count on first + # call (only). + psutil.net_if_addrs() # Note: verified that on Windows this was a false positive. self.execute(psutil.net_if_addrs, tolerance=80 * 1024 if WINDOWS else 4096) @unittest.skipIf(TRAVIS, "EPERM on travis") def test_net_if_stats(self): + if WINDOWS: + # GetAdaptersAddresses() increases the handle count on first + # call (only). + psutil.net_if_stats() self.execute(psutil.net_if_stats) # --- sensors diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py index c7091ac4..4f1e65ed 100755 --- a/scripts/internal/winmake.py +++ b/scripts/internal/winmake.py @@ -397,11 +397,11 @@ def lint(): sh("%s -m flake8 %s" % (PYTHON, py_files), nolog=True) -def test(name=""): +def test(name=RUNNER_PY): """Run tests""" build() test_setup() - sh("%s %s %s" % (PYTHON, RUNNER_PY, name)) + sh("%s %s" % (PYTHON, name)) def coverage(): @@ -113,9 +113,9 @@ def silenced_output(stream_name): def missdeps(msg): - s = hilite("C compiler or Python headers are not installed ", ok=False) - s += hilite("on this system. Try to run:\n", ok=False) - s += hilite(msg, ok=False, bold=True) + s = hilite("C compiler or Python headers are not installed ", color="red") + s += hilite("on this system. Try to run:\n", color="red") + s += hilite(msg, color="red", bold=True) print(s, file=sys.stderr) @@ -402,7 +402,7 @@ def main(): missdeps("sudo yum install gcc python%s-devel" % py3) elif MACOS: print(hilite("XCode (https://developer.apple.com/xcode/) " - "is not installed"), ok=False, file=sys.stderr) + "is not installed"), color="red", file=sys.stderr) elif FREEBSD: missdeps("pkg install gcc python%s" % py3) elif OPENBSD: @@ -419,7 +419,7 @@ def main(): ur = "http://www.microsoft.com/en-us/download/" ur += "details.aspx?id=44266" s = "VisualStudio is not installed; get it from %s" % ur - print(hilite(s, ok=False), file=sys.stderr) + print(hilite(s, color="red"), file=sys.stderr) if __name__ == '__main__': |