Skip to content

Commit c15c296

Browse files
committed
[lldb/test] Reduce boilerplate in lldb-server tests
Nearly all of our lldb-server tests have two flavours (lldb-server and debugserver). Each of them is tagged with an appropriate decorator, and each of them starts with a call to a matching "init" method. The init calls are mandatory, and it's not possible to meaningfully combine them with a different decorator. This patch leverages the existing decorators to also tag the tests with the appropriate debug server tag, similar to how we do with debug info flavours. This allows us to make the "init" calls from inside the common setUp method.
1 parent 52e4084 commit c15c296

30 files changed

+14
-180
lines changed

lldb/packages/Python/lldbsuite/test/decorators.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,13 @@ def should_skip_simulator_test():
373373

374374
def debugserver_test(func):
375375
"""Decorate the item as a debugserver test."""
376+
func.debug_server = "debugserver"
376377
return add_test_categories(["debugserver"])(func)
377378

378379

379380
def llgs_test(func):
380381
"""Decorate the item as a lldb-server test."""
382+
func.debug_server = "llgs"
381383
return add_test_categories(["llgs"])(func)
382384

383385

lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ def isVerboseLoggingRequested(self):
8080
return any(("gdb-remote" in channel)
8181
for channel in lldbtest_config.channels)
8282

83+
def getDebugServer(self):
84+
method = getattr(self, self.testMethodName)
85+
return getattr(method, "debug_server", None)
86+
8387
def setUp(self):
8488
super(GdbRemoteTestCaseBase, self).setUp()
8589

@@ -114,6 +118,12 @@ def setUp(self):
114118
else:
115119
self.stub_hostname = "localhost"
116120

121+
debug_server = self.getDebugServer()
122+
if debug_server == "debugserver":
123+
self._init_debugserver_test()
124+
else:
125+
self._init_llgs_test()
126+
117127
def tearDown(self):
118128
self.logger.removeHandler(self._verbose_log_handler)
119129
self._verbose_log_handler = None
@@ -150,7 +160,7 @@ def reset_test_sequence(self):
150160
self.test_sequence = GdbRemoteTestSequence(self.logger)
151161

152162

153-
def init_llgs_test(self):
163+
def _init_llgs_test(self):
154164
reverse_connect = True
155165
if lldb.remote_platform:
156166
# Reverse connections may be tricky due to firewalls/NATs.
@@ -198,7 +208,7 @@ def init_llgs_test(self):
198208

199209
self.reverse_connect = reverse_connect
200210

201-
def init_debugserver_test(self):
211+
def _init_debugserver_test(self):
202212
self.debug_monitor_exe = get_debugserver_exe()
203213
if not self.debug_monitor_exe:
204214
self.skipTest("debugserver exe not found")

lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class TestAutoInstallMainExecutable(gdbremote_testcase.GdbRemoteTestCaseBase):
1919
@expectedFailureAll(hostoslist=["windows"], triple='.*-android')
2020
def test_target_auto_install_main_executable(self):
2121
self.build()
22-
self.init_llgs_test()
2322

2423
# Manually install the modified binary.
2524
working_dir = lldb.remote_platform.GetWorkingDirectory()

lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def check_simulator_ostype(self, sdk, platform, arch='x86_64'):
7575
self.assertIsNotNone(pid)
7676

7777
# Launch debug monitor attaching to the simulated process
78-
self.init_debugserver_test()
7978
server = self.connect_to_debug_monitor(attach_pid=pid)
8079

8180
# Setup packet sequences

lldb/test/API/tools/lldb-server/TestGdbRemoteAttach.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,12 @@ def attach_with_vAttach(self):
5353

5454
@debugserver_test
5555
def test_attach_with_vAttach_debugserver(self):
56-
self.init_debugserver_test()
5756
self.build()
5857
self.set_inferior_startup_attach_manually()
5958
self.attach_with_vAttach()
6059

6160
@llgs_test
6261
def test_attach_with_vAttach_llgs(self):
63-
self.init_llgs_test()
6462
self.build()
6563
self.set_inferior_startup_attach_manually()
6664
self.attach_with_vAttach()

lldb/test/API/tools/lldb-server/TestGdbRemoteAuxvSupport.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def supports_auxv(self):
104104
@skipIfWindows # no auxv support.
105105
@llgs_test
106106
def test_supports_auxv_llgs(self):
107-
self.init_llgs_test()
108107
self.build()
109108
self.set_inferior_startup_launch()
110109
self.supports_auxv()
@@ -120,7 +119,6 @@ def auxv_data_is_correct_size(self):
120119

121120
@debugserver_test
122121
def test_auxv_data_is_correct_size_debugserver(self):
123-
self.init_debugserver_test()
124122
self.build()
125123
self.set_inferior_startup_launch()
126124
self.auxv_data_is_correct_size()
@@ -129,7 +127,6 @@ def test_auxv_data_is_correct_size_debugserver(self):
129127
@expectedFailureNetBSD
130128
@llgs_test
131129
def test_auxv_data_is_correct_size_llgs(self):
132-
self.init_llgs_test()
133130
self.build()
134131
self.set_inferior_startup_launch()
135132
self.auxv_data_is_correct_size()
@@ -160,7 +157,6 @@ def auxv_keys_look_valid(self):
160157

161158
@debugserver_test
162159
def test_auxv_keys_look_valid_debugserver(self):
163-
self.init_debugserver_test()
164160
self.build()
165161
self.set_inferior_startup_launch()
166162
self.auxv_keys_look_valid()
@@ -169,7 +165,6 @@ def test_auxv_keys_look_valid_debugserver(self):
169165
@expectedFailureNetBSD
170166
@llgs_test
171167
def test_auxv_keys_look_valid_llgs(self):
172-
self.init_llgs_test()
173168
self.build()
174169
self.set_inferior_startup_launch()
175170
self.auxv_keys_look_valid()
@@ -209,7 +204,6 @@ def auxv_chunked_reads_work(self):
209204

210205
@debugserver_test
211206
def test_auxv_chunked_reads_work_debugserver(self):
212-
self.init_debugserver_test()
213207
self.build()
214208
self.set_inferior_startup_launch()
215209
self.auxv_chunked_reads_work()
@@ -218,7 +212,6 @@ def test_auxv_chunked_reads_work_debugserver(self):
218212
@expectedFailureNetBSD
219213
@llgs_test
220214
def test_auxv_chunked_reads_work_llgs(self):
221-
self.init_llgs_test()
222215
self.build()
223216
self.set_inferior_startup_launch()
224217
self.auxv_chunked_reads_work()

lldb/test/API/tools/lldb-server/TestGdbRemoteExitCode.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ def inferior_exit_0(self):
2424
@debugserver_test
2525
@skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
2626
def test_inferior_exit_0_debugserver(self):
27-
self.init_debugserver_test()
2827
self.build()
2928
self.inferior_exit_0()
3029

3130
@llgs_test
3231
def test_inferior_exit_0_llgs(self):
33-
self.init_llgs_test()
3432
self.build()
3533
self.inferior_exit_0()
3634

@@ -50,12 +48,10 @@ def inferior_exit_42(self):
5048
@debugserver_test
5149
@skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
5250
def test_inferior_exit_42_debugserver(self):
53-
self.init_debugserver_test()
5451
self.build()
5552
self.inferior_exit_42()
5653

5754
@llgs_test
5855
def test_inferior_exit_42_llgs(self):
59-
self.init_llgs_test()
6056
self.build()
6157
self.inferior_exit_42()

lldb/test/API/tools/lldb-server/TestGdbRemoteExpeditedRegisters.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,12 @@ def stop_notification_contains_any_registers(self):
8686

8787
@debugserver_test
8888
def test_stop_notification_contains_any_registers_debugserver(self):
89-
self.init_debugserver_test()
9089
self.build()
9190
self.set_inferior_startup_launch()
9291
self.stop_notification_contains_any_registers()
9392

9493
@llgs_test
9594
def test_stop_notification_contains_any_registers_llgs(self):
96-
self.init_llgs_test()
9795
self.build()
9896
self.set_inferior_startup_launch()
9997
self.stop_notification_contains_any_registers()
@@ -112,14 +110,12 @@ def stop_notification_contains_no_duplicate_registers(self):
112110
@debugserver_test
113111
def test_stop_notification_contains_no_duplicate_registers_debugserver(
114112
self):
115-
self.init_debugserver_test()
116113
self.build()
117114
self.set_inferior_startup_launch()
118115
self.stop_notification_contains_no_duplicate_registers()
119116

120117
@llgs_test
121118
def test_stop_notification_contains_no_duplicate_registers_llgs(self):
122-
self.init_llgs_test()
123119
self.build()
124120
self.set_inferior_startup_launch()
125121
self.stop_notification_contains_no_duplicate_registers()
@@ -129,14 +125,12 @@ def stop_notification_contains_pc_register(self):
129125

