199451b44SJordan Rupprecht# Test the SBAPI for GetStatistics() 299451b44SJordan Rupprecht 399451b44SJordan Rupprechtimport json 499451b44SJordan Rupprechtimport lldb 599451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 699451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 799451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 899451b44SJordan Rupprecht 999451b44SJordan Rupprecht 1099451b44SJordan Rupprechtclass TestStatsAPI(TestBase): 1199451b44SJordan Rupprecht 12d7b33853SGreg Clayton NO_DEBUG_INFO_TESTCASE = True 13d7b33853SGreg Clayton 1499451b44SJordan Rupprecht def test_stats_api(self): 1599451b44SJordan Rupprecht self.build() 1699451b44SJordan Rupprecht exe = self.getBuildArtifact("a.out") 1799451b44SJordan Rupprecht target = self.dbg.CreateTarget(exe) 1899451b44SJordan Rupprecht 1999451b44SJordan Rupprecht # Test enabling/disabling stats 2099451b44SJordan Rupprecht self.assertFalse(target.GetCollectingStats()) 2199451b44SJordan Rupprecht target.SetCollectingStats(True) 2299451b44SJordan Rupprecht self.assertTrue(target.GetCollectingStats()) 2399451b44SJordan Rupprecht target.SetCollectingStats(False) 2499451b44SJordan Rupprecht self.assertFalse(target.GetCollectingStats()) 2599451b44SJordan Rupprecht 2699451b44SJordan Rupprecht # Test the function to get the statistics in JSON'ish. 2799451b44SJordan Rupprecht stats = target.GetStatistics() 2899451b44SJordan Rupprecht stream = lldb.SBStream() 2999451b44SJordan Rupprecht res = stats.GetAsJSON(stream) 30*c571988eSGreg Clayton debug_stats = json.loads(stream.GetData()) 31*c571988eSGreg Clayton self.assertEqual('targets' in debug_stats, True, 32*c571988eSGreg Clayton 'Make sure the "targets" key in in target.GetStatistics()') 33*c571988eSGreg Clayton self.assertEqual('modules' in debug_stats, True, 34*c571988eSGreg Clayton 'Make sure the "modules" key in in target.GetStatistics()') 35*c571988eSGreg Clayton stats_json = debug_stats['targets'][0] 36d7b33853SGreg Clayton self.assertEqual('expressionEvaluation' in stats_json, True, 37*c571988eSGreg Clayton 'Make sure the "expressionEvaluation" key in in target.GetStatistics()["targets"][0]') 38d7b33853SGreg Clayton self.assertEqual('frameVariable' in stats_json, True, 39*c571988eSGreg Clayton 'Make sure the "frameVariable" key in in target.GetStatistics()["targets"][0]') 40d7b33853SGreg Clayton expressionEvaluation = stats_json['expressionEvaluation'] 41d7b33853SGreg Clayton self.assertEqual('successes' in expressionEvaluation, True, 42d7b33853SGreg Clayton 'Make sure the "successes" key in in "expressionEvaluation" dictionary"') 43d7b33853SGreg Clayton self.assertEqual('failures' in expressionEvaluation, True, 44d7b33853SGreg Clayton 'Make sure the "failures" key in in "expressionEvaluation" dictionary"') 45d7b33853SGreg Clayton frameVariable = stats_json['frameVariable'] 46d7b33853SGreg Clayton self.assertEqual('successes' in frameVariable, True, 47d7b33853SGreg Clayton 'Make sure the "successes" key in in "frameVariable" dictionary"') 48d7b33853SGreg Clayton self.assertEqual('failures' in frameVariable, True, 49d7b33853SGreg Clayton 'Make sure the "failures" key in in "frameVariable" dictionary"') 50