test_efi_selftest.py 7.6 KB

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