130126
@debugserver_test
131127
def test_stop_notification_contains_pc_register_debugserver(self):
132-
self.init_debugserver_test()
133128
self.build()
134129
self.set_inferior_startup_launch()
135130
self.stop_notification_contains_pc_register()
136131

137132
@llgs_test
138133
def test_stop_notification_contains_pc_register_llgs(self):
139-
self.init_llgs_test()
140134
self.build()
141135
self.set_inferior_startup_launch()
142136
self.stop_notification_contains_pc_register()
@@ -148,14 +142,12 @@ def stop_notification_contains_fp_register(self):
148142

149143
@debugserver_test
150144
def test_stop_notification_contains_fp_register_debugserver(self):
151-
self.init_debugserver_test()
152145
self.build()
153146
self.set_inferior_startup_launch()
154147
self.stop_notification_contains_fp_register()
155148

156149
@llgs_test
157150
def test_stop_notification_contains_fp_register_llgs(self):
158-
self.init_llgs_test()
159151
self.build()
160152
self.set_inferior_startup_launch()
161153
self.stop_notification_contains_fp_register()
@@ -165,14 +157,12 @@ def stop_notification_contains_sp_register(self):
165157

166158
@debugserver_test
167159
def test_stop_notification_contains_sp_register_debugserver(self):
168-
self.init_debugserver_test()
169160
self.build()
170161
self.set_inferior_startup_launch()
171162
self.stop_notification_contains_sp_register()
172163

173164
@llgs_test
174165
def test_stop_notification_contains_sp_register_llgs(self):
175-
self.init_llgs_test()
176166
self.build()
177167
self.set_inferior_startup_launch()
178168
self.stop_notification_contains_sp_register()
@@ -183,7 +173,6 @@ def test_stop_notification_contains_sp_register_llgs(self):
183173
def test_stop_notification_contains_vg_register_llgs(self):
184174
if not self.isAArch64SVE():
185175
self.skipTest('SVE registers must be supported.')
186-
self.init_llgs_test()
187176
self.build()
188177
self.set_inferior_startup_launch()
189178
self.stop_notification_contains_aarch64_vg_register()

lldb/test/API/tools/lldb-server/TestGdbRemoteHostInfo.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,19 @@ def validate_darwin_minimum_host_info_keys(self, host_info_dict):
102102
@skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
103103
@debugserver_test
104104
def test_qHostInfo_returns_at_least_one_key_val_pair_debugserver(self):
105-
self.init_debugserver_test()
106105
self.build()
107106
self.get_qHostInfo_response()
108107

109108
@skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
110109
@llgs_test
111110
def test_qHostInfo_returns_at_least_one_key_val_pair_llgs(self):
112-
self.init_llgs_test()
113111
self.build()
114112
self.get_qHostInfo_response()
115113

116114
@skipUnlessDarwin
117115
@skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
118116
@debugserver_test
119117
def test_qHostInfo_contains_darwin_required_keys_debugserver(self):
120-
self.init_debugserver_test()
121118
self.build()
122119
host_info_dict = self.get_qHostInfo_response()
123120
self.validate_darwin_minimum_host_info_keys(host_info_dict)
@@ -126,7 +123,6 @@ def test_qHostInfo_contains_darwin_required_keys_debugserver(self):
126123
@skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
127124
@llgs_test
128125
def test_qHostInfo_contains_darwin_required_keys_llgs(self):
129-
self.init_llgs_test()
130126
self.build()
131127
host_info_dict = self.get_qHostInfo_response()
132128
self.validate_darwin_minimum_host_info_keys(host_info_dict)

lldb/test/API/tools/lldb-server/TestGdbRemoteKill.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,12 @@ def attach_commandline_kill_after_initial_stop(self):
4646

4747
@debugserver_test
4848
def test_attach_commandline_kill_after_initial_stop_debugserver(self):
49-
self.init_debugserver_test()
5049
self.build()
5150
self.set_inferior_startup_attach()
5251
self.attach_commandline_kill_after_initial_stop()
5352

5453
@llgs_test
5554
def test_attach_commandline_kill_after_initial_stop_llgs(self):
56-
self.init_llgs_test()
5755
self.build()
5856
self.set_inferior_startup_attach()
5957
self.attach_commandline_kill_after_initial_stop()

lldb/test/API/tools/lldb-server/TestGdbRemoteModuleInfo.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def module_info(self):
3737

