From patchwork Wed Sep 19 07:43:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 971481 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=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42FX0z5D5hz9sB5; Wed, 19 Sep 2018 17:43:47 +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 1g2X9D-0006x5-6t; Wed, 19 Sep 2018 07:43:43 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1g2X9B-0006wX-31 for fwts-devel@lists.ubuntu.com; Wed, 19 Sep 2018 07:43:41 +0000 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1g2X9A-0006X2-Rb; Wed, 19 Sep 2018 07:43:40 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] kernelscan: add -k option to specify klog json filename Date: Wed, 19 Sep 2018 09:43:40 +0200 Message-Id: <20180919074340.15656-1-colin.king@canonical.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 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: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" From: Colin Ian King This allows one to specify the location of the klog json file. Currently this is hard coded to be /usr/share/fwts/klog.json, but this new option allows one to specify the full path. This allows us to use the json file in the fwts src rather than the installed version. E.g. ./kernelscan.sh -k ~/repos/fwts/data/klog.json ~/repos/linux Signed-off-by: Colin Ian King Acked-by: Alex Hung Acked-by: Ivan Hu --- src/utilities/kernelscan.c | 29 ++++++++++++++++++++++++++--- src/utilities/kernelscan.sh | 33 +++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/utilities/kernelscan.c b/src/utilities/kernelscan.c index 1974f53a..c1655fe4 100644 --- a/src/utilities/kernelscan.c +++ b/src/utilities/kernelscan.c @@ -191,6 +191,8 @@ static char *funcs[] = { #define TABLE_SIZE (5000) +static char *klog_file = DATAROOTDIR "/fwts/klog.json"; + static char *hash_funcs[TABLE_SIZE]; static int get_token(parser *p, token *t); @@ -348,7 +350,7 @@ static klog_pattern *klog_load(const char *table) json_object *klog_table; klog_pattern *patterns; - klog_objs = json_object_from_file(DATAROOTDIR "/fwts/klog.json"); + klog_objs = json_object_from_file(klog_file); if (JSON_ERROR(klog_objs)) { fprintf(stderr, "Cannot load klog data\n"); exit(EXIT_FAILURE); @@ -1015,6 +1017,13 @@ static void hash_init(void) } } +void help(void) +{ + printf("kernelscan:\n"); + printf("-h\t\thelp\n"); + printf("-k file\t\tspecify klog json file\n"); +} + /* * Scan kernel source for printk KERN_ERR and dev_err * calls. @@ -1030,8 +1039,22 @@ static void hash_init(void) */ int main(int argc, char **argv) { - (void)argc; - (void)argv; + for (;;) { + int c = getopt(argc, argv, "hk:"); + if (c == -1) + break; + switch (c) { + case 'h': + help(); + exit(0); + case 'k': + klog_file = optarg; + break; + default: + help(); + exit(1); + } + } patterns = klog_load("firmware_error_warning_patterns"); hash_init(); diff --git a/src/utilities/kernelscan.sh b/src/utilities/kernelscan.sh index 7b274959..61207662 100755 --- a/src/utilities/kernelscan.sh +++ b/src/utilities/kernelscan.sh @@ -32,17 +32,42 @@ if [ $# -lt 1 ]; then exit 1 fi -src=$1 +KLOG=/usr/share/fwts/klog.json -if [ ! -d $1 ]; then - echo "Path '$1' not found" +while [[ $# -gt 0 ]] +do + +case "$1" in + -k) + shift + KLOG=$1 + shift + ;; + *) + src=$1 + shift + ;; +esac +done + +if [ "$src" == "" ]; then + echo "Please provide path to linux source" + exit 1 +fi + +if [ ! -d "$src" ]; then + echo "Path '$src' not found" + exit 1 +fi +if [ ! -e "${KLOG}" ]; then + echo "Path '${KLOG}' not found" exit 1 fi scan_source_file() { if [ -f $1 ]; then - $KERNELSCAN -P < $1 > $TMP + $KERNELSCAN -k ${KLOG} < $1 > $TMP if [ $(stat -c%s $TMP) -gt 0 ]; then echo "Source: $1" cat $TMP