diff mbox series

[i-g-t,v2,04/17] lib/kunit: Optimize calls to igt_success/skip/fail()

Message ID 20230908123233.137134-23-janusz.krzysztofik@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series Fix IGT Kunit implementation issues | expand

Commit Message

Janusz Krzysztofik Sept. 8, 2023, 12:32 p.m. UTC
Calling igt_success() explicitly at the end of subtest body is not needed.
Other calls to igt_success() can be usually avoided by inverting test
result checks.  Optimize the code that now calls igt_success().

Moreover, using more advanced variants of igt_skip() and igt_fail() where
applicable makes the code more compact.  Go for it.

Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
---
 lib/igt_kmod.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

Comments

Mauro Carvalho Chehab Sept. 11, 2023, 8:49 a.m. UTC | #1
On Fri,  8 Sep 2023 14:32:38 +0200
Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com> wrote:

> Calling igt_success() explicitly at the end of subtest body is not needed.
> Other calls to igt_success() can be usually avoided by inverting test
> result checks.  Optimize the code that now calls igt_success().
> 
> Moreover, using more advanced variants of igt_skip() and igt_fail() where
> applicable makes the code more compact.  Go for it.

Reviewed-by: Mauro Carvalho Chehab <mchehab@kernel.org>

> 
> Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
> ---
>  lib/igt_kmod.c | 14 +++-----------
>  1 file changed, 3 insertions(+), 11 deletions(-)
> 
> diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
> index 34ddec3fad..1d1cd51170 100644
> --- a/lib/igt_kmod.c
> +++ b/lib/igt_kmod.c
> @@ -814,12 +814,8 @@ static void __igt_kunit(const char *module_name, const char *opts)
>  		if (READ_ONCE(results->head) != NULL) {
>  			pthread_mutex_lock(&results->mutex);
>  
> -			igt_dynamic(results->head->test_name) {
> -				if (READ_ONCE(results->head->passed))
> -					igt_success();
> -				else
> -					igt_fail(IGT_EXIT_FAILURE);
> -			}
> +			igt_dynamic(results->head->test_name)
> +				igt_assert(READ_ONCE(results->head->passed));
>  
>  			temp = results->head;
>  			results->head = results->head->next;
> @@ -834,8 +830,7 @@ unload:
>  
>  	igt_ktest_fini(&tst);
>  
> -	if (skip)
> -		igt_skip("Skipping test, as probing KUnit module returned %d", skip);
> +	igt_skip_on_f(skip, "Skipping test, as probing KUnit module failed\n");
>  
>  	if (fail)
>  		igt_fail(IGT_EXIT_ABORT);
> @@ -844,9 +839,6 @@ unload:
>  
>  	if (ret != 0)
>  		igt_fail(IGT_EXIT_ABORT);
> -
> -	if (ret == 0)
> -		igt_success();
>  }
>  
>  void igt_kunit(const char *module_name, const char *name, const char *opts)
diff mbox series

Patch

diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index 34ddec3fad..1d1cd51170 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -814,12 +814,8 @@  static void __igt_kunit(const char *module_name, const char *opts)
 		if (READ_ONCE(results->head) != NULL) {
 			pthread_mutex_lock(&results->mutex);
 
-			igt_dynamic(results->head->test_name) {
-				if (READ_ONCE(results->head->passed))
-					igt_success();
-				else
-					igt_fail(IGT_EXIT_FAILURE);
-			}
+			igt_dynamic(results->head->test_name)
+				igt_assert(READ_ONCE(results->head->passed));
 
 			temp = results->head;
 			results->head = results->head->next;
@@ -834,8 +830,7 @@  unload:
 
 	igt_ktest_fini(&tst);
 
-	if (skip)
-		igt_skip("Skipping test, as probing KUnit module returned %d", skip);
+	igt_skip_on_f(skip, "Skipping test, as probing KUnit module failed\n");
 
 	if (fail)
 		igt_fail(IGT_EXIT_ABORT);
@@ -844,9 +839,6 @@  unload:
 
 	if (ret != 0)
 		igt_fail(IGT_EXIT_ABORT);
-
-	if (ret == 0)
-		igt_success();
 }
 
 void igt_kunit(const char *module_name, const char *name, const char *opts)