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
13*d7b33853SGreg Clayton    NO_DEBUG_INFO_TESTCASE = True
14*d7b33853SGreg 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*d7b33853SGreg Clayton        stats_json = json.loads(stream.GetData())
32*d7b33853SGreg Clayton        self.assertEqual('expressionEvaluation' in stats_json, True,
33*d7b33853SGreg Clayton                'Make sure the "expressionEvaluation" key in in target.GetStatistics()')
34*d7b33853SGreg Clayton        self.assertEqual('frameVariable' in stats_json, True,
35*d7b33853SGreg Clayton                'Make sure the "frameVariable" key in in target.GetStatistics()')
36*d7b33853SGreg Clayton        expressionEvaluation = stats_json['expressionEvaluation']
37*d7b33853SGreg Clayton        self.assertEqual('successes' in expressionEvaluation, True,
38*d7b33853SGreg Clayton                'Make sure the "successes" key in in "expressionEvaluation" dictionary"')
39*d7b33853SGreg Clayton        self.assertEqual('failures' in expressionEvaluation, True,
40*d7b33853SGreg Clayton                'Make sure the "failures" key in in "expressionEvaluation" dictionary"')
41*d7b33853SGreg Clayton        frameVariable = stats_json['frameVariable']
42*d7b33853SGreg Clayton        self.assertEqual('successes' in frameVariable, True,
43*d7b33853SGreg Clayton                'Make sure the "successes" key in in "frameVariable" dictionary"')
44*d7b33853SGreg Clayton        self.assertEqual('failures' in frameVariable, True,
45*d7b33853SGreg Clayton                'Make sure the "failures" key in in "frameVariable" dictionary"')
46