1import lldb
2from intelpt_testcase import *
3from lldbsuite.test.lldbtest import *
4from lldbsuite.test import lldbutil
5from lldbsuite.test.decorators import *
6
7class TestTraceDumpInfo(TraceIntelPTTestCaseBase):
8
9    def testErrorMessages(self):
10        # We first check the output when there are no targets
11        self.expect("thread trace dump info",
12            substrs=["error: invalid target, create a target using the 'target create' command"],
13            error=True)
14
15        # We now check the output when there's a non-running target
16        self.expect("target create " +
17            os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))
18
19        self.expect("thread trace dump info",
20            substrs=["error: Command requires a current process."],
21            error=True)
22
23        # Now we check the output when there's a running target without a trace
24        self.expect("b main")
25        self.expect("run")
26
27        self.expect("thread trace dump info",
28            substrs=["error: Process is not being traced"],
29            error=True)
30
31    def testDumpRawTraceSize(self):
32        self.expect("trace load -v " +
33        os.path.join(self.getSourceDir(), "intelpt-trace", "trace.json"),
34        substrs=["intel-pt"])
35
36        self.expect("thread trace dump info",
37            substrs=['''thread #1: tid = 3842849
38
39  Trace technology: intel-pt
40
41  Total number of trace items: 23
42
43  Memory usage:
44    Raw trace size: 4 KiB
45    Total approximate memory usage (excluding raw trace): 0.20 KiB
46    Average memory usage per item (excluding raw trace): 9.00 bytes
47
48  Timing for this thread:
49    Decoding instructions: ''', '''
50
51  Events:
52    Number of individual events: 2
53      software disabled tracing: 2
54
55  Errors:
56    Number of TSC decoding errors: 0'''],
57            patterns=["Decoding instructions: \d.\d\ds"])
58
59    def testDumpRawTraceSizeJSON(self):
60        self.expect("trace load -v " +
61        os.path.join(self.getSourceDir(), "intelpt-trace", "trace.json"),
62        substrs=["intel-pt"])
63
64        self.expect("thread trace dump info --json ",
65            substrs=['''{
66  "traceTechnology": "intel-pt",
67  "threadStats": {
68    "tid": 3842849,
69    "traceItemsCount": 23,
70    "memoryUsage": {
71      "totalInBytes": "207",
72      "avgPerItemInBytes": 9
73    },
74    "timingInSeconds": {
75      "Decoding instructions": 0''', '''
76    },
77    "events": {
78      "totalCount": 2,
79      "individualCounts": {
80        "software disabled tracing": 2
81      }
82    },
83    "errorItems": {
84      "total": 0,
85      "individualErrors": {}
86    }
87  },
88  "globalStats": {
89    "timingInSeconds": {}
90  }
91}'''])
92