llvm-project/lldb/test/logging/TestLogging.py

99 lines
3.4 KiB
Python
Raw Normal View History

"""
Test lldb logging.
"""
import os, time
import unittest2
import lldb
from lldbtest import *
class LogTestCase(TestBase):
mydir = "logging"
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
@dsym_test
def test_with_dsym (self):
self.buildDsym ()
self.command_log_tests ("dsym")
@dwarf_test
def test_with_dwarf (self):
self.buildDwarf ()
self.command_log_tests ("dwarf")
def command_log_tests (self, type):
exe = os.path.join (os.getcwd(), "a.out")
self.expect("file " + exe,
patterns = [ "Current executable set to .*a.out" ])
Add the ability for the test suite to specify a list of compilers and a list of architectures on the command line. For example, use '-A x86_64^i386' to launch the inferior use both x86_64 and i386. This is an example of building the debuggee using both clang and gcc compiers: [17:30:46] johnny:/Volumes/data/lldb/svn/trunk/test $ ./dotest.py -C clang^gcc -v -f SourceManagerTestCase.test_modify_source_file_while_debugging Session logs for test failures/errors will go into directory '2011-03-03-17_31_39' Command invoked: python ./dotest.py -C clang^gcc -v -f SourceManagerTestCase.test_modify_source_file_while_debugging Configuration: compiler=clang ---------------------------------------------------------------------- Collected 1 test 1: test_modify_source_file_while_debugging (TestSourceManager.SourceManagerTestCase) Modify a source file while debugging the executable. ... Command 'run' failed! original content: #include <stdio.h> int main(int argc, char const *argv[]) { printf("Hello world.\n"); // Set break point at this line. return 0; } new content: #include <stdio.h> int main(int argc, char const *argv[]) { printf("Hello lldb.\n"); // Set break point at this line. return 0; } os.path.getmtime() after writing new content: 1299202305.0 content restored to: #include <stdio.h> int main(int argc, char const *argv[]) { printf("Hello world.\n"); // Set break point at this line. return 0; } os.path.getmtime() after restore: 1299202307.0 ok ---------------------------------------------------------------------- Ran 1 test in 8.259s OK Configuration: compiler=gcc ---------------------------------------------------------------------- Collected 1 test 1: test_modify_source_file_while_debugging (TestSourceManager.SourceManagerTestCase) Modify a source file while debugging the executable. ... original content: #include <stdio.h> int main(int argc, char const *argv[]) { printf("Hello world.\n"); // Set break point at this line. return 0; } new content: #include <stdio.h> int main(int argc, char const *argv[]) { printf("Hello lldb.\n"); // Set break point at this line. return 0; } os.path.getmtime() after writing new content: 1299202307.0 content restored to: #include <stdio.h> int main(int argc, char const *argv[]) { printf("Hello world.\n"); // Set break point at this line. return 0; } os.path.getmtime() after restore: 1299202309.0 ok ---------------------------------------------------------------------- Ran 1 test in 2.301s OK [17:31:49] johnny:/Volumes/data/lldb/svn/trunk/test $ llvm-svn: 126979
2011-03-04 01:35:22 +00:00
log_file = os.path.join (os.getcwd(), "lldb-commands-log-%s-%s-%s.txt" % (type,
os.path.basename(self.getCompiler()),
Add the ability for the test suite to specify a list of compilers and a list of architectures on the command line. For example, use '-A x86_64^i386' to launch the inferior use both x86_64 and i386. This is an example of building the debuggee using both clang and gcc compiers: [17:30:46] johnny:/Volumes/data/lldb/svn/trunk/test $ ./dotest.py -C clang^gcc -v -f SourceManagerTestCase.test_modify_source_file_while_debugging Session logs for test failures/errors will go into directory '2011-03-03-17_31_39' Command invoked: python ./dotest.py -C clang^gcc -v -f SourceManagerTestCase.test_modify_source_file_while_debugging Configuration: compiler=clang ---------------------------------------------------------------------- Collected 1 test 1: test_modify_source_file_while_debugging (TestSourceManager.SourceManagerTestCase) Modify a source file while debugging the executable. ... Command 'run' failed! original content: #include <stdio.h> int main(int argc, char const *argv[]) { printf("Hello world.\n"); // Set break point at this line. return 0; } new content: #include <stdio.h> int main(int argc, char const *argv[]) { printf("Hello lldb.\n"); // Set break point at this line. return 0; } os.path.getmtime() after writing new content: 1299202305.0 content restored to: #include <stdio.h> int main(int argc, char const *argv[]) { printf("Hello world.\n"); // Set break point at this line. return 0; } os.path.getmtime() after restore: 1299202307.0 ok ---------------------------------------------------------------------- Ran 1 test in 8.259s OK Configuration: compiler=gcc ---------------------------------------------------------------------- Collected 1 test 1: test_modify_source_file_while_debugging (TestSourceManager.SourceManagerTestCase) Modify a source file while debugging the executable. ... original content: #include <stdio.h> int main(int argc, char const *argv[]) { printf("Hello world.\n"); // Set break point at this line. return 0; } new content: #include <stdio.h> int main(int argc, char const *argv[]) { printf("Hello lldb.\n"); // Set break point at this line. return 0; } os.path.getmtime() after writing new content: 1299202307.0 content restored to: #include <stdio.h> int main(int argc, char const *argv[]) { printf("Hello world.\n"); // Set break point at this line. return 0; } os.path.getmtime() after restore: 1299202309.0 ok ---------------------------------------------------------------------- Ran 1 test in 2.301s OK [17:31:49] johnny:/Volumes/data/lldb/svn/trunk/test $ llvm-svn: 126979
2011-03-04 01:35:22 +00:00
self.getArchitecture()))
if (os.path.exists (log_file)):
os.remove (log_file)
self.runCmd ("log enable -f '%s' lldb commands" % (log_file))
self.runCmd ("command alias bp breakpoint")
self.runCmd ("bp set -n main")
self.runCmd ("bp l")
expected_log_lines = [
"Processing command: command alias bp breakpoint\n",
"HandleCommand, cmd_obj : 'command alias'\n",
"HandleCommand, revised_command_line: 'command alias bp breakpoint'\n",
"HandleCommand, wants_raw_input:'True'\n",
"HandleCommand, command line after removing command name(s): 'bp breakpoint'\n",
"HandleCommand, command succeeded\n",
"Processing command: bp set -n main\n",
"HandleCommand, cmd_obj : 'breakpoint set'\n",
"HandleCommand, revised_command_line: 'breakpoint set -n main'\n",
"HandleCommand, wants_raw_input:'False'\n",
"HandleCommand, command line after removing command name(s): '-n main'\n",
"HandleCommand, command succeeded\n",
"Processing command: bp l\n",
"HandleCommand, cmd_obj : 'breakpoint list'\n",
"HandleCommand, revised_command_line: 'breakpoint l'\n",
"HandleCommand, wants_raw_input:'False'\n",
"HandleCommand, command line after removing command name(s): ''\n",
"HandleCommand, command succeeded\n",
]
self.assertTrue (os.path.isfile (log_file))
idx = 0
end = len (expected_log_lines)
f = open (log_file)
log_lines = f.readlines()
f.close ()
self.runCmd("log disable lldb")
os.remove (log_file)
err_msg = ""
success = True
if len (log_lines) != len (expected_log_lines):
success = False
err_msg = "Wrong number of lines in log file; expected: " + repr (len (expected_log_lines)) + " found: " + repr(len (log_lines))
else:
for line1, line2 in zip (log_lines, expected_log_lines):
if line1 != line2:
success = False
err_msg = "Expected '" + line2 + "'; Found '" + line1 + "'"
break
if not success:
self.fail (err_msg)
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()