Patchwork [2/4] lib: fwts_framework: remove fwts_framework_results, remove redundant code

login
register
mail settings
Submitter Colin King
Date May 30, 2012, 6:40 p.m.
Message ID <1338403238-14029-3-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/162054/
State Accepted
Headers show

Comments

Colin King - May 30, 2012, 6:40 p.m.
From: Colin Ian King <colin.king@canonical.com>

By removing fwts_framework_results and using the underlying log
type fwts_log_field we can remove a lot of crufty code.  Also since
nobody seems to be using the obscure enviroment settings for the
text of passed/failed/warning etc messages we can throw away
fwts_framework_get_env and just use fwts_log_field_to_str_upper()
instead.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/include/fwts_framework.h |   31 +++------
 src/lib/src/fwts_framework.c     |  132 ++++++--------------------------------
 2 files changed, 27 insertions(+), 136 deletions(-)
Ivan Hu - June 1, 2012, 6:35 a.m.
On 05/31/2012 02:40 AM, Colin King wrote:
> From: Colin Ian King<colin.king@canonical.com>
>
> By removing fwts_framework_results and using the underlying log
> type fwts_log_field we can remove a lot of crufty code.  Also since
> nobody seems to be using the obscure enviroment settings for the
> text of passed/failed/warning etc messages we can throw away
> fwts_framework_get_env and just use fwts_log_field_to_str_upper()
> instead.
>
> Signed-off-by: Colin Ian King<colin.king@canonical.com>
> ---
>   src/lib/include/fwts_framework.h |   31 +++------
>   src/lib/src/fwts_framework.c     |  132 ++++++--------------------------------
>   2 files changed, 27 insertions(+), 136 deletions(-)
>
> diff --git a/src/lib/include/fwts_framework.h b/src/lib/include/fwts_framework.h
> index fb74253..de28612 100644
> --- a/src/lib/include/fwts_framework.h
> +++ b/src/lib/include/fwts_framework.h
> @@ -52,21 +52,6 @@ typedef enum {
>   	FWTS_FRAMEWORK_FLAGS_SHOW_TESTS_FULL           = 0x80000000,
>   } fwts_framework_flags;
>
> -typedef enum {
> -	FWTS_FRAMEWORK_PASSED,
> -	FWTS_FRAMEWORK_FAILED,
> -	FWTS_FRAMEWORK_FAILED_LOW,
> -	FWTS_FRAMEWORK_FAILED_HIGH,
> -	FWTS_FRAMEWORK_FAILED_MEDIUM,
> -	FWTS_FRAMEWORK_FAILED_CRITICAL,
> -	FWTS_FRAMEWORK_WARNING,
> -	FWTS_FRAMEWORK_ERROR,
> -	FWTS_FRAMEWORK_ADVICE,
> -	FWTS_FRAMEWORK_SKIPPED,
> -	FWTS_FRAMEWORK_ABORTED,
> -	FWTS_FRAMEWORK_INFOONLY,
> -} fwts_framework_results;
> -
>   #define FWTS_FRAMEWORK_FLAGS_TEST_MASK		\
>   	(FWTS_FRAMEWORK_FLAGS_TEST_BIOS |	\
>   	 FWTS_FRAMEWORK_FLAGS_TEST_UEFI |	\
> @@ -198,7 +183,7 @@ void fwts_framework_infoonly(fwts_framework *fw);
>   void fwts_framework_minor_test_progress(fwts_framework *fw, const int percent, const char *message);
>
>   void fwts_framework_log(fwts_framework *fw,
> -        fwts_framework_results result,
> +	fwts_log_field field,
>   	const char *label,
>           fwts_log_level level,
>           uint32_t *count,
> @@ -210,19 +195,19 @@ void fwts_framework_log(fwts_framework *fw,
>
>   /* Helpers to report tests results */
>   #define fwts_passed(fw, fmt, args...) \
> -	fwts_framework_log(fw, FWTS_FRAMEWORK_PASSED, NULL, LOG_LEVEL_NONE,&fw->minor_tests.passed, fmt, ## args)
> +	fwts_framework_log(fw, LOG_PASSED, NULL, LOG_LEVEL_NONE,&fw->minor_tests.passed, fmt, ## args)
>   #define fwts_failed(fw, level, label, fmt, args...) \
> -	fwts_framework_log(fw, FWTS_FRAMEWORK_FAILED, label, level,&fw->minor_tests.failed, fmt, ## args)
> +	fwts_framework_log(fw, LOG_FAILED, label, level,&fw->minor_tests.failed, fmt, ## args)
>   #define fwts_warning(fw, fmt, args...) \
> -	fwts_framework_log(fw, FWTS_FRAMEWORK_WARNING, NULL, LOG_LEVEL_MEDIUM,&fw->minor_tests.warning, fmt, ## args)
> +	fwts_framework_log(fw, LOG_WARNING, NULL, LOG_LEVEL_MEDIUM,&fw->minor_tests.warning, fmt, ## args)
>   #define fwts_advice(fw, fmt, args...) \
> -	fwts_framework_log(fw, FWTS_FRAMEWORK_ADVICE, NULL, LOG_LEVEL_NONE, NULL, fmt, ## args)
> +	fwts_framework_log(fw, LOG_ADVICE, NULL, LOG_LEVEL_NONE, NULL, fmt, ## args)
>   #define fwts_skipped(fw, fmt, args...) \
> -	fwts_framework_log(fw, FWTS_FRAMEWORK_SKIPPED, NULL, LOG_LEVEL_MEDIUM,&fw->minor_tests.skipped, fmt, ## args)
> +	fwts_framework_log(fw, LOG_SKIPPED, NULL, LOG_LEVEL_MEDIUM,&fw->minor_tests.skipped, fmt, ## args)
>   #define fwts_aborted(fw, fmt, args...) \
> -	fwts_framework_log(fw, FWTS_FRAMEWORK_ABORTED, NULL, LOG_LEVEL_MEDIUM,&fw->minor_tests.aborted, fmt, ## args)
> +	fwts_framework_log(fw, LOG_ABORTED, NULL, LOG_LEVEL_MEDIUM,&fw->minor_tests.aborted, fmt, ## args)
>   #define fwts_infoonly(fw) \
> -	fwts_framework_log(fw, FWTS_FRAMEWORK_INFOONLY, NULL, LOG_LEVEL_NONE,&fw->minor_tests.infoonly, NULL)
> +	fwts_framework_log(fw, LOG_INFOONLY, NULL, LOG_LEVEL_NONE,&fw->minor_tests.infoonly, NULL)
>
>   static inline int fwts_tests_passed(const fwts_framework *fw)
>   {
> diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
> index 9ff8c20..78a715d 100644
> --- a/src/lib/src/fwts_framework.c
> +++ b/src/lib/src/fwts_framework.c
> @@ -89,62 +89,12 @@ typedef struct {
>   	char *env_value;
>   } fwts_framework_setting;
>
> -#define ID_NAME(id)	id, # id
> -
>   static const char *fwts_copyright[] = {
>   	"Some of this work - Copyright (c) 1999 - 2010, Intel Corp. All rights reserved.",
>   	"Some of this work - Copyright (c) 2010 - 2012, Canonical.",	
>   	NULL
>   };
>
> -static fwts_framework_setting fwts_framework_settings[] = {
> -	{ ID_NAME(FWTS_FRAMEWORK_PASSED),		"PASSED",  NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_FAILED),		"FAILED",  NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_FAILED_LOW),		"FAILED_LOW", NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_FAILED_HIGH),		"FAILED_HIGH", NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_FAILED_MEDIUM),	"FAILED_MEDIUM", NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_FAILED_CRITICAL),	"FAILED_CRITICAL", NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_WARNING),		"WARNING", NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_ERROR),		"ERROR",   NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_ADVICE),		"ADVICE",  NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_SKIPPED),		"SKIPPED", NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_ABORTED),		"ABORTED", NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_INFOONLY),		"INFO", NULL },
> -};
> -
> -#if 0
> -static const char *fwts_framework_results_to_str(fwts_framework_results result)
> -{
> -	switch (result) {
> -	case FWTS_FRAMEWORK_PASSED:
> -		return "Passed";
> -	case FWTS_FRAMEWORK_FAILED:	
> -		return "Failed";
> -	case FWTS_FRAMEWORK_FAILED_LOW:
> -		return "Failed Low";
> -	case FWTS_FRAMEWORK_FAILED_HIGH:
> -		return "Failed High";
> -	case FWTS_FRAMEWORK_FAILED_MEDIUM:
> -		return "Failed Medium";
> -	case FWTS_FRAMEWORK_FAILED_CRITICAL:
> -		return "Failed Critical";
> -	case FWTS_FRAMEWORK_WARNING:
> -		return "Warning";
> -	case FWTS_FRAMEWORK_ERROR:
> -		return "Error";
> -	case FWTS_FRAMEWORK_ADVICE:
> -		return "Advice";
> -	case FWTS_FRAMEWORK_SKIPPED:
> -		return "Skipped";
> -        case FWTS_FRAMEWORK_ABORTED:
> -		return "Aborted";
> -	case FWTS_FRAMEWORK_INFOONLY:
> -		return "Info";
> -	default:
> -		return "Unknown";
> -}
> -#endif
> -
>   /*
>    *  fwts_framework_compare_priority()
>    *	used to register tests sorted on run priority
> @@ -460,49 +410,6 @@ static inline void fwts_framework_underline(fwts_framework *fw, const int ch)
>   	fwts_log_underline(fw->results, ch);
>   }
>
> -/*
> - *  fwts_framework_get_env()
> - *	get a variable - if already fetched return cached value, otherwise
> - *	try to gather from environment. If not in environment, return
> - *	predefined default.
> - */
> -static char *fwts_framework_get_env(const int env_id)
> -{
> -	int i;
> -
> -	for (i=0;i<(int)sizeof(fwts_framework_settings)/sizeof(fwts_framework_setting);i++) {
> -		if (fwts_framework_settings[i].env_id == env_id) {	
> -			if (fwts_framework_settings[i].env_value)
> -				return fwts_framework_settings[i].env_value;
> -			else {
> -				const char *value = getenv(fwts_framework_settings[i].env_name);
> -				if (value == NULL) {
> -					value = fwts_framework_settings[i].env_default;
> -				}
> -				fwts_framework_settings[i].env_value = strdup(value);
> -				if (fwts_framework_settings[i].env_value)
> -					return fwts_framework_settings[i].env_value;
> -				else
> -					return "";
> -			}
> -		}
> -	}
> -	return "";
> -}
> -
> -/*
> - *  fwts_framework_free_env()
> - *	free alloc'd environment variables
> - */
> -static void fwts_framework_free_env(void)
> -{
> -	int i;
> -
> -	for (i=0;i<(int)sizeof(fwts_framework_settings)/sizeof(fwts_framework_setting);i++)
> -		if (fwts_framework_settings[i].env_value)
> -			free(fwts_framework_settings[i].env_value);
> -}
> -
>   static int fwts_framework_test_summary(fwts_framework *fw)
>   {
>   	char buffer[128];
> @@ -516,25 +423,25 @@ static int fwts_framework_test_summary(fwts_framework *fw)
>
>   	if (fw->flags&  FWTS_FRAMEWORK_FLAGS_STDOUT_SUMMARY) {
>   		if (results->aborted>  0)
> -			printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_ABORTED));
> +			printf("%s\n", fwts_log_field_to_str_upper(LOG_ABORTED));
>   		else if (results->skipped>  0)
> -			printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_SKIPPED));
> +			printf("%s\n", fwts_log_field_to_str_upper(LOG_SKIPPED));
>   		else if (results->failed>  0) {
>   			/* We intentionally report the highest logged error level */
>   			if (fw->failed_level&  LOG_LEVEL_CRITICAL)
> -				printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED_CRITICAL));
> +				printf("%s_CRITICAL\n", fwts_log_field_to_str_upper(LOG_FAILED));
>   			else if (fw->failed_level&  LOG_LEVEL_HIGH)
> -				printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED_HIGH));
> +				printf("%s_HIGH\n", fwts_log_field_to_str_upper(LOG_FAILED));
>   			else if (fw->failed_level&  LOG_LEVEL_MEDIUM)
> -				printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED_MEDIUM));
> +				printf("%s_MEDIUM\n", fwts_log_field_to_str_upper(LOG_FAILED));
>   			else if (fw->failed_level&  LOG_LEVEL_LOW)
> -				printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED_LOW));
> -			else printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED));
> +				printf("%s_LOW\n", fwts_log_field_to_str_upper(LOG_FAILED));
> +			else printf("%s\n", fwts_log_field_to_str_upper(LOG_FAILED));
>   		}
>   		else if (results->warning>  0)
> -			printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_WARNING));
> +			printf("%s\n", fwts_log_field_to_str_upper(LOG_WARNING));
>   		else
> -			printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_PASSED));
> +			printf("%s\n", fwts_log_field_to_str_upper(LOG_PASSED));
>   	}
>
>   	if (!(fw->flags&  FWTS_FRAMEWORK_FLAGS_LP_TAGS))
> @@ -739,7 +646,7 @@ static fwts_framework_test *fwts_framework_test_find(fwts_framework *fw, const c
>    *	log a test result
>    */
>   void fwts_framework_log(fwts_framework *fw,
> -	fwts_framework_results result,
> +	fwts_log_field field,
>   	const char *label,
>   	fwts_log_level level,
>   	uint32_t *count,
> @@ -747,7 +654,7 @@ void fwts_framework_log(fwts_framework *fw,
>   {
>   	char buffer[4096];
>   	char prefix[256];
> -	char *str = fwts_framework_get_env(result);
> +	char *str = fwts_log_field_to_str_upper(field);
>
>   	if (fmt) {
>   		va_list ap;
> @@ -761,29 +668,29 @@ void fwts_framework_log(fwts_framework *fw,
>   	if (count)
>   		(*count)++;
>
> -	switch (result) {
> -	case FWTS_FRAMEWORK_ADVICE:
> +	switch (field) {
> +	case LOG_ADVICE:
>   		fwts_log_nl(fw);
>   		snprintf(prefix, sizeof(prefix), "%s: ", str);
>   		fwts_log_printf(fw->results, LOG_RESULT, level, str, label, prefix, "%s", buffer);
>   		fwts_log_nl(fw);
>   		break;
> -	case FWTS_FRAMEWORK_FAILED:
> +	case LOG_FAILED:
>   		fw->failed_level |= level;
>   		fwts_summary_add(fw, fw->current_major_test->name, level, buffer);
>   		snprintf(prefix, sizeof(prefix), "%s [%s] %s: Test %d, ",
>   			str, fwts_log_level_to_str(level), label, fw->current_minor_test_num);
>   		fwts_log_printf(fw->results, LOG_RESULT, level, str, label, prefix, "%s", buffer);
>   		break;
> -	case FWTS_FRAMEWORK_PASSED:
> -	case FWTS_FRAMEWORK_WARNING:
> -	case FWTS_FRAMEWORK_SKIPPED:
> -	case FWTS_FRAMEWORK_ABORTED:
> +	case LOG_PASSED:
> +	case LOG_WARNING:
> +	case LOG_SKIPPED:
> +	case LOG_ABORTED:
>   		snprintf(prefix, sizeof(prefix), "%s: Test %d, ",
>   			str, fw->current_minor_test_num);
>   		fwts_log_printf(fw->results, LOG_RESULT, level, str, label, prefix, "%s", buffer);
>   		break;
> -	case FWTS_FRAMEWORK_INFOONLY:
> +	case LOG_INFOONLY:
>   		break;	/* no-op */
>   	default:
>   		break;
> @@ -1272,7 +1179,6 @@ tidy_close:
>   	free(fw->results_logname);
>   	free(fw->klog);
>   	free(fw->json_data_path);
> -	fwts_framework_free_env();
>   	fwts_list_free_items(&fw->total_taglist, free);
>   	fwts_list_free_items(&fwts_framework_test_list, free);
>
Acked-by: Ivan Hu<ivan.hu@canonical.com>
Keng-Yu Lin - June 1, 2012, 8:48 a.m.
On Thu, May 31, 2012 at 2:40 AM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> By removing fwts_framework_results and using the underlying log
> type fwts_log_field we can remove a lot of crufty code.  Also since
> nobody seems to be using the obscure enviroment settings for the
> text of passed/failed/warning etc messages we can throw away
> fwts_framework_get_env and just use fwts_log_field_to_str_upper()
> instead.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/include/fwts_framework.h |   31 +++------
>  src/lib/src/fwts_framework.c     |  132 ++++++--------------------------------
>  2 files changed, 27 insertions(+), 136 deletions(-)
>
> diff --git a/src/lib/include/fwts_framework.h b/src/lib/include/fwts_framework.h
> index fb74253..de28612 100644
> --- a/src/lib/include/fwts_framework.h
> +++ b/src/lib/include/fwts_framework.h
> @@ -52,21 +52,6 @@ typedef enum {
>        FWTS_FRAMEWORK_FLAGS_SHOW_TESTS_FULL           = 0x80000000,
>  } fwts_framework_flags;
>
> -typedef enum {
> -       FWTS_FRAMEWORK_PASSED,
> -       FWTS_FRAMEWORK_FAILED,
> -       FWTS_FRAMEWORK_FAILED_LOW,
> -       FWTS_FRAMEWORK_FAILED_HIGH,
> -       FWTS_FRAMEWORK_FAILED_MEDIUM,
> -       FWTS_FRAMEWORK_FAILED_CRITICAL,
> -       FWTS_FRAMEWORK_WARNING,
> -       FWTS_FRAMEWORK_ERROR,
> -       FWTS_FRAMEWORK_ADVICE,
> -       FWTS_FRAMEWORK_SKIPPED,
> -       FWTS_FRAMEWORK_ABORTED,
> -       FWTS_FRAMEWORK_INFOONLY,
> -} fwts_framework_results;
> -
>  #define FWTS_FRAMEWORK_FLAGS_TEST_MASK         \
>        (FWTS_FRAMEWORK_FLAGS_TEST_BIOS |       \
>         FWTS_FRAMEWORK_FLAGS_TEST_UEFI |       \
> @@ -198,7 +183,7 @@ void fwts_framework_infoonly(fwts_framework *fw);
>  void fwts_framework_minor_test_progress(fwts_framework *fw, const int percent, const char *message);
>
>  void fwts_framework_log(fwts_framework *fw,
> -        fwts_framework_results result,
> +       fwts_log_field field,
>        const char *label,
>         fwts_log_level level,
>         uint32_t *count,
> @@ -210,19 +195,19 @@ void fwts_framework_log(fwts_framework *fw,
>
>  /* Helpers to report tests results */
>  #define fwts_passed(fw, fmt, args...) \
> -       fwts_framework_log(fw, FWTS_FRAMEWORK_PASSED, NULL, LOG_LEVEL_NONE, &fw->minor_tests.passed, fmt, ## args)
> +       fwts_framework_log(fw, LOG_PASSED, NULL, LOG_LEVEL_NONE, &fw->minor_tests.passed, fmt, ## args)
>  #define fwts_failed(fw, level, label, fmt, args...) \
> -       fwts_framework_log(fw, FWTS_FRAMEWORK_FAILED, label, level, &fw->minor_tests.failed, fmt, ## args)
> +       fwts_framework_log(fw, LOG_FAILED, label, level, &fw->minor_tests.failed, fmt, ## args)
>  #define fwts_warning(fw, fmt, args...) \
> -       fwts_framework_log(fw, FWTS_FRAMEWORK_WARNING, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.warning, fmt, ## args)
> +       fwts_framework_log(fw, LOG_WARNING, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.warning, fmt, ## args)
>  #define fwts_advice(fw, fmt, args...) \
> -       fwts_framework_log(fw, FWTS_FRAMEWORK_ADVICE, NULL, LOG_LEVEL_NONE, NULL, fmt, ## args)
> +       fwts_framework_log(fw, LOG_ADVICE, NULL, LOG_LEVEL_NONE, NULL, fmt, ## args)
>  #define fwts_skipped(fw, fmt, args...) \
> -       fwts_framework_log(fw, FWTS_FRAMEWORK_SKIPPED, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.skipped, fmt, ## args)
> +       fwts_framework_log(fw, LOG_SKIPPED, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.skipped, fmt, ## args)
>  #define fwts_aborted(fw, fmt, args...) \
> -       fwts_framework_log(fw, FWTS_FRAMEWORK_ABORTED, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.aborted, fmt, ## args)
> +       fwts_framework_log(fw, LOG_ABORTED, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.aborted, fmt, ## args)
>  #define fwts_infoonly(fw) \
> -       fwts_framework_log(fw, FWTS_FRAMEWORK_INFOONLY, NULL, LOG_LEVEL_NONE, &fw->minor_tests.infoonly, NULL)
> +       fwts_framework_log(fw, LOG_INFOONLY, NULL, LOG_LEVEL_NONE, &fw->minor_tests.infoonly, NULL)
>
>  static inline int fwts_tests_passed(const fwts_framework *fw)
>  {
> diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
> index 9ff8c20..78a715d 100644
> --- a/src/lib/src/fwts_framework.c
> +++ b/src/lib/src/fwts_framework.c
> @@ -89,62 +89,12 @@ typedef struct {
>        char *env_value;
>  } fwts_framework_setting;
>
> -#define ID_NAME(id)    id, # id
> -
>  static const char *fwts_copyright[] = {
>        "Some of this work - Copyright (c) 1999 - 2010, Intel Corp. All rights reserved.",
>        "Some of this work - Copyright (c) 2010 - 2012, Canonical.",
>        NULL
>  };
>
> -static fwts_framework_setting fwts_framework_settings[] = {
> -       { ID_NAME(FWTS_FRAMEWORK_PASSED),               "PASSED",  NULL },
> -       { ID_NAME(FWTS_FRAMEWORK_FAILED),               "FAILED",  NULL },
> -       { ID_NAME(FWTS_FRAMEWORK_FAILED_LOW),           "FAILED_LOW", NULL },
> -       { ID_NAME(FWTS_FRAMEWORK_FAILED_HIGH),          "FAILED_HIGH", NULL },
> -       { ID_NAME(FWTS_FRAMEWORK_FAILED_MEDIUM),        "FAILED_MEDIUM", NULL },
> -       { ID_NAME(FWTS_FRAMEWORK_FAILED_CRITICAL),      "FAILED_CRITICAL", NULL },
> -       { ID_NAME(FWTS_FRAMEWORK_WARNING),              "WARNING", NULL },
> -       { ID_NAME(FWTS_FRAMEWORK_ERROR),                "ERROR",   NULL },
> -       { ID_NAME(FWTS_FRAMEWORK_ADVICE),               "ADVICE",  NULL },
> -       { ID_NAME(FWTS_FRAMEWORK_SKIPPED),              "SKIPPED", NULL },
> -       { ID_NAME(FWTS_FRAMEWORK_ABORTED),              "ABORTED", NULL },
> -       { ID_NAME(FWTS_FRAMEWORK_INFOONLY),             "INFO", NULL },
> -};
> -
> -#if 0
> -static const char *fwts_framework_results_to_str(fwts_framework_results result)
> -{
> -       switch (result) {
> -       case FWTS_FRAMEWORK_PASSED:
> -               return "Passed";
> -       case FWTS_FRAMEWORK_FAILED:
> -               return "Failed";
> -       case FWTS_FRAMEWORK_FAILED_LOW:
> -               return "Failed Low";
> -       case FWTS_FRAMEWORK_FAILED_HIGH:
> -               return "Failed High";
> -       case FWTS_FRAMEWORK_FAILED_MEDIUM:
> -               return "Failed Medium";
> -       case FWTS_FRAMEWORK_FAILED_CRITICAL:
> -               return "Failed Critical";
> -       case FWTS_FRAMEWORK_WARNING:
> -               return "Warning";
> -       case FWTS_FRAMEWORK_ERROR:
> -               return "Error";
> -       case FWTS_FRAMEWORK_ADVICE:
> -               return "Advice";
> -       case FWTS_FRAMEWORK_SKIPPED:
> -               return "Skipped";
> -        case FWTS_FRAMEWORK_ABORTED:
> -               return "Aborted";
> -       case FWTS_FRAMEWORK_INFOONLY:
> -               return "Info";
> -       default:
> -               return "Unknown";
> -}
> -#endif
> -
>  /*
>  *  fwts_framework_compare_priority()
>  *     used to register tests sorted on run priority
> @@ -460,49 +410,6 @@ static inline void fwts_framework_underline(fwts_framework *fw, const int ch)
>        fwts_log_underline(fw->results, ch);
>  }
>
> -/*
> - *  fwts_framework_get_env()
> - *     get a variable - if already fetched return cached value, otherwise
> - *     try to gather from environment. If not in environment, return
> - *     predefined default.
> - */
> -static char *fwts_framework_get_env(const int env_id)
> -{
> -       int i;
> -
> -       for (i=0;i<(int)sizeof(fwts_framework_settings)/sizeof(fwts_framework_setting);i++) {
> -               if (fwts_framework_settings[i].env_id == env_id) {
> -                       if (fwts_framework_settings[i].env_value)
> -                               return fwts_framework_settings[i].env_value;
> -                       else {
> -                               const char *value = getenv(fwts_framework_settings[i].env_name);
> -                               if (value == NULL) {
> -                                       value = fwts_framework_settings[i].env_default;
> -                               }
> -                               fwts_framework_settings[i].env_value = strdup(value);
> -                               if (fwts_framework_settings[i].env_value)
> -                                       return fwts_framework_settings[i].env_value;
> -                               else
> -                                       return "";
> -                       }
> -               }
> -       }
> -       return "";
> -}
> -
> -/*
> - *  fwts_framework_free_env()
> - *     free alloc'd environment variables
> - */
> -static void fwts_framework_free_env(void)
> -{
> -       int i;
> -
> -       for (i=0;i<(int)sizeof(fwts_framework_settings)/sizeof(fwts_framework_setting);i++)
> -               if (fwts_framework_settings[i].env_value)
> -                       free(fwts_framework_settings[i].env_value);
> -}
> -
>  static int fwts_framework_test_summary(fwts_framework *fw)
>  {
>        char buffer[128];
> @@ -516,25 +423,25 @@ static int fwts_framework_test_summary(fwts_framework *fw)
>
>        if (fw->flags & FWTS_FRAMEWORK_FLAGS_STDOUT_SUMMARY) {
>                if (results->aborted > 0)
> -                       printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_ABORTED));
> +                       printf("%s\n", fwts_log_field_to_str_upper(LOG_ABORTED));
>                else if (results->skipped > 0)
> -                       printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_SKIPPED));
> +                       printf("%s\n", fwts_log_field_to_str_upper(LOG_SKIPPED));
>                else if (results->failed > 0) {
>                        /* We intentionally report the highest logged error level */
>                        if (fw->failed_level & LOG_LEVEL_CRITICAL)
> -                               printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED_CRITICAL));
> +                               printf("%s_CRITICAL\n", fwts_log_field_to_str_upper(LOG_FAILED));
>                        else if (fw->failed_level & LOG_LEVEL_HIGH)
> -                               printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED_HIGH));
> +                               printf("%s_HIGH\n", fwts_log_field_to_str_upper(LOG_FAILED));
>                        else if (fw->failed_level & LOG_LEVEL_MEDIUM)
> -                               printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED_MEDIUM));
> +                               printf("%s_MEDIUM\n", fwts_log_field_to_str_upper(LOG_FAILED));
>                        else if (fw->failed_level & LOG_LEVEL_LOW)
> -                               printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED_LOW));
> -                       else printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED));
> +                               printf("%s_LOW\n", fwts_log_field_to_str_upper(LOG_FAILED));
> +                       else printf("%s\n", fwts_log_field_to_str_upper(LOG_FAILED));
>                }
>                else if (results->warning > 0)
> -                       printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_WARNING));
> +                       printf("%s\n", fwts_log_field_to_str_upper(LOG_WARNING));
>                else
> -                       printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_PASSED));
> +                       printf("%s\n", fwts_log_field_to_str_upper(LOG_PASSED));
>        }
>
>        if (!(fw->flags & FWTS_FRAMEWORK_FLAGS_LP_TAGS))
> @@ -739,7 +646,7 @@ static fwts_framework_test *fwts_framework_test_find(fwts_framework *fw, const c
>  *     log a test result
>  */
>  void fwts_framework_log(fwts_framework *fw,
> -       fwts_framework_results result,
> +       fwts_log_field field,
>        const char *label,
>        fwts_log_level level,
>        uint32_t *count,
> @@ -747,7 +654,7 @@ void fwts_framework_log(fwts_framework *fw,
>  {
>        char buffer[4096];
>        char prefix[256];
> -       char *str = fwts_framework_get_env(result);
> +       char *str = fwts_log_field_to_str_upper(field);
>
>        if (fmt) {
>                va_list ap;
> @@ -761,29 +668,29 @@ void fwts_framework_log(fwts_framework *fw,
>        if (count)
>                (*count)++;
>
> -       switch (result) {
> -       case FWTS_FRAMEWORK_ADVICE:
> +       switch (field) {
> +       case LOG_ADVICE:
>                fwts_log_nl(fw);
>                snprintf(prefix, sizeof(prefix), "%s: ", str);
>                fwts_log_printf(fw->results, LOG_RESULT, level, str, label, prefix, "%s", buffer);
>                fwts_log_nl(fw);
>                break;
> -       case FWTS_FRAMEWORK_FAILED:
> +       case LOG_FAILED:
>                fw->failed_level |= level;
>                fwts_summary_add(fw, fw->current_major_test->name, level, buffer);
>                snprintf(prefix, sizeof(prefix), "%s [%s] %s: Test %d, ",
>                        str, fwts_log_level_to_str(level), label, fw->current_minor_test_num);
>                fwts_log_printf(fw->results, LOG_RESULT, level, str, label, prefix, "%s", buffer);
>                break;
> -       case FWTS_FRAMEWORK_PASSED:
> -       case FWTS_FRAMEWORK_WARNING:
> -       case FWTS_FRAMEWORK_SKIPPED:
> -       case FWTS_FRAMEWORK_ABORTED:
> +       case LOG_PASSED:
> +       case LOG_WARNING:
> +       case LOG_SKIPPED:
> +       case LOG_ABORTED:
>                snprintf(prefix, sizeof(prefix), "%s: Test %d, ",
>                        str, fw->current_minor_test_num);
>                fwts_log_printf(fw->results, LOG_RESULT, level, str, label, prefix, "%s", buffer);
>                break;
> -       case FWTS_FRAMEWORK_INFOONLY:
> +       case LOG_INFOONLY:
>                break;  /* no-op */
>        default:
>                break;
> @@ -1272,7 +1179,6 @@ tidy_close:
>        free(fw->results_logname);
>        free(fw->klog);
>        free(fw->json_data_path);
> -       fwts_framework_free_env();
>        fwts_list_free_items(&fw->total_taglist, free);
>        fwts_list_free_items(&fwts_framework_test_list, free);
>
> --
> 1.7.9.5
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Chris Van Hoof - June 11, 2012, 4:04 p.m.
On 05/30/2012 02:40 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> By removing fwts_framework_results and using the underlying log
> type fwts_log_field we can remove a lot of crufty code.  Also since
> nobody seems to be using the obscure enviroment settings for the
> text of passed/failed/warning etc messages we can throw away
> fwts_framework_get_env and just use fwts_log_field_to_str_upper()
> instead.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/include/fwts_framework.h |   31 +++------
>  src/lib/src/fwts_framework.c     |  132 ++++++--------------------------------
>  2 files changed, 27 insertions(+), 136 deletions(-)
> 
> diff --git a/src/lib/include/fwts_framework.h b/src/lib/include/fwts_framework.h
> index fb74253..de28612 100644
> --- a/src/lib/include/fwts_framework.h
> +++ b/src/lib/include/fwts_framework.h
> @@ -52,21 +52,6 @@ typedef enum {
>  	FWTS_FRAMEWORK_FLAGS_SHOW_TESTS_FULL           = 0x80000000,
>  } fwts_framework_flags;
>  
> -typedef enum {
> -	FWTS_FRAMEWORK_PASSED,
> -	FWTS_FRAMEWORK_FAILED,
> -	FWTS_FRAMEWORK_FAILED_LOW,
> -	FWTS_FRAMEWORK_FAILED_HIGH,
> -	FWTS_FRAMEWORK_FAILED_MEDIUM,
> -	FWTS_FRAMEWORK_FAILED_CRITICAL,
> -	FWTS_FRAMEWORK_WARNING,
> -	FWTS_FRAMEWORK_ERROR,
> -	FWTS_FRAMEWORK_ADVICE,
> -	FWTS_FRAMEWORK_SKIPPED,
> -	FWTS_FRAMEWORK_ABORTED,
> -	FWTS_FRAMEWORK_INFOONLY,
> -} fwts_framework_results;
> -
>  #define FWTS_FRAMEWORK_FLAGS_TEST_MASK		\
>  	(FWTS_FRAMEWORK_FLAGS_TEST_BIOS |	\
>  	 FWTS_FRAMEWORK_FLAGS_TEST_UEFI |	\
> @@ -198,7 +183,7 @@ void fwts_framework_infoonly(fwts_framework *fw);
>  void fwts_framework_minor_test_progress(fwts_framework *fw, const int percent, const char *message);
>  
>  void fwts_framework_log(fwts_framework *fw,
> -        fwts_framework_results result,
> +	fwts_log_field field,
>  	const char *label,
>          fwts_log_level level,
>          uint32_t *count,
> @@ -210,19 +195,19 @@ void fwts_framework_log(fwts_framework *fw,
>  
>  /* Helpers to report tests results */
>  #define fwts_passed(fw, fmt, args...) \
> -	fwts_framework_log(fw, FWTS_FRAMEWORK_PASSED, NULL, LOG_LEVEL_NONE, &fw->minor_tests.passed, fmt, ## args)
> +	fwts_framework_log(fw, LOG_PASSED, NULL, LOG_LEVEL_NONE, &fw->minor_tests.passed, fmt, ## args)
>  #define fwts_failed(fw, level, label, fmt, args...) \
> -	fwts_framework_log(fw, FWTS_FRAMEWORK_FAILED, label, level, &fw->minor_tests.failed, fmt, ## args)
> +	fwts_framework_log(fw, LOG_FAILED, label, level, &fw->minor_tests.failed, fmt, ## args)
>  #define fwts_warning(fw, fmt, args...) \
> -	fwts_framework_log(fw, FWTS_FRAMEWORK_WARNING, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.warning, fmt, ## args)
> +	fwts_framework_log(fw, LOG_WARNING, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.warning, fmt, ## args)
>  #define fwts_advice(fw, fmt, args...) \
> -	fwts_framework_log(fw, FWTS_FRAMEWORK_ADVICE, NULL, LOG_LEVEL_NONE, NULL, fmt, ## args)
> +	fwts_framework_log(fw, LOG_ADVICE, NULL, LOG_LEVEL_NONE, NULL, fmt, ## args)
>  #define fwts_skipped(fw, fmt, args...) \
> -	fwts_framework_log(fw, FWTS_FRAMEWORK_SKIPPED, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.skipped, fmt, ## args)
> +	fwts_framework_log(fw, LOG_SKIPPED, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.skipped, fmt, ## args)
>  #define fwts_aborted(fw, fmt, args...) \
> -	fwts_framework_log(fw, FWTS_FRAMEWORK_ABORTED, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.aborted, fmt, ## args)
> +	fwts_framework_log(fw, LOG_ABORTED, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.aborted, fmt, ## args)
>  #define fwts_infoonly(fw) \
> -	fwts_framework_log(fw, FWTS_FRAMEWORK_INFOONLY, NULL, LOG_LEVEL_NONE, &fw->minor_tests.infoonly, NULL)
> +	fwts_framework_log(fw, LOG_INFOONLY, NULL, LOG_LEVEL_NONE, &fw->minor_tests.infoonly, NULL)
>  
>  static inline int fwts_tests_passed(const fwts_framework *fw)
>  {
> diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
> index 9ff8c20..78a715d 100644
> --- a/src/lib/src/fwts_framework.c
> +++ b/src/lib/src/fwts_framework.c
> @@ -89,62 +89,12 @@ typedef struct {
>  	char *env_value;
>  } fwts_framework_setting;
>  
> -#define ID_NAME(id)	id, # id
> -
>  static const char *fwts_copyright[] = {
>  	"Some of this work - Copyright (c) 1999 - 2010, Intel Corp. All rights reserved.",
>  	"Some of this work - Copyright (c) 2010 - 2012, Canonical.",	
>  	NULL
>  };
>  
> -static fwts_framework_setting fwts_framework_settings[] = {
> -	{ ID_NAME(FWTS_FRAMEWORK_PASSED),		"PASSED",  NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_FAILED),		"FAILED",  NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_FAILED_LOW),		"FAILED_LOW", NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_FAILED_HIGH),		"FAILED_HIGH", NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_FAILED_MEDIUM),	"FAILED_MEDIUM", NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_FAILED_CRITICAL),	"FAILED_CRITICAL", NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_WARNING),		"WARNING", NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_ERROR),		"ERROR",   NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_ADVICE),		"ADVICE",  NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_SKIPPED),		"SKIPPED", NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_ABORTED),		"ABORTED", NULL },
> -	{ ID_NAME(FWTS_FRAMEWORK_INFOONLY),		"INFO", NULL },
> -};
> -
> -#if 0
> -static const char *fwts_framework_results_to_str(fwts_framework_results result)
> -{
> -	switch (result) {
> -	case FWTS_FRAMEWORK_PASSED:
> -		return "Passed";
> -	case FWTS_FRAMEWORK_FAILED:	
> -		return "Failed";
> -	case FWTS_FRAMEWORK_FAILED_LOW:
> -		return "Failed Low";
> -	case FWTS_FRAMEWORK_FAILED_HIGH:
> -		return "Failed High";
> -	case FWTS_FRAMEWORK_FAILED_MEDIUM:
> -		return "Failed Medium";
> -	case FWTS_FRAMEWORK_FAILED_CRITICAL:
> -		return "Failed Critical";
> -	case FWTS_FRAMEWORK_WARNING:
> -		return "Warning";
> -	case FWTS_FRAMEWORK_ERROR:
> -		return "Error";
> -	case FWTS_FRAMEWORK_ADVICE:
> -		return "Advice";
> -	case FWTS_FRAMEWORK_SKIPPED:
> -		return "Skipped";
> -        case FWTS_FRAMEWORK_ABORTED:
> -		return "Aborted";
> -	case FWTS_FRAMEWORK_INFOONLY:
> -		return "Info";
> -	default:
> -		return "Unknown";
> -}
> -#endif
> -
>  /*
>   *  fwts_framework_compare_priority()
>   *	used to register tests sorted on run priority
> @@ -460,49 +410,6 @@ static inline void fwts_framework_underline(fwts_framework *fw, const int ch)
>  	fwts_log_underline(fw->results, ch);
>  }
>  
> -/*
> - *  fwts_framework_get_env()
> - *	get a variable - if already fetched return cached value, otherwise
> - *	try to gather from environment. If not in environment, return
> - *	predefined default.
> - */
> -static char *fwts_framework_get_env(const int env_id)
> -{
> -	int i;
> -
> -	for (i=0;i<(int)sizeof(fwts_framework_settings)/sizeof(fwts_framework_setting);i++) {
> -		if (fwts_framework_settings[i].env_id == env_id) {	
> -			if (fwts_framework_settings[i].env_value)
> -				return fwts_framework_settings[i].env_value;
> -			else {
> -				const char *value = getenv(fwts_framework_settings[i].env_name);
> -				if (value == NULL) {
> -					value = fwts_framework_settings[i].env_default;
> -				}
> -				fwts_framework_settings[i].env_value = strdup(value);
> -				if (fwts_framework_settings[i].env_value)
> -					return fwts_framework_settings[i].env_value;
> -				else
> -					return "";
> -			}
> -		}
> -	}
> -	return "";
> -}
> -
> -/*
> - *  fwts_framework_free_env()
> - *	free alloc'd environment variables
> - */
> -static void fwts_framework_free_env(void)
> -{
> -	int i;
> -
> -	for (i=0;i<(int)sizeof(fwts_framework_settings)/sizeof(fwts_framework_setting);i++)
> -		if (fwts_framework_settings[i].env_value)
> -			free(fwts_framework_settings[i].env_value);
> -}
> -
>  static int fwts_framework_test_summary(fwts_framework *fw)
>  {
>  	char buffer[128];
> @@ -516,25 +423,25 @@ static int fwts_framework_test_summary(fwts_framework *fw)
>  
>  	if (fw->flags & FWTS_FRAMEWORK_FLAGS_STDOUT_SUMMARY) {
>  		if (results->aborted > 0)
> -			printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_ABORTED));
> +			printf("%s\n", fwts_log_field_to_str_upper(LOG_ABORTED));
>  		else if (results->skipped > 0)
> -			printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_SKIPPED));
> +			printf("%s\n", fwts_log_field_to_str_upper(LOG_SKIPPED));
>  		else if (results->failed > 0) {
>  			/* We intentionally report the highest logged error level */
>  			if (fw->failed_level & LOG_LEVEL_CRITICAL)
> -				printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED_CRITICAL));
> +				printf("%s_CRITICAL\n", fwts_log_field_to_str_upper(LOG_FAILED));
>  			else if (fw->failed_level & LOG_LEVEL_HIGH)
> -				printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED_HIGH));
> +				printf("%s_HIGH\n", fwts_log_field_to_str_upper(LOG_FAILED));
>  			else if (fw->failed_level & LOG_LEVEL_MEDIUM)
> -				printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED_MEDIUM));
> +				printf("%s_MEDIUM\n", fwts_log_field_to_str_upper(LOG_FAILED));
>  			else if (fw->failed_level & LOG_LEVEL_LOW)
> -				printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED_LOW));
> -			else printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED));
> +				printf("%s_LOW\n", fwts_log_field_to_str_upper(LOG_FAILED));
> +			else printf("%s\n", fwts_log_field_to_str_upper(LOG_FAILED));
>  		}
>  		else if (results->warning > 0)
> -			printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_WARNING));
> +			printf("%s\n", fwts_log_field_to_str_upper(LOG_WARNING));
>  		else
> -			printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_PASSED));
> +			printf("%s\n", fwts_log_field_to_str_upper(LOG_PASSED));
>  	}
>  
>  	if (!(fw->flags & FWTS_FRAMEWORK_FLAGS_LP_TAGS))
> @@ -739,7 +646,7 @@ static fwts_framework_test *fwts_framework_test_find(fwts_framework *fw, const c
>   *	log a test result
>   */
>  void fwts_framework_log(fwts_framework *fw, 
> -	fwts_framework_results result,
> +	fwts_log_field field,
>  	const char *label,
>  	fwts_log_level level,
>  	uint32_t *count,
> @@ -747,7 +654,7 @@ void fwts_framework_log(fwts_framework *fw,
>  {
>  	char buffer[4096];
>  	char prefix[256];
> -	char *str = fwts_framework_get_env(result);
> +	char *str = fwts_log_field_to_str_upper(field);
>  
>  	if (fmt) {
>  		va_list ap;
> @@ -761,29 +668,29 @@ void fwts_framework_log(fwts_framework *fw,
>  	if (count)
>  		(*count)++;
>  
> -	switch (result) {
> -	case FWTS_FRAMEWORK_ADVICE:
> +	switch (field) {
> +	case LOG_ADVICE:
>  		fwts_log_nl(fw);
>  		snprintf(prefix, sizeof(prefix), "%s: ", str);
>  		fwts_log_printf(fw->results, LOG_RESULT, level, str, label, prefix, "%s", buffer);
>  		fwts_log_nl(fw);
>  		break;
> -	case FWTS_FRAMEWORK_FAILED:
> +	case LOG_FAILED:
>  		fw->failed_level |= level;
>  		fwts_summary_add(fw, fw->current_major_test->name, level, buffer);
>  		snprintf(prefix, sizeof(prefix), "%s [%s] %s: Test %d, ",
>  			str, fwts_log_level_to_str(level), label, fw->current_minor_test_num);
>  		fwts_log_printf(fw->results, LOG_RESULT, level, str, label, prefix, "%s", buffer);
>  		break;
> -	case FWTS_FRAMEWORK_PASSED:
> -	case FWTS_FRAMEWORK_WARNING:
> -	case FWTS_FRAMEWORK_SKIPPED:
> -	case FWTS_FRAMEWORK_ABORTED:
> +	case LOG_PASSED:
> +	case LOG_WARNING:
> +	case LOG_SKIPPED:
> +	case LOG_ABORTED:
>  		snprintf(prefix, sizeof(prefix), "%s: Test %d, ",
>  			str, fw->current_minor_test_num);
>  		fwts_log_printf(fw->results, LOG_RESULT, level, str, label, prefix, "%s", buffer);
>  		break;
> -	case FWTS_FRAMEWORK_INFOONLY:
> +	case LOG_INFOONLY:
>  		break;	/* no-op */
>  	default:
>  		break;
> @@ -1272,7 +1179,6 @@ tidy_close:
>  	free(fw->results_logname);
>  	free(fw->klog);
>  	free(fw->json_data_path);
> -	fwts_framework_free_env();
>  	fwts_list_free_items(&fw->total_taglist, free);
>  	fwts_list_free_items(&fwts_framework_test_list, free);
>  

Tested-by: Chris Van Hoof <vanhoof@canonical.com>

Patch

diff --git a/src/lib/include/fwts_framework.h b/src/lib/include/fwts_framework.h
index fb74253..de28612 100644
--- a/src/lib/include/fwts_framework.h
+++ b/src/lib/include/fwts_framework.h
@@ -52,21 +52,6 @@  typedef enum {
 	FWTS_FRAMEWORK_FLAGS_SHOW_TESTS_FULL           = 0x80000000,
 } fwts_framework_flags;
 
-typedef enum {
-	FWTS_FRAMEWORK_PASSED,
-	FWTS_FRAMEWORK_FAILED,
-	FWTS_FRAMEWORK_FAILED_LOW,
-	FWTS_FRAMEWORK_FAILED_HIGH,
-	FWTS_FRAMEWORK_FAILED_MEDIUM,
-	FWTS_FRAMEWORK_FAILED_CRITICAL,
-	FWTS_FRAMEWORK_WARNING,
-	FWTS_FRAMEWORK_ERROR,
-	FWTS_FRAMEWORK_ADVICE,
-	FWTS_FRAMEWORK_SKIPPED,
-	FWTS_FRAMEWORK_ABORTED,
-	FWTS_FRAMEWORK_INFOONLY,
-} fwts_framework_results;
-
 #define FWTS_FRAMEWORK_FLAGS_TEST_MASK		\
 	(FWTS_FRAMEWORK_FLAGS_TEST_BIOS |	\
 	 FWTS_FRAMEWORK_FLAGS_TEST_UEFI |	\
@@ -198,7 +183,7 @@  void fwts_framework_infoonly(fwts_framework *fw);
 void fwts_framework_minor_test_progress(fwts_framework *fw, const int percent, const char *message);
 
 void fwts_framework_log(fwts_framework *fw,
-        fwts_framework_results result,
+	fwts_log_field field,
 	const char *label,
         fwts_log_level level,
         uint32_t *count,
@@ -210,19 +195,19 @@  void fwts_framework_log(fwts_framework *fw,
 
 /* Helpers to report tests results */
 #define fwts_passed(fw, fmt, args...) \
-	fwts_framework_log(fw, FWTS_FRAMEWORK_PASSED, NULL, LOG_LEVEL_NONE, &fw->minor_tests.passed, fmt, ## args)
+	fwts_framework_log(fw, LOG_PASSED, NULL, LOG_LEVEL_NONE, &fw->minor_tests.passed, fmt, ## args)
 #define fwts_failed(fw, level, label, fmt, args...) \
-	fwts_framework_log(fw, FWTS_FRAMEWORK_FAILED, label, level, &fw->minor_tests.failed, fmt, ## args)
+	fwts_framework_log(fw, LOG_FAILED, label, level, &fw->minor_tests.failed, fmt, ## args)
 #define fwts_warning(fw, fmt, args...) \
-	fwts_framework_log(fw, FWTS_FRAMEWORK_WARNING, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.warning, fmt, ## args)
+	fwts_framework_log(fw, LOG_WARNING, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.warning, fmt, ## args)
 #define fwts_advice(fw, fmt, args...) \
-	fwts_framework_log(fw, FWTS_FRAMEWORK_ADVICE, NULL, LOG_LEVEL_NONE, NULL, fmt, ## args)
+	fwts_framework_log(fw, LOG_ADVICE, NULL, LOG_LEVEL_NONE, NULL, fmt, ## args)
 #define fwts_skipped(fw, fmt, args...) \
-	fwts_framework_log(fw, FWTS_FRAMEWORK_SKIPPED, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.skipped, fmt, ## args)
+	fwts_framework_log(fw, LOG_SKIPPED, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.skipped, fmt, ## args)
 #define fwts_aborted(fw, fmt, args...) \
-	fwts_framework_log(fw, FWTS_FRAMEWORK_ABORTED, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.aborted, fmt, ## args)
+	fwts_framework_log(fw, LOG_ABORTED, NULL, LOG_LEVEL_MEDIUM, &fw->minor_tests.aborted, fmt, ## args)
 #define fwts_infoonly(fw) \
-	fwts_framework_log(fw, FWTS_FRAMEWORK_INFOONLY, NULL, LOG_LEVEL_NONE, &fw->minor_tests.infoonly, NULL)
+	fwts_framework_log(fw, LOG_INFOONLY, NULL, LOG_LEVEL_NONE, &fw->minor_tests.infoonly, NULL)
 
 static inline int fwts_tests_passed(const fwts_framework *fw)
 {
diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
index 9ff8c20..78a715d 100644
--- a/src/lib/src/fwts_framework.c
+++ b/src/lib/src/fwts_framework.c
@@ -89,62 +89,12 @@  typedef struct {
 	char *env_value;
 } fwts_framework_setting;
 
-#define ID_NAME(id)	id, # id
-
 static const char *fwts_copyright[] = {
 	"Some of this work - Copyright (c) 1999 - 2010, Intel Corp. All rights reserved.",
 	"Some of this work - Copyright (c) 2010 - 2012, Canonical.",	
 	NULL
 };
 
-static fwts_framework_setting fwts_framework_settings[] = {
-	{ ID_NAME(FWTS_FRAMEWORK_PASSED),		"PASSED",  NULL },
-	{ ID_NAME(FWTS_FRAMEWORK_FAILED),		"FAILED",  NULL },
-	{ ID_NAME(FWTS_FRAMEWORK_FAILED_LOW),		"FAILED_LOW", NULL },
-	{ ID_NAME(FWTS_FRAMEWORK_FAILED_HIGH),		"FAILED_HIGH", NULL },
-	{ ID_NAME(FWTS_FRAMEWORK_FAILED_MEDIUM),	"FAILED_MEDIUM", NULL },
-	{ ID_NAME(FWTS_FRAMEWORK_FAILED_CRITICAL),	"FAILED_CRITICAL", NULL },
-	{ ID_NAME(FWTS_FRAMEWORK_WARNING),		"WARNING", NULL },
-	{ ID_NAME(FWTS_FRAMEWORK_ERROR),		"ERROR",   NULL },
-	{ ID_NAME(FWTS_FRAMEWORK_ADVICE),		"ADVICE",  NULL },
-	{ ID_NAME(FWTS_FRAMEWORK_SKIPPED),		"SKIPPED", NULL },
-	{ ID_NAME(FWTS_FRAMEWORK_ABORTED),		"ABORTED", NULL },
-	{ ID_NAME(FWTS_FRAMEWORK_INFOONLY),		"INFO", NULL },
-};
-
-#if 0
-static const char *fwts_framework_results_to_str(fwts_framework_results result)
-{
-	switch (result) {
-	case FWTS_FRAMEWORK_PASSED:
-		return "Passed";
-	case FWTS_FRAMEWORK_FAILED:	
-		return "Failed";
-	case FWTS_FRAMEWORK_FAILED_LOW:
-		return "Failed Low";
-	case FWTS_FRAMEWORK_FAILED_HIGH:
-		return "Failed High";
-	case FWTS_FRAMEWORK_FAILED_MEDIUM:
-		return "Failed Medium";
-	case FWTS_FRAMEWORK_FAILED_CRITICAL:
-		return "Failed Critical";
-	case FWTS_FRAMEWORK_WARNING:
-		return "Warning";
-	case FWTS_FRAMEWORK_ERROR:
-		return "Error";
-	case FWTS_FRAMEWORK_ADVICE:
-		return "Advice";
-	case FWTS_FRAMEWORK_SKIPPED:
-		return "Skipped";
-        case FWTS_FRAMEWORK_ABORTED:
-		return "Aborted";
-	case FWTS_FRAMEWORK_INFOONLY:
-		return "Info";
-	default:
-		return "Unknown";
-}
-#endif
-
 /*
  *  fwts_framework_compare_priority()
  *	used to register tests sorted on run priority
@@ -460,49 +410,6 @@  static inline void fwts_framework_underline(fwts_framework *fw, const int ch)
 	fwts_log_underline(fw->results, ch);
 }
 
-/*
- *  fwts_framework_get_env()
- *	get a variable - if already fetched return cached value, otherwise
- *	try to gather from environment. If not in environment, return
- *	predefined default.
- */
-static char *fwts_framework_get_env(const int env_id)
-{
-	int i;
-
-	for (i=0;i<(int)sizeof(fwts_framework_settings)/sizeof(fwts_framework_setting);i++) {
-		if (fwts_framework_settings[i].env_id == env_id) {	
-			if (fwts_framework_settings[i].env_value)
-				return fwts_framework_settings[i].env_value;
-			else {
-				const char *value = getenv(fwts_framework_settings[i].env_name);
-				if (value == NULL) {
-					value = fwts_framework_settings[i].env_default;
-				}
-				fwts_framework_settings[i].env_value = strdup(value);
-				if (fwts_framework_settings[i].env_value)
-					return fwts_framework_settings[i].env_value;
-				else
-					return "";
-			}
-		}
-	}
-	return "";
-}
-
-/*
- *  fwts_framework_free_env()
- *	free alloc'd environment variables
- */
-static void fwts_framework_free_env(void)
-{
-	int i;
-
-	for (i=0;i<(int)sizeof(fwts_framework_settings)/sizeof(fwts_framework_setting);i++)
-		if (fwts_framework_settings[i].env_value)
-			free(fwts_framework_settings[i].env_value);
-}
-
 static int fwts_framework_test_summary(fwts_framework *fw)
 {
 	char buffer[128];
@@ -516,25 +423,25 @@  static int fwts_framework_test_summary(fwts_framework *fw)
 
 	if (fw->flags & FWTS_FRAMEWORK_FLAGS_STDOUT_SUMMARY) {
 		if (results->aborted > 0)
-			printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_ABORTED));
+			printf("%s\n", fwts_log_field_to_str_upper(LOG_ABORTED));
 		else if (results->skipped > 0)
-			printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_SKIPPED));
+			printf("%s\n", fwts_log_field_to_str_upper(LOG_SKIPPED));
 		else if (results->failed > 0) {
 			/* We intentionally report the highest logged error level */
 			if (fw->failed_level & LOG_LEVEL_CRITICAL)
-				printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED_CRITICAL));
+				printf("%s_CRITICAL\n", fwts_log_field_to_str_upper(LOG_FAILED));
 			else if (fw->failed_level & LOG_LEVEL_HIGH)
-				printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED_HIGH));
+				printf("%s_HIGH\n", fwts_log_field_to_str_upper(LOG_FAILED));
 			else if (fw->failed_level & LOG_LEVEL_MEDIUM)
-				printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED_MEDIUM));
+				printf("%s_MEDIUM\n", fwts_log_field_to_str_upper(LOG_FAILED));
 			else if (fw->failed_level & LOG_LEVEL_LOW)
-				printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED_LOW));
-			else printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_FAILED));
+				printf("%s_LOW\n", fwts_log_field_to_str_upper(LOG_FAILED));
+			else printf("%s\n", fwts_log_field_to_str_upper(LOG_FAILED));
 		}
 		else if (results->warning > 0)
-			printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_WARNING));
+			printf("%s\n", fwts_log_field_to_str_upper(LOG_WARNING));
 		else
-			printf("%s\n", fwts_framework_get_env(FWTS_FRAMEWORK_PASSED));
+			printf("%s\n", fwts_log_field_to_str_upper(LOG_PASSED));
 	}
 
 	if (!(fw->flags & FWTS_FRAMEWORK_FLAGS_LP_TAGS))
@@ -739,7 +646,7 @@  static fwts_framework_test *fwts_framework_test_find(fwts_framework *fw, const c
  *	log a test result
  */
 void fwts_framework_log(fwts_framework *fw, 
-	fwts_framework_results result,
+	fwts_log_field field,
 	const char *label,
 	fwts_log_level level,
 	uint32_t *count,
@@ -747,7 +654,7 @@  void fwts_framework_log(fwts_framework *fw,
 {
 	char buffer[4096];
 	char prefix[256];
-	char *str = fwts_framework_get_env(result);
+	char *str = fwts_log_field_to_str_upper(field);
 
 	if (fmt) {
 		va_list ap;
@@ -761,29 +668,29 @@  void fwts_framework_log(fwts_framework *fw,
 	if (count)
 		(*count)++;
 
-	switch (result) {
-	case FWTS_FRAMEWORK_ADVICE:
+	switch (field) {
+	case LOG_ADVICE:
 		fwts_log_nl(fw);
 		snprintf(prefix, sizeof(prefix), "%s: ", str);
 		fwts_log_printf(fw->results, LOG_RESULT, level, str, label, prefix, "%s", buffer);
 		fwts_log_nl(fw);
 		break;
-	case FWTS_FRAMEWORK_FAILED:
+	case LOG_FAILED:
 		fw->failed_level |= level;
 		fwts_summary_add(fw, fw->current_major_test->name, level, buffer);
 		snprintf(prefix, sizeof(prefix), "%s [%s] %s: Test %d, ",
 			str, fwts_log_level_to_str(level), label, fw->current_minor_test_num);
 		fwts_log_printf(fw->results, LOG_RESULT, level, str, label, prefix, "%s", buffer);
 		break;
-	case FWTS_FRAMEWORK_PASSED:
-	case FWTS_FRAMEWORK_WARNING:
-	case FWTS_FRAMEWORK_SKIPPED:
-	case FWTS_FRAMEWORK_ABORTED:
+	case LOG_PASSED:
+	case LOG_WARNING:
+	case LOG_SKIPPED:
+	case LOG_ABORTED:
 		snprintf(prefix, sizeof(prefix), "%s: Test %d, ",
 			str, fw->current_minor_test_num);
 		fwts_log_printf(fw->results, LOG_RESULT, level, str, label, prefix, "%s", buffer);
 		break;
-	case FWTS_FRAMEWORK_INFOONLY:
+	case LOG_INFOONLY:
 		break;	/* no-op */
 	default:
 		break;
@@ -1272,7 +1179,6 @@  tidy_close:
 	free(fw->results_logname);
 	free(fw->klog);
 	free(fw->json_data_path);
-	fwts_framework_free_env();
 	fwts_list_free_items(&fw->total_taglist, free);
 	fwts_list_free_items(&fwts_framework_test_list, free);