diff options
| author | royitaqi <royitaqi@users.noreply.github.com> | 2024-06-03 13:52:03 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-03 13:52:03 -0700 |
| commit | c2d061da7e17e61d4a0efad261e5280793c1b7ce (patch) | |
| tree | 1d569a2d7ff416b699b93ab55b71db7492b27089 /lldb/test/API/python_api | |
| parent | b61d7ec16bf5c740346e87b8b03315e38fe31725 (diff) | |
| download | llvm-c2d061da7e17e61d4a0efad261e5280793c1b7ce.zip llvm-c2d061da7e17e61d4a0efad261e5280793c1b7ce.tar.gz llvm-c2d061da7e17e61d4a0efad261e5280793c1b7ce.tar.bz2 | |
Re-merge `A few updates around "transcript"` (#92843) (#94067)
Problematic PR: https://github.com/llvm/llvm-project/pull/92843
Reverted by: https://github.com/llvm/llvm-project/pull/94088
The first PR added a test which fails in Linux builds (see the last few
comments there).
This PR contains all the changes in the first PR, plus the fix to the
said test.
---------
Co-authored-by: Roy Shi <royshi@meta.com>
Diffstat (limited to 'lldb/test/API/python_api')
| -rw-r--r-- | lldb/test/API/python_api/interpreter/TestCommandInterpreterAPI.py | 67 |
1 files changed, 39 insertions, 28 deletions
diff --git a/lldb/test/API/python_api/interpreter/TestCommandInterpreterAPI.py b/lldb/test/API/python_api/interpreter/TestCommandInterpreterAPI.py index 95643ee..1029bdc 100644 --- a/lldb/test/API/python_api/interpreter/TestCommandInterpreterAPI.py +++ b/lldb/test/API/python_api/interpreter/TestCommandInterpreterAPI.py @@ -104,9 +104,10 @@ class CommandInterpreterAPICase(TestBase): return json.loads(stream.GetData()) - def test_structured_transcript(self): + def test_get_transcript(self): """Test structured transcript generation and retrieval.""" ci = self.buildAndCreateTarget() + self.assertTrue(ci, VALID_COMMAND_INTERPRETER) # Make sure the "save-transcript" setting is on self.runCmd("settings set interpreter.save-transcript true") @@ -118,8 +119,7 @@ class CommandInterpreterAPICase(TestBase): res = lldb.SBCommandReturnObject() ci.HandleCommand("version", res) ci.HandleCommand("an-unknown-command", res) - ci.HandleCommand("breakpoint set -f main.c -l %d" % self.line, res) - ci.HandleCommand("r", res) + ci.HandleCommand("br s -f main.c -l %d" % self.line, res) ci.HandleCommand("p a", res) ci.HandleCommand("statistics dump", res) total_number_of_commands = 6 @@ -130,22 +130,28 @@ class CommandInterpreterAPICase(TestBase): # All commands should have expected fields. for command in transcript: self.assertIn("command", command) + # Unresolved commands don't have "commandName"/"commandArguments". + # We will validate these fields below, instead of here. self.assertIn("output", command) self.assertIn("error", command) - self.assertIn("seconds", command) + self.assertIn("durationInSeconds", command) + self.assertIn("timestampInEpochSeconds", command) # The following validates individual commands in the transcript. # # Notes: # 1. Some of the asserts rely on the exact output format of the # commands. Hopefully we are not changing them any time soon. - # 2. We are removing the "seconds" field from each command, so that - # some of the validations below can be easier / more readable. + # 2. We are removing the time-related fields from each command, so + # that some of the validations below can be easier / more readable. for command in transcript: - del(command["seconds"]) + del command["durationInSeconds"] + del command["timestampInEpochSeconds"] # (lldb) version self.assertEqual(transcript[0]["command"], "version") + self.assertEqual(transcript[0]["commandName"], "version") + self.assertEqual(transcript[0]["commandArguments"], "") self.assertIn("lldb version", transcript[0]["output"]) self.assertEqual(transcript[0]["error"], "") @@ -153,33 +159,37 @@ class CommandInterpreterAPICase(TestBase): self.assertEqual(transcript[1], { "command": "an-unknown-command", + # Unresolved commands don't have "commandName"/"commandArguments" "output": "", "error": "error: 'an-unknown-command' is not a valid command.\n", }) - # (lldb) breakpoint set -f main.c -l <line> - self.assertEqual(transcript[2]["command"], "breakpoint set -f main.c -l %d" % self.line) + # (lldb) br s -f main.c -l <line> + self.assertEqual(transcript[2]["command"], "br s -f main.c -l %d" % self.line) + self.assertEqual(transcript[2]["commandName"], "breakpoint set") + self.assertEqual( + transcript[2]["commandArguments"], "-f main.c -l %d" % self.line + ) # Breakpoint 1: where = a.out`main + 29 at main.c:5:3, address = 0x0000000100000f7d self.assertIn("Breakpoint 1: where = a.out`main ", transcript[2]["output"]) self.assertEqual(transcript[2]["error"], "") - # (lldb) r - self.assertEqual(transcript[3]["command"], "r") - # Process 25494 launched: '<path>/TestCommandInterpreterAPI.test_structured_transcript/a.out' (x86_64) - self.assertIn("Process", transcript[3]["output"]) - self.assertIn("launched", transcript[3]["output"]) - self.assertEqual(transcript[3]["error"], "") - # (lldb) p a - self.assertEqual(transcript[4], + self.assertEqual(transcript[3], { "command": "p a", - "output": "(int) 123\n", - "error": "", + "commandName": "dwim-print", + "commandArguments": "-- a", + "output": "", + "error": "error: <user expression 0>:1:1: use of undeclared identifier 'a'\n 1 | a\n | ^\n", }) # (lldb) statistics dump - statistics_dump = json.loads(transcript[5]["output"]) + self.assertEqual(transcript[4]["command"], "statistics dump") + self.assertEqual(transcript[4]["commandName"], "statistics dump") + self.assertEqual(transcript[4]["commandArguments"], "") + self.assertEqual(transcript[4]["error"], "") + statistics_dump = json.loads(transcript[4]["output"]) # Dump result should be valid JSON self.assertTrue(statistics_dump is not json.JSONDecodeError) # Dump result should contain expected fields @@ -189,15 +199,15 @@ class CommandInterpreterAPICase(TestBase): self.assertIn("targets", statistics_dump) def test_save_transcript_setting_default(self): - ci = self.buildAndCreateTarget() - res = lldb.SBCommandReturnObject() + ci = self.dbg.GetCommandInterpreter() + self.assertTrue(ci, VALID_COMMAND_INTERPRETER) # The setting's default value should be "false" self.runCmd("settings show interpreter.save-transcript", "interpreter.save-transcript (boolean) = false\n") - # self.assertEqual(res.GetOutput(), ) def test_save_transcript_setting_off(self): - ci = self.buildAndCreateTarget() + ci = self.dbg.GetCommandInterpreter() + self.assertTrue(ci, VALID_COMMAND_INTERPRETER) # Make sure the setting is off self.runCmd("settings set interpreter.save-transcript false") @@ -208,8 +218,8 @@ class CommandInterpreterAPICase(TestBase): self.assertEqual(transcript, []) def test_save_transcript_setting_on(self): - ci = self.buildAndCreateTarget() - res = lldb.SBCommandReturnObject() + ci = self.dbg.GetCommandInterpreter() + self.assertTrue(ci, VALID_COMMAND_INTERPRETER) # Make sure the setting is on self.runCmd("settings set interpreter.save-transcript true") @@ -220,7 +230,7 @@ class CommandInterpreterAPICase(TestBase): self.assertEqual(len(transcript), 1) self.assertEqual(transcript[0]["command"], "version") - def test_save_transcript_returns_copy(self): + def test_get_transcript_returns_copy(self): """ Test that the returned structured data is *at least* a shallow copy. @@ -229,7 +239,8 @@ class CommandInterpreterAPICase(TestBase): because there is no logic in the command interpreter to modify a transcript item (representing a command) after it has been returned. """ - ci = self.buildAndCreateTarget() + ci = self.dbg.GetCommandInterpreter() + self.assertTrue(ci, VALID_COMMAND_INTERPRETER) # Make sure the setting is on self.runCmd("settings set interpreter.save-transcript true") |
