test_efi_selftest.py 7.6 KB

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