|
1 #!/usr/bin/env python |
|
2 |
|
3 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. |
|
4 # Use of this source code is governed by a BSD-style license that can be |
|
5 # found in the LICENSE file. |
|
6 |
|
7 """Sun OS specific tests. These are implicitly run by test_psutil.py.""" |
|
8 |
|
9 import psutil |
|
10 from test_psutil import * |
|
11 |
|
12 |
|
13 class SunOSSpecificTestCase(unittest.TestCase): |
|
14 |
|
15 def test_swap_memory(self): |
|
16 out = sh('swap -l -k') |
|
17 lines = out.strip().split('\n')[1:] |
|
18 if not lines: |
|
19 raise ValueError('no swap device(s) configured') |
|
20 total = free = 0 |
|
21 for line in lines: |
|
22 line = line.split() |
|
23 t, f = line[-2:] |
|
24 t = t.replace('K', '') |
|
25 f = f.replace('K', '') |
|
26 total += int(int(t) * 1024) |
|
27 free += int(int(f) * 1024) |
|
28 used = total - free |
|
29 |
|
30 psutil_swap = psutil.swap_memory() |
|
31 self.assertEqual(psutil_swap.total, total) |
|
32 self.assertEqual(psutil_swap.used, used) |
|
33 self.assertEqual(psutil_swap.free, free) |
|
34 |
|
35 |
|
36 def test_main(): |
|
37 test_suite = unittest.TestSuite() |
|
38 test_suite.addTest(unittest.makeSuite(SunOSSpecificTestCase)) |
|
39 result = unittest.TextTestRunner(verbosity=2).run(test_suite) |
|
40 return result.wasSuccessful() |
|
41 |
|
42 if __name__ == '__main__': |
|
43 if not test_main(): |
|
44 sys.exit(1) |