From: Yang Xu via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] bind: Add negative tests for bind
Date: Sun, 5 May 2024 02:17:46 -0400 [thread overview]
Message-ID: <20240505061746.77510-1-xuyang2018.jy@fujitsu.com> (raw)
Add negative cases for bind(), when errno is EBADF or ENOTDIR.
Also fix some format check warning for existed code.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/bind/bind01.c | 36 ++++++++++++++++++-------
1 file changed, 27 insertions(+), 9 deletions(-)
diff --git a/testcases/kernel/syscalls/bind/bind01.c b/testcases/kernel/syscalls/bind/bind01.c
index c008819a8..6d8338a22 100644
--- a/testcases/kernel/syscalls/bind/bind01.c
+++ b/testcases/kernel/syscalls/bind/bind01.c
@@ -17,11 +17,16 @@
#include "tst_test.h"
-int inet_socket;
-int dev_null;
+#define DIR_ENOTDIR "dir_enotdir"
+#define TEST_ENOTDIR "test_enotdir"
-struct sockaddr_in sin1, sin2, sin3;
-struct sockaddr_un sun;
+static int inet_socket;
+static int dev_null;
+static int fd_ebadf;
+static int fd_enotdir;
+
+static struct sockaddr_in sin1, sin2, sin3;
+static struct sockaddr_un sun, sock_enotdir;
static struct test_case {
int *socket_fd;
@@ -41,24 +46,28 @@ static struct test_case {
EAFNOSUPPORT, "UNIX-domain of current directory" },
{ &inet_socket, (struct sockaddr *)&sin3, sizeof(sin3), -1,
EADDRNOTAVAIL, "non-local address" },
+ { &fd_ebadf, (struct sockaddr *)&sin1, sizeof(sin1), -1,
+ EBADF, "sockfd is not a valid file descriptor" },
+ { &fd_enotdir, (struct sockaddr *)&sock_enotdir, sizeof(sock_enotdir), -1,
+ ENOTDIR, "a component of addr prefix is not a directory"},
};
-void verify_bind(unsigned int nr)
+static void verify_bind(unsigned int nr)
{
struct test_case *tcase = &tcases[nr];
if (tcase->experrno) {
TST_EXP_FAIL(bind(*tcase->socket_fd, tcase->sockaddr, tcase->salen),
- tcase->experrno, "%s", tcase->desc);
+ tcase->experrno, "%s", tcase->desc);
} else {
TST_EXP_PASS(bind(*tcase->socket_fd, tcase->sockaddr, tcase->salen),
- "%s", tcase->desc);
+ "%s", tcase->desc);
SAFE_CLOSE(inet_socket);
inet_socket = SAFE_SOCKET(PF_INET, SOCK_STREAM, 0);
}
}
-void test_setup(void)
+static void test_setup(void)
{
/* initialize sockaddr's */
sin1.sin_family = AF_INET;
@@ -78,14 +87,22 @@ void test_setup(void)
sun.sun_family = AF_UNIX;
strncpy(sun.sun_path, ".", sizeof(sun.sun_path));
+ SAFE_TOUCH(DIR_ENOTDIR, 0777, NULL);
+ sock_enotdir.sun_family = AF_UNIX;
+ strncpy(sock_enotdir.sun_path, DIR_ENOTDIR "/" TEST_ENOTDIR,
+ sizeof(sock_enotdir.sun_path));
+
inet_socket = SAFE_SOCKET(PF_INET, SOCK_STREAM, 0);
dev_null = SAFE_OPEN("/dev/null", O_WRONLY);
+ fd_ebadf = -1;
+ fd_enotdir = SAFE_SOCKET(AF_UNIX, SOCK_STREAM, 0);
}
-void test_cleanup(void)
+static void test_cleanup(void)
{
SAFE_CLOSE(inet_socket);
SAFE_CLOSE(dev_null);
+ SAFE_CLOSE(fd_enotdir);
}
static struct tst_test test = {
@@ -93,4 +110,5 @@ static struct tst_test test = {
.setup = test_setup,
.cleanup = test_cleanup,
.test = verify_bind,
+ .needs_tmpdir = 1,
};
--
2.39.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2024-05-08 2:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-05 6:17 Yang Xu via ltp [this message]
2024-05-13 10:58 ` [LTP] [PATCH v2] bind: Add negative tests for bind Petr Vorel
2024-05-14 12:29 ` Martin Doucha
2024-05-14 13:00 ` Petr Vorel
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=20240505061746.77510-1-xuyang2018.jy@fujitsu.com \
--to=ltp@lists.linux.it \
--cc=xuyang2018.jy@fujitsu.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).