public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v2] setuid03.c: using TST_EXP_FAIL() and SAFE_SETUID() macros
@ 2022-08-11  6:11 Avinesh Kumar
  2022-10-11 11:26 ` Richard Palethorpe
  0 siblings, 1 reply; 2+ messages in thread
From: Avinesh Kumar @ 2022-08-11  6:11 UTC (permalink / raw)
  To: ltp

use TST_EXP_FAIL() with expected errno code, use SAFE_SETUID() in setup
and turn comment into docparse

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/setuid/setuid03.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/testcases/kernel/syscalls/setuid/setuid03.c b/testcases/kernel/syscalls/setuid/setuid03.c
index f2e007f8d..06934f142 100644
--- a/testcases/kernel/syscalls/setuid/setuid03.c
+++ b/testcases/kernel/syscalls/setuid/setuid03.c
@@ -1,9 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines Corp., 2001
+ * Copyright (c) Linux Test Project, 2009-2022
  */
 
-/* DESCRIPTION
+/*\
+ * [Description]
+ *
  * This test will switch to nobody user for correct error code collection.
  * Verify setuid returns errno EPERM when it switches to root_user.
  */
@@ -19,16 +22,7 @@
 
 static void verify_setuid(void)
 {
-	TEST(SETUID(ROOT_USER));
-	if (TST_RET != -1) {
-		tst_res(TFAIL | TTERRNO, "setuid() succeeded unexpectedly");
-		return;
-	}
-
-	if (TST_ERR == EPERM)
-		tst_res(TPASS, "setuid() returned errno EPERM");
-	else
-		tst_res(TFAIL | TTERRNO, "setuid() returned unexpected errno");
+	TST_EXP_FAIL(SETUID(ROOT_USER), EPERM);
 }
 
 static void setup(void)
@@ -39,10 +33,7 @@ static void setup(void)
 	pw = SAFE_GETPWNAM("nobody");
 	uid = pw->pw_uid;
 
-	if (SETUID(uid) == -1) {
-		tst_brk(TBROK,
-			"setuid() failed to set the effective uid to %d", uid);
-	}
+	SAFE_SETUID(uid);
 
 	umask(0);
 }
-- 
2.36.1


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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [LTP] [PATCH v2] setuid03.c: using TST_EXP_FAIL() and SAFE_SETUID() macros
  2022-08-11  6:11 [LTP] [PATCH v2] setuid03.c: using TST_EXP_FAIL() and SAFE_SETUID() macros Avinesh Kumar
@ 2022-10-11 11:26 ` Richard Palethorpe
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Palethorpe @ 2022-10-11 11:26 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hello,

Merged! thanks

Avinesh Kumar <akumar@suse.de> writes:

> use TST_EXP_FAIL() with expected errno code, use SAFE_SETUID() in setup
> and turn comment into docparse
>
> Signed-off-by: Avinesh Kumar <akumar@suse.de>
> ---
>  testcases/kernel/syscalls/setuid/setuid03.c | 21 ++++++---------------
>  1 file changed, 6 insertions(+), 15 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/setuid/setuid03.c b/testcases/kernel/syscalls/setuid/setuid03.c
> index f2e007f8d..06934f142 100644
> --- a/testcases/kernel/syscalls/setuid/setuid03.c
> +++ b/testcases/kernel/syscalls/setuid/setuid03.c
> @@ -1,9 +1,12 @@
>  // SPDX-License-Identifier: GPL-2.0-or-later
>  /*
>   * Copyright (c) International Business Machines Corp., 2001
> + * Copyright (c) Linux Test Project, 2009-2022
>   */
>  
> -/* DESCRIPTION
> +/*\
> + * [Description]
> + *
>   * This test will switch to nobody user for correct error code collection.
>   * Verify setuid returns errno EPERM when it switches to root_user.
>   */
> @@ -19,16 +22,7 @@
>  
>  static void verify_setuid(void)
>  {
> -	TEST(SETUID(ROOT_USER));
> -	if (TST_RET != -1) {
> -		tst_res(TFAIL | TTERRNO, "setuid() succeeded unexpectedly");
> -		return;
> -	}
> -
> -	if (TST_ERR == EPERM)
> -		tst_res(TPASS, "setuid() returned errno EPERM");
> -	else
> -		tst_res(TFAIL | TTERRNO, "setuid() returned unexpected errno");
> +	TST_EXP_FAIL(SETUID(ROOT_USER), EPERM);
>  }
>  
>  static void setup(void)
> @@ -39,10 +33,7 @@ static void setup(void)
>  	pw = SAFE_GETPWNAM("nobody");
>  	uid = pw->pw_uid;
>  
> -	if (SETUID(uid) == -1) {
> -		tst_brk(TBROK,
> -			"setuid() failed to set the effective uid to %d", uid);
> -	}
> +	SAFE_SETUID(uid);
>  
>  	umask(0);
>  }
> -- 
> 2.36.1


-- 
Thank you,
Richard.

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-11 11:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-11  6:11 [LTP] [PATCH v2] setuid03.c: using TST_EXP_FAIL() and SAFE_SETUID() macros Avinesh Kumar
2022-10-11 11:26 ` Richard Palethorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox