From patchwork Thu Dec 19 13:18:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pengfei Xu X-Patchwork-Id: 1213369 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=intel.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47dsjt2JRnz9sQp for ; Fri, 20 Dec 2019 00:12:34 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 50F863C2384 for ; Thu, 19 Dec 2019 14:12:31 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id 991563C2284 for ; Thu, 19 Dec 2019 14:12:29 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 82F3B14012C9 for ; Thu, 19 Dec 2019 14:12:27 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Dec 2019 05:12:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,332,1571727600"; d="scan'208";a="390529908" Received: from xpf-desktop.sh.intel.com ([10.239.13.102]) by orsmga005.jf.intel.com with ESMTP; 19 Dec 2019 05:12:23 -0800 From: Pengfei Xu To: ltp , Pengfei Xu , Neri Ricardo , Su Heng , Cyril Hrubis Date: Thu, 19 Dec 2019 21:18:52 +0800 Message-Id: <20191219131855.28799-1-pengfei.xu@intel.com> X-Mailer: git-send-email 2.14.1 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v4 1/4] lib/tst_kconfig.c: Add any kconfig to match the expected value function X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Example: CONFIG_X86_INTEL_UMIP=y for umip kconfig before and v5.4 mainline kernel. CONFIG_X86_UMIP=y for umip kconfig after v5.5 mainline kernel. Format: CONFIG_X86_INTEL_UMIP|CONFIG_X86_UMIP=y Signed-off-by: Pengfei Xu Reviewed-by: Yang Xu --- lib/tst_kconfig.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c index 4b51413e5..74c46ebec 100644 --- a/lib/tst_kconfig.c +++ b/lib/tst_kconfig.c @@ -167,7 +167,8 @@ void tst_kconfig_read(const char *const *kconfigs, struct match matches[cnt]; FILE *fp; unsigned int i, j; - char buf[1024]; + char buf[1024], kconfig_multi[100]; + char *kconfig_token = NULL, *p_left = NULL; for (i = 0; i < cnt; i++) { const char *val = strchr(kconfigs[i], '='); @@ -176,12 +177,9 @@ void tst_kconfig_read(const char *const *kconfigs, tst_brk(TBROK, "Invalid config string '%s'", kconfigs[i]); matches[i].match = 0; - matches[i].len = strlen(kconfigs[i]); - if (val) { + if (val) matches[i].val = val + 1; - matches[i].len -= strlen(val); - } results[i].match = 0; results[i].value = NULL; @@ -193,17 +191,29 @@ void tst_kconfig_read(const char *const *kconfigs, while (fgets(buf, sizeof(buf), fp)) { for (i = 0; i < cnt; i++) { - if (match(&matches[i], kconfigs[i], &results[i], buf)) { - for (j = 0; j < cnt; j++) { - if (matches[j].match) - break; + memset(kconfig_multi, 0, sizeof(kconfig_multi)); + /* strtok_r will split kconfigs[i] to multi string, so copy it */ + memcpy(kconfig_multi, kconfigs[i], strlen(kconfigs[i])); + kconfig_token = strtok_r(kconfig_multi, "|=", &p_left); + + while (kconfig_token != NULL) { + if (strncmp("CONFIG_", kconfig_token, 7)) + tst_brk(TBROK, "Invalid config string '%s'", kconfig_token); + matches[i].len = strlen(kconfig_token); + if (match(&matches[i], kconfig_token, &results[i], buf)) { + for (j = 0; j < cnt; j++) { + if (matches[j].match) + break; + } } - - if (j == cnt) - goto exit; + kconfig_token = strtok_r(NULL, "|=", &p_left); + /* avoid to use after "=" string */ + if (strlen(p_left) == 0) + break; } + if (j == cnt) + goto exit; } - } exit: