test_sunos.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """Sun OS specific tests."""
  6. import os
  7. import psutil
  8. from psutil import SUNOS
  9. from psutil.tests import PsutilTestCase
  10. from psutil.tests import sh
  11. from psutil.tests import unittest
  12. @unittest.skipIf(not SUNOS, "SUNOS only")
  13. class SunOSSpecificTestCase(PsutilTestCase):
  14. def test_swap_memory(self):
  15. out = sh('env PATH=/usr/sbin:/sbin:%s swap -l' % os.environ['PATH'])
  16. lines = out.strip().split('\n')[1:]
  17. if not lines:
  18. raise ValueError('no swap device(s) configured')
  19. total = free = 0
  20. for line in lines:
  21. line = line.split()
  22. t, f = line[-2:]
  23. total += int(int(t) * 512)
  24. free += int(int(f) * 512)
  25. used = total - free
  26. psutil_swap = psutil.swap_memory()
  27. self.assertEqual(psutil_swap.total, total)
  28. self.assertEqual(psutil_swap.used, used)
  29. self.assertEqual(psutil_swap.free, free)
  30. def test_cpu_count(self):
  31. out = sh("/usr/sbin/psrinfo")
  32. self.assertEqual(psutil.cpu_count(), len(out.split('\n')))
  33. if __name__ == '__main__':
  34. from psutil.tests.runner import run_from_name
  35. run_from_name(__file__)