diff mbox series

setuid03.c: using TST_EXP_FAIL() and SAFE_SETUID() macros

Message ID 20220727165542.2861-1-akumar@suse.de
State Superseded
Headers show
Series setuid03.c: using TST_EXP_FAIL() and SAFE_SETUID() macros | expand

Commit Message

Avinesh Kumar July 27, 2022, 4:55 p.m. UTC
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 | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

Comments

Avinesh Kumar Aug. 11, 2022, 6:13 a.m. UTC | #1
Sent a v2 for this with correct docparse format and updated copyright.

On Wednesday, July 27, 2022 10:25:42 PM IST Avinesh Kumar wrote:
> 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 | 20 +++++---------------
>  1 file changed, 5 insertions(+), 15 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/setuid/setuid03.c b/testcases/kernel/syscalls/setuid/setuid03.c
> index f2e007f8d..61529b1ff 100644
> --- a/testcases/kernel/syscalls/setuid/setuid03.c
> +++ b/testcases/kernel/syscalls/setuid/setuid03.c
> @@ -3,7 +3,9 @@
>   * Copyright (c) International Business Machines Corp., 2001
>   */
>  
> -/* 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 +21,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 +32,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);
>  }
> 

Regards,
Avinesh
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/setuid/setuid03.c b/testcases/kernel/syscalls/setuid/setuid03.c
index f2e007f8d..61529b1ff 100644
--- a/testcases/kernel/syscalls/setuid/setuid03.c
+++ b/testcases/kernel/syscalls/setuid/setuid03.c
@@ -3,7 +3,9 @@ 
  * Copyright (c) International Business Machines Corp., 2001
  */
 
-/* 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 +21,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 +32,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);
 }