Patchwork lib: fwts_framework: set log name suffix when using --log-type option

login
register
mail settings
Submitter Colin King
Date May 31, 2012, 8:24 a.m.
Message ID <1338452665-3903-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/162115/
State Accepted
Headers show

Comments

Colin King - May 31, 2012, 8:24 a.m.
From: Colin Ian King <colin.king@canonical.com>

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_framework.c |   42 +++++++++++++++++++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 5 deletions(-)
Keng-Yu Lin - June 4, 2012, 8:32 a.m.
On Thu, May 31, 2012 at 4:24 PM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_framework.c |   42 +++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 37 insertions(+), 5 deletions(-)
>
> diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
> index 721f4de..a43d31b 100644
> --- a/src/lib/src/fwts_framework.c
> +++ b/src/lib/src/fwts_framework.c
> @@ -96,6 +96,34 @@ static const char *fwts_copyright[] = {
>  };
>
>  /*
> + *  fwts_framework_log_suffix()
> + *     set the log name suffix
> + */
> +static void fwts_framework_log_suffix(fwts_framework *fw, const char *suffix)
> +{
> +       char *ptr;
> +       char *new;
> +       size_t len;
> +
> +       /* Locate old suffix and kill it */
> +       ptr = rindex(fw->results_logname, '.');
> +       if (ptr != NULL)
> +               *ptr = '\0';
> +
> +       /* Space for old log name sans old suffix + new suffix + '.' + '\0' */
> +       len = strlen(fw->results_logname) + strlen(suffix) + 2;
> +
> +       if ((new = calloc(len, 1)) == NULL) {
> +               fprintf(stderr, "Cannot allocate log name.\n");
> +               exit(EXIT_FAILURE);
> +       }
> +
> +       snprintf(new, len, "%s.%s", fw->results_logname, suffix);
> +       free(fw->results_logname);
> +       fw->results_logname = new;
> +}
> +
> +/*
>  *  fwts_framework_compare_priority()
>  *     used to register tests sorted on run priority
>  */
> @@ -943,15 +971,19 @@ int fwts_framework_options_handler(fwts_framework *fw, int argc, char * const ar
>                        fwts_iasl_disassemble_all_to_file(fw);
>                        return FWTS_COMPLETE;
>                case 32: /* --log-type */
> -                       if (!strcmp(optarg, "plaintext"))
> +                       if (!strcmp(optarg, "plaintext")) {
>                                fw->log_type = LOG_TYPE_PLAINTEXT;
> -                       else if (!strcmp(optarg, "json"))
> +                               fwts_framework_log_suffix(fw, "log");
> +                       } else if (!strcmp(optarg, "json")) {
>                                fw->log_type = LOG_TYPE_JSON;
> -                       else if (!strcmp(optarg, "xml"))
> +                               fwts_framework_log_suffix(fw, "json");
> +                       } else if (!strcmp(optarg, "xml")) {
>                                fw->log_type = LOG_TYPE_XML;
> -                       else if (!strcmp(optarg, "html"))
> +                               fwts_framework_log_suffix(fw, "xml");
> +                       } else if (!strcmp(optarg, "html")) {
>                                fw->log_type = LOG_TYPE_HTML;
> -                       else {
> +                               fwts_framework_log_suffix(fw, "html");
> +                       } else {
>                                fprintf(stderr, "--log-type can be either plaintext, xml, html or json.\n");
>                                return FWTS_ERROR;
>                        }
> --
> 1.7.10
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Ivan Hu - June 6, 2012, 3:25 a.m.
On 05/31/2012 04:24 PM, Colin King wrote:
> From: Colin Ian King<colin.king@canonical.com>
>
> Signed-off-by: Colin Ian King<colin.king@canonical.com>
> ---
>   src/lib/src/fwts_framework.c |   42 +++++++++++++++++++++++++++++++++++++-----
>   1 file changed, 37 insertions(+), 5 deletions(-)
>
> diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
> index 721f4de..a43d31b 100644
> --- a/src/lib/src/fwts_framework.c
> +++ b/src/lib/src/fwts_framework.c
> @@ -96,6 +96,34 @@ static const char *fwts_copyright[] = {
>   };
>
>   /*
> + *  fwts_framework_log_suffix()
> + *	set the log name suffix
> + */
> +static void fwts_framework_log_suffix(fwts_framework *fw, const char *suffix)
> +{
> +	char *ptr;
> +	char *new;
> +	size_t len;
> +
> +	/* Locate old suffix and kill it */
> +	ptr = rindex(fw->results_logname, '.');
> +	if (ptr != NULL)
> +		*ptr = '\0';
> +
> +	/* Space for old log name sans old suffix + new suffix + '.' + '\0' */
> +	len = strlen(fw->results_logname) + strlen(suffix) + 2;
> +
> +	if ((new = calloc(len, 1)) == NULL) {
> +		fprintf(stderr, "Cannot allocate log name.\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	snprintf(new, len, "%s.%s", fw->results_logname, suffix);
> +	free(fw->results_logname);
> +	fw->results_logname = new;
> +}
> +
> +/*
>    *  fwts_framework_compare_priority()
>    *	used to register tests sorted on run priority
>    */
> @@ -943,15 +971,19 @@ int fwts_framework_options_handler(fwts_framework *fw, int argc, char * const ar
>   			fwts_iasl_disassemble_all_to_file(fw);
>   			return FWTS_COMPLETE;
>   		case 32: /* --log-type */
> -			if (!strcmp(optarg, "plaintext"))
> +			if (!strcmp(optarg, "plaintext")) {
>   				fw->log_type = LOG_TYPE_PLAINTEXT;
> -			else if (!strcmp(optarg, "json"))
> +				fwts_framework_log_suffix(fw, "log");
> +			} else if (!strcmp(optarg, "json")) {
>   				fw->log_type = LOG_TYPE_JSON;
> -			else if (!strcmp(optarg, "xml"))
> +				fwts_framework_log_suffix(fw, "json");
> +			} else if (!strcmp(optarg, "xml")) {
>   				fw->log_type = LOG_TYPE_XML;
> -			else if (!strcmp(optarg, "html"))
> +				fwts_framework_log_suffix(fw, "xml");
> +			} else if (!strcmp(optarg, "html")) {
>   				fw->log_type = LOG_TYPE_HTML;
> -			else {
> +				fwts_framework_log_suffix(fw, "html");
> +			} else {
>   				fprintf(stderr, "--log-type can be either plaintext, xml, html or json.\n");
>   				return FWTS_ERROR;
>   			}
Acked-by: Ivan Hu<ivan.hu@canonical.com>
Chris Van Hoof - June 11, 2012, 4:02 p.m.
On 05/31/2012 04:24 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_framework.c |   42 +++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 37 insertions(+), 5 deletions(-)
> 
> diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
> index 721f4de..a43d31b 100644
> --- a/src/lib/src/fwts_framework.c
> +++ b/src/lib/src/fwts_framework.c
> @@ -96,6 +96,34 @@ static const char *fwts_copyright[] = {
>  };
>  
>  /*
> + *  fwts_framework_log_suffix()
> + *	set the log name suffix
> + */
> +static void fwts_framework_log_suffix(fwts_framework *fw, const char *suffix)
> +{
> +	char *ptr;
> +	char *new;
> +	size_t len;
> +
> +	/* Locate old suffix and kill it */
> +	ptr = rindex(fw->results_logname, '.');
> +	if (ptr != NULL)
> +		*ptr = '\0';
> +
> +	/* Space for old log name sans old suffix + new suffix + '.' + '\0' */
> +	len = strlen(fw->results_logname) + strlen(suffix) + 2;
> +
> +	if ((new = calloc(len, 1)) == NULL) {
> +		fprintf(stderr, "Cannot allocate log name.\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	snprintf(new, len, "%s.%s", fw->results_logname, suffix);
> +	free(fw->results_logname);
> +	fw->results_logname = new;
> +}
> +
> +/*
>   *  fwts_framework_compare_priority()
>   *	used to register tests sorted on run priority
>   */
> @@ -943,15 +971,19 @@ int fwts_framework_options_handler(fwts_framework *fw, int argc, char * const ar
>  			fwts_iasl_disassemble_all_to_file(fw);
>  			return FWTS_COMPLETE;
>  		case 32: /* --log-type */
> -			if (!strcmp(optarg, "plaintext"))
> +			if (!strcmp(optarg, "plaintext")) {
>  				fw->log_type = LOG_TYPE_PLAINTEXT;
> -			else if (!strcmp(optarg, "json"))
> +				fwts_framework_log_suffix(fw, "log");
> +			} else if (!strcmp(optarg, "json")) {
>  				fw->log_type = LOG_TYPE_JSON;
> -			else if (!strcmp(optarg, "xml"))
> +				fwts_framework_log_suffix(fw, "json");
> +			} else if (!strcmp(optarg, "xml")) {
>  				fw->log_type = LOG_TYPE_XML;
> -			else if (!strcmp(optarg, "html"))
> +				fwts_framework_log_suffix(fw, "xml");
> +			} else if (!strcmp(optarg, "html")) {
>  				fw->log_type = LOG_TYPE_HTML;
> -			else {
> +				fwts_framework_log_suffix(fw, "html");
> +			} else {
>  				fprintf(stderr, "--log-type can be either plaintext, xml, html or json.\n");
>  				return FWTS_ERROR;
>  			}

This worked prior to today's updates as well, testing when only one
--log-type was supported (eg: html), yielded a results.html file.

Testing today with --log-type html,plaintext yielded both a results.html
and results.log file.

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

Patch

diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
index 721f4de..a43d31b 100644
--- a/src/lib/src/fwts_framework.c
+++ b/src/lib/src/fwts_framework.c
@@ -96,6 +96,34 @@  static const char *fwts_copyright[] = {
 };
 
 /*
+ *  fwts_framework_log_suffix()
+ *	set the log name suffix
+ */
+static void fwts_framework_log_suffix(fwts_framework *fw, const char *suffix)
+{
+	char *ptr;
+	char *new;
+	size_t len;
+
+	/* Locate old suffix and kill it */
+	ptr = rindex(fw->results_logname, '.');
+	if (ptr != NULL)
+		*ptr = '\0';
+
+	/* Space for old log name sans old suffix + new suffix + '.' + '\0' */
+	len = strlen(fw->results_logname) + strlen(suffix) + 2;
+
+	if ((new = calloc(len, 1)) == NULL) {
+		fprintf(stderr, "Cannot allocate log name.\n");
+		exit(EXIT_FAILURE);
+	}
+
+	snprintf(new, len, "%s.%s", fw->results_logname, suffix);
+	free(fw->results_logname);
+	fw->results_logname = new;
+}
+
+/*
  *  fwts_framework_compare_priority()
  *	used to register tests sorted on run priority
  */
@@ -943,15 +971,19 @@  int fwts_framework_options_handler(fwts_framework *fw, int argc, char * const ar
 			fwts_iasl_disassemble_all_to_file(fw);
 			return FWTS_COMPLETE;
 		case 32: /* --log-type */
-			if (!strcmp(optarg, "plaintext"))
+			if (!strcmp(optarg, "plaintext")) {
 				fw->log_type = LOG_TYPE_PLAINTEXT;
-			else if (!strcmp(optarg, "json"))
+				fwts_framework_log_suffix(fw, "log");
+			} else if (!strcmp(optarg, "json")) {
 				fw->log_type = LOG_TYPE_JSON;
-			else if (!strcmp(optarg, "xml"))
+				fwts_framework_log_suffix(fw, "json");
+			} else if (!strcmp(optarg, "xml")) {
 				fw->log_type = LOG_TYPE_XML;
-			else if (!strcmp(optarg, "html"))
+				fwts_framework_log_suffix(fw, "xml");
+			} else if (!strcmp(optarg, "html")) {
 				fw->log_type = LOG_TYPE_HTML;
-			else {
+				fwts_framework_log_suffix(fw, "html");
+			} else {
 				fprintf(stderr, "--log-type can be either plaintext, xml, html or json.\n");
 				return FWTS_ERROR;
 			}