Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

af_vsock: SOCK_SEQPACKET receive timeout test

Test for receive timeout check: connection is established,
receiver sets timeout, but sender does nothing. Receiver's
'read()' call must return EAGAIN.

Signed-off-by: Krasnov Arseniy Vladimirovich <AVKrasnov@sberdevices.ru>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Krasnov Arseniy Vladimirovich and committed by
David S. Miller
efb3719f dca51fe7

+84
+84
tools/testing/vsock/vsock_test.c
··· 16 16 #include <linux/kernel.h> 17 17 #include <sys/types.h> 18 18 #include <sys/socket.h> 19 + #include <time.h> 19 20 20 21 #include "timeout.h" 21 22 #include "control.h" ··· 392 391 close(fd); 393 392 } 394 393 394 + static time_t current_nsec(void) 395 + { 396 + struct timespec ts; 397 + 398 + if (clock_gettime(CLOCK_REALTIME, &ts)) { 399 + perror("clock_gettime(3) failed"); 400 + exit(EXIT_FAILURE); 401 + } 402 + 403 + return (ts.tv_sec * 1000000000ULL) + ts.tv_nsec; 404 + } 405 + 406 + #define RCVTIMEO_TIMEOUT_SEC 1 407 + #define READ_OVERHEAD_NSEC 250000000 /* 0.25 sec */ 408 + 409 + static void test_seqpacket_timeout_client(const struct test_opts *opts) 410 + { 411 + int fd; 412 + struct timeval tv; 413 + char dummy; 414 + time_t read_enter_ns; 415 + time_t read_overhead_ns; 416 + 417 + fd = vsock_seqpacket_connect(opts->peer_cid, 1234); 418 + if (fd < 0) { 419 + perror("connect"); 420 + exit(EXIT_FAILURE); 421 + } 422 + 423 + tv.tv_sec = RCVTIMEO_TIMEOUT_SEC; 424 + tv.tv_usec = 0; 425 + 426 + if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv, sizeof(tv)) == -1) { 427 + perror("setsockopt 'SO_RCVTIMEO'"); 428 + exit(EXIT_FAILURE); 429 + } 430 + 431 + read_enter_ns = current_nsec(); 432 + 433 + if (read(fd, &dummy, sizeof(dummy)) != -1) { 434 + fprintf(stderr, 435 + "expected 'dummy' read(2) failure\n"); 436 + exit(EXIT_FAILURE); 437 + } 438 + 439 + if (errno != EAGAIN) { 440 + perror("EAGAIN expected"); 441 + exit(EXIT_FAILURE); 442 + } 443 + 444 + read_overhead_ns = current_nsec() - read_enter_ns - 445 + 1000000000ULL * RCVTIMEO_TIMEOUT_SEC; 446 + 447 + if (read_overhead_ns > READ_OVERHEAD_NSEC) { 448 + fprintf(stderr, 449 + "too much time in read(2), %lu > %i ns\n", 450 + read_overhead_ns, READ_OVERHEAD_NSEC); 451 + exit(EXIT_FAILURE); 452 + } 453 + 454 + control_writeln("WAITDONE"); 455 + close(fd); 456 + } 457 + 458 + static void test_seqpacket_timeout_server(const struct test_opts *opts) 459 + { 460 + int fd; 461 + 462 + fd = vsock_seqpacket_accept(VMADDR_CID_ANY, 1234, NULL); 463 + if (fd < 0) { 464 + perror("accept"); 465 + exit(EXIT_FAILURE); 466 + } 467 + 468 + control_expectln("WAITDONE"); 469 + close(fd); 470 + } 471 + 395 472 static struct test_case test_cases[] = { 396 473 { 397 474 .name = "SOCK_STREAM connection reset", ··· 509 430 .name = "SOCK_SEQPACKET MSG_TRUNC flag", 510 431 .run_client = test_seqpacket_msg_trunc_client, 511 432 .run_server = test_seqpacket_msg_trunc_server, 433 + }, 434 + { 435 + .name = "SOCK_SEQPACKET timeout", 436 + .run_client = test_seqpacket_timeout_client, 437 + .run_server = test_seqpacket_timeout_server, 512 438 }, 513 439 {}, 514 440 };