Skip to content

Commit 3d32e1c

Browse files
committed
chore(tests): fix python tests style
- fix test line spacing, import ordering, indentation, formatting function calls Signed-off-by: aerosouund <aerosound161@gmail.com>
1 parent 9287177 commit 3d32e1c

4 files changed

Lines changed: 61 additions & 22 deletions

File tree

tests/conftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,11 @@ def bin_vsock_path(test_fc_session_root_path):
240240
def bin_vsock_seqpacket_listener_path(test_fc_session_root_path):
241241
"""Build a simple vsock seqpacket server application."""
242242
vsock_seq_srv_bin_path = os.path.join(test_fc_session_root_path, "vsock_seq_server")
243-
build_tools.gcc_compile("host_tools/vsock_seq_server.c", vsock_seq_srv_bin_path, extra_flags="-lpthread -O3")
243+
build_tools.gcc_compile(
244+
"host_tools/vsock_seq_server.c",
245+
vsock_seq_srv_bin_path,
246+
extra_flags="-lpthread -O3",
247+
)
244248
yield vsock_seq_srv_bin_path
245249

246250

tests/framework/utils_vsock.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def start_guest_echo_server(vm):
111111

112112
return os.path.join(vm.jailer.chroot_path(), VSOCK_UDS_PATH)
113113

114+
114115
def start_seqpacket_echo_server(vm):
115116
"""Start a vsock seqpacket echo server in the microVM.
116117
@@ -147,16 +148,20 @@ def check_host_connections(uds_path, blob_path, blob_hash, vsock_type=SOCK_STREA
147148
assert wrk.hash == blob_hash
148149

149150

150-
def check_guest_connections_seqpacket(vm, server_port_path, server_bin_path ,blob_path, blob_hash):
151+
def check_guest_connections_seqpacket(
152+
vm, server_port_path, server_bin_path, blob_path, blob_hash
153+
):
151154
"""Test guest-initiated connections.
152155
153156
This will start an echo server on the host (in its own thread), then
154157
start `TEST_CONNECTION_COUNT` workers inside the guest VM, all
155158
communicating with the echo server.
156159
"""
157-
port = server_port_path.split("_")[-1]
160+
port = server_port_path.split("_")[-1]
158161
if Path(server_port_path).exists():
159-
Path(server_port_path).unlink() # the vsock server program doesn't have reuseaddr
162+
Path(
163+
server_port_path
164+
).unlink() # the vsock server program doesn't have reuseaddr
160165

161166
echo_server = Popen([server_bin_path, "serve", port, "af_unix", server_port_path])
162167

@@ -189,7 +194,9 @@ def check_guest_connections_seqpacket(vm, server_port_path, server_bin_path ,blo
189194
# comparison sets the exit status of the worker command.
190195
worker_cmd = "hash=$("
191196
worker_cmd += "cat {}".format(blob_path)
192-
worker_cmd += " | /tmp/vsock_helper echo 2 {} seqpacket".format(ECHO_SERVER_PORT)
197+
worker_cmd += " | /tmp/vsock_helper echo 2 {} seqpacket".format(
198+
ECHO_SERVER_PORT
199+
)
193200
worker_cmd += " | md5sum | cut -f1 -d\\ "
194201
worker_cmd += ")"
195202
worker_cmd += ' && [[ "$hash" = "{}" ]]'.format(blob_hash)
@@ -209,7 +216,7 @@ def check_guest_connections_seqpacket(vm, server_port_path, server_bin_path ,blo
209216
finally:
210217
echo_server.terminate()
211218
echo_server.wait()
212-
219+
213220

214221
def check_guest_connections(vm, server_port_path, blob_path, blob_hash):
215222
"""Test guest-initiated connections.
@@ -295,7 +302,9 @@ def _vsock_connect_to_guest(uds_path, port, vsock_type):
295302
return sock
296303

297304

