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    mydir = TestBase.compute_mydir(__file__)
1299451b44SJordan Rupprecht
13d7b33853SGreg Clayton    NO_DEBUG_INFO_TESTCASE = True
14d7b33853SGreg Clayton
1599451b44SJordan Rupprecht    def test_stats_api(self):
1699451b44SJordan Rupprecht        self.build()
1799451b44SJordan Rupprecht        exe = self.getBuildArtifact("a.out")
1899451b44SJordan Rupprecht        target = self.dbg.CreateTarget(exe)
1999451b44SJordan Rupprecht
2099451b44SJordan Rupprecht        # Test enabling/disabling stats
2199451b44SJordan Rupprecht        self.assertFalse(target.GetCollectingStats())
2299451b44SJordan Rupprecht        target.SetCollectingStats(True)
2399451b44SJordan Rupprecht        self.assertTrue(target.GetCollectingStats())
2499451b44SJordan Rupprecht        target.SetCollectingStats(False)
2599451b44SJordan Rupprecht        self.assertFalse(target.GetCollectingStats())
2699451b44SJordan Rupprecht
2799451b44SJordan Rupprecht        # Test the function to get the statistics in JSON'ish.
2899451b44SJordan Rupprecht        stats = target.GetStatistics()
2999451b44SJordan Rupprecht        stream = lldb.SBStream()
3099451b44SJordan Rupprecht        res = stats.GetAsJSON(stream)
31*c571988eSGreg Clayton        debug_stats = json.loads(stream.GetData())
32*c571988eSGreg Clayton        self.assertEqual('targets' in debug_stats, True,
33*c571988eSGreg Clayton                'Make sure the "targets" key in in target.GetStatistics()')
34*c571988eSGreg Clayton        self.assertEqual('modules' in debug_stats, True,
35*c571988eSGreg Clayton                'Make sure the "modules" key in in target.GetStatistics()')
36*c571988eSGreg Clayton        stats_json = debug_stats['targets'][0]
37d7b33853SGreg Clayton        self.assertEqual('expressionEvaluation' in stats_json, True,
38*c571988eSGreg Clayton                'Make sure the "expressionEvaluation" key in in target.GetStatistics()["targets"][0]')
39d7b33853SGreg Clayton        self.assertEqual('frameVariable' in stats_json, True,
40*c571988eSGreg Clayton                'Make sure the "frameVariable" key in in target.GetStatistics()["targets"][0]')
41d7b33853SGreg Clayton        expressionEvaluation = stats_json['expressionEvaluation']
42d7b33853SGreg Clayton        self.assertEqual('successes' in expressionEvaluation, True,
43d7b33853SGreg Clayton                'Make sure the "successes" key in in "expressionEvaluation" dictionary"')
44d7b33853SGreg Clayton        self.assertEqual('failures' in expressionEvaluation, True,
45d7b33853SGreg Clayton                'Make sure the "failures" key in in "expressionEvaluation" dictionary"')
46d7b33853SGreg Clayton        frameVariable = stats_json['frameVariable']
47d7b33853SGreg Clayton        self.assertEqual('successes' in frameVariable, True,
48d7b33853SGreg Clayton                'Make sure the "successes" key in in "frameVariable" dictionary"')
49d7b33853SGreg Clayton        self.assertEqual('failures' in frameVariable, True,
50d7b33853SGreg Clayton                'Make sure the "failures" key in in "frameVariable" dictionary"')
51