1# Test the SBAPI for GetStatistics() 2 3import json 4import lldb 5from lldbsuite.test.decorators import * 6from lldbsuite.test.lldbtest import * 7from lldbsuite.test import lldbutil 8 9 10class TestStatsAPI(TestBase): 11 12 NO_DEBUG_INFO_TESTCASE = True 13 14 def test_stats_api(self): 15 self.build() 16 exe = self.getBuildArtifact("a.out") 17 target = self.dbg.CreateTarget(exe) 18 19 # Test enabling/disabling stats 20 self.assertFalse(target.GetCollectingStats()) 21 target.SetCollectingStats(True) 22 self.assertTrue(target.GetCollectingStats()) 23 target.SetCollectingStats(False) 24 self.assertFalse(target.GetCollectingStats()) 25 26 # Test the function to get the statistics in JSON'ish. 27 stats = target.GetStatistics() 28 stream = lldb.SBStream() 29 res = stats.GetAsJSON(stream) 30 debug_stats = json.loads(stream.GetData()) 31 self.assertEqual('targets' in debug_stats, True, 32 'Make sure the "targets" key in in target.GetStatistics()') 33 self.assertEqual('modules' in debug_stats, True, 34 'Make sure the "modules" key in in target.GetStatistics()') 35 stats_json = debug_stats['targets'][0] 36 self.assertEqual('expressionEvaluation' in stats_json, True, 37 'Make sure the "expressionEvaluation" key in in target.GetStatistics()["targets"][0]') 38 self.assertEqual('frameVariable' in stats_json, True, 39 'Make sure the "frameVariable" key in in target.GetStatistics()["targets"][0]') 40 expressionEvaluation = stats_json['expressionEvaluation'] 41 self.assertEqual('successes' in expressionEvaluation, True, 42 'Make sure the "successes" key in in "expressionEvaluation" dictionary"') 43 self.assertEqual('failures' in expressionEvaluation, True, 44 'Make sure the "failures" key in in "expressionEvaluation" dictionary"') 45 frameVariable = stats_json['frameVariable'] 46 self.assertEqual('successes' in frameVariable, True, 47 'Make sure the "successes" key in in "frameVariable" dictionary"') 48 self.assertEqual('failures' in frameVariable, True, 49 'Make sure the "failures" key in in "frameVariable" dictionary"') 50