test-gdb 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env python3
  2. import threading
  3. import os
  4. import common
  5. import lkmc.import_path
  6. class Main(common.TestCliFunction):
  7. def __init__(self):
  8. super().__init__(
  9. description='''\
  10. https://github.com/cirosantilli/linux-kernel-module-cheat#test-gdb
  11. '''
  12. )
  13. self.add_argument(
  14. 'tests',
  15. nargs='*',
  16. help='''\
  17. If given, run only the given tests. Otherwise, run all tests,
  18. found by searching for the Python test files.
  19. '''
  20. )
  21. def timed_main(self):
  22. run = lkmc.import_path.import_path_main('run')
  23. run_gdb = lkmc.import_path.import_path_main('run-gdb')
  24. if self.env['arch'] in self.env['crosstool_ng_supported_archs']:
  25. test_sources = []
  26. if self.env['tests'] == []:
  27. source_paths = []
  28. for filename in sorted(os.listdir(self.env['baremetal_source_dir'])):
  29. base, ext = os.path.splitext(filename)
  30. if ext in self.env['build_in_exts']:
  31. test_sources.append(
  32. os.path.join(
  33. self.env['baremetal_source_dir'],
  34. filename
  35. )
  36. )
  37. for root, dirnames, filenames in os.walk(
  38. os.path.join(
  39. self.env['baremetal_source_dir'],
  40. 'arch',
  41. self.env['arch']
  42. )
  43. ):
  44. for filename in filenames:
  45. base, ext = os.path.splitext(filename)
  46. if ext in self.env['build_in_exts']:
  47. test_sources.append(os.path.join(root, filename))
  48. else:
  49. test_sources = self.env['tests']
  50. for test_source_full in test_sources:
  51. base, ext = os.path.splitext(test_source_full)
  52. if os.path.exists(base + '.py'):
  53. test_source_base = os.path.relpath(base, self.env['root_dir'])
  54. common_args = self.get_common_args()
  55. common_args['baremetal'] = test_source_base + ext
  56. run_args = common_args.copy()
  57. run_args['gdb_wait'] = True
  58. run_args['background'] = True
  59. test_id_string = self.test_setup(run_args, test_source_base)
  60. run_thread = threading.Thread(target=lambda: run(**run_args))
  61. run_thread.start()
  62. gdb_args = common_args.copy()
  63. gdb_args['test'] = True
  64. run_gdb(**gdb_args)
  65. run_thread.join()
  66. self.test_teardown(run, 0, test_id_string)
  67. if __name__ == '__main__':
  68. Main().cli()