Commit 853540c84fdad4c2b0755c0041e87efba376aec2

Authored by Heinrich Schuchardt
Committed by Alexander Graf
1 parent ac02019616

efi_selftest: colored test output

Add color coding to output:
test section    blue
success         green
errors          red
todo            yellow
summary         white
others          light gray

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
[agraf: Fold in move of set_attribute before the print]
Signed-off-by: Alexander Graf <agraf@suse.de>

Showing 3 changed files with 40 additions and 25 deletions Side-by-side Diff

include/efi_selftest.h
... ... @@ -19,13 +19,19 @@
19 19 #define EFI_ST_FAILURE 1
20 20  
21 21 /*
  22 + * Prints a message.
  23 + */
  24 +#define efi_st_printf(...) \
  25 + (efi_st_printc(-1, __VA_ARGS__))
  26 +
  27 +/*
22 28 * Prints an error message.
23 29 *
24 30 * @... format string followed by fields to print
25 31 */
26 32 #define efi_st_error(...) \
27   - (efi_st_printf("%s(%u):\nERROR: ", __FILE__, __LINE__), \
28   - efi_st_printf(__VA_ARGS__)) \
  33 + (efi_st_printc(EFI_LIGHTRED, "%s(%u):\nERROR: ", __FILE__, __LINE__), \
  34 + efi_st_printc(EFI_LIGHTRED, __VA_ARGS__))
29 35  
30 36 /*
31 37 * Prints a TODO message.
... ... @@ -33,8 +39,8 @@
33 39 * @... format string followed by fields to print
34 40 */
35 41 #define efi_st_todo(...) \
36   - (efi_st_printf("%s(%u):\nTODO: ", __FILE__, __LINE__), \
37   - efi_st_printf(__VA_ARGS__)) \
  42 + (efi_st_printc(EFI_YELLOW, "%s(%u):\nTODO: ", __FILE__, __LINE__), \
  43 + efi_st_printc(EFI_YELLOW, __VA_ARGS__)) \
38 44  
39 45 /*
40 46 * A test may be setup and executed at boottime,
41 47  
42 48  
... ... @@ -61,14 +67,15 @@
61 67 void efi_st_exit_boot_services(void);
62 68  
63 69 /*
64   - * Print a pointer to an u16 string
  70 + * Print a colored message
65 71 *
66   - * @pointer: pointer
67   - * @buf: pointer to buffer address
68   - * on return position of terminating zero word
  72 + * @color color, see constants in efi_api.h, use -1 for no color
  73 + * @fmt printf format
  74 + * @... arguments to be printed
  75 + * on return position of terminating zero word
69 76 */
70   -void efi_st_printf(const char *fmt, ...)
71   - __attribute__ ((format (__printf__, 1, 2)));
  77 +void efi_st_printc(int color, const char *fmt, ...)
  78 + __attribute__ ((format (__printf__, 2, 3)));
72 79  
73 80 /*
74 81 * Compare memory.
lib/efi_selftest/efi_selftest.c
... ... @@ -65,7 +65,7 @@
65 65 efi_st_error("ExitBootServices did not return EFI_SUCCESS\n");
66 66 return;
67 67 }
68   - efi_st_printf("\nBoot services terminated\n");
  68 + efi_st_printc(EFI_WHITE, "\nBoot services terminated\n");
69 69 }
70 70  
71 71 /*
72 72  
... ... @@ -81,13 +81,14 @@
81 81  
82 82 if (!test->setup)
83 83 return EFI_ST_SUCCESS;
84   - efi_st_printf("\nSetting up '%s'\n", test->name);
  84 + efi_st_printc(EFI_LIGHTBLUE, "\nSetting up '%s'\n", test->name);
85 85 ret = test->setup(handle, systable);
86 86 if (ret != EFI_ST_SUCCESS) {
87 87 efi_st_error("Setting up '%s' failed\n", test->name);
88 88 ++*failures;
89 89 } else {
90   - efi_st_printf("Setting up '%s' succeeded\n", test->name);
  90 + efi_st_printc(EFI_LIGHTGREEN,
  91 + "Setting up '%s' succeeded\n", test->name);
91 92 }
92 93 return ret;
93 94 }
94 95  
... ... @@ -105,13 +106,14 @@
105 106  
106 107 if (!test->execute)
107 108 return EFI_ST_SUCCESS;
108   - efi_st_printf("\nExecuting '%s'\n", test->name);
  109 + efi_st_printc(EFI_LIGHTBLUE, "\nExecuting '%s'\n", test->name);
109 110 ret = test->execute();
110 111 if (ret != EFI_ST_SUCCESS) {
111 112 efi_st_error("Executing '%s' failed\n", test->name);
112 113 ++*failures;
113 114 } else {
114   - efi_st_printf("Executing '%s' succeeded\n", test->name);
  115 + efi_st_printc(EFI_LIGHTGREEN,
  116 + "Executing '%s' succeeded\n", test->name);
115 117 }
116 118 return ret;
117 119 }
118 120  
... ... @@ -129,13 +131,14 @@
129 131  
130 132 if (!test->teardown)
131 133 return EFI_ST_SUCCESS;
132   - efi_st_printf("\nTearing down '%s'\n", test->name);
  134 + efi_st_printc(EFI_LIGHTBLUE, "\nTearing down '%s'\n", test->name);
133 135 ret = test->teardown();
134 136 if (ret != EFI_ST_SUCCESS) {
135 137 efi_st_error("Tearing down '%s' failed\n", test->name);
136 138 ++*failures;
137 139 } else {
138   - efi_st_printf("Tearing down '%s' succeeded\n", test->name);
  140 + efi_st_printc(EFI_LIGHTGREEN,
  141 + "Tearing down '%s' succeeded\n", test->name);
139 142 }
140 143 return ret;
141 144 }
142 145  
143 146  
... ... @@ -262,12 +265,12 @@
262 265 }
263 266 }
264 267  
265   - efi_st_printf("\nTesting EFI API implementation\n");
  268 + efi_st_printc(EFI_WHITE, "\nTesting EFI API implementation\n");
266 269  
267 270 if (testname)
268   - efi_st_printf("\nSelected test: '%ps'\n", testname);
  271 + efi_st_printc(EFI_WHITE, "\nSelected test: '%ps'\n", testname);
269 272 else
270   - efi_st_printf("\nNumber of tests to execute: %u\n",
  273 + efi_st_printc(EFI_WHITE, "\nNumber of tests to execute: %u\n",
271 274 ll_entry_count(struct efi_unit_test,
272 275 efi_unit_test));
273 276  
... ... @@ -291,7 +294,7 @@
291 294 &failures);
292 295  
293 296 /* Give feedback */
294   - efi_st_printf("\nSummary: %u failures\n\n", failures);
  297 + efi_st_printc(EFI_WHITE, "\nSummary: %u failures\n\n", failures);
295 298  
296 299 /* Reset system */
297 300 efi_st_printf("Preparing for reset. Press any key.\n");
lib/efi_selftest/efi_selftest_console.c
... ... @@ -130,12 +130,13 @@
130 130 }
131 131  
132 132 /*
133   - * Print a formatted string to the EFI console
  133 + * Print a colored formatted string to the EFI console
134 134 *
135   - * @fmt: format string
136   - * @...: optional arguments
  135 + * @color color, see constants in efi_api.h, use -1 for no color
  136 + * @fmt format string
  137 + * @... optional arguments
137 138 */
138   -void efi_st_printf(const char *fmt, ...)
  139 +void efi_st_printc(int color, const char *fmt, ...)
139 140 {
140 141 va_list args;
141 142 u16 buf[160];
... ... @@ -146,6 +147,8 @@
146 147  
147 148 va_start(args, fmt);
148 149  
  150 + if (color >= 0)
  151 + con_out->set_attribute(con_out, (unsigned long)color);
149 152 c = fmt;
150 153 for (; *c; ++c) {
151 154 switch (*c) {
... ... @@ -220,6 +223,8 @@
220 223 va_end(args);
221 224 *pos = 0;
222 225 con_out->output_string(con_out, buf);
  226 + if (color >= 0)
  227 + con_out->set_attribute(con_out, EFI_LIGHTGRAY);
223 228 }
224 229  
225 230 /*