All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 01/16] efi_selftest: colored test output
Date: Thu, 11 Jan 2018 08:15:54 +0100	[thread overview]
Message-ID: <20180111071609.4058-2-xypron.glpk@gmx.de> (raw)
In-Reply-To: <20180111071609.4058-1-xypron.glpk@gmx.de>

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>
---
v3
	add more comments for function parameters
v2
	no change
---
 include/efi_selftest.h                  | 27 +++++++++++++++++----------
 lib/efi_selftest/efi_selftest.c         | 25 ++++++++++++++-----------
 lib/efi_selftest/efi_selftest_console.c | 13 +++++++++----
 3 files changed, 40 insertions(+), 25 deletions(-)

diff --git a/include/efi_selftest.h b/include/efi_selftest.h
index be5ba4bfa9..08dd8e43ad 100644
--- a/include/efi_selftest.h
+++ b/include/efi_selftest.h
@@ -18,14 +18,20 @@
 #define EFI_ST_SUCCESS 0
 #define EFI_ST_FAILURE 1
 
+/*
+ * Prints a message.
+ */
+#define efi_st_printf(...) \
+	(efi_st_printc(-1, __VA_ARGS__))
+
 /*
  * Prints an error message.
  *
  * @...	format string followed by fields to print
  */
 #define efi_st_error(...) \
-	(efi_st_printf("%s(%u):\nERROR: ", __FILE__, __LINE__), \
-	efi_st_printf(__VA_ARGS__)) \
+	(efi_st_printc(EFI_LIGHTRED, "%s(%u):\nERROR: ", __FILE__, __LINE__), \
+	efi_st_printc(EFI_LIGHTRED, __VA_ARGS__))
 
 /*
  * Prints a TODO message.
@@ -33,8 +39,8 @@
  * @...	format string followed by fields to print
  */
 #define efi_st_todo(...) \
-	(efi_st_printf("%s(%u):\nTODO: ", __FILE__, __LINE__), \
-	efi_st_printf(__VA_ARGS__)) \
+	(efi_st_printc(EFI_YELLOW, "%s(%u):\nTODO: ", __FILE__, __LINE__), \
+	efi_st_printc(EFI_YELLOW, __VA_ARGS__)) \
 
 /*
  * A test may be setup and executed at boottime,
@@ -61,14 +67,15 @@ extern struct efi_simple_input_interface *con_in;
 void efi_st_exit_boot_services(void);
 
 /*
- * Print a pointer to an u16 string
+ * Print a colored message
  *
- * @pointer: pointer
- * @buf: pointer to buffer address
- * on return position of terminating zero word
+ * @color	color, see constants in efi_api.h, use -1 for no color
+ * @fmt		printf format
+ * @...		arguments to be printed
+ *		on return position of terminating zero word
  */
-void efi_st_printf(const char *fmt, ...)
-		 __attribute__ ((format (__printf__, 1, 2)));
+void efi_st_printc(int color, const char *fmt, ...)
+		 __attribute__ ((format (__printf__, 2, 3)));
 
 /*
  * Compare memory.
diff --git a/lib/efi_selftest/efi_selftest.c b/lib/efi_selftest/efi_selftest.c
index 4e5a12c47c..fc5ef254a1 100644
--- a/lib/efi_selftest/efi_selftest.c
+++ b/lib/efi_selftest/efi_selftest.c
@@ -65,7 +65,7 @@ void efi_st_exit_boot_services(void)
 		efi_st_error("ExitBootServices did not return EFI_SUCCESS\n");
 		return;
 	}
-	efi_st_printf("\nBoot services terminated\n");
+	efi_st_printc(EFI_WHITE, "\nBoot services terminated\n");
 }
 
 /*
@@ -81,13 +81,14 @@ static int setup(struct efi_unit_test *test, unsigned int *failures)
 
 	if (!test->setup)
 		return EFI_ST_SUCCESS;
-	efi_st_printf("\nSetting up '%s'\n", test->name);
+	efi_st_printc(EFI_LIGHTBLUE, "\nSetting up '%s'\n", test->name);
 	ret = test->setup(handle, systable);
 	if (ret != EFI_ST_SUCCESS) {
 		efi_st_error("Setting up '%s' failed\n", test->name);
 		++*failures;
 	} else {
-		efi_st_printf("Setting up '%s' succeeded\n", test->name);
+		efi_st_printc(EFI_LIGHTGREEN,
+			      "Setting up '%s' succeeded\n", test->name);
 	}
 	return ret;
 }
@@ -105,13 +106,14 @@ static int execute(struct efi_unit_test *test, unsigned int *failures)
 
 	if (!test->execute)
 		return EFI_ST_SUCCESS;
-	efi_st_printf("\nExecuting '%s'\n", test->name);
+	efi_st_printc(EFI_LIGHTBLUE, "\nExecuting '%s'\n", test->name);
 	ret = test->execute();
 	if (ret != EFI_ST_SUCCESS) {
 		efi_st_error("Executing '%s' failed\n", test->name);
 		++*failures;
 	} else {
-		efi_st_printf("Executing '%s' succeeded\n", test->name);
+		efi_st_printc(EFI_LIGHTGREEN,
+			      "Executing '%s' succeeded\n", test->name);
 	}
 	return ret;
 }
@@ -129,13 +131,14 @@ static int teardown(struct efi_unit_test *test, unsigned int *failures)
 
 	if (!test->teardown)
 		return EFI_ST_SUCCESS;
-	efi_st_printf("\nTearing down '%s'\n", test->name);
+	efi_st_printc(EFI_LIGHTBLUE, "\nTearing down '%s'\n", test->name);
 	ret = test->teardown();
 	if (ret != EFI_ST_SUCCESS) {
 		efi_st_error("Tearing down '%s' failed\n", test->name);
 		++*failures;
 	} else {
-		efi_st_printf("Tearing down '%s' succeeded\n", test->name);
+		efi_st_printc(EFI_LIGHTGREEN,
+			      "Tearing down '%s' succeeded\n", test->name);
 	}
 	return ret;
 }
@@ -262,12 +265,12 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle,
 		}
 	}
 
-	efi_st_printf("\nTesting EFI API implementation\n");
+	efi_st_printc(EFI_WHITE, "\nTesting EFI API implementation\n");
 
 	if (testname)
-		efi_st_printf("\nSelected test: '%ps'\n", testname);
+		efi_st_printc(EFI_WHITE, "\nSelected test: '%ps'\n", testname);
 	else
-		efi_st_printf("\nNumber of tests to execute: %u\n",
+		efi_st_printc(EFI_WHITE, "\nNumber of tests to execute: %u\n",
 			      ll_entry_count(struct efi_unit_test,
 					     efi_unit_test));
 
@@ -291,7 +294,7 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle,
 			&failures);
 
 	/* Give feedback */