3838
@llgs_test
3939
def test_module_info(self):
40-
self.init_llgs_test()
4140
self.build()
4241
self.set_inferior_startup_launch()
4342
self.module_info()

lldb/test/API/tools/lldb-server/TestGdbRemoteProcessInfo.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@ def qProcessInfo_returns_running_process(self):
3636
@debugserver_test
3737
@skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
3838
def test_qProcessInfo_returns_running_process_debugserver(self):
39-
self.init_debugserver_test()
4039
self.build()
4140
self.qProcessInfo_returns_running_process()
4241

4342
@llgs_test
4443
def test_qProcessInfo_returns_running_process_llgs(self):
45-
self.init_llgs_test()
4644
self.build()
4745
self.qProcessInfo_returns_running_process()
4846

@@ -69,14 +67,12 @@ def attach_commandline_qProcessInfo_reports_correct_pid(self):
6967
@skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
7068
def test_attach_commandline_qProcessInfo_reports_correct_pid_debugserver(
7169
self):
72-
self.init_debugserver_test()
7370
self.build()
7471
self.set_inferior_startup_attach()
7572
self.attach_commandline_qProcessInfo_reports_correct_pid()
7673

7774
@llgs_test
7875
def test_attach_commandline_qProcessInfo_reports_correct_pid_llgs(self):
79-
self.init_llgs_test()
8076
self.build()
8177
self.set_inferior_startup_attach()
8278
self.attach_commandline_qProcessInfo_reports_correct_pid()
@@ -101,13 +97,11 @@ def qProcessInfo_reports_valid_endian(self):
10197
@debugserver_test
10298
@skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
10399
def test_qProcessInfo_reports_valid_endian_debugserver(self):
104-
self.init_debugserver_test()
105100
self.build()
106101
self.qProcessInfo_reports_valid_endian()
107102

108103
@llgs_test
109104
def test_qProcessInfo_reports_valid_endian_llgs(self):
110-
self.init_llgs_test()
111105
self.build()
112106
self.qProcessInfo_reports_valid_endian()
113107

@@ -162,28 +156,24 @@ def qProcessInfo_does_not_contain_keys(self, absent_key_set):
162156
@debugserver_test
163157
@skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
164158
def test_qProcessInfo_contains_cputype_cpusubtype_debugserver_darwin(self):
165-
self.init_debugserver_test()
166159
self.build()
167160
self.qProcessInfo_contains_keys(set(['cputype', 'cpusubtype']))
168161

169162
@skipUnlessDarwin
170163
@llgs_test
171164
def test_qProcessInfo_contains_cputype_cpusubtype_llgs_darwin(self):
172-
self.init_llgs_test()
173165
self.build()
174166
self.qProcessInfo_contains_keys(set(['cputype', 'cpusubtype']))
175167

176168
@llgs_test
177169
def test_qProcessInfo_contains_triple_ppid_llgs(self):
178-
self.init_llgs_test()
179170
self.build()
180171
self.qProcessInfo_contains_keys(set(['triple', 'parent-pid']))
181172

182173
@skipUnlessDarwin
183174
@debugserver_test
184175
@skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
185176
def test_qProcessInfo_does_not_contain_triple_debugserver_darwin(self):
186-
self.init_debugserver_test()
187177
self.build()
188178
# We don't expect to see triple on darwin. If we do, we'll prefer triple
189179
# to cputype/cpusubtype and skip some darwin-based ProcessGDBRemote ArchSpec setup
@@ -193,7 +183,6 @@ def test_qProcessInfo_does_not_contain_triple_debugserver_darwin(self):
193183
@skipUnlessDarwin
194184
@llgs_test
195185
def test_qProcessInfo_does_not_contain_triple_llgs_darwin(self):
196-
self.init_llgs_test()
197186
self.build()
198187
# We don't expect to see triple on darwin. If we do, we'll prefer triple
199188
# to cputype/cpusubtype and skip some darwin-based ProcessGDBRemote ArchSpec setup
@@ -203,6 +192,5 @@ def test_qProcessInfo_does_not_contain_triple_llgs_darwin(self):
203192
@skipIfDarwin
204193
@llgs_test
205194
def test_qProcessInfo_does_not_contain_cputype_cpusubtype_llgs(self):
206-
self.init_llgs_test()
207195
self.build()
208196
self.qProcessInfo_does_not_contain_keys(set(['cputype', 'cpusubtype']))

0 commit comments

Comments
 (0)