diff mbox series

[v3,2/2] selftests: clone3: simplify return logic in clone3_set_tid()

Message ID 20211118095852.616256-2-anders.roxell@linaro.org (mailing list archive)
State New
Headers show
Series [v3,1/2] selftests: kselftest.h: mark functions with 'noreturn' | expand

Commit Message

Anders Roxell Nov. 18, 2021, 9:58 a.m. UTC
Use ksft_exit_* and exit instead of using goto.

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 tools/testing/selftests/clone3/clone3_set_tid.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

Comments

Anders Roxell Nov. 18, 2021, 10:03 a.m. UTC | #1
On Thu, 18 Nov 2021 at 10:58, Anders Roxell <anders.roxell@linaro.org> wrote:
>
> Use ksft_exit_* and exit instead of using goto.
>

I'm sorry, I should have added Nick to this patch, since he suggested it.

Suggested-by: Nick Desaulniers <ndesaulniers@google.com>

Cheers,
Anders

> Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
> ---
>  tools/testing/selftests/clone3/clone3_set_tid.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/tools/testing/selftests/clone3/clone3_set_tid.c b/tools/testing/selftests/clone3/clone3_set_tid.c
> index a755fcd3af89..1b950c3c3b7c 100644
> --- a/tools/testing/selftests/clone3/clone3_set_tid.c
> +++ b/tools/testing/selftests/clone3/clone3_set_tid.c
> @@ -250,7 +250,8 @@ int main(int argc, char *argv[])
>                  * that all those tests are skipped as non-root.
>                  */
>                 ksft_cnt.ksft_xskip += ksft_plan - ksft_test_num();
> -               goto out;
> +               ksft_exit_skip(
> +                       "Please run the remaining tests as root - Exiting.\n");
>         }
>
>         /* Find the current active PID */
> @@ -371,9 +372,7 @@ int main(int argc, char *argv[])
>         close(pipe_2[1]);
>
>         if (waitpid(ns_pid, &status, 0) < 0) {
> -               ksft_print_msg("Child returned %s\n", strerror(errno));
> -               ret = -errno;
> -               goto out;
> +               ksft_exit_fail_msg("Child returned %s\n", strerror(errno));
>         }
>
>         if (!WIFEXITED(status))
> @@ -390,10 +389,6 @@ int main(int argc, char *argv[])
>                 ksft_test_result_fail(
>                         "PIDs in all namespaces not as expected (%d,%d,%d)\n",
>                         ns3, ns2, ns1);
> -out:
> -       ret = 0;
>
> -       if (ret)
> -               ksft_exit_fail();
>         ksft_exit_pass();
>  }
> --
> 2.33.0
>
Nick Desaulniers Nov. 18, 2021, 6:43 p.m. UTC | #2
On Thu, Nov 18, 2021 at 2:03 AM Anders Roxell <anders.roxell@linaro.org> wrote:
>
> On Thu, 18 Nov 2021 at 10:58, Anders Roxell <anders.roxell@linaro.org> wrote:
> >
> > Use ksft_exit_* and exit instead of using goto.
> >
>
> I'm sorry, I should have added Nick to this patch, since he suggested it.
>
> Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
>
> Cheers,
> Anders
>
> > Signed-off-by: Anders Roxell <anders.roxell@linaro.org>

Thanks for the patch!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> > ---
> >  tools/testing/selftests/clone3/clone3_set_tid.c | 11 +++--------
> >  1 file changed, 3 insertions(+), 8 deletions(-)
> >
> > diff --git a/tools/testing/selftests/clone3/clone3_set_tid.c b/tools/testing/selftests/clone3/clone3_set_tid.c
> > index a755fcd3af89..1b950c3c3b7c 100644
> > --- a/tools/testing/selftests/clone3/clone3_set_tid.c
> > +++ b/tools/testing/selftests/clone3/clone3_set_tid.c
> > @@ -250,7 +250,8 @@ int main(int argc, char *argv[])
> >                  * that all those tests are skipped as non-root.
> >                  */
> >                 ksft_cnt.ksft_xskip += ksft_plan - ksft_test_num();
> > -               goto out;
> > +               ksft_exit_skip(
> > +                       "Please run the remaining tests as root - Exiting.\n");
> >         }
> >
> >         /* Find the current active PID */
> > @@ -371,9 +372,7 @@ int main(int argc, char *argv[])
> >         close(pipe_2[1]);
> >
> >         if (waitpid(ns_pid, &status, 0) < 0) {
> > -               ksft_print_msg("Child returned %s\n", strerror(errno));
> > -               ret = -errno;
> > -               goto out;
> > +               ksft_exit_fail_msg("Child returned %s\n", strerror(errno));
> >         }
> >
> >         if (!WIFEXITED(status))
> > @@ -390,10 +389,6 @@ int main(int argc, char *argv[])
> >                 ksft_test_result_fail(
> >                         "PIDs in all namespaces not as expected (%d,%d,%d)\n",
> >                         ns3, ns2, ns1);
> > -out:
> > -       ret = 0;
> >
> > -       if (ret)
> > -               ksft_exit_fail();
> >         ksft_exit_pass();
> >  }
> > --
> > 2.33.0
> >
diff mbox series

Patch

diff --git a/tools/testing/selftests/clone3/clone3_set_tid.c b/tools/testing/selftests/clone3/clone3_set_tid.c
index a755fcd3af89..1b950c3c3b7c 100644
--- a/tools/testing/selftests/clone3/clone3_set_tid.c
+++ b/tools/testing/selftests/clone3/clone3_set_tid.c
@@ -250,7 +250,8 @@  int main(int argc, char *argv[])
 		 * that all those tests are skipped as non-root.
 		 */
 		ksft_cnt.ksft_xskip += ksft_plan - ksft_test_num();
-		goto out;
+		ksft_exit_skip(
+			"Please run the remaining tests as root - Exiting.\n");
 	}
 
 	/* Find the current active PID */
@@ -371,9 +372,7 @@  int main(int argc, char *argv[])
 	close(pipe_2[1]);
 
 	if (waitpid(ns_pid, &status, 0) < 0) {
-		ksft_print_msg("Child returned %s\n", strerror(errno));
-		ret = -errno;
-		goto out;
+		ksft_exit_fail_msg("Child returned %s\n", strerror(errno));
 	}
 
 	if (!WIFEXITED(status))
@@ -390,10 +389,6 @@  int main(int argc, char *argv[])
 		ksft_test_result_fail(
 			"PIDs in all namespaces not as expected (%d,%d,%d)\n",
 			ns3, ns2, ns1);
-out:
-	ret = 0;
 
-	if (ret)
-		ksft_exit_fail();
 	ksft_exit_pass();
 }