Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: tc-testing: cleanup on Ctrl-C

Cleanup net namespaces and other resources if we get a SIGINT (Ctrl-C).
As user visible resources are allocated on a per test basis, it's only
required to catch this condition when (possibly) running tests.

So far calling post_suite is enough to free up anything that might
linger.

A missing keyword replacement for nsPlugin is also included.

Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Link: https://lore.kernel.org/r/20231124154248.315470-5-pctammela@mojatatu.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Pedro Tammela and committed by
Jakub Kicinski
501679f5 56e16bc6

+6 -2
+1 -1
tools/testing/selftests/tc-testing/plugin-lib/nsPlugin.py
··· 78 78 print('{}.post_suite'.format(self.sub_class)) 79 79 80 80 # Make sure we don't leak resources 81 - cmd = "$IP -a netns del" 81 + cmd = self._replace_keywords("$IP -a netns del") 82 82 83 83 if self.args.verbose > 3: 84 84 print('_exec_cmd: command "{}"'.format(cmd))
+5 -1
tools/testing/selftests/tc-testing/tdc.py
··· 1018 1018 if args.verbose > 2: 1019 1019 print('args is {}'.format(args)) 1020 1020 1021 - set_operation_mode(pm, parser, args, remaining) 1021 + try: 1022 + set_operation_mode(pm, parser, args, remaining) 1023 + except KeyboardInterrupt: 1024 + # Cleanup on Ctrl-C 1025 + pm.call_post_suite(None) 1022 1026 1023 1027 if __name__ == "__main__": 1024 1028 main()