Skip to content

Commit a386406

Browse files
committed
Add plugin stats test
1 parent ef976cc commit a386406

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

lldb/test/API/commands/statistics/basic/TestStats.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,3 +1022,89 @@ def test_multiple_targets(self):
10221022
all_targets_stats = self.get_stats("--all-targets")
10231023
self.assertIsNotNone(self.find_module_in_metrics(main_exe, all_targets_stats))
10241024
self.assertIsNotNone(self.find_module_in_metrics(second_exe, all_targets_stats))
1025+
1026+
# Return some level of the plugin stats hierarchy.
1027+
# Will return either the top-level node, the namespace node, or a specific
1028+
# plugin node based on requested values.
1029+
#
1030+
# If any of the requested keys are not found in the stats then return None.
1031+
#
1032+
# Plugin stats look like this:
1033+
#
1034+
# "plugins": {
1035+
# "system-runtime": [
1036+
# {
1037+
# "enabled": true,
1038+
# "name": "systemruntime-macosx"
1039+
# }
1040+
# ]
1041+
# },
1042+
def get_plugin_stats(self, debugger_stats, plugin_namespace=None, plugin_name=None):
1043+
# Get top level plugin stats.
1044+
if "plugins" not in debugger_stats:
1045+
return None
1046+
plugins = debugger_stats["plugins"]
1047+
if not plugin_namespace:
1048+
return plugins
1049+
1050+
# Plugin namespace stats.
1051+
if plugin_namespace not in plugins:
1052+
return None
1053+
plugins_for_namespace = plugins[plugin_namespace]
1054+
if not plugin_name:
1055+
return plugins_for_namespace
1056+
1057+
# Specific plugin stats.
1058+
for plugin in debugger_stats["plugins"][plugin_namespace]:
1059+
if plugin["name"] == plugin_name:
1060+
return plugin
1061+
return None
1062+
1063+
def test_plugin_stats(self):
1064+
"""
1065+
Test "statistics dump" contains plugin info.
1066+
"""
1067+
self.build()
1068+
exe = self.getBuildArtifact("a.out")
1069+
target = self.createTestTarget(file_path=exe)
1070+
debugger_stats = self.get_stats()
1071+
1072+
# Verify that the statistics dump contains the plugin information.
1073+
plugins = self.get_plugin_stats(debugger_stats)
1074+
self.assertIsNotNone(plugins)
1075+
1076+
# Check for a known plugin namespace that should be in the stats.
1077+
system_runtime_plugins = self.get_plugin_stats(debugger_stats, "system-runtime")
1078+
self.assertIsNotNone(system_runtime_plugins)
1079+
1080+
# Validate the keys exists for the bottom-level plugin stats.
1081+
plugin_keys_exist = [
1082+
"name",
1083+
"enabled",
1084+
]
1085+
for plugin in system_runtime_plugins:
1086+
self.verify_keys(
1087+
plugin, 'debugger_stats["plugins"]["system-runtime"]', plugin_keys_exist
1088+
)
1089+
1090+
# Check for a known plugin that is enabled by default.
1091+
system_runtime_macosx_plugin = self.get_plugin_stats(
1092+
debugger_stats, "system-runtime", "systemruntime-macosx"
1093+
)
1094+
self.assertIsNotNone(system_runtime_macosx_plugin)
1095+
self.assertTrue(system_runtime_macosx_plugin["enabled"])
1096+
1097+
# Now disable the plugin and check the stats again.
1098+
# The stats should show the plugin is disabled.
1099+
self.runCmd("plugin disable system-runtime.systemruntime-macosx")
1100+
debugger_stats = self.get_stats()
1101+
system_runtime_macosx_plugin = self.get_plugin_stats(
1102+
debugger_stats, "system-runtime", "systemruntime-macosx"
1103+
)
1104+
self.assertIsNotNone(system_runtime_macosx_plugin)
1105+
self.assertFalse(system_runtime_macosx_plugin["enabled"])
1106+
1107+
# Plugins should not show up in the stats when disabled with an option.
1108+
debugger_stats = self.get_stats("--plugins false")
1109+
plugins = self.get_plugin_stats(debugger_stats)
1110+
self.assertIsNone(plugins)

0 commit comments

Comments
 (0)