298-
def _copy_vsock_data_to_guest(ssh_connection, blob_path, vm_blob_path, vsock_helper=None, vsock_seq_server=None):
305+
def _copy_vsock_data_to_guest(
306+
ssh_connection, blob_path, vm_blob_path, vsock_helper=None, vsock_seq_server=None
307+
):
299308
# Copy the data file and a vsock helper to the guest.
300309

301310
cmd = "mkdir -p /tmp/vsock"

tests/integration_tests/functional/test_snapshot_basic.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,9 @@ def test_snapshot_rename_vsock(
598598
"""
599599

600600
vm = uvm_nano
601-
vm.api.vsock.put(vsock_id="vsock0", guest_cid=3, uds_path="/v.sock1", vsock_type="stream")
601+
vm.api.vsock.put(
602+
vsock_id="vsock0", guest_cid=3, uds_path="/v.sock1", vsock_type="stream"
603+
)
602604
vm.add_net_iface()
603605
vm.start()
604606

tests/integration_tests/functional/test_vsock.py

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
import subprocess
1919
import time
2020
from pathlib import Path
21+
from socket import SOCK_SEQPACKET
2122
from socket import timeout as SocketTimeout
2223
from ssl import SOCK_STREAM
23-
from socket import SOCK_SEQPACKET
2424
from threading import Thread
2525

2626
import pytest
@@ -32,13 +32,13 @@
3232
_copy_vsock_data_to_guest,
3333
_vsock_connect_to_guest,
3434
check_guest_connections,
35-
check_host_connections,
3635
check_guest_connections_seqpacket,
36+
check_host_connections,
3737
check_vsock_device,
3838
make_blob,
3939
make_host_port_path,
4040
start_guest_echo_server,
41-
start_seqpacket_echo_server
41+
start_seqpacket_echo_server,
4242
)
4343
from host_tools.fcmetrics import validate_fc_metrics
4444

@@ -115,6 +115,7 @@ def negative_test_host_connections(vm, blob_path, blob_hash, vsock_type):
115115
metrics = vm.flush_metrics()
116116
validate_fc_metrics(metrics)
117117

118+
118119
def test_vsock_epipe(uvm_plain_any, bin_vsock_path, test_fc_session_root_path):
119120
"""
120121
Vsock negative test to validate SIGPIPE/EPIPE handling.
@@ -313,7 +314,9 @@ def test_vsock_transport_reset_g2h(uvm_plain_any, microvm_factory):
313314
new_vm.kill()
314315

315316

316-
def test_vsock_seqpacket_h2g(uvm_plain_6_1, bin_vsock_seqpacket_listener_path, test_fc_session_root_path):
317+
def test_vsock_seqpacket_h2g(
318+
uvm_plain_6_1, bin_vsock_seqpacket_listener_path, test_fc_session_root_path
319+
):
317320
vm = uvm_plain_6_1
318321
vm.spawn()
319322
vm.basic_config()
@@ -323,22 +326,32 @@ def test_vsock_seqpacket_h2g(uvm_plain_6_1, bin_vsock_seqpacket_listener_path, t
323326
guest_cid=3,
324327
uds_path=f"/{VSOCK_UDS_PATH}",
325328
vsock_type="seqpacket",
326-
conn_buffer_size=16*1024,
329+
conn_buffer_size=16 * 1024,
327330
)
328331
vm.start()
329332

330-
blob_path, blob_hash = make_blob(test_fc_session_root_path, 16*1024)
333+
blob_path, blob_hash = make_blob(test_fc_session_root_path, 16 * 1024)
331334
vm_blob_path = "/tmp/vsock/test.blob"
332335

333-
_copy_vsock_data_to_guest(vm.ssh, blob_path, vm_blob_path, vsock_seq_server=bin_vsock_seqpacket_listener_path)
336+
_copy_vsock_data_to_guest(
337+
vm.ssh,
338+
blob_path,
339+
vm_blob_path,
340+
vsock_seq_server=bin_vsock_seqpacket_listener_path,
341+
)
334342
path = start_seqpacket_echo_server(vm)
335343

336344
check_host_connections(path, blob_path, blob_hash, SOCK_SEQPACKET)
337345
metrics = vm.flush_metrics()
338346
validate_fc_metrics(metrics)
339347

340348

341-
def test_vsock_seqpacket_g2h(uvm_plain_6_1, bin_vsock_seqpacket_listener_path, bin_vsock_path, test_fc_session_root_path):
349+
def test_vsock_seqpacket_g2h(
350+
uvm_plain_6_1,
351+
bin_vsock_seqpacket_listener_path,
352+
bin_vsock_path,
353+
test_fc_session_root_path,
354+
):
342355
vm = uvm_plain_6_1
343356
vm.spawn()
344357
vm.basic_config()
@@ -348,23 +361,27 @@ def test_vsock_seqpacket_g2h(uvm_plain_6_1, bin_vsock_seqpacket_listener_path, b
348361
guest_cid=3,
349362
uds_path=f"/{VSOCK_UDS_PATH}",
350363
vsock_type="seqpacket",
351-
conn_buffer_size=16*1024,
364+
conn_buffer_size=16 * 1024,
352365
)
353366
vm.start()
354367

355-
blob_path, blob_hash = make_blob(test_fc_session_root_path, 16*1024)
368+
blob_path, blob_hash = make_blob(test_fc_session_root_path, 16 * 1024)
356369
vm_blob_path = "/tmp/vsock/test.blob"
357370

358371
_copy_vsock_data_to_guest(vm.ssh, blob_path, vm_blob_path, bin_vsock_path)
359372

360373
path = os.path.join(vm.path, make_host_port_path(VSOCK_UDS_PATH, ECHO_SERVER_PORT))
361-
check_guest_connections_seqpacket(vm, path, bin_vsock_seqpacket_listener_path, vm_blob_path, blob_hash)
374+
check_guest_connections_seqpacket(
375+
vm, path, bin_vsock_seqpacket_listener_path, vm_blob_path, blob_hash
376+
)
362377

363378
metrics = vm.flush_metrics()
364379
validate_fc_metrics(metrics)
365380

366381

367-
def test_vsock_seqpacket_h2g_overflow(uvm_plain_6_1, bin_vsock_seqpacket_listener_path, test_fc_session_root_path):
382+
def test_vsock_seqpacket_h2g_overflow(
383+
uvm_plain_6_1, bin_vsock_seqpacket_listener_path, test_fc_session_root_path
384+
):
368385
"""Test that sending a message larger than conn_buffer_size errors."""
369386
conn_buffer_size = 16 * 1024
370387

@@ -383,7 +400,12 @@ def test_vsock_seqpacket_h2g_overflow(uvm_plain_6_1, bin_vsock_seqpacket_listene
383400

384401
blob_path, _ = make_blob(test_fc_session_root_path, 1024)
385402
vm_blob_path = "/tmp/vsock/test.blob"
386-
_copy_vsock_data_to_guest(vm.ssh, blob_path, vm_blob_path, vsock_seq_server=bin_vsock_seqpacket_listener_path)
403+
_copy_vsock_data_to_guest(
404+
vm.ssh,
405+
blob_path,
406+
vm_blob_path,
407+
vsock_seq_server=bin_vsock_seqpacket_listener_path,
408+
)
387409
path = start_seqpacket_echo_server(vm)
388410

389411
worker_error = None
@@ -402,7 +424,9 @@ def worker():
402424
t.start()
403425
t.join()
404426

405-
assert worker_error is not None, "Expected an error when sending message larger than conn_buffer_size"
427+
assert (
428+
worker_error is not None
429+
), "Expected an error when sending message larger than conn_buffer_size"
406430

407431

408432
def test_vsock_after_override(

0 commit comments

Comments
 (0)