Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/psutil/tests/test_aix.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
| author | shellac |
|---|---|
| date | Sat, 02 May 2020 07:14:21 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:26e78fe6e8c4 |
|---|---|
| 1 #!/usr/bin/env python3 | |
| 2 | |
| 3 # Copyright (c) 2009, Giampaolo Rodola' | |
| 4 # Copyright (c) 2017, Arnon Yaari | |
| 5 # All rights reserved. | |
| 6 # Use of this source code is governed by a BSD-style license that can be | |
| 7 # found in the LICENSE file. | |
| 8 | |
| 9 """AIX specific tests.""" | |
| 10 | |
| 11 import re | |
| 12 | |
| 13 from psutil import AIX | |
| 14 from psutil.tests import sh | |
| 15 from psutil.tests import unittest | |
| 16 import psutil | |
| 17 | |
| 18 | |
| 19 @unittest.skipIf(not AIX, "AIX only") | |
| 20 class AIXSpecificTestCase(unittest.TestCase): | |
| 21 | |
| 22 def test_virtual_memory(self): | |
| 23 out = sh('/usr/bin/svmon -O unit=KB') | |
| 24 re_pattern = r"memory\s*" | |
| 25 for field in ("size inuse free pin virtual available mmode").split(): | |
| 26 re_pattern += r"(?P<%s>\S+)\s+" % (field,) | |
| 27 matchobj = re.search(re_pattern, out) | |
| 28 | |
| 29 self.assertIsNotNone( | |
| 30 matchobj, "svmon command returned unexpected output") | |
| 31 | |
| 32 KB = 1024 | |
| 33 total = int(matchobj.group("size")) * KB | |
| 34 available = int(matchobj.group("available")) * KB | |
| 35 used = int(matchobj.group("inuse")) * KB | |
| 36 free = int(matchobj.group("free")) * KB | |
| 37 | |
| 38 psutil_result = psutil.virtual_memory() | |
| 39 | |
| 40 # MEMORY_TOLERANCE from psutil.tests is not enough. For some reason | |
| 41 # we're seeing differences of ~1.2 MB. 2 MB is still a good tolerance | |
| 42 # when compared to GBs. | |
| 43 MEMORY_TOLERANCE = 2 * KB * KB # 2 MB | |
| 44 self.assertEqual(psutil_result.total, total) | |
| 45 self.assertAlmostEqual( | |
| 46 psutil_result.used, used, delta=MEMORY_TOLERANCE) | |
| 47 self.assertAlmostEqual( | |
| 48 psutil_result.available, available, delta=MEMORY_TOLERANCE) | |
| 49 self.assertAlmostEqual( | |
| 50 psutil_result.free, free, delta=MEMORY_TOLERANCE) | |
| 51 | |
| 52 def test_swap_memory(self): | |
| 53 out = sh('/usr/sbin/lsps -a') | |
| 54 # From the man page, "The size is given in megabytes" so we assume | |
| 55 # we'll always have 'MB' in the result | |
| 56 # TODO maybe try to use "swap -l" to check "used" too, but its units | |
| 57 # are not guaranteed to be "MB" so parsing may not be consistent | |
| 58 matchobj = re.search(r"(?P<space>\S+)\s+" | |
| 59 r"(?P<vol>\S+)\s+" | |
| 60 r"(?P<vg>\S+)\s+" | |
| 61 r"(?P<size>\d+)MB", out) | |
| 62 | |
| 63 self.assertIsNotNone( | |
| 64 matchobj, "lsps command returned unexpected output") | |
| 65 | |
| 66 total_mb = int(matchobj.group("size")) | |
| 67 MB = 1024 ** 2 | |
| 68 psutil_result = psutil.swap_memory() | |
| 69 # we divide our result by MB instead of multiplying the lsps value by | |
| 70 # MB because lsps may round down, so we round down too | |
| 71 self.assertEqual(int(psutil_result.total / MB), total_mb) | |
| 72 | |
| 73 def test_cpu_stats(self): | |
| 74 out = sh('/usr/bin/mpstat -a') | |
| 75 | |
| 76 re_pattern = r"ALL\s*" | |
| 77 for field in ("min maj mpcs mpcr dev soft dec ph cs ics bound rq " | |
| 78 "push S3pull S3grd S0rd S1rd S2rd S3rd S4rd S5rd " | |
| 79 "sysc").split(): | |
| 80 re_pattern += r"(?P<%s>\S+)\s+" % (field,) | |
| 81 matchobj = re.search(re_pattern, out) | |
| 82 | |
| 83 self.assertIsNotNone( | |
| 84 matchobj, "mpstat command returned unexpected output") | |
| 85 | |
| 86 # numbers are usually in the millions so 1000 is ok for tolerance | |
| 87 CPU_STATS_TOLERANCE = 1000 | |
| 88 psutil_result = psutil.cpu_stats() | |
| 89 self.assertAlmostEqual( | |
| 90 psutil_result.ctx_switches, | |
| 91 int(matchobj.group("cs")), | |
| 92 delta=CPU_STATS_TOLERANCE) | |
| 93 self.assertAlmostEqual( | |
| 94 psutil_result.syscalls, | |
| 95 int(matchobj.group("sysc")), | |
| 96 delta=CPU_STATS_TOLERANCE) | |
| 97 self.assertAlmostEqual( | |
| 98 psutil_result.interrupts, | |
| 99 int(matchobj.group("dev")), | |
| 100 delta=CPU_STATS_TOLERANCE) | |
| 101 self.assertAlmostEqual( | |
| 102 psutil_result.soft_interrupts, | |
| 103 int(matchobj.group("soft")), | |
| 104 delta=CPU_STATS_TOLERANCE) | |
| 105 | |
| 106 def test_cpu_count_logical(self): | |
| 107 out = sh('/usr/bin/mpstat -a') | |
| 108 mpstat_lcpu = int(re.search(r"lcpu=(\d+)", out).group(1)) | |
| 109 psutil_lcpu = psutil.cpu_count(logical=True) | |
| 110 self.assertEqual(mpstat_lcpu, psutil_lcpu) | |
| 111 | |
| 112 def test_net_if_addrs_names(self): | |
| 113 out = sh('/etc/ifconfig -l') | |
| 114 ifconfig_names = set(out.split()) | |
| 115 psutil_names = set(psutil.net_if_addrs().keys()) | |
| 116 self.assertSetEqual(ifconfig_names, psutil_names) | |
| 117 | |
| 118 | |
| 119 if __name__ == '__main__': | |
| 120 from psutil.tests.runner import run | |
| 121 run(__file__) |
