diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-10-20 09:54:20 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-10-20 09:54:20 +0200 |
commit | dd80a8b94b3e5135b11700a5ef9e4665d76db1fd (patch) | |
tree | 5c1128abd3332a4be1e7f3b0be23c46a96190f8b | |
parent | 2fd5679f6b61cb8cc5b358a2d298f6338c1c915b (diff) | |
parent | 548656a636da14636c44fd1ce64c677dbcb6e15d (diff) | |
download | psutil-dd80a8b94b3e5135b11700a5ef9e4665d76db1fd.tar.gz |
Merge branch 'master' of github.com:giampaolo/psutil
-rw-r--r-- | IDEAS | 1 | ||||
-rw-r--r-- | psutil/TODO.aix | 4 | ||||
-rw-r--r-- | psutil/_psutil_windows.c | 3 | ||||
-rw-r--r-- | psutil/tests/__init__.py | 3 | ||||
-rwxr-xr-x | psutil/tests/test_posix.py | 35 | ||||
-rwxr-xr-x | psutil/tests/test_process.py | 14 |
6 files changed, 37 insertions, 23 deletions
@@ -9,7 +9,6 @@ PLATFORMS ========= - #355: Android (with patch) -- #605: AIX (with branch) - #82: Cygwin (PR at #998) - #276: GNU/Hurd - #693: Windows Nano diff --git a/psutil/TODO.aix b/psutil/TODO.aix index 671372dc..e1d428bd 100644 --- a/psutil/TODO.aix +++ b/psutil/TODO.aix @@ -9,7 +9,3 @@ Known limitations: reading basic process info may fail or return incorrect values when process is starting (see IBM APAR IV58499 - fixed in newer AIX versions) sockets and pipes may not be counted in num_fds (fixed in newer AIX versions) - -The following unit tests may fail: - test_prog_w_funky_name funky name tests don't work, name is truncated - test_cmdline long args are cut from cmdline in /proc/pid/psinfo and getargs diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index bca6cac0..d908a1c7 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -25,6 +25,7 @@ #include <wtsapi32.h> #include <Winsvc.h> #include <PowrProf.h> +#include <signal.h> // Link with Iphlpapi.lib #pragma comment(lib, "IPHLPAPI.lib") @@ -349,7 +350,7 @@ psutil_proc_kill(PyObject *self, PyObject *args) { } // kill the process - if (! TerminateProcess(hProcess, 0)) { + if (! TerminateProcess(hProcess, SIGTERM)) { err = GetLastError(); // See: https://github.com/giampaolo/psutil/issues/1099 if (err != ERROR_ACCESS_DENIED) { diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index 033d925e..5bb54017 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -690,7 +690,7 @@ def create_exe(outpath, c_code=None): if c_code: if not which("gcc"): raise ValueError("gcc is not installed") - if c_code is None: + if isinstance(c_code, bool): # c_code is True c_code = textwrap.dedent( """ #include <unistd.h> @@ -699,6 +699,7 @@ def create_exe(outpath, c_code=None): return 1; } """) + assert isinstance(c_code, str), c_code with tempfile.NamedTemporaryFile( suffix='.c', delete=False, mode='wt') as f: f.write(c_code) diff --git a/psutil/tests/test_posix.py b/psutil/tests/test_posix.py index f42a6e63..d1f9e54a 100755 --- a/psutil/tests/test_posix.py +++ b/psutil/tests/test_posix.py @@ -47,7 +47,6 @@ def ps(cmd): if not LINUX: cmd = cmd.replace(" --no-headers ", " ") if SUNOS: - cmd = cmd.replace("-o command", "-o comm") cmd = cmd.replace("-o start", "-o stime") if AIX: cmd = cmd.replace("-o rss", "-o rssize") @@ -59,6 +58,28 @@ def ps(cmd): except ValueError: return output +# ps "-o" field names differ wildly between platforms. +# "comm" means "only executable name" but is not available on BSD platforms. +# "args" means "command with all its arguments", and is also not available +# on BSD platforms. +# "command" is like "args" on most platforms, but like "comm" on AIX, +# and not available on SUNOS. +# so for the executable name we can use "comm" on Solaris and split "command" +# on other platforms. +# to get the cmdline (with args) we have to use "args" on AIX and +# Solaris, and can use "command" on all others. + +def ps_name(pid): + field = "command" + if SUNOS: + field = "comm" + return ps("ps --no-headers -o %s -p %s" % (field, pid)).split(' ')[0] + +def ps_args(pid): + field = "command" + if AIX or SUNOS: + field = "args" + return ps("ps --no-headers -o %s -p %s" % (field, pid)) @unittest.skipIf(not POSIX, "POSIX only") class TestProcess(unittest.TestCase): @@ -124,9 +145,7 @@ class TestProcess(unittest.TestCase): self.assertEqual(vsz_ps, vsz_psutil) def test_name(self): - # use command + arg since "comm" keyword not supported on all platforms - name_ps = ps("ps --no-headers -o command -p %s" % ( - self.pid)).split(' ')[0] + name_ps = ps_name(self.pid) # remove path if there is any, from the command name_ps = os.path.basename(name_ps).lower() name_psutil = psutil.Process(self.pid).name().lower() @@ -182,8 +201,7 @@ class TestProcess(unittest.TestCase): self.assertIn(time_ps, [time_psutil_tstamp, round_time_psutil_tstamp]) def test_exe(self): - ps_pathname = ps("ps --no-headers -o command -p %s" % - self.pid).split(' ')[0] + ps_pathname = ps_name(self.pid) psutil_pathname = psutil.Process(self.pid).exe() try: self.assertEqual(ps_pathname, psutil_pathname) @@ -198,11 +216,8 @@ class TestProcess(unittest.TestCase): self.assertEqual(ps_pathname, adjusted_ps_pathname) def test_cmdline(self): - ps_cmdline = ps("ps --no-headers -o command -p %s" % self.pid) + ps_cmdline = ps_args(self.pid) psutil_cmdline = " ".join(psutil.Process(self.pid).cmdline()) - if SUNOS: - # ps on Solaris only shows the first part of the cmdline - psutil_cmdline = psutil_cmdline.split(" ")[0] self.assertEqual(ps_cmdline, psutil_cmdline) # On SUNOS "ps" reads niceness /proc/pid/psinfo which returns an diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 45e79bbb..fa07f5a9 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -151,7 +151,7 @@ class TestProcess(unittest.TestCase): if POSIX: self.assertEqual(code, -signal.SIGKILL) else: - self.assertEqual(code, 0) + self.assertEqual(code, signal.SIGTERM) self.assertFalse(p.is_running()) sproc = get_test_subprocess() @@ -161,7 +161,7 @@ class TestProcess(unittest.TestCase): if POSIX: self.assertEqual(code, -signal.SIGTERM) else: - self.assertEqual(code, 0) + self.assertEqual(code, signal.SIGTERM) self.assertFalse(p.is_running()) # check sys.exit() code @@ -207,8 +207,8 @@ class TestProcess(unittest.TestCase): # to get None. self.assertEqual(ret2, None) else: - self.assertEqual(ret1, 0) - self.assertEqual(ret1, 0) + self.assertEqual(ret1, signal.SIGTERM) + self.assertEqual(ret1, signal.SIGTERM) def test_wait_timeout_0(self): sproc = get_test_subprocess() @@ -227,7 +227,7 @@ class TestProcess(unittest.TestCase): if POSIX: self.assertEqual(code, -signal.SIGKILL) else: - self.assertEqual(code, 0) + self.assertEqual(code, signal.SIGTERM) self.assertFalse(p.is_running()) def test_cpu_percent(self): @@ -724,7 +724,8 @@ class TestProcess(unittest.TestCase): # and Open BSD returns a truncated string. # Also /proc/pid/cmdline behaves the same so it looks # like this is a kernel bug. - if NETBSD or OPENBSD: + # XXX - AIX truncates long arguments in /proc/pid/cmdline + if NETBSD or OPENBSD or AIX: self.assertEqual( psutil.Process(sproc.pid).cmdline()[0], PYTHON) else: @@ -738,6 +739,7 @@ class TestProcess(unittest.TestCase): # XXX @unittest.skipIf(SUNOS, "broken on SUNOS") + @unittest.skipIf(AIX, "broken on AIX") def test_prog_w_funky_name(self): # Test that name(), exe() and cmdline() correctly handle programs # with funky chars such as spaces and ")", see: |