1
0

test_win_pdh.py 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # -*- coding: utf-8 -*-
  2. # Import Python Libs
  3. from __future__ import absolute_import, unicode_literals, print_function
  4. # Import Salt Testing Libs
  5. from tests.support.unit import TestCase, skipIf
  6. # Import Salt Libs
  7. import salt.utils.platform
  8. import salt.utils.win_pdh as win_pdh
  9. @skipIf(not salt.utils.platform.is_windows(), 'System is not Windows')
  10. class WinPdhTestCase(TestCase):
  11. def test_list_objects(self):
  12. known_objects = ['Cache', 'Memory', 'Process', 'Processor', 'System']
  13. objects = win_pdh.list_objects()
  14. for item in known_objects:
  15. self.assertTrue(item in objects)
  16. def test_list_counters(self):
  17. counters = win_pdh.list_counters('Processor')
  18. known_counters = ['% Processor Time', '% User Time', '% DPC Time']
  19. for item in known_counters:
  20. self.assertTrue(item in counters)
  21. def test_list_instances(self):
  22. instances = win_pdh.list_instances('Processor')
  23. known_instances = ['0', '_Total']
  24. for item in known_instances:
  25. self.assertTrue(item in instances)
  26. def test_build_counter_list(self):
  27. counter_list = [
  28. ('Memory', None, 'Available Bytes'),
  29. ('Paging File', '*', '% Usage'),
  30. ('Processor', '*', '% Processor Time'),
  31. ('Server', None, 'Work Item Shortages'),
  32. ('Server Work Queues', '*', 'Queue Length'),
  33. ('System', None, 'Context Switches/sec'),
  34. ]
  35. resulting_list = win_pdh.build_counter_list(counter_list)
  36. for counter in resulting_list:
  37. self.assertTrue(isinstance(counter, win_pdh.Counter))
  38. resulting_paths = []
  39. for counter in resulting_list:
  40. resulting_paths.append(counter.path)
  41. expected_paths = [
  42. '\\Memory\\Available Bytes',
  43. '\\Paging File(*)\\% Usage',
  44. '\\Processor(*)\\% Processor Time',
  45. '\\Server\\Work Item Shortages',
  46. '\\Server Work Queues(*)\\Queue Length',
  47. '\\System\\Context Switches/sec']
  48. self.assertEqual(resulting_paths, expected_paths)
  49. def test_get_all_counters(self):
  50. results = win_pdh.get_all_counters('Processor')
  51. known_counters = [
  52. '\\Processor(*)\\% Processor Time',
  53. '\\Processor(*)\\% Idle Time',
  54. '\\Processor(*)\\DPC Rate',
  55. '\\Processor(*)\\% Privileged Time',
  56. '\\Processor(*)\\DPCs Queued/sec',
  57. '\\Processor(*)\\% Interrupt Time',
  58. '\\Processor(*)\\Interrupts/sec',
  59. ]
  60. for item in known_counters:
  61. self.assertTrue(item in results)
  62. def test_get_counters(self):
  63. counter_list = [
  64. ('Memory', None, 'Available Bytes'),
  65. ('Paging File', '*', '% Usage'),
  66. ('Processor', '*', '% Processor Time'),
  67. ('Server', None, 'Work Item Shortages'),
  68. ('Server Work Queues', '*', 'Queue Length'),
  69. ('System', None, 'Context Switches/sec'),
  70. ]
  71. results = win_pdh.get_counters(counter_list)
  72. expected_counters = [
  73. '\\Memory\\Available Bytes',
  74. '\\Paging File(*)\\% Usage',
  75. '\\Processor(*)\\% Processor Time',
  76. '\\Server\\Work Item Shortages',
  77. '\\Server Work Queues(*)\\Queue Length',
  78. '\\System\\Context Switches/sec'
  79. ]
  80. for item in expected_counters:
  81. self.assertTrue(item in results)
  82. def test_get_counter(self):
  83. results = win_pdh.get_counter('Processor', '*', '% Processor Time')
  84. self.assertTrue('\\Processor(*)\\% Processor Time' in results)