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 mydir = TestBase.compute_mydir(__file__) 12 13 NO_DEBUG_INFO_TESTCASE = True 14 15 def test_stats_api(self): 16 self.build() 17 exe = self.getBuildArtifact("a.out") 18 target = self.dbg.CreateTarget(exe) 19 20 # Test enabling/disabling stats 21 self.assertFalse(target.GetCollectingStats()) 22 target.SetCollectingStats(True) 23 self.assertTrue(target.GetCollectingStats()) 24 target.SetCollectingStats(False) 25 self.assertFalse(target.GetCollectingStats()) 26 27 # Test the function to get the statistics in JSON'ish. 28 stats = target.GetStatistics() 29 stream = lldb.SBStream() 30 res = stats.GetAsJSON(stream) 31 debug_stats = json.loads(stream.GetData()) 32 self.assertEqual('targets' in debug_stats, True, 33 'Make sure the "targets" key in in target.GetStatistics()') 34 self.assertEqual('modules' in debug_stats, True, 35 'Make sure the "modules" key in in target.GetStatistics()') 36 stats_json = debug_stats['targets'][0] 37 self.assertEqual('expressionEvaluation' in stats_json, True, 38 'Make sure the "expressionEvaluation" key in in target.GetStatistics()["targets"][0]') 39 self.assertEqual('frameVariable' in stats_json, True, 40 'Make sure the "frameVariable" key in in target.GetStatistics()["targets"][0]') 41 expressionEvaluation = stats_json['expressionEvaluation'] 42 self.assertEqual('successes' in expressionEvaluation, True, 43 'Make sure the "successes" key in in "expressionEvaluation" dictionary"') 44 self.assertEqual('failures' in expressionEvaluation, True, 45 'Make sure the "failures" key in in "expressionEvaluation" dictionary"') 46 frameVariable = stats_json['frameVariable'] 47 self.assertEqual('successes' in frameVariable, True, 48 'Make sure the "successes" key in in "frameVariable" dictionary"') 49 self.assertEqual('failures' in frameVariable, True, 50 'Make sure the "failures" key in in "frameVariable" dictionary"') 51