comparison env/lib/python3.9/site-packages/psutil/tests/test_aix.py @ 0:4f3585e2f14b draft default tip

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