* [LTP] [PATCH v2] bind: Add negative tests for bind
@ 2024-05-05 6:17 Yang Xu via ltp
2024-05-13 10:58 ` Petr Vorel
2024-05-14 12:29 ` Martin Doucha
0 siblings, 2 replies; 4+ messages in thread
From: Yang Xu via ltp @ 2024-05-05 6:17 UTC (permalink / raw)
To: ltp
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
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [LTP] [PATCH v2] bind: Add negative tests for bind
2024-05-05 6:17 [LTP] [PATCH v2] bind: Add negative tests for bind Yang Xu via ltp
@ 2024-05-13 10:58 ` Petr Vorel
2024-05-14 12:29 ` Martin Doucha
1 sibling, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2024-05-13 10:58 UTC (permalink / raw)
To: Yang Xu; +Cc: Martin Doucha, ltp
Hi Xu,
> Add negative cases for bind(), when errno is EBADF or ENOTDIR.
> Also fix some format check warning for existed code.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
@Martin FYI if you want to review before merge.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v2] bind: Add negative tests for bind
2024-05-05 6:17 [LTP] [PATCH v2] bind: Add negative tests for bind Yang Xu via ltp
2024-05-13 10:58 ` Petr Vorel
@ 2024-05-14 12:29 ` Martin Doucha
2024-05-14 13:00 ` Petr Vorel
1 sibling, 1 reply; 4+ messages in thread
From: Martin Doucha @ 2024-05-14 12:29 UTC (permalink / raw)
To: Yang Xu, ltp
Hi,
small nit below, otherwise looks good to me.
Reviewed-by: Martin Doucha <mdoucha@suse.cz>
On 05. 05. 24 8:17, Yang Xu via ltp wrote:
> 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;
Nit: fd_ebadf could be initialized when it's declared above. But that
can be fixed during merge.
> + 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,
> };
--
Martin Doucha mdoucha@suse.cz
SW Quality Engineer
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-14 13:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-05 6:17 [LTP] [PATCH v2] bind: Add negative tests for bind Yang Xu via ltp
2024-05-13 10:58 ` Petr Vorel
2024-05-14 12:29 ` Martin Doucha
2024-05-14 13:00 ` Petr Vorel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox