Patchwork acpi: syntaxcheck: ensure error message strings are in sync with error (LP: #1200568)

login
register
mail settings
Submitter Colin King
Date July 12, 2013, 11:03 a.m.
Message ID <1373627004-32380-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/258737/
State Accepted
Headers show

Comments

Colin King - July 12, 2013, 11:03 a.m.
From: Colin Ian King <colin.king@canonical.com>

We should use the AslErrorLevel[] strings that 1-to-1 match the ASL_MESSAGE_TYPES
rather than defining our own.  These strings come with trailing spaces, so we need
to trim these off.

Also report ASL_REMARKS since these may be helful and we've not yet been tracking these.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/acpi/syntaxcheck/syntaxcheck.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
Alex Hung - July 15, 2013, 6:10 a.m.
On 07/12/2013 07:03 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> We should use the AslErrorLevel[] strings that 1-to-1 match the ASL_MESSAGE_TYPES
> rather than defining our own.  These strings come with trailing spaces, so we need
> to trim these off.
>
> Also report ASL_REMARKS since these may be helful and we've not yet been tracking these.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpi/syntaxcheck/syntaxcheck.c | 26 +++++++++++++++-----------
>   1 file changed, 15 insertions(+), 11 deletions(-)
>
> diff --git a/src/acpi/syntaxcheck/syntaxcheck.c b/src/acpi/syntaxcheck/syntaxcheck.c
> index 61d46f8..44399cb 100644
> --- a/src/acpi/syntaxcheck/syntaxcheck.c
> +++ b/src/acpi/syntaxcheck/syntaxcheck.c
> @@ -29,6 +29,8 @@
>
>   #include <json/json.h>
>
> +#define ASL_EXCEPTIONS	/* so we can include AslErrorLevel in aslmessages.h */
> +
>   #include "aslmessages.h"
>
>   typedef struct {
> @@ -259,20 +261,20 @@ static const char *syntaxcheck_error_code_to_id(const uint32_t error_code)
>   static const char *syntaxcheck_error_level(uint32_t error_code)
>   {
>   	uint16_t error_level = syntaxcheck_error_code_to_error_level(error_code);
> +	static char buf[64];
> +	char *ptr;
>
> -	static char *error_levels[] = {
> -		"warning (level 0)",
> -		"warning (level 1)",
> -		"warning (level 2)",
> -		"error",
> -		"remark",
> -		"optimization",
> -		"unknown",
> -	};
> +	/* Out of range for some reason? */
> +	if (error_level >= ASL_NUM_REPORT_LEVELS)
> +		return "Unknown";
>
> -	const int max_levels = (sizeof(error_levels) / sizeof(char*)) - 1;
> +	/* AslErrorLevel strings are end-space padded, so strip off end spaces if any */
> +	strcpy(buf, AslErrorLevel[error_level]);
> +	ptr = strchr(buf, ' ');
> +	if (ptr)
> +		*ptr = '\0';
>
> -	return error_levels[error_level > max_levels ? max_levels : error_level];
> +	return buf;
>   }
>
>   /*
> @@ -508,6 +510,8 @@ static int syntaxcheck_table(fwts_framework *fw, char *tablename, int which)
>   							fwts_failed(fw, LOG_LEVEL_HIGH, label, "Assembler error in line %d", num);
>   							break;
>   						case ASL_REMARK:
> +							fwts_log_info(fw, "Assembler remark in line %d", num);
> +							break;
>   						case ASL_OPTIMIZATION:
>   							skip = true;
>   							break;
>

Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu - July 16, 2013, 8:49 a.m.
On 07/12/2013 07:03 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> We should use the AslErrorLevel[] strings that 1-to-1 match the ASL_MESSAGE_TYPES
> rather than defining our own.  These strings come with trailing spaces, so we need
> to trim these off.
>
> Also report ASL_REMARKS since these may be helful and we've not yet been tracking these.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpi/syntaxcheck/syntaxcheck.c | 26 +++++++++++++++-----------
>   1 file changed, 15 insertions(+), 11 deletions(-)
>
> diff --git a/src/acpi/syntaxcheck/syntaxcheck.c b/src/acpi/syntaxcheck/syntaxcheck.c
> index 61d46f8..44399cb 100644
> --- a/src/acpi/syntaxcheck/syntaxcheck.c
> +++ b/src/acpi/syntaxcheck/syntaxcheck.c
> @@ -29,6 +29,8 @@
>
>   #include <json/json.h>
>
> +#define ASL_EXCEPTIONS	/* so we can include AslErrorLevel in aslmessages.h */
> +
>   #include "aslmessages.h"
>
>   typedef struct {
> @@ -259,20 +261,20 @@ static const char *syntaxcheck_error_code_to_id(const uint32_t error_code)
>   static const char *syntaxcheck_error_level(uint32_t error_code)
>   {
>   	uint16_t error_level = syntaxcheck_error_code_to_error_level(error_code);
> +	static char buf[64];
> +	char *ptr;
>
> -	static char *error_levels[] = {
> -		"warning (level 0)",
> -		"warning (level 1)",
> -		"warning (level 2)",
> -		"error",
> -		"remark",
> -		"optimization",
> -		"unknown",
> -	};
> +	/* Out of range for some reason? */
> +	if (error_level >= ASL_NUM_REPORT_LEVELS)
> +		return "Unknown";
>
> -	const int max_levels = (sizeof(error_levels) / sizeof(char*)) - 1;
> +	/* AslErrorLevel strings are end-space padded, so strip off end spaces if any */
> +	strcpy(buf, AslErrorLevel[error_level]);
> +	ptr = strchr(buf, ' ');
> +	if (ptr)
> +		*ptr = '\0';
>
> -	return error_levels[error_level > max_levels ? max_levels : error_level];
> +	return buf;
>   }
>
>   /*
> @@ -508,6 +510,8 @@ static int syntaxcheck_table(fwts_framework *fw, char *tablename, int which)
>   							fwts_failed(fw, LOG_LEVEL_HIGH, label, "Assembler error in line %d", num);
>   							break;
>   						case ASL_REMARK:
> +							fwts_log_info(fw, "Assembler remark in line %d", num);
> +							break;
>   						case ASL_OPTIMIZATION:
>   							skip = true;
>   							break;
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch

diff --git a/src/acpi/syntaxcheck/syntaxcheck.c b/src/acpi/syntaxcheck/syntaxcheck.c
index 61d46f8..44399cb 100644
--- a/src/acpi/syntaxcheck/syntaxcheck.c
+++ b/src/acpi/syntaxcheck/syntaxcheck.c
@@ -29,6 +29,8 @@ 
 
 #include <json/json.h>
 
+#define ASL_EXCEPTIONS	/* so we can include AslErrorLevel in aslmessages.h */
+
 #include "aslmessages.h"
 
 typedef struct {
@@ -259,20 +261,20 @@  static const char *syntaxcheck_error_code_to_id(const uint32_t error_code)
 static const char *syntaxcheck_error_level(uint32_t error_code)
 {
 	uint16_t error_level = syntaxcheck_error_code_to_error_level(error_code);
+	static char buf[64];
+	char *ptr;
 
-	static char *error_levels[] = {
-		"warning (level 0)",
-		"warning (level 1)",
-		"warning (level 2)",
-		"error",
-		"remark",
-		"optimization",
-		"unknown",
-	};
+	/* Out of range for some reason? */
+	if (error_level >= ASL_NUM_REPORT_LEVELS)
+		return "Unknown";
 
-	const int max_levels = (sizeof(error_levels) / sizeof(char*)) - 1;
+	/* AslErrorLevel strings are end-space padded, so strip off end spaces if any */
+	strcpy(buf, AslErrorLevel[error_level]);
+	ptr = strchr(buf, ' ');
+	if (ptr)
+		*ptr = '\0';
 
-	return error_levels[error_level > max_levels ? max_levels : error_level];
+	return buf;
 }
 
 /*
@@ -508,6 +510,8 @@  static int syntaxcheck_table(fwts_framework *fw, char *tablename, int which)
 							fwts_failed(fw, LOG_LEVEL_HIGH, label, "Assembler error in line %d", num);
 							break;
 						case ASL_REMARK:
+							fwts_log_info(fw, "Assembler remark in line %d", num);
+							break;
 						case ASL_OPTIMIZATION:
 							skip = true;
 							break;