blob: a3023c82567ca817001856d26ccf9fbc2a46a399 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heinrich Schuchardt45bb4dc2017-10-18 18:13:19 +02002/*
3 * efi_selftest_textoutput
4 *
5 * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
6 *
Heinrich Schuchardt45bb4dc2017-10-18 18:13:19 +02007 * 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 Schuchardtfbe90212022-01-20 19:48:20 +010018 * Return: EFI_ST_SUCCESS for success
Heinrich Schuchardt45bb4dc2017-10-18 18:13:19 +020019 */
20static int execute(void)
21{
22 size_t foreground;
23 size_t background;
24 size_t attrib;
25 efi_status_t ret;
Heinrich Schuchardt9c14ab22018-04-29 16:24:26 +020026 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 Schuchardt45bb4dc2017-10-18 18:13:19 +020033
Andre Przywara346382e2024-03-16 22:50:21 +010034 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 Przywara87564b22024-03-16 22:50:22 +010049 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 Grunau69392852024-03-16 22:50:23 +010063 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 Schuchardt45bb4dc2017-10-18 18:13:19 +020070 /* 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 Glass90975372022-01-23 12:55:12 -070083 u" !\"#$%&'()*+,-./0-9:;<=>?@A-Z[\\]^_`a-z{|}~\n");
Heinrich Schuchardt45bb4dc2017-10-18 18:13:19 +020084 if (ret != EFI_ST_SUCCESS) {
85 efi_st_error("TestString failed for ANSI characters\n");
86 return EFI_ST_FAILURE;
87 }
Heinrich Schuchardt9c14ab22018-04-29 16:24:26 +020088 /* OutputString */
89 ret = con_out->output_string(con_out,
Simon Glass90975372022-01-23 12:55:12 -070090 u"Testing cursor column update\n");
Heinrich Schuchardt9c14ab22018-04-29 16:24:26 +020091 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 Glass90975372022-01-23 12:55:12 -0700114 ret = con_out->output_string(con_out, u"123");
Heinrich Schuchardt9c14ab22018-04-29 16:24:26 +0200115 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 Glass90975372022-01-23 12:55:12 -0700123 ret = con_out->output_string(con_out, u"\b");
Heinrich Schuchardt9c14ab22018-04-29 16:24:26 +0200124 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 Glass90975372022-01-23 12:55:12 -0700132 ret = con_out->output_string(con_out, u"\b\b");
Heinrich Schuchardt9c14ab22018-04-29 16:24:26 +0200133 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 Glass90975372022-01-23 12:55:12 -0700141 ret = con_out->output_string(con_out, u"\b\b");
Heinrich Schuchardt9c14ab22018-04-29 16:24:26 +0200142 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 Przywara346382e2024-03-16 22:50:21 +0100158 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 Przywara87564b22024-03-16 22:50:22 +0100164 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 Grunau69392852024-03-16 22:50:23 +0100170 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 Schuchardt9c14ab22018-04-29 16:24:26 +0200176
Heinrich Schuchardt45bb4dc2017-10-18 18:13:19 +0200177 return EFI_ST_SUCCESS;
178}
179
180EFI_UNIT_TEST(textoutput) = {
181 .name = "text output",
182 .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
183 .execute = execute,
184};