-	efi_st_printf("\nSummary: %u failures\n\n", failures);
+	efi_st_printc(EFI_WHITE, "\nSummary: %u failures\n\n", failures);
 
 	/* Reset system */
 	efi_st_printf("Preparing for reset. Press any key.\n");
diff --git a/lib/efi_selftest/efi_selftest_console.c b/lib/efi_selftest/efi_selftest_console.c
index 6a7fd20da5..d528fc56ff 100644
--- a/lib/efi_selftest/efi_selftest_console.c
+++ b/lib/efi_selftest/efi_selftest_console.c
@@ -130,12 +130,13 @@ static void int2dec(s32 value, u16 **buf)
 }
 
 /*
- * Print a formatted string to the EFI console
+ * Print a colored formatted string to the EFI console
  *
- * @fmt: format string
- * @...: optional arguments
+ * @color	color, see constants in efi_api.h, use -1 for no color
+ * @fmt		format string
+ * @...		optional arguments
  */
-void efi_st_printf(const char *fmt, ...)
+void efi_st_printc(int color, const char *fmt, ...)
 {
 	va_list args;
 	u16 buf[160];
@@ -215,7 +216,11 @@ void efi_st_printf(const char *fmt, ...)
 	}
 	va_end(args);
 	*pos = 0;
+	if (color >= 0)
+		con_out->set_attribute(con_out, (unsigned long)color);
 	con_out->output_string(con_out, buf);
+	if (color >= 0)
+		con_out->set_attribute(con_out, EFI_LIGHTGRAY);
 }
 
 /*
-- 
2.14.2

  reply	other threads:[~2018-01-11  7:15 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-11  7:15 [U-Boot] [PATCH v3 00/16] efi_loader: implement driver management Heinrich Schuchardt
2018-01-11  7:15 ` Heinrich Schuchardt [this message]
2018-01-16 14:56   ` [U-Boot] [PATCH v3 01/16] efi_selftest: colored test output Simon Glass
2018-01-11  7:15 ` [U-Boot] [PATCH v3 02/16] efi_loader: simplify efi_remove_all_protocols Heinrich Schuchardt
2018-01-16 14:56   ` Simon Glass
2018-01-11  7:15 ` [U-Boot] [PATCH v3 03/16] efi_selftest: do not try to close device path protocol Heinrich Schuchardt
2018-01-16 14:56   ` Simon Glass
2018-01-11  7:15 ` [U-Boot] [PATCH v3 04/16] efi_loader: list of open protocol infos Heinrich Schuchardt
2018-01-11  7:15 ` [U-Boot] [PATCH v3 05/16] efi_loader: open_info in OpenProtocol Heinrich Schuchardt
2018-01-11  7:15 ` [U-Boot] [PATCH v3 06/16] efi_loader: open_info in CloseProtocol Heinrich Schuchardt
2018-01-11  7:16 ` [U-Boot] [PATCH v3 07/16] efi_loader: implement OpenProtocolInformation Heinrich Schuchardt
2018-01-19 16:30   ` Alexander Graf
2018-01-11  7:16 ` [U-Boot] [PATCH v3 08/16] efi_loader: debug output installed device path Heinrich Schuchardt
2018-01-11  7:16 ` [U-Boot] [PATCH v3 09/16] efi_loader: implement ConnectController Heinrich Schuchardt
2018-01-11  7:16 ` [U-Boot] [PATCH v3 10/16] efi_loader: fix signature of efi_disconnect_controller Heinrich Schuchardt
2018-01-11  7:16 ` [U-Boot] [PATCH v3 11/16] efi_loader: implement DisconnectController Heinrich Schuchardt
2018-01-11  7:16 ` [U-Boot] [PATCH v3 12/16] efi_loader: disconnect controllers in UninstallProtocol Heinrich Schuchardt
2018-01-11  7:16 ` [U-Boot] [PATCH v3 13/16] efi_selftest: remove todo in manage protocols Heinrich Schuchardt
2018-01-11  7:16 ` [U-Boot] [PATCH v3 14/16] efi_selftest: remove todo in device path test Heinrich Schuchardt
2018-01-11  7:16 ` [U-Boot] [PATCH v3 15/16] efi_selftest: test for (Dis)ConnectController Heinrich Schuchardt
2018-01-11  7:16 ` [U-Boot] [PATCH v3 16/16] efi_loader: consistently use efi_handle_t for handles Heinrich Schuchardt
2018-01-16 14:56   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180111071609.4058-2-xypron.glpk@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.