Skip to content

Commit 7af2914

Browse files
dlatypovshuahkh
authored andcommitted
kunit: tool: fix unintentional statefulness in run_kernel()
This is a bug that has been present since the first version of this code. Using [] as a default parameter is dangerous, since it's mutable. Example using the REPL: >>> def bad(param = []): ... param.append(len(param)) ... print(param) ... >>> bad() [0] >>> bad() [0, 1] This wasn't a concern in the past since it would just keep appending the same values to it. E.g. before, `args` would just grow in size like: [mem=1G', 'console=tty'] [mem=1G', 'console=tty', mem=1G', 'console=tty'] But with now filter_glob, this is more dangerous, e.g. run_kernel(filter_glob='my-test*') # default modified here run_kernel() # filter_glob still applies here! That earlier `filter_glob` will affect all subsequent calls that don't specify `args`. Note: currently the kunit tool only calls run_kernel() at most once, so it's not possible to trigger any negative side-effects right now. Fixes: 6ebf586 ("kunit: tool: add Python wrappers for running KUnit tests") Signed-off-by: Daniel Latypov <[email protected]> Reviewed-by: Brendan Higgins <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent d992880 commit 7af2914

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tools/testing/kunit/kunit_kernel.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ def build_um_kernel(self, alltests, jobs, build_dir, make_options) -> bool:
203203
return False
204204
return self.validate_config(build_dir)
205205

206-
def run_kernel(self, args=[], build_dir='', filter_glob='', timeout=None) -> Iterator[str]:
206+
def run_kernel(self, args=None, build_dir='', filter_glob='', timeout=None) -> Iterator[str]:
207+
if not args:
208+
args = []
207209
args.extend(['mem=1G', 'console=tty'])
208210
if filter_glob:
209211
args.append('kunit.filter_glob='+filter_glob)

0 commit comments

Comments
 (0)