Linux Test Project
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Wei Gao <wegao@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v7 1/2] connect01: Convert to new API
Date: Wed, 1 Jul 2026 10:34:22 +0200	[thread overview]
Message-ID: <20260701083422.GA477554@pevik> (raw)
In-Reply-To: <20260616093119.8654-2-wegao@suse.com>

Hi Wei,

to speedup I dared to merge with following diff.

My changes are:
* use designated initializers
* improve doc
* specify salen only     when not detectable
* void => struct sockaddr_in

Thanks!

Kind regards,
Petr

+++ testcases/kernel/syscalls/connect/connect01.c
@@ -1,11 +1,19 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) International Business Machines  Corp., 2001
+ * Copyright (c) International Business Machines Corp., 2001
  * Copyright (c) Linux Test Project, 2006-2026
  */
 
 /*\
- * Verify that :manpage:`connect(2)` returns the proper errno for various failure cases.
+ * Verify that :manpage:`connect(2)` fails with -1 and sets proper errno:
+ *
+ * - EBADF if sockfd is not a valid open file descriptor
+ * - EFAULT if socket structure address is outside the user's address space
+ * - EINVAL if addrlen is not valid
+ * - ENOTSOCK if file descriptor sockfd does not refer to a socket
+ * - EISCONN if socket is already connected
+ * - ECONNREFUSED if connect on a socket found nothing listening on remote address
+ * - EAFNOSUPPORT if address doesn't have the correct address family in sa_family
  */
 
 #include <sys/types.h>
@@ -30,25 +38,25 @@ static pid_t pid;
 
 static struct test_case_t {
 	int *fd;
-	void *addr;
+	struct sockaddr_in *addr;
 	socklen_t salen;
 	int exp_errno;
 	char *desc;
 } tcases[] = {
-	{&fd_invalid, &sock1, sizeof(sock1), EBADF,
-		"sockfd is not a valid open file descriptor"},
-	{&fd_socket, NULL, sizeof(sock1), EFAULT,
-		"socket structure address is outside the user's address space"},
-	{&fd_socket, &sock1, 3, EINVAL,
-		"addrlen is not valid"},
-	{&fd_null, &sock1, sizeof(sock1), ENOTSOCK,
-		"file descriptor sockfd does not refer to a socket"},
-	{&fd_connected, &sock1, sizeof(sock1), EISCONN,
-		"socket is already connected"},
-	{&fd_socket, &sock2, sizeof(sock2), ECONNREFUSED,
-		"connect on a socket found no one listening on remote address"},
-	{&fd_socket, &sock3, sizeof(sock3), EAFNOSUPPORT,
-		"address doesn't have the correct address family in sa_family"},
+	{ .fd = &fd_invalid, .addr = &sock1, .exp_errno = EBADF,
+		.desc = "sockfd is not a valid open file descriptor"},
+	{ .fd = &fd_socket, .salen = sizeof(sock1), .exp_errno = EFAULT,
+		.desc = "socket structure address is outside the user's address space"},
+	{ .fd = &fd_socket, .addr = &sock1, .salen = 3, .exp_errno = EINVAL,
+		.desc = "addrlen is not valid"},
+	{ .fd = &fd_null, .addr = &sock1, .exp_errno = ENOTSOCK,
+		.desc = "file descriptor sockfd does not refer to a socket"},
+	{ .fd = &fd_connected, .addr = &sock1, .exp_errno = EISCONN,
+		.desc = "socket is already connected"},
+	{ .fd = &fd_socket, .addr = &sock2, .exp_errno = ECONNREFUSED,
+		.desc = "connect on a socket found nothing listening on remote address"},
+	{ .fd = &fd_socket, .addr = &sock3, .exp_errno = EAFNOSUPPORT,
+		.desc = "address doesn't have the correct address family in sa_family"},
 };
 
 static int sys_connect(int sockfd, const struct sockaddr *addr,
@@ -126,8 +134,9 @@ static void verify_connect(unsigned int i)
 {
 	struct test_case_t *tc = &tcases[i];
 	void *addr = tc->addr ? tc->addr : bad_addr;
+	socklen_t salen = tc->salen ?: sizeof(*tc->addr);
 
-	TST_EXP_FAIL(sys_connect(*tc->fd, addr, tc->salen),
+	TST_EXP_FAIL(sys_connect(*tc->fd, addr, salen),
 		     tc->exp_errno, "%s", tc->desc);
 }
 

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2026-07-01  8:34 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-14  4:51 [LTP] [PATCH v2 1/2] connect01: Convert to new API Yang Xu via ltp
2024-05-14  4:51 ` [LTP] [PATCH v2 2/2] connect01: Add negative tests Yang Xu via ltp
2024-07-17 12:30 ` [LTP] [PATCH v2 1/2] connect01: Convert to new API Cyril Hrubis
2026-05-25  9:02 ` [LTP] [PATCH v3 0/2] " Wei Gao via ltp
2026-05-25  9:02   ` [LTP] [PATCH v3 1/2] " Wei Gao via ltp
2026-05-25 10:12     ` [LTP] " linuxtestproject.agent
2026-05-28  4:43       ` Wei Gao via ltp
2026-06-04  4:49     ` [LTP] [PATCH v4 0/2] " Wei Gao via ltp
2026-06-04  4:49       ` [LTP] [PATCH v4 1/2] " Wei Gao via ltp
2026-06-04  7:15         ` [LTP] " linuxtestproject.agent
2026-06-16  1:47         ` [LTP] [PATCH v5 0/2] " Wei Gao via ltp
2026-06-16  1:47           ` [LTP] [PATCH v5 1/2] " Wei Gao via ltp
2026-06-16  4:07             ` [LTP] " linuxtestproject.agent
2026-06-16  5:24             ` [LTP] [PATCH v6 0/2] " Wei Gao via ltp
2026-06-16  5:24               ` [LTP] [PATCH v6 1/2] " Wei Gao via ltp
2026-06-16  8:35                 ` [LTP] " linuxtestproject.agent
2026-06-16  9:31                 ` [LTP] [PATCH v7 0/2] " Wei Gao via ltp
2026-06-16  9:31                   ` [LTP] [PATCH v7 1/2] " Wei Gao via ltp
2026-06-16 10:12                     ` [LTP] " linuxtestproject.agent
2026-07-01  8:34                     ` Petr Vorel [this message]
2026-06-16  9:31                   ` [LTP] [PATCH v7 2/2] connect01: Add negative tests Wei Gao via ltp
2026-07-01  8:38                     ` Petr Vorel
2026-07-06  6:02                     ` [LTP] [PATCH v8] connect03: New test case for EPROTOTYPE and EACCES errors Wei Gao via ltp
2026-07-06  8:22                       ` [LTP] " linuxtestproject.agent
2026-07-06 23:39                       ` [LTP] [PATCH v9] " Wei Gao via ltp
2026-07-07  3:25                         ` [LTP] " linuxtestproject.agent
2026-06-16  5:24               ` [LTP] [PATCH v6 2/2] connect01: Add negative tests Wei Gao via ltp
2026-06-16  1:47           ` [LTP] [PATCH v5 " Wei Gao via ltp
2026-06-04  4:49       ` [LTP] [PATCH v4 " Wei Gao via ltp
2026-05-25  9:02   ` [LTP] [PATCH v3 " Wei Gao via ltp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260701083422.GA477554@pevik \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=wegao@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox