Skip to contentSkip to conversation

tools/testing/kunit/kunit.py: remove redundant double check

PATCH Superseded Alexander Pantyukhin 3 participants 6 messages Jan 15, 2023 – Jan 18, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/testing/kunit/kunit.py: remove redundant double check

The build_tests function contained the doulbe checking for not success result. It is fixed in the current patch. Additional small simplifications of code like useing ternary if were applied (avoid use the same operation by calculation times differ in two places).

---
 tools/testing/kunit/kunit.py | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
tools/testing/kunit/kunit.py +5 -12
index 43fbe96318fe..481c213818bd 100755
@@ -77,10 +77,8 @@ def config_tests(linux: kunit_kernel.LinuxSourceTree,
 	config_start = time.time()
 	success = linux.build_reconfig(request.build_dir, request.make_options)
 	config_end = time.time()
-	if not success:
-		return KunitResult(KunitStatus.CONFIG_FAILURE,
-				   config_end - config_start)
-	return KunitResult(KunitStatus.SUCCESS,
+	status = KunitStatus.SUCCESS if success else KunitStatus.CONFIG_FAILURE
+	return KunitResult(status,
 			   config_end - config_start)
 
 def build_tests(linux: kunit_kernel.LinuxSourceTree,
@@ -92,13 +90,8 @@ def build_tests(linux: kunit_kernel.LinuxSourceTree,
 				     request.build_dir,
 				     request.make_options)
 	build_end = time.time()
-	if not success:
-		return KunitResult(KunitStatus.BUILD_FAILURE,
-				   build_end - build_start)
-	if not success:
-		return KunitResult(KunitStatus.BUILD_FAILURE,
-				   build_end - build_start)
-	return KunitResult(KunitStatus.SUCCESS,
+	status = KunitStatus.SUCCESS if success else KunitStatus.BUILD_FAILURE
+	return KunitResult(status,
 			   build_end - build_start)
 
 def config_and_build_tests(linux: kunit_kernel.LinuxSourceTree,
@@ -145,7 +138,7 @@ def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) -
 		tests = _list_tests(linux, request)
 		if request.run_isolated == 'test':
 			filter_globs = tests
-		if request.run_isolated == 'suite':
+		elif request.run_isolated == 'suite':
 			filter_globs = _suites_from_test_list(tests)
 			# Apply the test-part of the user's glob, if present.
 			if '.' in request.filter_glob:
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Alexander Pantyukhin

The build_tests function contained the doulbe checking for not success

Nit: "double" -> "double"

Quoted 2 lines

result. It is fixed in the current patch. Additional small simplifications of code like useing ternary if were applied (avoid use

Nit: "useing" -> "using"

Quoted 4 lines

the same operation by calculation times differ in two places).

---

Thanks for catching these!
This looks good to me, save for a few typos (which you should fix if there's a v2, but it isn't important enough to do another version...)

Unless someone with more Python knowledge than me jumps in and complains, this is:

Cheers,
-- David

Quoted 48 lines
 tools/testing/kunit/kunit.py | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
tools/testing/kunit/kunit.py +5 -13
index 43fbe96318fe..481c213818bd 100755
@@ -77,10 +77,8 @@ def config_tests(linux: kunit_kernel.LinuxSourceTree,
        config_start = time.time()
        success = linux.build_reconfig(request.build_dir, request.make_options)
        config_end = time.time()
-       if not success:
-               return KunitResult(KunitStatus.CONFIG_FAILURE,
-                                  config_end - config_start)
-       return KunitResult(KunitStatus.SUCCESS,
+       status = KunitStatus.SUCCESS if success else KunitStatus.CONFIG_FAILURE
+       return KunitResult(status,
                           config_end - config_start)
 
 def build_tests(linux: kunit_kernel.LinuxSourceTree,
@@ -92,13 +90,8 @@ def build_tests(linux: kunit_kernel.LinuxSourceTree,
                                     request.build_dir,
                                     request.make_options)
        build_end = time.time()
-       if not success:
-               return KunitResult(KunitStatus.BUILD_FAILURE,
-                                  build_end - build_start)
-       if not success:
-               return KunitResult(KunitStatus.BUILD_FAILURE,
-                                  build_end - build_start)
-       return KunitResult(KunitStatus.SUCCESS,
+       status = KunitStatus.SUCCESS if success else KunitStatus.BUILD_FAILURE
+       return KunitResult(status,
                           build_end - build_start)
 
 def config_and_build_tests(linux: kunit_kernel.LinuxSourceTree,
@@ -145,7 +138,7 @@ def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) -
                tests = _list_tests(linux, request)
                if request.run_isolated == 'test':
                        filter_globs = tests
-               if request.run_isolated == 'suite':
+               elif request.run_isolated == 'suite':
                        filter_globs = _suites_from_test_list(tests)
                        # Apply the test-part of the user's glob, if present.
                        if '.' in request.filter_glob:
--

2.25.1

#2 lore raw

Hello, David.
Thank you very much for your review!
There is no v2 yet.

Quoted 73 lines · Alexander Pantyukhin
Quoted 2 lines

The build_tests function contained the doulbe checking for not success

Nit: "double" -> "double"

Quoted 2 lines

result. It is fixed in the current patch. Additional small simplifications of code like useing ternary if were applied (avoid use

Nit: "useing" -> "using"

Quoted 4 lines

the same operation by calculation times differ in two places).

---

Thanks for catching these!
This looks good to me, save for a few typos (which you should fix if there's a v2, but it isn't important enough to do another version...)

Unless someone with more Python knowledge than me jumps in and complains, this is:

Cheers,
-- David

Quoted 48 lines
 tools/testing/kunit/kunit.py | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
tools/testing/kunit/kunit.py +5 -13
index 43fbe96318fe..481c213818bd 100755
@@ -77,10 +77,8 @@ def config_tests(linux: kunit_kernel.LinuxSourceTree,
        config_start = time.time()
        success = linux.build_reconfig(request.build_dir, request.make_options)
        config_end = time.time()
-       if not success:
-               return KunitResult(KunitStatus.CONFIG_FAILURE,
-                                  config_end - config_start)
-       return KunitResult(KunitStatus.SUCCESS,
+       status = KunitStatus.SUCCESS if success else KunitStatus.CONFIG_FAILURE
+       return KunitResult(status,
                           config_end - config_start)
 
 def build_tests(linux: kunit_kernel.LinuxSourceTree,
@@ -92,13 +90,8 @@ def build_tests(linux: kunit_kernel.LinuxSourceTree,
                                     request.build_dir,
                                     request.make_options)
        build_end = time.time()
-       if not success:
-               return KunitResult(KunitStatus.BUILD_FAILURE,
-                                  build_end - build_start)
-       if not success:
-               return KunitResult(KunitStatus.BUILD_FAILURE,
-                                  build_end - build_start)
-       return KunitResult(KunitStatus.SUCCESS,
+       status = KunitStatus.SUCCESS if success else KunitStatus.BUILD_FAILURE
+       return KunitResult(status,
                           build_end - build_start)
 
 def config_and_build_tests(linux: kunit_kernel.LinuxSourceTree,
@@ -145,7 +138,7 @@ def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) -
                tests = _list_tests(linux, request)
                if request.run_isolated == 'test':
                        filter_globs = tests
-               if request.run_isolated == 'suite':
+               elif request.run_isolated == 'suite':
                        filter_globs = _suites_from_test_list(tests)
                        # Apply the test-part of the user's glob, if present.
                        if '.' in request.filter_glob:
--

2.25.1

Reviewed-by on v1 1/1
#3 lore raw
In reply to Alexander Pantyukhin
Quoted 2 lines · Alexander Pantyukhin

The build_tests function contained the doulbe checking for not success

very nit: if we're fixing the "doulbe" typo, can we also do
"the doulbe" => "double" (drop the "the")

Quoted 5 lines

result. It is fixed in the current patch. Additional small simplifications of code like useing ternary if were applied (avoid use the same operation by calculation times differ in two places).

Thanks!
I can't believe we never noticed the duplicate if not success blocks before now.

Some minor suggestions below if we're already going to send a v2 out for typos.

Quoted 9 lines
---
 tools/testing/kunit/kunit.py | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
tools/testing/kunit/kunit.py +0 -0
index 43fbe96318fe..481c213818bd 100755

tools/testing/kunit/kunit.py def config_tests(linux: kunit_kernel.LinuxSourceTree, · line 82

Quoted 10 lines
tools/testing/kunit/kunit.py +2 -4
@@ -77,10 +77,8 @@ def config_tests(linux: kunit_kernel.LinuxSourceTree,
        config_start = time.time()
        success = linux.build_reconfig(request.build_dir, request.make_options)
        config_end = time.time()
-       if not success:
-               return KunitResult(KunitStatus.CONFIG_FAILURE,
-                                  config_end - config_start)
-       return KunitResult(KunitStatus.SUCCESS,
+       status = KunitStatus.SUCCESS if success else KunitStatus.CONFIG_FAILURE
+       return KunitResult(status,
                           config_end - config_start)

nit: perhaps we can shorten this to one line, i.e.
return KunitResult(status, config_end - config_start)

tools/testing/kunit/kunit.py def build_tests(linux: kunit_kernel.LinuxSourceTree, · line 100

Quoted 12 lines
tools/testing/kunit/kunit.py +0 -6
 def build_tests(linux: kunit_kernel.LinuxSourceTree,
@@ -92,13 +90,8 @@ def build_tests(linux: kunit_kernel.LinuxSourceTree,
                                     request.build_dir,
                                     request.make_options)
        build_end = time.time()
-       if not success:
-               return KunitResult(KunitStatus.BUILD_FAILURE,
-                                  build_end - build_start)
-       if not success:
-               return KunitResult(KunitStatus.BUILD_FAILURE,
-                                  build_end - build_start)

Oh huh, I guess this duplication comes from commit 45ba7a893ad8 ("kunit: kunit_tool: Separate out config/build/exec/parse")

@@ -64,78 +84,167 @@ def run_tests(linux: kunit_kernel.LinuxSourceTree,
build_end = time.time()
if not success:
return KunitResult(KunitStatus.BUILD_FAILURE, 'could
not build kernel')
+ if not success:
+ return KunitResult(KunitStatus.BUILD_FAILURE,
+ 'could not build kernel',

tools/testing/kunit/kunit.py def build_tests(linux: kunit_kernel.LinuxSourceTree, · line 95

Quoted 4 lines
tools/testing/kunit/kunit.py +2 -1
-       return KunitResult(KunitStatus.SUCCESS,
+       status = KunitStatus.SUCCESS if success else KunitStatus.BUILD_FAILURE
+       return KunitResult(status,
                           build_end - build_start)

ditto here,
return KunitResult(status, build_end - build_start)

tools/testing/kunit/kunit.py def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) - · line 141

Quoted 8 lines
tools/testing/kunit/kunit.py +1 -1
 def config_and_build_tests(linux: kunit_kernel.LinuxSourceTree,
@@ -145,7 +138,7 @@ def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) -
                tests = _list_tests(linux, request)
                if request.run_isolated == 'test':
                        filter_globs = tests
-               if request.run_isolated == 'suite':
+               elif request.run_isolated == 'suite':

This is better, thanks.

Daniel

#4 lore raw

Hello Daniel.
Thank you very much for your review!
Could you advise me whom I can address the V2 patch "to"?

Best, Alex.

ср, 18 янв. 2023 г. в 01:56, Daniel Latypov <[email protected]>:

Quoted 91 lines
Quoted 2 lines · Alexander Pantyukhin

The build_tests function contained the doulbe checking for not success

very nit: if we're fixing the "doulbe" typo, can we also do
"the doulbe" => "double" (drop the "the")

Quoted 5 lines

result. It is fixed in the current patch. Additional small simplifications of code like useing ternary if were applied (avoid use the same operation by calculation times differ in two places).

Thanks!
I can't believe we never noticed the duplicate if not success blocks before now.

Some minor suggestions below if we're already going to send a v2 out for typos.

Quoted 9 lines
---
 tools/testing/kunit/kunit.py | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
tools/testing/kunit/kunit.py +0 -0
index 43fbe96318fe..481c213818bd 100755

tools/testing/kunit/kunit.py def config_tests(linux: kunit_kernel.LinuxSourceTree, · line 82

Quoted 10 lines
tools/testing/kunit/kunit.py +2 -4
@@ -77,10 +77,8 @@ def config_tests(linux: kunit_kernel.LinuxSourceTree,
        config_start = time.time()
        success = linux.build_reconfig(request.build_dir, request.make_options)
        config_end = time.time()
-       if not success:
-               return KunitResult(KunitStatus.CONFIG_FAILURE,
-                                  config_end - config_start)
-       return KunitResult(KunitStatus.SUCCESS,
+       status = KunitStatus.SUCCESS if success else KunitStatus.CONFIG_FAILURE
+       return KunitResult(status,
                           config_end - config_start)

nit: perhaps we can shorten this to one line, i.e.
return KunitResult(status, config_end - config_start)

tools/testing/kunit/kunit.py def build_tests(linux: kunit_kernel.LinuxSourceTree, · line 100

Quoted 12 lines
tools/testing/kunit/kunit.py +0 -6
 def build_tests(linux: kunit_kernel.LinuxSourceTree,
@@ -92,13 +90,8 @@ def build_tests(linux: kunit_kernel.LinuxSourceTree,
                                     request.build_dir,
                                     request.make_options)
        build_end = time.time()
-       if not success:
-               return KunitResult(KunitStatus.BUILD_FAILURE,
-                                  build_end - build_start)
-       if not success:
-               return KunitResult(KunitStatus.BUILD_FAILURE,
-                                  build_end - build_start)

Oh huh, I guess this duplication comes from commit 45ba7a893ad8 ("kunit: kunit_tool: Separate out config/build/exec/parse")

(quoted diff) +3 -0
@@ -64,78 +84,167 @@ def run_tests(linux: kunit_kernel.LinuxSourceTree,
        build_end = time.time()
        if not success:
                return KunitResult(KunitStatus.BUILD_FAILURE, 'could
 not build kernel')
+       if not success:
+               return KunitResult(KunitStatus.BUILD_FAILURE,
+                                  'could not build kernel',
 
 > -       return KunitResult(KunitStatus.SUCCESS,

tools/testing/kunit/kunit.py def build_tests(linux: kunit_kernel.LinuxSourceTree, · line 95

Quoted 3 lines
tools/testing/kunit/kunit.py +2 -0
+       status = KunitStatus.SUCCESS if success else KunitStatus.BUILD_FAILURE
+       return KunitResult(status,
                           build_end - build_start)

ditto here,
return KunitResult(status, build_end - build_start)

tools/testing/kunit/kunit.py def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) - · line 141

Quoted 8 lines
tools/testing/kunit/kunit.py +1 -1
 def config_and_build_tests(linux: kunit_kernel.LinuxSourceTree,
@@ -145,7 +138,7 @@ def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) -
                tests = _list_tests(linux, request)
                if request.run_isolated == 'test':
                        filter_globs = tests
-               if request.run_isolated == 'suite':
+               elif request.run_isolated == 'suite':

This is better, thanks.

Daniel

#5 lore raw
Quoted 4 lines · Alexander Pantyukhin

Hello Daniel.
Thank you very much for your review!
Could you advise me whom I can address the V2 patch "to"?

[email protected] is the more active maintainer right now.

But since you've got his Reviewed-by already, as long as you CC kunit-dev@ and linux-kselftest@, whatever you want to put is fine. We can make sure v2 gets picked up.

You'll ultimately see the patch go in through
https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/?h=kunit
and hopefully merged into 6.3.

Daniel