Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(618)

Unified Diff: third_party/psutil/test/_bsd.py

Issue 8159001: Update third_party/psutil and fix the licence issue with it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove the suppression and unnecessary files. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/psutil/setup.py ('k') | third_party/psutil/test/_linux.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/psutil/test/_bsd.py
diff --git a/third_party/psutil/test/_bsd.py b/third_party/psutil/test/_bsd.py
index f2df15d4fd20e9ff356a19b47c0d0b1c82463db9..0296b05239a5cb78d5a14dd49b04c16a2e1f8679 100644
--- a/third_party/psutil/test/_bsd.py
+++ b/third_party/psutil/test/_bsd.py
@@ -1,7 +1,12 @@
#!/usr/bin/env python
#
-# $Id: _bsd.py 664 2010-10-09 16:14:34Z g.rodola $
+# $Id: _bsd.py 1142 2011-10-05 18:45:49Z g.rodola $
#
+# Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""BSD specific tests. These are implicitly run by test_psutil.py."""
import unittest
import subprocess
@@ -11,18 +16,14 @@ import sys
import psutil
-from test_psutil import reap_children, get_test_subprocess
-from _posix import ps
-
+from test_psutil import reap_children, get_test_subprocess, sh
def sysctl(cmdline):
"""Expects a sysctl command with an argument and parse the result
returning only the value of interest.
"""
- p = subprocess.Popen(cmdline, shell=1, stdout=subprocess.PIPE)
- result = p.communicate()[0].strip().split()[1]
- if sys.version_info >= (3,):
- result = str(result, sys.stdout.encoding)
+ result = sh("sysctl " + cmdline)
+ result = result[result.find(": ") + 2:]
try:
return int(result)
except ValueError:
@@ -54,6 +55,13 @@ class BSDSpecificTestCase(unittest.TestCase):
sysctl_hwphymem = sysctl('sysctl hw.physmem')
self.assertEqual(sysctl_hwphymem, psutil.TOTAL_PHYMEM)
+ def test_BOOT_TIME(self):
+ s = sysctl('sysctl kern.boottime')
+ s = s[s.find(" sec = ") + 7:]
+ s = s[:s.find(',')]
+ btime = int(s)
+ self.assertEqual(btime, psutil.BOOT_TIME)
+
def test_avail_phymem(self):
# This test is not particularly accurate and may fail if the OS is
# consuming memory for other applications.
@@ -65,7 +73,7 @@ class BSDSpecificTestCase(unittest.TestCase):
))
_pagesize = sysctl("sysctl hw.pagesize")
sysctl_avail_phymem = _sum * _pagesize
- psutil_avail_phymem = psutil.avail_phymem()
+ psutil_avail_phymem = psutil.phymem_usage().free
difference = abs(psutil_avail_phymem - sysctl_avail_phymem)
# On my system both sysctl and psutil report the same values.
# Let's use a tollerance of 0.5 MB and consider the test as failed
@@ -84,7 +92,7 @@ class BSDSpecificTestCase(unittest.TestCase):
if sys.version_info >= (3,):
result = str(result, sys.stdout.encoding)
sysctl_total_virtmem, _ = parse_sysctl_vmtotal(result)
- psutil_total_virtmem = psutil.total_virtmem()
+ psutil_total_virtmem = psutil.virtmem_usage().total
difference = abs(sysctl_total_virtmem - psutil_total_virtmem)
# On my system I get a difference of 4657152 bytes, probably because
@@ -93,8 +101,7 @@ class BSDSpecificTestCase(unittest.TestCase):
# the test as failed if we go over it.
if difference > (10 * 2**20):
self.fail("sysctl=%s; psutil=%s; difference=%s;" %(
- sysctl_total_virtmem, psutil_total_virtmem, difference)
- )
+ sysctl_total_virtmem, psutil_total_virtmem, difference))
def test_avail_virtmem(self):
# This test is not particularly accurate and may fail if the OS is
@@ -106,12 +113,11 @@ class BSDSpecificTestCase(unittest.TestCase):
if sys.version_info >= (3,):
result = str(result, sys.stdout.encoding)
_, sysctl_avail_virtmem = parse_sysctl_vmtotal(result)
- psutil_avail_virtmem = psutil.avail_virtmem()
+ psutil_avail_virtmem = psutil.virtmem_usage().free
difference = abs(sysctl_avail_virtmem - psutil_avail_virtmem)
# let's assume the test is failed if difference is > 0.5 MB
if difference > (0.5 * 2**20):
- self.fail("sysctl=%s; psutil=%s; difference=%s;" %(
- sysctl_avail_virtmem, psutil_avail_virtmem, difference))
+ self.fail(difference)
def test_process_create_time(self):
cmdline = "ps -o lstart -p %s" %self.pid
@@ -125,12 +131,35 @@ class BSDSpecificTestCase(unittest.TestCase):
time.localtime(start_psutil))
self.assertEqual(start_ps, start_psutil)
+ def test_disks(self):
+ # test psutil.disk_usage() and psutil.disk_partitions()
+ # against "df -a"
+ def df(path):
+ out = sh('df -k "%s"' % path).strip()
+ lines = out.split('\n')
+ lines.pop(0)
+ line = lines.pop(0)
+ dev, total, used, free = line.split()[:4]
+ if dev == 'none':
+ dev = ''
+ total = int(total) * 1024
+ used = int(used) * 1024
+ free = int(free) * 1024
+ return dev, total, used, free
+
+ for part in psutil.disk_partitions(all=False):
+ usage = psutil.disk_usage(part.mountpoint)
+ dev, total, used, free = df(part.mountpoint)
+ self.assertEqual(part.device, dev)
+ self.assertEqual(usage.total, total)
+ # 10 MB tollerance
+ if abs(usage.free - free) > 10 * 1024 * 1024:
+ self.fail("psutil=%s, df=%s" % usage.free, free)
+ if abs(usage.used - used) > 10 * 1024 * 1024:
+ self.fail("psutil=%s, df=%s" % usage.used, used)
+
if __name__ == '__main__':
test_suite = unittest.TestSuite()
test_suite.addTest(unittest.makeSuite(BSDSpecificTestCase))
unittest.TextTestRunner(verbosity=2).run(test_suite)
-
-
-
-
« no previous file with comments | « third_party/psutil/setup.py ('k') | third_party/psutil/test/_linux.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698