blob: cc44b38bc23ac2efb70ccfadbef714246f6a9aa1 [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
34 /* SetAttribute */
35 efi_st_printf("\nColor palette\n");
36 for (foreground = 0; foreground < 0x10; ++foreground) {
37 for (background = 0; background < 0x80; background += 0x10) {
38 attrib = foreground | background;
39 con_out->set_attribute(con_out, attrib);
40 efi_st_printf("%p", (void *)attrib);
41 }
42 con_out->set_attribute(con_out, 0);
43 efi_st_printf("\n");
44 }
45 /* TestString */
46 ret = con_out->test_string(con_out,
Simon Glass90975372022-01-23 12:55:12 -070047 u" !\"#$%&'()*+,-./0-9:;<=>?@A-Z[\\]^_`a-z{|}~\n");
Heinrich Schuchardt45bb4dc2017-10-18 18:13:19 +020048 if (ret != EFI_ST_SUCCESS) {
49 efi_st_error("TestString failed for ANSI characters\n");
50 return EFI_ST_FAILURE;
51 }
Heinrich Schuchardt9c14ab22018-04-29 16:24:26 +020052 /* OutputString */
53 ret = con_out->output_string(con_out,
Simon Glass90975372022-01-23 12:55:12 -070054 u"Testing cursor column update\n");
Heinrich Schuchardt9c14ab22018-04-29 16:24:26 +020055 if (ret != EFI_ST_SUCCESS) {
56 efi_st_error("OutputString failed for ANSI characters");
57 return EFI_ST_FAILURE;
58 }
59 col = con_out->mode->cursor_column;
60 ret = con_out->output_string(con_out, lf);
61 if (ret != EFI_ST_SUCCESS) {
62 efi_st_error("OutputString failed for line feed\n");
63 return EFI_ST_FAILURE;
64 }
65 if (con_out->mode->cursor_column != col) {
66 efi_st_error("Cursor column changed by line feed\n");
67 return EFI_ST_FAILURE;
68 }
69 ret = con_out->output_string(con_out, cr);
70 if (ret != EFI_ST_SUCCESS) {
71 efi_st_error("OutputString failed for carriage return\n");
72 return EFI_ST_FAILURE;
73 }
74 if (con_out->mode->cursor_column) {
75 efi_st_error("Cursor column not 0 at beginning of line\n");
76 return EFI_ST_FAILURE;
77 }
Simon Glass90975372022-01-23 12:55:12 -070078 ret = con_out->output_string(con_out, u"123");
Heinrich Schuchardt9c14ab22018-04-29 16:24:26 +020079 if (ret != EFI_ST_SUCCESS) {
80 efi_st_error("OutputString failed for ANSI characters\n");
81 return EFI_ST_FAILURE;
82 }
83 if (con_out->mode->cursor_column != 3) {
84 efi_st_error("Cursor column not incremented properly\n");
85 return EFI_ST_FAILURE;
86 }
Simon Glass90975372022-01-23 12:55:12 -070087 ret = con_out->output_string(con_out, u"\b");
Heinrich Schuchardt9c14ab22018-04-29 16:24:26 +020088 if (ret != EFI_ST_SUCCESS) {
89 efi_st_error("OutputString failed for backspace\n");
90 return EFI_ST_FAILURE;
91 }
92 if (con_out->mode->cursor_column != 2) {
93 efi_st_error("Cursor column not decremented properly\n");
94 return EFI_ST_FAILURE;
95 }
Simon Glass90975372022-01-23 12:55:12 -070096 ret = con_out->output_string(con_out, u"\b\b");
Heinrich Schuchardt9c14ab22018-04-29 16:24:26 +020097 if (ret != EFI_ST_SUCCESS) {
98 efi_st_error("OutputString failed for backspace\n");
99 return EFI_ST_FAILURE;
100 }
101 if (con_out->mode->cursor_column) {
102 efi_st_error("Cursor column not decremented properly\n");
103 return EFI_ST_FAILURE;
104 }
Simon Glass90975372022-01-23 12:55:12 -0700105 ret = con_out->output_string(con_out, u"\b\b");
Heinrich Schuchardt9c14ab22018-04-29 16:24:26 +0200106 if (ret != EFI_ST_SUCCESS) {
107 efi_st_error("OutputString failed for backspace\n");
108 return EFI_ST_FAILURE;
109 }
110 if (con_out->mode->cursor_column) {
111 efi_st_error("Cursor column decremented past zero\n");
112 return EFI_ST_FAILURE;
113 }
114 ret = con_out->output_string(con_out, brahmi);
115 if (ret != EFI_ST_SUCCESS) {
116 efi_st_todo("Unicode output not fully supported\n");
117 } else if (con_out->mode->cursor_column != 2) {
118 efi_st_printf("Unicode not handled properly\n");
119 return EFI_ST_FAILURE;
120 }
121 efi_st_printf("\n");
122
Heinrich Schuchardt45bb4dc2017-10-18 18:13:19 +0200123 return EFI_ST_SUCCESS;
124}
125
126EFI_UNIT_TEST(textoutput) = {
127 .name = "text output",
128 .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
129 .execute = execute,
130};