test-baremetal 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env python3
  2. import os
  3. import sys
  4. import common
  5. import lkmc.import_path
  6. import path_properties
  7. import thread_pool
  8. class Main(common.TestCliFunction):
  9. def __init__(self):
  10. super().__init__(
  11. is_baremetal=True,
  12. supported_archs=common.consts['crosstool_ng_supported_archs'],
  13. )
  14. self.add_argument(
  15. 'tests',
  16. nargs='*',
  17. help='''\
  18. If given, run only the given tests. Otherwise, run all tests.
  19. '''
  20. )
  21. def setup_one(self):
  22. self.env['tests'] = self.resolve_targets(
  23. [
  24. self.env['baremetal_source_dir'],
  25. self.env['userland_source_dir']
  26. ],
  27. self.env['tests']
  28. )
  29. def timed_main(self):
  30. run_args = self.get_common_args()
  31. rootdir_abs_len = len(self.env['root_dir'])
  32. with thread_pool.ThreadPool(
  33. self.run_test,
  34. handle_output=self.handle_output_function,
  35. nthreads=self.env['nproc'],
  36. thread_id_arg='thread_id',
  37. submit_raise_exit=self.env['quit_on_fail'],
  38. ) as my_thread_pool:
  39. for test in self.env['tests']:
  40. for path, in_dirnames, in_filenames in self.sh.walk(test):
  41. path_abs = os.path.abspath(path)
  42. dirpath_relative_root = path_abs[rootdir_abs_len + 1:]
  43. for in_filename in in_filenames:
  44. if os.path.splitext(in_filename)[1] in self.env['baremetal_build_in_exts']:
  45. path_relative_root = os.path.join(dirpath_relative_root, in_filename)
  46. my_path_properties = path_properties.get(path_relative_root)
  47. if my_path_properties.should_be_tested(self.env, is_baremetal=True):
  48. cur_run_args = run_args.copy()
  49. cur_run_args.update({
  50. 'baremetal': os.path.relpath(os.path.join(path_abs, in_filename), os.getcwd()),
  51. })
  52. cur_run_args.update(my_path_properties['test_run_args'])
  53. run_test_args = {
  54. 'expected_exit_status': my_path_properties['exit_status'],
  55. 'run_args': cur_run_args,
  56. 'run_obj': lkmc.import_path.import_path_main('run'),
  57. 'test_id': path_relative_root,
  58. }
  59. signal = my_path_properties['signal_received']
  60. if signal is not None:
  61. run_test_args['expected_exit_status'] = 128 + signal.value
  62. my_thread_pool.submit(run_test_args)
  63. return self._handle_thread_pool_errors(my_thread_pool)
  64. if __name__ == '__main__':
  65. Main().cli()