1818import subprocess
1919import time
2020from pathlib import Path
21+ from socket import SOCK_SEQPACKET
2122from socket import timeout as SocketTimeout
2223from ssl import SOCK_STREAM
23- from socket import SOCK_SEQPACKET
2424from threading import Thread
2525
2626import pytest
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)
4343from 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+
118119def 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
408432def test_vsock_after_override (
0 commit comments