annotate lldb/test/API/macosx/nslog/TestDarwinNSLogOutput.py @ 180:680fa57a2f20

fix compile errors.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 30 May 2020 17:44:06 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 """
anatofuz
parents:
diff changeset
2 Test DarwinLog "source include debug-level" functionality provided by the
anatofuz
parents:
diff changeset
3 StructuredDataDarwinLog plugin.
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 These tests are currently only supported when running against Darwin
anatofuz
parents:
diff changeset
6 targets.
anatofuz
parents:
diff changeset
7 """
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9
anatofuz
parents:
diff changeset
10 import lldb
anatofuz
parents:
diff changeset
11 import platform
anatofuz
parents:
diff changeset
12 import re
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 from lldbsuite.test.decorators import *
anatofuz
parents:
diff changeset
15 from lldbsuite.test.lldbtest import *
anatofuz
parents:
diff changeset
16 from lldbsuite.test import lldbtest_config
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 class DarwinNSLogOutputTestCase(TestBase):
anatofuz
parents:
diff changeset
20 NO_DEBUG_INFO_TESTCASE = True
anatofuz
parents:
diff changeset
21 mydir = TestBase.compute_mydir(__file__)
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 @skipUnlessDarwin
anatofuz
parents:
diff changeset
24 @skipIfRemote # this test is currently written using lldb commands & assumes running on local system
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 def setUp(self):
anatofuz
parents:
diff changeset
27 # Call super's setUp().
anatofuz
parents:
diff changeset
28 TestBase.setUp(self)
anatofuz
parents:
diff changeset
29 self.child = None
anatofuz
parents:
diff changeset
30 self.child_prompt = '(lldb) '
anatofuz
parents:
diff changeset
31 self.strict_sources = False
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 # Source filename.
anatofuz
parents:
diff changeset
34 self.source = 'main.m'
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 # Output filename.
anatofuz
parents:
diff changeset
37 self.exe_name = self.getBuildArtifact("a.out")
anatofuz
parents:
diff changeset
38 self.d = {'OBJC_SOURCES': self.source, 'EXE': self.exe_name}
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 # Locate breakpoint.
anatofuz
parents:
diff changeset
41 self.line = line_number(self.source, '// break here')
anatofuz
parents:
diff changeset
42
anatofuz
parents:
diff changeset
43 def tearDown(self):
anatofuz
parents:
diff changeset
44 # Shut down the process if it's still running.
anatofuz
parents:
diff changeset
45 if self.child:
anatofuz
parents:
diff changeset
46 self.runCmd('process kill')
anatofuz
parents:
diff changeset
47 self.expect_prompt()
anatofuz
parents:
diff changeset
48 self.runCmd('quit')
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 # Let parent clean up
anatofuz
parents:
diff changeset
51 super(DarwinNSLogOutputTestCase, self).tearDown()
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 def run_lldb_to_breakpoint(self, exe, source_file, line,
anatofuz
parents:
diff changeset
54 settings_commands=None):
anatofuz
parents:
diff changeset
55 # Set self.child_prompt, which is "(lldb) ".
anatofuz
parents:
diff changeset
56 prompt = self.child_prompt
anatofuz
parents:
diff changeset
57
anatofuz
parents:
diff changeset
58 # So that the child gets torn down after the test.
anatofuz
parents:
diff changeset
59 import pexpect
anatofuz
parents:
diff changeset
60 import sys
anatofuz
parents:
diff changeset
61 if sys.version_info.major == 3:
anatofuz
parents:
diff changeset
62 self.child = pexpect.spawnu('%s %s %s' % (lldbtest_config.lldbExec,
anatofuz
parents:
diff changeset
63 self.lldbOption, exe))
anatofuz
parents:
diff changeset
64 else:
anatofuz
parents:
diff changeset
65 self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec,
anatofuz
parents:
diff changeset
66 self.lldbOption, exe))
anatofuz
parents:
diff changeset
67 child = self.child
anatofuz
parents:
diff changeset
68
anatofuz
parents:
diff changeset
69 # Turn on logging for what the child sends back.
anatofuz
parents:
diff changeset
70 if self.TraceOn():
anatofuz
parents:
diff changeset
71 child.logfile_read = sys.stdout
anatofuz
parents:
diff changeset
72
anatofuz
parents:
diff changeset
73 # Disable showing of source lines at our breakpoint.
anatofuz
parents:
diff changeset
74 # This is necessary for the logging tests, because the very
anatofuz
parents:
diff changeset
75 # text we want to match for output from the running inferior
anatofuz
parents:
diff changeset
76 # will show up in the source as well. We don't want the source
anatofuz
parents:
diff changeset
77 # output to erroneously make a match with our expected output.
anatofuz
parents:
diff changeset
78 self.runCmd("settings set stop-line-count-before 0")
anatofuz
parents:
diff changeset
79 self.expect_prompt()
anatofuz
parents:
diff changeset
80 self.runCmd("settings set stop-line-count-after 0")
anatofuz
parents:
diff changeset
81 self.expect_prompt()
anatofuz
parents:
diff changeset
82
anatofuz
parents:
diff changeset
83 # Run any test-specific settings commands now.
anatofuz
parents:
diff changeset
84 if settings_commands is not None:
anatofuz
parents:
diff changeset
85 for setting_command in settings_commands:
anatofuz
parents:
diff changeset
86 self.runCmd(setting_command)
anatofuz
parents:
diff changeset
87 self.expect_prompt()
anatofuz
parents:
diff changeset
88
anatofuz
parents:
diff changeset
89 # Set the breakpoint, and run to it.
anatofuz
parents:
diff changeset
90 child.sendline('breakpoint set -f %s -l %d' % (source_file, line))
anatofuz
parents:
diff changeset
91 child.expect_exact(prompt)
anatofuz
parents:
diff changeset
92 child.sendline('run')
anatofuz
parents:
diff changeset
93 child.expect_exact(prompt)
anatofuz
parents:
diff changeset
94
anatofuz
parents:
diff changeset
95 # Ensure we stopped at a breakpoint.
anatofuz
parents:
diff changeset
96 self.runCmd("thread list")
anatofuz
parents:
diff changeset
97 self.expect(re.compile(r"stop reason = .*breakpoint"))
anatofuz
parents:
diff changeset
98
anatofuz
parents:
diff changeset
99 def runCmd(self, cmd):
anatofuz
parents:
diff changeset
100 if self.child:
anatofuz
parents:
diff changeset
101 self.child.sendline(cmd)
anatofuz
parents:
diff changeset
102
anatofuz
parents:
diff changeset
103 def expect_prompt(self, exactly=True):
anatofuz
parents:
diff changeset
104 self.expect(self.child_prompt, exactly=exactly)
anatofuz
parents:
diff changeset
105
anatofuz
parents:
diff changeset
106 def expect(self, pattern, exactly=False, *args, **kwargs):
anatofuz
parents:
diff changeset
107 if exactly:
anatofuz
parents:
diff changeset
108 return self.child.expect_exact(pattern, *args, **kwargs)
anatofuz
parents:
diff changeset
109 return self.child.expect(pattern, *args, **kwargs)
anatofuz
parents:
diff changeset
110
anatofuz
parents:
diff changeset
111 def do_test(self, expect_regexes=None, settings_commands=None):
anatofuz
parents:
diff changeset
112 """ Run a test. """
anatofuz
parents:
diff changeset
113 self.build(dictionary=self.d)
anatofuz
parents:
diff changeset
114 self.setTearDownCleanup(dictionary=self.d)
anatofuz
parents:
diff changeset
115
anatofuz
parents:
diff changeset
116 exe = self.getBuildArtifact(self.exe_name)
anatofuz
parents:
diff changeset
117 self.run_lldb_to_breakpoint(exe, self.source, self.line,
anatofuz
parents:
diff changeset
118 settings_commands=settings_commands)
anatofuz
parents:
diff changeset
119 self.expect_prompt()
anatofuz
parents:
diff changeset
120
anatofuz
parents:
diff changeset
121 # Now go.
anatofuz
parents:
diff changeset
122 self.runCmd("process continue")
anatofuz
parents:
diff changeset
123 self.expect(expect_regexes)
anatofuz
parents:
diff changeset
124
anatofuz
parents:
diff changeset
125 def test_nslog_output_is_displayed(self):
anatofuz
parents:
diff changeset
126 """Test that NSLog() output shows up in the command-line debugger."""
anatofuz
parents:
diff changeset
127 self.do_test(expect_regexes=[
anatofuz
parents:
diff changeset
128 re.compile(r"(This is a message from NSLog)"),
anatofuz
parents:
diff changeset
129 re.compile(r"Process \d+ exited with status")
anatofuz
parents:
diff changeset
130 ])
anatofuz
parents:
diff changeset
131 self.assertIsNotNone(self.child.match)
anatofuz
parents:
diff changeset
132 self.assertGreater(len(self.child.match.groups()), 0)
anatofuz
parents:
diff changeset
133 self.assertEqual(
anatofuz
parents:
diff changeset
134 "This is a message from NSLog",
anatofuz
parents:
diff changeset
135 self.child.match.group(1))
anatofuz
parents:
diff changeset
136
anatofuz
parents:
diff changeset
137 def test_nslog_output_is_suppressed_with_env_var(self):
anatofuz
parents:
diff changeset
138 """Test that NSLog() output does not show up with the ignore env var."""
anatofuz
parents:
diff changeset
139 # This test will only work properly on macOS 10.12+. Skip it on earlier versions.
anatofuz
parents:
diff changeset
140 # This will require some tweaking on iOS.
anatofuz
parents:
diff changeset
141 match = re.match(r"^\d+\.(\d+)", platform.mac_ver()[0])
anatofuz
parents:
diff changeset
142 if match is None or int(match.group(1)) < 12:
anatofuz
parents:
diff changeset
143 self.skipTest("requires macOS 10.12 or higher")
anatofuz
parents:
diff changeset
144
anatofuz
parents:
diff changeset
145 self.do_test(
anatofuz
parents:
diff changeset
146 expect_regexes=[
anatofuz
parents:
diff changeset
147 re.compile(r"(This is a message from NSLog)"),
anatofuz
parents:
diff changeset
148 re.compile(r"Process \d+ exited with status")
anatofuz
parents:
diff changeset
149 ],
anatofuz
parents:
diff changeset
150 settings_commands=[
anatofuz
parents:
diff changeset
151 "settings set target.env-vars "
anatofuz
parents:
diff changeset
152 "\"IDE_DISABLED_OS_ACTIVITY_DT_MODE=1\""
anatofuz
parents:
diff changeset
153 ])
anatofuz
parents:
diff changeset
154 self.assertIsNotNone(self.child.match)
anatofuz
parents:
diff changeset
155 self.assertEqual(len(self.child.match.groups()), 0)