From patchwork Thu May 31 08:24:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 162115 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id E8D7AB6FC5 for ; Thu, 31 May 2012 18:24:29 +1000 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1Sa0gF-00013I-Vs for incoming@patchwork.ozlabs.org; Thu, 31 May 2012 08:24:28 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1Sa0gE-00010z-7P for fwts-devel@lists.ubuntu.com; Thu, 31 May 2012 08:24:26 +0000 Received: from cpc19-craw6-2-0-cust5.croy.cable.virginmedia.com ([77.102.228.6] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1Sa0gE-0005Hm-4N for fwts-devel@lists.ubuntu.com; Thu, 31 May 2012 08:24:26 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] lib: fwts_framework: set log name suffix when using --log-type option Date: Thu, 31 May 2012 09:24:25 +0100 Message-Id: <1338452665-3903-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.7.10 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King Signed-off-by: Colin Ian King Acked-by: Keng-Yu Lin Acked-by: Ivan Hu Tested-by: Chris Van Hoof --- 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; }