Message ID | 20230131220355.1603527-2-rmoar@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp57495wrn; Tue, 31 Jan 2023 14:06:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXvaaKow1OsOuEaJDlKe7BvunlVdkZpF4goO3mCfEWDvRjCqMrpNNqyQToyYMZgyH6U6zciU X-Received: by 2002:a17:907:a2cb:b0:870:7b:94db with SMTP id re11-20020a170907a2cb00b00870007b94dbmr67757207ejc.28.1675202783814; Tue, 31 Jan 2023 14:06:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675202783; cv=none; d=google.com; s=arc-20160816; b=J4nQkTGWZVo/FqgP+5uLvafAch8ect8bZjQTCyou8++aAkFbd39geZtLqBv38fP0/g l/v803I3e+7l4DO7dqDsXtIVAHAovfXd0VrvHMLx8EvCs72pCjORq9TVgpiG4/zXZTDQ dpPv4/DaxPREjIpaIGAcpaUC12E5WtiKxlazAoNQifFynQTwSB1l+wCW5uxwnhJShs/f z8oGZmB+XynJhtGdasAI0k9sINOnyuLUEkCsgJVTZQzJLbuoX+jK8yM+vMDIU21VlPp+ dv3Cc9n7Us+BjTGmMobVx07qAEhxRSRIDsrUkG53tKvM0sfpgB2RmYMHN+gN8FKLmsu2 59RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=meTLPB0S8isCGh32fDdvuybRpGWXcZkpfQ+uXtFdMFQ=; b=X+o0NgmZpTOXUR5H9iXHJi8v+o1VbJwgoBe3TXIoeqyfKS+7ZHlE3HestkZR5MWABz ToJPJh2CYzqLcM8RnphagBemJkdNszuzTcL99XVVeG95kiCSaZwQTtmBLUg22Z7n4udi 5egxRaFrRPkDxxTna3mNtbhWfZpTuNxEgY3P+l/dG97FNW1oyoFOWixMO+e8sKtejsiy zrRT1s6DG63UOeMqOa/XUJTa98bt9eqA4xsZKwCkDJbmvlgiYNLW9gv1tKws9acEBlrl xw1+YvRSlymVsLcmY5DroOQ/GuaRd4bIjFdtjLwMEDOdUDRTzWRQbEJcG05f01JTEcmf LdRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Xsd5tBjM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id vl11-20020a17090730cb00b0088ac4402980si5662508ejb.489.2023.01.31.14.06.00; Tue, 31 Jan 2023 14:06:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Xsd5tBjM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231137AbjAaWEK (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Tue, 31 Jan 2023 17:04:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230364AbjAaWEG (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 31 Jan 2023 17:04:06 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E93A65A376 for <linux-kernel@vger.kernel.org>; Tue, 31 Jan 2023 14:04:05 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id g138-20020a25db90000000b0080c27bde887so14049334ybf.18 for <linux-kernel@vger.kernel.org>; Tue, 31 Jan 2023 14:04:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=meTLPB0S8isCGh32fDdvuybRpGWXcZkpfQ+uXtFdMFQ=; b=Xsd5tBjM1lfSWnku+1fCrRq6TpFyYgHrqqrStFmgQulM46YKhzw95lcbuLT+XV4I+L U5GynEi8XZ09sJSsFe9ObfcmT/c5gP1dSMxk7kq6VRjy+1NhCXDwg6SQjgEvQgHxAGCL wKSpMUrcj2u5LhBLq2V22IlUES1INRe4k9mrwlPm0i1JrJQf5mJ2IRfDoLNL7XzEG+Nm dpe6o4t5d7wMKnrEFcQXbQGntxUQfkx+XVJOmDgVrggrcImZEe8zMyMTFM7ogLMqifb7 dEiGmsBxVZ31z6MR1l3GMLxN2JaNGdQdh+1Qr7MaNUd7DRjbnDoKXMwT0PVGXn27v97N cUMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=meTLPB0S8isCGh32fDdvuybRpGWXcZkpfQ+uXtFdMFQ=; b=FmPXRmaHz9dYV5cm5S6KNZYU4H8rQp+gE9zXA4FdSaKtrz30G8XXZ+5UH4RM3wseWU s84IuIVwe5AgbPMmG9vJydhiRp0LjtbJuEcx11HpqDNQEEGqQ2r6H7YADj2Uo8wM6b1X OQGfA8M/xfgneoxo9QkYeriue67zBi8ZxSpzhDeD2EFL7mqEpZagVtFSpo6M25Dv2E6S ADQdDhsLQN0POv75nVGxzuOk3yWq7ei9C7HvZ/H0ofy49eASPXdfGStqyYIRFB0HGmiO M/qBgDafkAQJgRfsJAB1CzTu4n7oYPi87Gh20ozDTeKEDWh1RXdRYU3utNhbMvg/rsO1 H2VQ== X-Gm-Message-State: AO0yUKUuirUt7Ro/+IQO0GByX1/iDQszQoDkDmPCo3HxcEMmIT+06Pj+ UFYTdGsdwjW7BuI414LXq2B4QDdK8g== X-Received: from rmoar-specialist.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:45d3]) (user=rmoar job=sendgmr) by 2002:a81:1109:0:b0:506:3b2d:da68 with SMTP id 9-20020a811109000000b005063b2dda68mr3173122ywr.94.1675202645233; Tue, 31 Jan 2023 14:04:05 -0800 (PST) Date: Tue, 31 Jan 2023 22:03:53 +0000 In-Reply-To: <20230131220355.1603527-1-rmoar@google.com> Mime-Version: 1.0 References: <20230131220355.1603527-1-rmoar@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Message-ID: <20230131220355.1603527-2-rmoar@google.com> Subject: [PATCH v1 1/3] kunit: fix bug in debugfs logs of parameterized tests From: Rae Moar <rmoar@google.com> To: brendanhiggins@google.com, davidgow@google.com, dlatypov@google.com Cc: skhan@linuxfoundation.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Rae Moar <rmoar@google.com> Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756577434658914361?= X-GMAIL-MSGID: =?utf-8?q?1756577434658914361?= |
Series |
kunit: fix bugs in debugfs logs
|
|
Commit Message
Rae Moar
Jan. 31, 2023, 10:03 p.m. UTC
Fix bug in debugfs logs that causes parameterized results to not appear
in the log because the log is reintialized (cleared) when each parameter is
run.
Ensure these results appear in the debugfs logs and increase log size to
allow for the size of parameterized results.
Signed-off-by: Rae Moar <rmoar@google.com>
---
include/kunit/test.h | 2 +-
lib/kunit/test.c | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
Comments
Hi Rae,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on 766f4f2514d2d18bcbd60a058188fb502dea5ddf]
url: https://github.com/intel-lab-lkp/linux/commits/Rae-Moar/kunit-fix-bug-in-debugfs-logs-of-parameterized-tests/20230201-060537
base: 766f4f2514d2d18bcbd60a058188fb502dea5ddf
patch link: https://lore.kernel.org/r/20230131220355.1603527-2-rmoar%40google.com
patch subject: [PATCH v1 1/3] kunit: fix bug in debugfs logs of parameterized tests
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20230201/202302010709.7ZmEen4w-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/c8b669e1d139e1ee08121b184d859e45d7a02940
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Rae-Moar/kunit-fix-bug-in-debugfs-logs-of-parameterized-tests/20230201-060537
git checkout c8b669e1d139e1ee08121b184d859e45d7a02940
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash lib/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
lib/kunit/test.c: In function '__kunit_fail_current_test_impl':
lib/kunit/test.c:40:9: warning: function '__kunit_fail_current_test_impl' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]
40 | len = vsnprintf(NULL, 0, fmt, args) + 1;
| ^~~
lib/kunit/test.c:48:9: warning: function '__kunit_fail_current_test_impl' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]
48 | vsnprintf(buffer, len, fmt, args);
| ^~~~~~~~~
lib/kunit/test.c: In function 'kunit_log_append':
>> lib/kunit/test.c:133:1: warning: the frame size of 1500 bytes is larger than 1024 bytes [-Wframe-larger-than=]
133 | }
| ^
vim +133 lib/kunit/test.c
acd8e8407b8fcc David Gow 2021-08-03 110
e2219db280e3fe Alan Maguire 2020-03-26 111 /*
e2219db280e3fe Alan Maguire 2020-03-26 112 * Append formatted message to log, size of which is limited to
e2219db280e3fe Alan Maguire 2020-03-26 113 * KUNIT_LOG_SIZE bytes (including null terminating byte).
e2219db280e3fe Alan Maguire 2020-03-26 114 */
e2219db280e3fe Alan Maguire 2020-03-26 115 void kunit_log_append(char *log, const char *fmt, ...)
e2219db280e3fe Alan Maguire 2020-03-26 116 {
e2219db280e3fe Alan Maguire 2020-03-26 117 char line[KUNIT_LOG_SIZE];
e2219db280e3fe Alan Maguire 2020-03-26 118 va_list args;
e2219db280e3fe Alan Maguire 2020-03-26 119 int len_left;
e2219db280e3fe Alan Maguire 2020-03-26 120
e2219db280e3fe Alan Maguire 2020-03-26 121 if (!log)
e2219db280e3fe Alan Maguire 2020-03-26 122 return;
e2219db280e3fe Alan Maguire 2020-03-26 123
e2219db280e3fe Alan Maguire 2020-03-26 124 len_left = KUNIT_LOG_SIZE - strlen(log) - 1;
e2219db280e3fe Alan Maguire 2020-03-26 125 if (len_left <= 0)
e2219db280e3fe Alan Maguire 2020-03-26 126 return;
e2219db280e3fe Alan Maguire 2020-03-26 127
e2219db280e3fe Alan Maguire 2020-03-26 128 va_start(args, fmt);
e2219db280e3fe Alan Maguire 2020-03-26 129 vsnprintf(line, sizeof(line), fmt, args);
e2219db280e3fe Alan Maguire 2020-03-26 130 va_end(args);
e2219db280e3fe Alan Maguire 2020-03-26 131
e2219db280e3fe Alan Maguire 2020-03-26 132 strncat(log, line, len_left);
e2219db280e3fe Alan Maguire 2020-03-26 @133 }
e2219db280e3fe Alan Maguire 2020-03-26 134 EXPORT_SYMBOL_GPL(kunit_log_append);
e2219db280e3fe Alan Maguire 2020-03-26 135
Hi Rae,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on 766f4f2514d2d18bcbd60a058188fb502dea5ddf]
url: https://github.com/intel-lab-lkp/linux/commits/Rae-Moar/kunit-fix-bug-in-debugfs-logs-of-parameterized-tests/20230201-060537
base: 766f4f2514d2d18bcbd60a058188fb502dea5ddf
patch link: https://lore.kernel.org/r/20230131220355.1603527-2-rmoar%40google.com
patch subject: [PATCH v1 1/3] kunit: fix bug in debugfs logs of parameterized tests
config: hexagon-randconfig-r045-20230202 (https://download.01.org/0day-ci/archive/20230203/202302031414.TsTAA8Dr-lkp@intel.com/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 4196ca3278f78c6e19246e54ab0ecb364e37d66a)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/c8b669e1d139e1ee08121b184d859e45d7a02940
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Rae-Moar/kunit-fix-bug-in-debugfs-logs-of-parameterized-tests/20230201-060537
git checkout c8b669e1d139e1ee08121b184d859e45d7a02940
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash lib/kunit/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
>> lib/kunit/test.c:115:6: warning: stack frame size (1536) exceeds limit (1024) in 'kunit_log_append' [-Wframe-larger-than]
void kunit_log_append(char *log, const char *fmt, ...)
^
12/1536 (0.78%) spills, 1524/1536 (99.22%) variables
1 warning generated.
vim +/kunit_log_append +115 lib/kunit/test.c
acd8e8407b8fcc David Gow 2021-08-03 110
e2219db280e3fe Alan Maguire 2020-03-26 111 /*
e2219db280e3fe Alan Maguire 2020-03-26 112 * Append formatted message to log, size of which is limited to
e2219db280e3fe Alan Maguire 2020-03-26 113 * KUNIT_LOG_SIZE bytes (including null terminating byte).
e2219db280e3fe Alan Maguire 2020-03-26 114 */
e2219db280e3fe Alan Maguire 2020-03-26 @115 void kunit_log_append(char *log, const char *fmt, ...)
e2219db280e3fe Alan Maguire 2020-03-26 116 {
e2219db280e3fe Alan Maguire 2020-03-26 117 char line[KUNIT_LOG_SIZE];
e2219db280e3fe Alan Maguire 2020-03-26 118 va_list args;
e2219db280e3fe Alan Maguire 2020-03-26 119 int len_left;
e2219db280e3fe Alan Maguire 2020-03-26 120
e2219db280e3fe Alan Maguire 2020-03-26 121 if (!log)
e2219db280e3fe Alan Maguire 2020-03-26 122 return;
e2219db280e3fe Alan Maguire 2020-03-26 123
e2219db280e3fe Alan Maguire 2020-03-26 124 len_left = KUNIT_LOG_SIZE - strlen(log) - 1;
e2219db280e3fe Alan Maguire 2020-03-26 125 if (len_left <= 0)
e2219db280e3fe Alan Maguire 2020-03-26 126 return;
e2219db280e3fe Alan Maguire 2020-03-26 127
e2219db280e3fe Alan Maguire 2020-03-26 128 va_start(args, fmt);
e2219db280e3fe Alan Maguire 2020-03-26 129 vsnprintf(line, sizeof(line), fmt, args);
e2219db280e3fe Alan Maguire 2020-03-26 130 va_end(args);
e2219db280e3fe Alan Maguire 2020-03-26 131
e2219db280e3fe Alan Maguire 2020-03-26 132 strncat(log, line, len_left);
e2219db280e3fe Alan Maguire 2020-03-26 133 }
e2219db280e3fe Alan Maguire 2020-03-26 134 EXPORT_SYMBOL_GPL(kunit_log_append);
e2219db280e3fe Alan Maguire 2020-03-26 135
On Wed, 1 Feb 2023 at 06:04, Rae Moar <rmoar@google.com> wrote: > > Fix bug in debugfs logs that causes parameterized results to not appear > in the log because the log is reintialized (cleared) when each parameter is Nit: s/reintialized/reinitialized > run. > > Ensure these results appear in the debugfs logs and increase log size to > allow for the size of parameterized results. > > Signed-off-by: Rae Moar <rmoar@google.com> > --- This looks pretty good to me, but we may need to restrict the size of a single log line separately from that of the whole log. (It'd also be nice to include a before/after in the commit description.) With the stack size issue fixed, though, this looks good to me: Reviewed-by: David Gow <davidgow@google.com> Cheers, -- David > include/kunit/test.h | 2 +- > lib/kunit/test.c | 3 ++- > 2 files changed, 3 insertions(+), 2 deletions(-) > > diff --git a/include/kunit/test.h b/include/kunit/test.h > index 87ea90576b50..0a077a4c067c 100644 > --- a/include/kunit/test.h > +++ b/include/kunit/test.h > @@ -34,7 +34,7 @@ DECLARE_STATIC_KEY_FALSE(kunit_running); > struct kunit; > > /* Size of log associated with test. */ > -#define KUNIT_LOG_SIZE 512 > +#define KUNIT_LOG_SIZE 1500 This is used both as the overall log size, and the size of a single line in kunit_log_append. As the latter involves a local 'line' array, it can bloat out stack usage. Could we either restrict the maximum line length separately, or rework kunit_log_append() to not use a local variable? (I imagine we could just vsnprintf() directly into the log buffer. We could make two sprintf calls to calculate the length required to maintain some atomicity as well (this could open us up to time-of-check/time-of-use vulnerabilities, but I think the vulnerability ship has sailed if you're passing untrusted pointers into the kunit_log macro anyway)) > > /* Maximum size of parameter description string. */ > #define KUNIT_PARAM_DESC_SIZE 128 > diff --git a/lib/kunit/test.c b/lib/kunit/test.c > index 51cae59d8aae..66ba93b8222c 100644 > --- a/lib/kunit/test.c > +++ b/lib/kunit/test.c > @@ -437,7 +437,6 @@ static void kunit_run_case_catch_errors(struct kunit_suite *suite, > struct kunit_try_catch_context context; > struct kunit_try_catch *try_catch; > > - kunit_init_test(test, test_case->name, test_case->log); > try_catch = &test->try_catch; > > kunit_try_catch_init(try_catch, > @@ -533,6 +532,8 @@ int kunit_run_tests(struct kunit_suite *suite) > struct kunit_result_stats param_stats = { 0 }; > test_case->status = KUNIT_SKIPPED; > > + kunit_init_test(&test, test_case->name, test_case->log); > + > if (!test_case->generate_params) { > /* Non-parameterised test. */ > kunit_run_case_catch_errors(suite, test_case, &test); > -- > 2.39.1.456.gfc5497dd1b-goog >
On Thu, Feb 9, 2023 at 12:06 AM David Gow <davidgow@google.com> wrote: > > On Wed, 1 Feb 2023 at 06:04, Rae Moar <rmoar@google.com> wrote: > > > > Fix bug in debugfs logs that causes parameterized results to not appear > > in the log because the log is reintialized (cleared) when each parameter is > Hi David! > Nit: s/reintialized/reinitialized > Oops. Thanks for pointing this out. Will fix in v2. > > run. > > > > Ensure these results appear in the debugfs logs and increase log size to > > allow for the size of parameterized results. > > > > Signed-off-by: Rae Moar <rmoar@google.com> > > --- > > This looks pretty good to me, but we may need to restrict the size of > a single log line separately from that of the whole log. > > (It'd also be nice to include a before/after in the commit description.) Yes, as mentioned in the other patches, I will add an individual "before and after" comparison to each of the patches in v2. This is much clearer than just the overall comparison in the cover letter. > > With the stack size issue fixed, though, this looks good to me: > Reviewed-by: David Gow <davidgow@google.com> > > Cheers, > -- David > > > include/kunit/test.h | 2 +- > > lib/kunit/test.c | 3 ++- > > 2 files changed, 3 insertions(+), 2 deletions(-) > > > > diff --git a/include/kunit/test.h b/include/kunit/test.h > > index 87ea90576b50..0a077a4c067c 100644 > > --- a/include/kunit/test.h > > +++ b/include/kunit/test.h > > @@ -34,7 +34,7 @@ DECLARE_STATIC_KEY_FALSE(kunit_running); > > struct kunit; > > > > /* Size of log associated with test. */ > > -#define KUNIT_LOG_SIZE 512 > > +#define KUNIT_LOG_SIZE 1500 > > This is used both as the overall log size, and the size of a single > line in kunit_log_append. > > As the latter involves a local 'line' array, it can bloat out stack usage. > > Could we either restrict the maximum line length separately, or rework > kunit_log_append() to not use a local variable? > (I imagine we could just vsnprintf() directly into the log buffer. We > could make two sprintf calls to calculate the length required to > maintain some atomicity as well (this could open us up to > time-of-check/time-of-use vulnerabilities, but I think the > vulnerability ship has sailed if you're passing untrusted pointers > into the kunit_log macro anyway)) > Thanks for your help here. I will play around with these two options. Although, I think I am leaning toward restricting the maximum line length separately. Thanks! -Rae > > > > /* Maximum size of parameter description string. */ > > #define KUNIT_PARAM_DESC_SIZE 128 > > diff --git a/lib/kunit/test.c b/lib/kunit/test.c > > index 51cae59d8aae..66ba93b8222c 100644 > > --- a/lib/kunit/test.c > > +++ b/lib/kunit/test.c > > @@ -437,7 +437,6 @@ static void kunit_run_case_catch_errors(struct kunit_suite *suite, > > struct kunit_try_catch_context context; > > struct kunit_try_catch *try_catch; > > > > - kunit_init_test(test, test_case->name, test_case->log); > > try_catch = &test->try_catch; > > > > kunit_try_catch_init(try_catch, > > @@ -533,6 +532,8 @@ int kunit_run_tests(struct kunit_suite *suite) > > struct kunit_result_stats param_stats = { 0 }; > > test_case->status = KUNIT_SKIPPED; > > > > + kunit_init_test(&test, test_case->name, test_case->log); > > + > > if (!test_case->generate_params) { > > /* Non-parameterised test. */ > > kunit_run_case_catch_errors(suite, test_case, &test); > > -- > > 2.39.1.456.gfc5497dd1b-goog > >
diff --git a/include/kunit/test.h b/include/kunit/test.h index 87ea90576b50..0a077a4c067c 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -34,7 +34,7 @@ DECLARE_STATIC_KEY_FALSE(kunit_running); struct kunit; /* Size of log associated with test. */ -#define KUNIT_LOG_SIZE 512 +#define KUNIT_LOG_SIZE 1500 /* Maximum size of parameter description string. */ #define KUNIT_PARAM_DESC_SIZE 128 diff --git a/lib/kunit/test.c b/lib/kunit/test.c index 51cae59d8aae..66ba93b8222c 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -437,7 +437,6 @@ static void kunit_run_case_catch_errors(struct kunit_suite *suite, struct kunit_try_catch_context context; struct kunit_try_catch *try_catch; - kunit_init_test(test, test_case->name, test_case->log); try_catch = &test->try_catch; kunit_try_catch_init(try_catch, @@ -533,6 +532,8 @@ int kunit_run_tests(struct kunit_suite *suite) struct kunit_result_stats param_stats = { 0 }; test_case->status = KUNIT_SKIPPED; + kunit_init_test(&test, test_case->name, test_case->log); + if (!test_case->generate_params) { /* Non-parameterised test. */ kunit_run_case_catch_errors(suite, test_case, &test);