[PATCH] lib: fwts_framework: set log name suffix when using --log-type option

Chris Van Hoof vanhoof at canonical.com
Mon Jun 11 16:02:10 UTC 2012


On 05/31/2012 04:24 AM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
> 
> Signed-off-by: Colin Ian King <colin.king at 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 at canonical.com>




More information about the fwts-devel mailing list