Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heinrich Schuchardt | 45bb4dc | 2017-10-18 18:13:19 +0200 | [diff] [blame] | 2 | /* |
| 3 | * efi_selftest_textoutput |
| 4 | * |
| 5 | * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de> |
| 6 | * |
Heinrich Schuchardt | 45bb4dc | 2017-10-18 18:13:19 +0200 | [diff] [blame] | 7 | * Test the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL. |
| 8 | * |
| 9 | * The following services are tested: |
| 10 | * OutputString, TestString, SetAttribute. |
| 11 | */ |
| 12 | |
| 13 | #include <efi_selftest.h> |
| 14 | |
| 15 | /* |
| 16 | * Execute unit test. |
| 17 | * |
Heinrich Schuchardt | fbe9021 | 2022-01-20 19:48:20 +0100 | [diff] [blame] | 18 | * Return: EFI_ST_SUCCESS for success |
Heinrich Schuchardt | 45bb4dc | 2017-10-18 18:13:19 +0200 | [diff] [blame] | 19 | */ |
| 20 | static int execute(void) |
| 21 | { |
| 22 | size_t foreground; |
| 23 | size_t background; |
| 24 | size_t attrib; |
| 25 | efi_status_t ret; |
Heinrich Schuchardt | 9c14ab2 | 2018-04-29 16:24:26 +0200 | [diff] [blame] | 26 | s16 col; |
| 27 | u16 cr[] = { 0x0d, 0x00 }; |
| 28 | u16 lf[] = { 0x0a, 0x00 }; |
| 29 | u16 brahmi[] = { /* 2 Brahmi letters */ |
| 30 | 0xD804, 0xDC05, |
| 31 | 0xD804, 0xDC22, |
| 32 | 0}; |
Heinrich Schuchardt | 45bb4dc | 2017-10-18 18:13:19 +0200 | [diff] [blame] | 33 | |
Andre Przywara | 346382e | 2024-03-16 22:50:21 +0100 | [diff] [blame] | 34 | const u16 text[] = |
| 35 | u"This should render international characters as described\n" |
| 36 | u"U+00D6 \u00D6 - Latin capital letter O with diaresis\n" |
| 37 | u"U+00DF \u00DF - Latin small letter sharp s\n" |
| 38 | u"U+00E5 \u00E5 - Latin small letter a with ring above\n" |
| 39 | u"U+00E9 \u00E9 - Latin small letter e with acute\n" |
| 40 | u"U+00F1 \u00F1 - Latin small letter n with tilde\n" |
| 41 | u"U+00F6 \u00F6 - Latin small letter o with diaresis\n" |
| 42 | u"The following characters will render as '?' with bitmap fonts\n" |
| 43 | u"U+00F8 \u00F8 - Latin small letter o with stroke\n" |
| 44 | u"U+03AC \u03AC - Greek small letter alpha with tonus\n" |
| 45 | u"U+03BB \u03BB - Greek small letter lambda\n" |
| 46 | u"U+03C2 \u03C2 - Greek small letter final sigma\n" |
| 47 | u"U+1F19 \u1F19 - Greek capital letter epsilon with dasia\n"; |
| 48 | |
Andre Przywara | 87564b2 | 2024-03-16 22:50:22 +0100 | [diff] [blame] | 49 | const u16 boxes[] = |
| 50 | u"This should render as four boxes with text\n" |
| 51 | u"\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" |
| 52 | u"\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500" |
| 53 | u"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502" |
| 54 | u" left top \u2502 right top \u2502\n\u251c\u2500" |
| 55 | u"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" |
| 56 | u"\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" |
| 57 | u"\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 " |
| 58 | u"left bottom \u2502 right bottom \u2502\n\u2514\u2500\u2500\u2500" |
| 59 | u"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534" |
| 60 | u"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" |
| 61 | u"\u2500\u2500\u2500\u2500\u2518\n"; |
| 62 | |
Janne Grunau | 6939285 | 2024-03-16 22:50:23 +0100 | [diff] [blame] | 63 | const u16 shapes[] = |
| 64 | u"Geometric shapes as described\n" |
| 65 | u"U+25B2 \u25B2 - Black up-pointing triangle\n" |
| 66 | u"U+25BA \u25BA - Black right-pointing pointer\n" |
| 67 | u"U+25BC \u25BC - Black down-pointing triangle\n" |
| 68 | u"U+25C4 \u25C4 - Black left-pointing pointer\n"; |
| 69 | |
Heinrich Schuchardt | 45bb4dc | 2017-10-18 18:13:19 +0200 | [diff] [blame] | 70 | /* SetAttribute */ |
| 71 | efi_st_printf("\nColor palette\n"); |
| 72 | for (foreground = 0; foreground < 0x10; ++foreground) { |
| 73 | for (background = 0; background < 0x80; background += 0x10) { |
| 74 | attrib = foreground | background; |
| 75 | con_out->set_attribute(con_out, attrib); |
| 76 | efi_st_printf("%p", (void *)attrib); |
| 77 | } |
| 78 | con_out->set_attribute(con_out, 0); |
| 79 | efi_st_printf("\n"); |
| 80 | } |
| 81 | /* TestString */ |
| 82 | ret = con_out->test_string(con_out, |
Simon Glass | 9097537 | 2022-01-23 12:55:12 -0700 | [diff] [blame] | 83 | u" !\"#$%&'()*+,-./0-9:;<=>?@A-Z[\\]^_`a-z{|}~\n"); |
Heinrich Schuchardt | 45bb4dc | 2017-10-18 18:13:19 +0200 | [diff] [blame] | 84 | if (ret != EFI_ST_SUCCESS) { |
| 85 | efi_st_error("TestString failed for ANSI characters\n"); |
| 86 | return EFI_ST_FAILURE; |
| 87 | } |
Heinrich Schuchardt | 9c14ab2 | 2018-04-29 16:24:26 +0200 | [diff] [blame] | 88 | /* OutputString */ |
| 89 | ret = con_out->output_string(con_out, |
Simon Glass | 9097537 | 2022-01-23 12:55:12 -0700 | [diff] [blame] | 90 | u"Testing cursor column update\n"); |
Heinrich Schuchardt | 9c14ab2 | 2018-04-29 16:24:26 +0200 | [diff] [blame] | 91 | if (ret != EFI_ST_SUCCESS) { |
| 92 | efi_st_error("OutputString failed for ANSI characters"); |
| 93 | return EFI_ST_FAILURE; |
| 94 | } |
| 95 | col = con_out->mode->cursor_column; |
| 96 | ret = con_out->output_string(con_out, lf); |
| 97 | if (ret != EFI_ST_SUCCESS) { |
| 98 | efi_st_error("OutputString failed for line feed\n"); |
| 99 | return EFI_ST_FAILURE; |
| 100 | } |
| 101 | if (con_out->mode->cursor_column != col) { |
| 102 | efi_st_error("Cursor column changed by line feed\n"); |
| 103 | return EFI_ST_FAILURE; |
| 104 | } |
| 105 | ret = con_out->output_string(con_out, cr); |
| 106 | if (ret != EFI_ST_SUCCESS) { |
| 107 | efi_st_error("OutputString failed for carriage return\n"); |
| 108 | return EFI_ST_FAILURE; |
| 109 | } |
| 110 | if (con_out->mode->cursor_column) { |
| 111 | efi_st_error("Cursor column not 0 at beginning of line\n"); |
| 112 | return EFI_ST_FAILURE; |
| 113 | } |
Simon Glass | 9097537 | 2022-01-23 12:55:12 -0700 | [diff] [blame] | 114 | ret = con_out->output_string(con_out, u"123"); |
Heinrich Schuchardt | 9c14ab2 | 2018-04-29 16:24:26 +0200 | [diff] [blame] | 115 | if (ret != EFI_ST_SUCCESS) { |
| 116 | efi_st_error("OutputString failed for ANSI characters\n"); |
| 117 | return EFI_ST_FAILURE; |
| 118 | } |
| 119 | if (con_out->mode->cursor_column != 3) { |
| 120 | efi_st_error("Cursor column not incremented properly\n"); |
| 121 | return EFI_ST_FAILURE; |
| 122 | } |
Simon Glass | 9097537 | 2022-01-23 12:55:12 -0700 | [diff] [blame] | 123 | ret = con_out->output_string(con_out, u"\b"); |
Heinrich Schuchardt | 9c14ab2 | 2018-04-29 16:24:26 +0200 | [diff] [blame] | 124 | if (ret != EFI_ST_SUCCESS) { |
| 125 | efi_st_error("OutputString failed for backspace\n"); |
| 126 | return EFI_ST_FAILURE; |
| 127 | } |
| 128 | if (con_out->mode->cursor_column != 2) { |
| 129 | efi_st_error("Cursor column not decremented properly\n"); |
| 130 | return EFI_ST_FAILURE; |
| 131 | } |
Simon Glass | 9097537 | 2022-01-23 12:55:12 -0700 | [diff] [blame] | 132 | ret = con_out->output_string(con_out, u"\b\b"); |
Heinrich Schuchardt | 9c14ab2 | 2018-04-29 16:24:26 +0200 | [diff] [blame] | 133 | if (ret != EFI_ST_SUCCESS) { |
| 134 | efi_st_error("OutputString failed for backspace\n"); |
| 135 | return EFI_ST_FAILURE; |
| 136 | } |
| 137 | if (con_out->mode->cursor_column) { |
| 138 | efi_st_error("Cursor column not decremented properly\n"); |
| 139 | return EFI_ST_FAILURE; |
| 140 | } |
Simon Glass | 9097537 | 2022-01-23 12:55:12 -0700 | [diff] [blame] | 141 | ret = con_out->output_string(con_out, u"\b\b"); |
Heinrich Schuchardt | 9c14ab2 | 2018-04-29 16:24:26 +0200 | [diff] [blame] | 142 | if (ret != EFI_ST_SUCCESS) { |
| 143 | efi_st_error("OutputString failed for backspace\n"); |
| 144 | return EFI_ST_FAILURE; |
| 145 | } |
| 146 | if (con_out->mode->cursor_column) { |
| 147 | efi_st_error("Cursor column decremented past zero\n"); |
| 148 | return EFI_ST_FAILURE; |
| 149 | } |
| 150 | ret = con_out->output_string(con_out, brahmi); |
| 151 | if (ret != EFI_ST_SUCCESS) { |
| 152 | efi_st_todo("Unicode output not fully supported\n"); |
| 153 | } else if (con_out->mode->cursor_column != 2) { |
| 154 | efi_st_printf("Unicode not handled properly\n"); |
| 155 | return EFI_ST_FAILURE; |
| 156 | } |
| 157 | efi_st_printf("\n"); |
Andre Przywara | 346382e | 2024-03-16 22:50:21 +0100 | [diff] [blame] | 158 | ret = con_out->output_string(con_out, text); |
| 159 | if (ret != EFI_ST_SUCCESS) { |
| 160 | efi_st_error("OutputString failed for international chars\n"); |
| 161 | return EFI_ST_FAILURE; |
| 162 | } |
| 163 | efi_st_printf("\n"); |
Andre Przywara | 87564b2 | 2024-03-16 22:50:22 +0100 | [diff] [blame] | 164 | ret = con_out->output_string(con_out, boxes); |
| 165 | if (ret != EFI_ST_SUCCESS) { |
| 166 | efi_st_error("OutputString failed for box drawing chars\n"); |
| 167 | return EFI_ST_FAILURE; |
| 168 | } |
| 169 | efi_st_printf("\n"); |
Janne Grunau | 6939285 | 2024-03-16 22:50:23 +0100 | [diff] [blame] | 170 | ret = con_out->output_string(con_out, shapes); |
| 171 | if (ret != EFI_ST_SUCCESS) { |
| 172 | efi_st_error("OutputString failed for geometric shapes\n"); |
| 173 | return EFI_ST_FAILURE; |
| 174 | } |
| 175 | efi_st_printf("\n"); |
Heinrich Schuchardt | 9c14ab2 | 2018-04-29 16:24:26 +0200 | [diff] [blame] | 176 | |
Heinrich Schuchardt | 45bb4dc | 2017-10-18 18:13:19 +0200 | [diff] [blame] | 177 | return EFI_ST_SUCCESS; |
| 178 | } |
| 179 | |
| 180 | EFI_UNIT_TEST(textoutput) = { |
| 181 | .name = "text output", |
| 182 | .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, |
| 183 | .execute = execute, |
| 184 | }; |