test_efi_selftest.py 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. # SPDX-License-Identifier: GPL-2.0
  2. # Copyright (c) 2017, Heinrich Schuchardt <xypron.glpk@gmx.de>
  3. """
  4. Test UEFI API implementation
  5. """
  6. import pytest
  7. @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
  8. def test_efi_selftest(u_boot_console):
  9. """Run UEFI unit tests
  10. :param u_boot_console: U-Boot console
  11. This function executes all selftests that are not marked as on request.
  12. """
  13. u_boot_console.run_command(cmd='setenv efi_selftest')
  14. u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
  15. m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
  16. if m != 0:
  17. raise Exception('Failures occurred during the EFI selftest')
  18. u_boot_console.restart_uboot()
  19. @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
  20. @pytest.mark.buildconfigspec('hush_parser')
  21. @pytest.mark.buildconfigspec('of_control')
  22. @pytest.mark.notbuildconfigspec('generate_acpi_table')
  23. def test_efi_selftest_device_tree(u_boot_console):
  24. """Test the device tree support in the UEFI sub-system
  25. :param u_boot_console: U-Boot console
  26. This test executes the UEFI unit test by calling 'bootefi selftest'.
  27. """
  28. u_boot_console.run_command(cmd='setenv efi_selftest list')
  29. output = u_boot_console.run_command('bootefi selftest')
  30. assert '\'device tree\'' in output
  31. u_boot_console.run_command(cmd='setenv efi_selftest device tree')
  32. # Set serial# if it is not already set.
  33. u_boot_console.run_command(cmd='setenv efi_test "${serial#}x"')
  34. u_boot_console.run_command(cmd='test "${efi_test}" = x && setenv serial# 0')
  35. u_boot_console.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False)
  36. m = u_boot_console.p.expect(['serial-number:', 'U-Boot'])
  37. if m != 0:
  38. raise Exception('serial-number missing in device tree')
  39. u_boot_console.restart_uboot()
  40. @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
  41. def test_efi_selftest_watchdog_reboot(u_boot_console):
  42. """Test the watchdog timer
  43. :param u_boot_console: U-Boot console
  44. This function executes the 'watchdog reboot' unit test.
  45. """
  46. u_boot_console.run_command(cmd='setenv efi_selftest list')
  47. output = u_boot_console.run_command('bootefi selftest')
  48. assert '\'watchdog reboot\'' in output
  49. u_boot_console.run_command(cmd='setenv efi_selftest watchdog reboot')
  50. u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
  51. m = u_boot_console.p.expect(['resetting', 'U-Boot'])
  52. if m != 0:
  53. raise Exception('Reset failed in \'watchdog reboot\' test')
  54. u_boot_console.restart_uboot()
  55. @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
  56. def test_efi_selftest_text_input(u_boot_console):
  57. """Test the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
  58. :param u_boot_console: U-Boot console
  59. This function calls the text input EFI selftest.
  60. """
  61. u_boot_console.run_command(cmd='setenv efi_selftest text input')
  62. output = u_boot_console.run_command(cmd='bootefi selftest',
  63. wait_for_prompt=False)
  64. m = u_boot_console.p.expect([r'To terminate type \'x\''])
  65. if m != 0:
  66. raise Exception('No prompt for \'text input\' test')
  67. u_boot_console.drain_console()
  68. u_boot_console.p.timeout = 500
  69. # EOT
  70. u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
  71. send_nl=False, wait_for_prompt=False)
  72. m = u_boot_console.p.expect(
  73. [r'Unicode char 4 \(unknown\), scan code 0 \(Null\)'])
  74. if m != 0:
  75. raise Exception('EOT failed in \'text input\' test')
  76. u_boot_console.drain_console()
  77. # BS
  78. u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
  79. send_nl=False, wait_for_prompt=False)
  80. m = u_boot_console.p.expect(
  81. [r'Unicode char 8 \(BS\), scan code 0 \(Null\)'])
  82. if m != 0:
  83. raise Exception('BS failed in \'text input\' test')
  84. u_boot_console.drain_console()
  85. # TAB
  86. u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
  87. send_nl=False, wait_for_prompt=False)
  88. m = u_boot_console.p.expect(
  89. [r'Unicode char 9 \(TAB\), scan code 0 \(Null\)'])
  90. if m != 0:
  91. raise Exception('BS failed in \'text input\' test')
  92. u_boot_console.drain_console()
  93. # a
  94. u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
  95. wait_for_prompt=False)
  96. m = u_boot_console.p.expect(
  97. [r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])
  98. if m != 0:
  99. raise Exception('\'a\' failed in \'text input\' test')
  100. u_boot_console.drain_console()
  101. # UP escape sequence
  102. u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
  103. send_nl=False, wait_for_prompt=False)
  104. m = u_boot_console.p.expect(
  105. [r'Unicode char 0 \(Null\), scan code 1 \(Up\)'])
  106. if m != 0:
  107. raise Exception('UP failed in \'text input\' test')
  108. u_boot_console.drain_console()
  109. # Euro sign
  110. u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
  111. send_nl=False, wait_for_prompt=False)
  112. m = u_boot_console.p.expect([r'Unicode char 8364 \(\''])
  113. if m != 0:
  114. raise Exception('Euro sign failed in \'text input\' test')
  115. u_boot_console.drain_console()
  116. u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False,
  117. wait_for_prompt=False)
  118. m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
  119. if m != 0:
  120. raise Exception('Failures occurred during the EFI selftest')
  121. u_boot_console.restart_uboot()
  122. @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
  123. def test_efi_selftest_text_input_ex(u_boot_console):
  124. """Test the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
  125. :param u_boot_console: U-Boot console
  126. This function calls the extended text input EFI selftest.
  127. """
  128. u_boot_console.run_command(cmd='setenv efi_selftest extended text input')
  129. output = u_boot_console.run_command(cmd='bootefi selftest',
  130. wait_for_prompt=False)
  131. m = u_boot_console.p.expect([r'To terminate type \'CTRL\+x\''])
  132. if m != 0:
  133. raise Exception('No prompt for \'text input\' test')
  134. u_boot_console.drain_console()
  135. u_boot_console.p.timeout = 500
  136. # EOT
  137. u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
  138. send_nl=False, wait_for_prompt=False)
  139. m = u_boot_console.p.expect(
  140. [r'Unicode char 100 \(\'d\'\), scan code 0 \(CTRL\+Null\)'])
  141. if m != 0:
  142. raise Exception('EOT failed in \'text input\' test')
  143. u_boot_console.drain_console()
  144. # BS
  145. u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
  146. send_nl=False, wait_for_prompt=False)
  147. m = u_boot_console.p.expect(
  148. [r'Unicode char 8 \(BS\), scan code 0 \(\+Null\)'])
  149. if m != 0:
  150. raise Exception('BS failed in \'text input\' test')
  151. u_boot_console.drain_console()
  152. # TAB
  153. u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
  154. send_nl=False, wait_for_prompt=False)
  155. m = u_boot_console.p.expect(
  156. [r'Unicode char 9 \(TAB\), scan code 0 \(\+Null\)'])
  157. if m != 0:
  158. raise Exception('TAB failed in \'text input\' test')
  159. u_boot_console.drain_console()
  160. # a
  161. u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
  162. wait_for_prompt=False)
  163. m = u_boot_console.p.expect(
  164. [r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])
  165. if m != 0:
  166. raise Exception('\'a\' failed in \'text input\' test')
  167. u_boot_console.drain_console()
  168. # UP escape sequence
  169. u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
  170. send_nl=False, wait_for_prompt=False)
  171. m = u_boot_console.p.expect(
  172. [r'Unicode char 0 \(Null\), scan code 1 \(\+Up\)'])
  173. if m != 0:
  174. raise Exception('UP failed in \'text input\' test')
  175. u_boot_console.drain_console()
  176. # Euro sign
  177. u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
  178. send_nl=False, wait_for_prompt=False)
  179. m = u_boot_console.p.expect([r'Unicode char 8364 \(\''])
  180. if m != 0:
  181. raise Exception('Euro sign failed in \'text input\' test')
  182. u_boot_console.drain_console()
  183. # SHIFT+ALT+FN 5
  184. u_boot_console.run_command(cmd=b'\x1b\x5b\x31\x35\x3b\x34\x7e'.decode(),
  185. wait_for_echo=False, send_nl=False,
  186. wait_for_prompt=False)
  187. m = u_boot_console.p.expect(
  188. [r'Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)'])
  189. if m != 0:
  190. raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test')
  191. u_boot_console.drain_console()
  192. u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False,
  193. wait_for_prompt=False)
  194. m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
  195. if m != 0:
  196. raise Exception('Failures occurred during the EFI selftest')
  197. u_boot_console.restart_uboot()