xref: /llvm-project/lldb/test/API/functionalities/stats_api/TestStatisticsAPI.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
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    NO_DEBUG_INFO_TESTCASE = True
12
13    def test_stats_api(self):
14        self.build()
15        exe = self.getBuildArtifact("a.out")
16        target = self.dbg.CreateTarget(exe)
17
18        # Test enabling/disabling stats
19        self.assertFalse(target.GetCollectingStats())
20        target.SetCollectingStats(True)
21        self.assertTrue(target.GetCollectingStats())
22        target.SetCollectingStats(False)
23        self.assertFalse(target.GetCollectingStats())
24
25        # Test the function to get the statistics in JSON'ish.
26        stats = target.GetStatistics()
27        stream = lldb.SBStream()
28        res = stats.GetAsJSON(stream)
29        debug_stats = json.loads(stream.GetData())
30        self.assertEqual(
31            "targets" in debug_stats,
32            True,
33            'Make sure the "targets" key in in target.GetStatistics()',
34        )
35        self.assertEqual(
36            "modules" in debug_stats,
37            True,
38            'Make sure the "modules" key in in target.GetStatistics()',
39        )
40        stats_json = debug_stats["targets"][0]
41        self.assertEqual(
42            "expressionEvaluation" in stats_json,
43            True,
44            'Make sure the "expressionEvaluation" key in in target.GetStatistics()["targets"][0]',
45        )
46        self.assertEqual(
47            "frameVariable" in stats_json,
48            True,
49            'Make sure the "frameVariable" key in in target.GetStatistics()["targets"][0]',
50        )
51        expressionEvaluation = stats_json["expressionEvaluation"]
52        self.assertEqual(
53            "successes" in expressionEvaluation,
54            True,
55            'Make sure the "successes" key in in "expressionEvaluation" dictionary"',
56        )
57        self.assertEqual(
58            "failures" in expressionEvaluation,
59            True,
60            'Make sure the "failures" key in in "expressionEvaluation" dictionary"',
61        )
62        frameVariable = stats_json["frameVariable"]
63        self.assertEqual(
64            "successes" in frameVariable,
65            True,
66            'Make sure the "successes" key in in "frameVariable" dictionary"',
67        )
68        self.assertEqual(
69            "failures" in frameVariable,
70            True,
71            'Make sure the "failures" key in in "frameVariable" dictionary"',
72        )
73