1import lldb 2from lldbsuite.test.lldbtest import * 3from lldbsuite.test import lldbutil 4from lldbsuite.test.decorators import * 5 6class TestTraceLoad(TestBase): 7 8 mydir = TestBase.compute_mydir(__file__) 9 NO_DEBUG_INFO_TESTCASE = True 10 11 def setUp(self): 12 TestBase.setUp(self) 13 if 'intel-pt' not in configuration.enabled_plugins: 14 self.skipTest("The intel-pt test plugin is not enabled") 15 16 17 def testLoadTrace(self): 18 src_dir = self.getSourceDir() 19 trace_definition_file = os.path.join(src_dir, "intelpt-trace", "trace.json") 20 self.expect("trace load -v " + trace_definition_file, substrs=["intel-pt"]) 21 22 target = self.dbg.GetSelectedTarget() 23 process = target.GetProcess() 24 self.assertEqual(process.GetProcessID(), 1234) 25 26 self.assertEqual(process.GetNumThreads(), 1) 27 self.assertEqual(process.GetThreadAtIndex(0).GetThreadID(), 3842849) 28 29 self.assertEqual(target.GetNumModules(), 1) 30 module = target.GetModuleAtIndex(0) 31 path = module.GetFileSpec() 32 self.assertEqual(path.fullpath, os.path.join(src_dir, "intelpt-trace", "a.out")) 33 self.assertGreater(module.GetNumSections(), 0) 34 self.assertEqual(module.GetSectionAtIndex(0).GetFileAddress(), 0x400000) 35 36 self.assertEqual("6AA9A4E2-6F28-2F33-377D-59FECE874C71-5B41261A", module.GetUUIDString()) 37 38 39 def testLoadInvalidTraces(self): 40 src_dir = self.getSourceDir() 41 # We test first an invalid type 42 trace_definition_file = os.path.join(src_dir, "intelpt-trace", "trace_bad.json") 43 self.expect("trace load -v " + trace_definition_file, error=True, 44 substrs=['error: JSON value is expected to be "object"', "Value", "123", "Schema"]) 45 46 # Now we test a missing field 47 trace_definition_file2 = os.path.join(src_dir, "intelpt-trace", "trace_bad2.json") 48 self.expect("trace load -v " + trace_definition_file2, error=True, 49 substrs=['error: JSON object is missing the "triple" field.', "Value", "pid", "12345", "Schema"]) 50 51 # The following wrong schema will have a valid target and an invalid one. In the case of failure, 52 # no targets should be created. 53 self.assertEqual(self.dbg.GetNumTargets(), 0) 54 trace_definition_file2 = os.path.join(src_dir, "intelpt-trace", "trace_bad3.json") 55 self.expect("trace load -v " + trace_definition_file2, error=True, 56 substrs=['error: JSON object is missing the "pid" field.']) 57 self.assertEqual(self.dbg.GetNumTargets(), 0) 58