diff options
author | wiggin15 <wiggin15@yahoo.com> | 2017-10-19 11:42:57 +0300 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-10-19 10:42:57 +0200 |
commit | 3e5e9b780c9e2809f7552f6218e5ae86cbd35e28 (patch) | |
tree | 52a8d062aeeb4850a38adf91678896da8f1e2782 | |
parent | 38f43df717386e767de0b1e044bb17510b0b1a6c (diff) | |
download | psutil-3e5e9b780c9e2809f7552f6218e5ae86cbd35e28.tar.gz |
fix or skip remaining AIX unit tests (#1145)
* create_exe should use default code if c_code is True
* fix or skip remaining AIX unit tests
-rw-r--r-- | IDEAS | 1 | ||||
-rw-r--r-- | psutil/TODO.aix | 4 | ||||
-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 | 4 |
5 files changed, 30 insertions, 17 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/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..bd13c2d2 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -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: |