efi_selftest_textoutput.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * efi_selftest_textoutput
  4. *
  5. * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
  6. *
  7. * Test the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.
  8. *
  9. * The following services are tested:
  10. * OutputString, TestString, SetAttribute.
  11. */
  12. #include <efi_selftest.h>
  13. /*
  14. * Execute unit test.
  15. *
  16. * @return: EFI_ST_SUCCESS for success
  17. */
  18. static int execute(void)
  19. {
  20. size_t foreground;
  21. size_t background;
  22. size_t attrib;
  23. efi_status_t ret;
  24. s16 col;
  25. u16 cr[] = { 0x0d, 0x00 };
  26. u16 lf[] = { 0x0a, 0x00 };
  27. u16 brahmi[] = { /* 2 Brahmi letters */
  28. 0xD804, 0xDC05,
  29. 0xD804, 0xDC22,
  30. 0};
  31. /* SetAttribute */
  32. efi_st_printf("\nColor palette\n");
  33. for (foreground = 0; foreground < 0x10; ++foreground) {
  34. for (background = 0; background < 0x80; background += 0x10) {
  35. attrib = foreground | background;
  36. con_out->set_attribute(con_out, attrib);
  37. efi_st_printf("%p", (void *)attrib);
  38. }
  39. con_out->set_attribute(con_out, 0);
  40. efi_st_printf("\n");
  41. }
  42. /* TestString */
  43. ret = con_out->test_string(con_out,
  44. L" !\"#$%&'()*+,-./0-9:;<=>?@A-Z[\\]^_`a-z{|}~\n");
  45. if (ret != EFI_ST_SUCCESS) {
  46. efi_st_error("TestString failed for ANSI characters\n");
  47. return EFI_ST_FAILURE;
  48. }
  49. /* OutputString */
  50. ret = con_out->output_string(con_out,
  51. L"Testing cursor column update\n");
  52. if (ret != EFI_ST_SUCCESS) {
  53. efi_st_error("OutputString failed for ANSI characters");
  54. return EFI_ST_FAILURE;
  55. }
  56. col = con_out->mode->cursor_column;
  57. ret = con_out->output_string(con_out, lf);
  58. if (ret != EFI_ST_SUCCESS) {
  59. efi_st_error("OutputString failed for line feed\n");
  60. return EFI_ST_FAILURE;
  61. }
  62. if (con_out->mode->cursor_column != col) {
  63. efi_st_error("Cursor column changed by line feed\n");
  64. return EFI_ST_FAILURE;
  65. }
  66. ret = con_out->output_string(con_out, cr);
  67. if (ret != EFI_ST_SUCCESS) {
  68. efi_st_error("OutputString failed for carriage return\n");
  69. return EFI_ST_FAILURE;
  70. }
  71. if (con_out->mode->cursor_column) {
  72. efi_st_error("Cursor column not 0 at beginning of line\n");
  73. return EFI_ST_FAILURE;
  74. }
  75. ret = con_out->output_string(con_out, L"123");
  76. if (ret != EFI_ST_SUCCESS) {
  77. efi_st_error("OutputString failed for ANSI characters\n");
  78. return EFI_ST_FAILURE;
  79. }
  80. if (con_out->mode->cursor_column != 3) {
  81. efi_st_error("Cursor column not incremented properly\n");
  82. return EFI_ST_FAILURE;
  83. }
  84. ret = con_out->output_string(con_out, L"\b");
  85. if (ret != EFI_ST_SUCCESS) {
  86. efi_st_error("OutputString failed for backspace\n");
  87. return EFI_ST_FAILURE;
  88. }
  89. if (con_out->mode->cursor_column != 2) {
  90. efi_st_error("Cursor column not decremented properly\n");
  91. return EFI_ST_FAILURE;
  92. }
  93. ret = con_out->output_string(con_out, L"\b\b");
  94. if (ret != EFI_ST_SUCCESS) {
  95. efi_st_error("OutputString failed for backspace\n");
  96. return EFI_ST_FAILURE;
  97. }
  98. if (con_out->mode->cursor_column) {
  99. efi_st_error("Cursor column not decremented properly\n");
  100. return EFI_ST_FAILURE;
  101. }
  102. ret = con_out->output_string(con_out, L"\b\b");
  103. if (ret != EFI_ST_SUCCESS) {
  104. efi_st_error("OutputString failed for backspace\n");
  105. return EFI_ST_FAILURE;
  106. }
  107. if (con_out->mode->cursor_column) {
  108. efi_st_error("Cursor column decremented past zero\n");
  109. return EFI_ST_FAILURE;
  110. }
  111. ret = con_out->output_string(con_out, brahmi);
  112. if (ret != EFI_ST_SUCCESS) {
  113. efi_st_todo("Unicode output not fully supported\n");
  114. } else if (con_out->mode->cursor_column != 2) {
  115. efi_st_printf("Unicode not handled properly\n");
  116. return EFI_ST_FAILURE;
  117. }
  118. efi_st_printf("\n");
  119. return EFI_ST_SUCCESS;
  120. }
  121. EFI_UNIT_TEST(textoutput) = {
  122. .name = "text output",
  123. .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
  124. .execute = execute,
  125. };