test_efi_selftest.py 9.2 KB

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