aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/testing/kunit
diff options
context:
space:
mode:
authorDaniel Latypov <dlatypov@google.com>2021-02-05 16:08:54 -0800
committerShuah Khan <skhan@linuxfoundation.org>2021-02-08 16:10:22 -0700
commit7af29141a31a2a2350589471c8979ff5f22fb9b7 (patch)
tree3333ee80df8218db88e74b69ae59254a2adf9e6b /tools/testing/kunit
parentkunit: tool: add support for filtering suites by glob (diff)
downloadwireguard-linux-7af29141a31a2a2350589471c8979ff5f22fb9b7.tar.xz
wireguard-linux-7af29141a31a2a2350589471c8979ff5f22fb9b7.zip
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: 6ebf5866f2e8 ("kunit: tool: add Python wrappers for running KUnit tests") Signed-off-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'tools/testing/kunit')
-rw-r--r--tools/testing/kunit/kunit_kernel.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
index 71a5f5c1750b..f309a33256cd 100644
--- a/tools/testing/kunit/kunit_kernel.py
+++ b/tools/testing/kunit/kunit_kernel.py
@@ -203,7 +203,9 @@ class LinuxSourceTree(object):
return False
return self.validate_config(build_dir)
- def run_kernel(self, args=[], build_dir='', filter_glob='', timeout=None) -> Iterator[str]:
+ def run_kernel(self, args=None, build_dir='', filter_glob='', timeout=None) -> Iterator[str]:
+ if not args:
+ args = []
args.extend(['mem=1G', 'console=tty'])
if filter_glob:
args.append('kunit.filter_glob='+filter_glob)