test-boot 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env python3
  2. import common
  3. import lkmc.import_path
  4. import thread_pool
  5. import shell_helpers
  6. from shell_helpers import LF
  7. class Main(common.TestCliFunction):
  8. def __init__(self):
  9. super().__init__(
  10. description='''\
  11. Test and benchmark the Linux kernel boot. Use inits that exit immediately.
  12. '''
  13. )
  14. self.add_argument(
  15. '--size',
  16. default=1,
  17. type=int,
  18. help='''\
  19. See ./test --help for --size.
  20. '''
  21. )
  22. def _bench(self, **run_args):
  23. run_obj = lkmc.import_path.import_path_main('run')
  24. words = []
  25. test_id_args = run_args.copy()
  26. del test_id_args['run_id']
  27. for line in run_obj.get_cli(**test_id_args):
  28. words.extend(line)
  29. test_id = shell_helpers.ShellHelpers().cmd_to_string(words, force_oneline=True)
  30. return self.run_test(run_obj, run_args, test_id)
  31. def setup(self, env):
  32. self.my_thread_pool = thread_pool.ThreadPool(
  33. self._bench,
  34. handle_output=self.handle_output_function,
  35. nthreads=env['nproc'],
  36. thread_id_arg='run_id',
  37. submit_skip_exit=env['quit_on_fail'],
  38. )
  39. def timed_main(self):
  40. # TODO bring this benchmark code back to life. Likely should go inside run with an option
  41. #gem5_insts() (
  42. # printf "instructions $(./gem5-stat --arch "$1" sim_insts)\n" >> "$self.env['test_boot_benchmark_file']"
  43. # newline
  44. #)
  45. #
  46. #qemu_insts() (
  47. # common_arch="$1"
  48. # ./qemu-trace2txt --arch "$common_arch"
  49. # common_qemu_trace_txt_file="$("$getvar" --arch "$common_arch" qemu_trace_txt_file)"
  50. # printf "instructions $(wc -l "${common_qemu_trace_txt_file}" | cut -d' ' -f1)\n" >> "$self.env['test_boot_benchmark_file']"
  51. # newline
  52. #)
  53. #
  54. #rm -f "${self.env['test_boot_benchmark_file']}"
  55. common_args = self.get_common_args()
  56. common_args['ctrl_c_host'] = True
  57. common_args['quit_after_boot'] = True
  58. # To see it blow up during development.
  59. # self.common_args['eval'] = 'insmod /lkmc/panic.ko'
  60. if (self.env['emulator'] == 'qemu' or
  61. (self.env['emulator'] == 'gem5' and self.env['size'] >= 2)):
  62. self.my_thread_pool.submit(common_args)
  63. if self.env['host_arch'] == self.env['arch']:
  64. # TODO: find out why it fails.
  65. if self.env['emulator'] != 'gem5':
  66. self.my_thread_pool.submit({**common_args, **{'kvm': True}})
  67. if self.env['emulator'] == 'qemu' and self.env['size'] >= 2:
  68. self.my_thread_pool.submit({**common_args, **{'trace': 'exec_tb'}})
  69. if self.env['emulator'] == 'gem5' and self.env['size'] >= 3:
  70. if self.env['arch'] == 'x86_64':
  71. cpu_types = [
  72. # TODO segfault
  73. #'DerivO3CPU'
  74. ]
  75. elif self.env['is_arm']:
  76. cpu_types = [
  77. 'DerivO3CPU',
  78. 'HPI',
  79. ]
  80. for cpu_type in cpu_types:
  81. self.my_thread_pool.submit({**common_args, **{
  82. 'extra_emulator_args': [
  83. '--cpu-type', cpu_type, LF,
  84. '--caches', LF,
  85. '--l2cache', LF,
  86. '--l1d_size', '1024kB', LF,
  87. '--l1i_size', '1024kB', LF,
  88. '--l2_size', '1024kB', LF,
  89. '--l3_size', '1024kB', LF,
  90. ],
  91. }})
  92. if self.env['arch'] == 'aarch64':
  93. # Do a fuller testing for aarch64.
  94. for build_type in ['debug', 'fast']:
  95. self.my_thread_pool.submit({**common_args, **{'gem5_build_type': build_type}})
  96. # Requires patching the executable.
  97. # self.my_thread_pool.submit({{**common_args, 'gem5_script': 'biglittle'}})
  98. def teardown(self):
  99. self.my_thread_pool.join()
  100. self._handle_thread_pool_errors(self.my_thread_pool)
  101. return super().teardown()
  102. if __name__ == '__main__':
  103. Main().cli()