1
0

test_win_pdh.py 3.6 KB

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