diff mbox series

getsockopt01: Add case for errno EINVAL

Message ID 20240422083657.28363-1-xuyang2018.jy@fujitsu.com
State Accepted
Headers show
Series getsockopt01: Add case for errno EINVAL | expand

Commit Message

Yang Xu \(Fujitsu\) April 22, 2024, 8:36 a.m. UTC
Currently there is no case for EINVAL, so a new case is added.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/kernel/syscalls/getsockopt/getsockopt01.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Petr Vorel May 16, 2024, 1:34 a.m. UTC | #1
Hi Xu,

...
> +++ b/testcases/kernel/syscalls/getsockopt/getsockopt01.c
> @@ -15,6 +15,7 @@
>   * - ENOTSOCK on a file descriptor not linked to a socket
>   * - EFAULT on invalid address of value or length
>   * - EOPNOTSUPP on invalid option name or protocol
> + * - EINVAL on an invalid optlen
>   */

>  #include "tst_test.h"
> @@ -24,6 +25,7 @@ static struct sockaddr_in sin0;
>  static int sinlen;
>  static int optval;
>  static socklen_t optlen;
> +static socklen_t optleninval;

Again, -1 should be added here (can be fixed before merge):

static socklen_t optleninval = -1;

>  static struct test_case {
>  	int *sockfd;
> @@ -56,7 +58,10 @@ static struct test_case {
>  	.optlen = &optlen, .experrno = ENOPROTOOPT, .desc =  "invalid option name (IP)"},

>  	{.sockfd = &sock_bind, .level = IPPROTO_TCP, .optname = -1, .optval = &optval,
> -	.optlen = &optlen, .experrno = ENOPROTOOPT, .desc = "invalid option name (TCP)"}
> +	.optlen = &optlen, .experrno = ENOPROTOOPT, .desc = "invalid option name (TCP)"},
> +
> +	{.sockfd = &sock_bind, .level = SOL_SOCKET, .optname = SO_OOBINLINE, .optval = &optval,
> +	.optlen = &optleninval, .experrno = EINVAL, .desc = "invalid optlen"},
>  };


> @@ -79,6 +84,7 @@ static void setup(void)
>  	SAFE_BIND(sock_bind, (struct sockaddr *)&sin0, sizeof(sin0));
>  	sinlen = sizeof(sin0);
>  	optlen = sizeof(optval);
> +	optleninval = -1;
And this can be removed.

With that:

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr
Petr Vorel May 16, 2024, 1:39 a.m. UTC | #2
Hi Xu,

> Hi Xu,

> ...
> > +++ b/testcases/kernel/syscalls/getsockopt/getsockopt01.c
> > @@ -15,6 +15,7 @@
> >   * - ENOTSOCK on a file descriptor not linked to a socket
> >   * - EFAULT on invalid address of value or length
> >   * - EOPNOTSUPP on invalid option name or protocol
> > + * - EINVAL on an invalid optlen
> >   */

> >  #include "tst_test.h"
> > @@ -24,6 +25,7 @@ static struct sockaddr_in sin0;
> >  static int sinlen;
> >  static int optval;
> >  static socklen_t optlen;
> > +static socklen_t optleninval;

> Again, -1 should be added here (can be fixed before merge):

Merged with this fix. Thanks!

Kind regards,
Petr
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/getsockopt/getsockopt01.c b/testcases/kernel/syscalls/getsockopt/getsockopt01.c
index 4da9bd0ea..05f2be890 100644
--- a/testcases/kernel/syscalls/getsockopt/getsockopt01.c
+++ b/testcases/kernel/syscalls/getsockopt/getsockopt01.c
@@ -15,6 +15,7 @@ 
  * - ENOTSOCK on a file descriptor not linked to a socket
  * - EFAULT on invalid address of value or length
  * - EOPNOTSUPP on invalid option name or protocol
+ * - EINVAL on an invalid optlen
  */
 
 #include "tst_test.h"
@@ -24,6 +25,7 @@  static struct sockaddr_in sin0;
 static int sinlen;
 static int optval;
 static socklen_t optlen;
+static socklen_t optleninval;
 
 static struct test_case {
 	int *sockfd;
@@ -56,7 +58,10 @@  static struct test_case {
 	.optlen = &optlen, .experrno = ENOPROTOOPT, .desc =  "invalid option name (IP)"},
 
 	{.sockfd = &sock_bind, .level = IPPROTO_TCP, .optname = -1, .optval = &optval,
-	.optlen = &optlen, .experrno = ENOPROTOOPT, .desc = "invalid option name (TCP)"}
+	.optlen = &optlen, .experrno = ENOPROTOOPT, .desc = "invalid option name (TCP)"},
+
+	{.sockfd = &sock_bind, .level = SOL_SOCKET, .optname = SO_OOBINLINE, .optval = &optval,
+	.optlen = &optleninval, .experrno = EINVAL, .desc = "invalid optlen"},
 };
 
 
@@ -79,6 +84,7 @@  static void setup(void)
 	SAFE_BIND(sock_bind, (struct sockaddr *)&sin0, sizeof(sin0));
 	sinlen = sizeof(sin0);
 	optlen = sizeof(optval);
+	optleninval = -1;
 }
 
 static struct tst_test test = {