From patchwork Wed Jun 20 12:14:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcello Sylvester Bauer X-Patchwork-Id: 932141 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=marcellobauer.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=marcellobauer.com header.i=@marcellobauer.com header.b="lHaMcqjS"; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 419kSK5Fkjz9s7F; Wed, 20 Jun 2018 22:20:33 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1fVc67-0003xq-24; Wed, 20 Jun 2018 12:20:27 +0000 Received: from mo4-p02-ob.smtp.rzone.de ([81.169.146.168]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1fVc10-0003S1-AK for fwts-devel@lists.ubuntu.com; Wed, 20 Jun 2018 12:15:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1529496910; s=strato-dkim-0002; d=marcellobauer.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=pmxH+saBGVH1jjMsvyjly16xgayqwzeAk+hUahNdENs=; b=lHaMcqjS/ETwQiQQ1N0fW3qTvDDyn6o593LR+HADnGh7sOHpsrTi1S6YMhODia3YT7 Qj0ow8JrwMyAoOeMhD+qcV4Wq1i5Qty31nc/bSXH1VqX+6rNt4kU4CUYLXBc3XzRSMua CcXs71MiHPbbprv7YZ7XWj5net2d6FHCADsqNF/nG+mm7PyJCp6A4wLBTVaFj/Pk7Bpb ncilDB3w85U/TFqruyKtAC8xwHF5DI6bks4x8SiMqC91dPecXiAOi9natFW+Rtty+R0S LR8iA+O6MnpjFJSbpVvOKJQJ5BfHeaipzZ3il0X52ctPMCnIgcImpu9kGGdaNClsAN6x Ac9A== X-RZG-AUTH: ":P3kGVU2pafwxDWbfd7lCAWBxt4VwoTflSh0zGwV+MScAah+CJf7PfB0eiCQ3DUlp/Rnv8orA" X-RZG-CLASS-ID: mo00 Received: from W530.9e.network by smtp.strato.de (RZmta 43.10 DYNA|AUTH) with ESMTPSA id Y09740u5KCF914q (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Wed, 20 Jun 2018 14:15:09 +0200 (CEST) From: Marcello Sylvester Bauer To: fwts-devel@lists.ubuntu.com Subject: [PATCH 05/20] fwts_log_scan: move fwts_log_scan Date: Wed, 20 Jun 2018 14:14:31 +0200 Message-Id: <20180620121446.31470-6-info@marcellobauer.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180620121446.31470-1-info@marcellobauer.com> References: <20180620121446.31470-1-info@marcellobauer.com> X-Mailman-Approved-At: Wed, 20 Jun 2018 12:20:25 +0000 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marcello Sylvester Bauer MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" Note: boolean remove_timestamp has been added as argument. Signed-off-by: Marcello Sylvester Bauer Acked-by: Colin Ian King Acked-by: Alex Hung --- src/lib/include/fwts_log_scan.h | 4 ++ src/lib/src/fwts_klog.c | 79 +-------------------------------- src/lib/src/fwts_log_scan.c | 98 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 78 deletions(-) diff --git a/src/lib/include/fwts_log_scan.h b/src/lib/include/fwts_log_scan.h index e08d0aac..31fa3f7e 100644 --- a/src/lib/include/fwts_log_scan.h +++ b/src/lib/include/fwts_log_scan.h @@ -38,8 +38,12 @@ typedef struct { bool compiled_ok; } fwts_log_pattern; +typedef void (*fwts_log_progress_func)(fwts_framework *fw, int percent); +typedef void (*fwts_log_scan_func)(fwts_framework *fw, char *line, int repeated, char *prevline, void *private, int *errors); + void fwts_log_free(fwts_list *list); fwts_list *fwts_log_find_changes(fwts_list *log_old, fwts_list *log_new); char *fwts_log_remove_timestamp(char *text); +int fwts_log_scan(fwts_framework *fw, fwts_list *log, fwts_log_scan_func callback, fwts_log_progress_func progress, void *private, int *errors, bool remove_timestamp); #endif diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c index 25491815..94195261 100644 --- a/src/lib/src/fwts_klog.c +++ b/src/lib/src/fwts_klog.c @@ -93,84 +93,7 @@ int fwts_klog_scan(fwts_framework *fw, void *private, int *match) { - typedef struct { - char *line; - int repeated; - } klog_reduced_item; - - char *prev; - fwts_list_link *item; - fwts_list *klog_reduced; - int i; - - *match = 0; - - if (!klog) - return FWTS_ERROR; - - if ((klog_reduced = fwts_list_new()) == NULL) - return FWTS_ERROR; - - /* - * Form a reduced log by stripping out repeated kernel warnings - */ - i = 0; - fwts_list_foreach(item, klog) { - char *newline = fwts_klog_remove_timestamp(fwts_list_data(char *, item)); - if (progress_func && ((i % 25) == 0)) - progress_func(fw, 50 * i / fwts_list_len(klog)); - if (*newline) { - bool matched = false; - fwts_list_link *l; - fwts_list_foreach(l, klog_reduced) { - char *line; - klog_reduced_item *reduced = fwts_list_data(klog_reduced_item *, l); - - line = fwts_klog_remove_timestamp(reduced->line); - if (strcmp(newline, line) == 0) { - reduced->repeated++; - matched = true; - break; - } - } - if (!matched) { - klog_reduced_item *new; - - if ((new = calloc(1, sizeof(klog_reduced_item))) == NULL) { - fwts_list_free(klog_reduced, free); - return FWTS_ERROR; - } - new->line = fwts_list_data(char *, item); - new->repeated = 0; - - fwts_list_append(klog_reduced, new); - } - } - i++; - } - - prev = ""; - - i = 0; - fwts_list_foreach(item, klog_reduced) { - klog_reduced_item *reduced = fwts_list_data(klog_reduced_item *, item); - char *line = reduced->line; - - if ((line[0] == '<') && (line[2] == '>')) - line += 3; - - scan_func(fw, line, reduced->repeated, prev, private, match); - if (progress_func && ((i % 25) == 0)) - progress_func(fw, (50+(50 * i)) / fwts_list_len(klog_reduced)); - prev = line; - i++; - } - if (progress_func) - progress_func(fw, 100); - - fwts_list_free(klog_reduced, free); - - return FWTS_OK; + return fwts_log_scan(fw, klog, scan_func, progress_func, private, match, true); } char *fwts_klog_unique_label(const char *str) diff --git a/src/lib/src/fwts_log_scan.c b/src/lib/src/fwts_log_scan.c index f6050fbc..9b9e9457 100644 --- a/src/lib/src/fwts_log_scan.c +++ b/src/lib/src/fwts_log_scan.c @@ -107,3 +107,101 @@ char *fwts_log_remove_timestamp(char *text) return ptr; } + +int fwts_log_scan(fwts_framework *fw, + fwts_list *log, + fwts_log_scan_func scan_func, + fwts_log_progress_func progress_func, + void *private, + int *match, + bool remove_timestamp) +{ + typedef struct { + char *line; + int repeated; + } log_reduced_item; + + char *prev; + fwts_list_link *item; + fwts_list *log_reduced; + int i; + char *newline = NULL; + + *match = 0; + + if (!log) + return FWTS_ERROR; + + if ((log_reduced = fwts_list_new()) == NULL) + return FWTS_ERROR; + + /* + * Form a reduced log by stripping out repeated warnings + */ + i = 0; + fwts_list_foreach(item, log) { + if (remove_timestamp) { + newline = fwts_log_remove_timestamp(fwts_list_data(char *, item)); + } else { + newline = fwts_list_data(char *, item); + } + + if (progress_func && ((i % 25) == 0)) + progress_func(fw, 50 * i / fwts_list_len(log)); + if (*newline) { + bool matched = false; + fwts_list_link *l; + fwts_list_foreach(l, log_reduced) { + char *line; + log_reduced_item *reduced = fwts_list_data(log_reduced_item *, l); + + if (remove_timestamp) + line = fwts_log_remove_timestamp(reduced->line); + else + line = reduced->line; + + if (strcmp(newline, line) == 0) { + reduced->repeated++; + matched = true; + break; + } + } + if (!matched) { + log_reduced_item *new; + + if ((new = calloc(1, sizeof(log_reduced_item))) == NULL) { + fwts_list_free(log_reduced, free); + return FWTS_ERROR; + } + new->line = fwts_list_data(char *, item); + new->repeated = 0; + + fwts_list_append(log_reduced, new); + } + } + i++; + } + + prev = ""; + + i = 0; + fwts_list_foreach(item, log_reduced) { + log_reduced_item *reduced = fwts_list_data(log_reduced_item *, item); + char *line = reduced->line; + + if ((line[0] == '<') && (line[2] == '>')) + line += 3; + + scan_func(fw, line, reduced->repeated, prev, private, match); + if (progress_func && ((i % 25) == 0)) + progress_func(fw, (50+(50 * i)) / fwts_list_len(log_reduced)); + prev = line; + i++; + } + if (progress_func) + progress_func(fw, 100); + + fwts_list_free(log_reduced, free); + + return FWTS_OK; +}