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