Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp694648rdg; Thu, 10 Aug 2023 17:07:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvM5LG89uuHuOT3BZuMs+bfb7STuFGjHMuZle7fxGgLKJuutLMslyK33BML1xIvsWUTeJF X-Received: by 2002:a17:902:6b4a:b0:1b8:4e69:c900 with SMTP id g10-20020a1709026b4a00b001b84e69c900mr265957plt.14.1691712439791; Thu, 10 Aug 2023 17:07:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691712439; cv=none; d=google.com; s=arc-20160816; b=pMehSGLBUqIpk4Bs8QXn8WehTQQb7Uu1nAdYcmEnK8HixUy3UPwHMqtrxZPC06swFo VhvCVQM6VzRTTjfFzXcqKzRPex2PrdbqaEnuF2Wl2C1qM+FHErcdoD0yADhMB15DdlGI odkDWKBJoqjaWtYt84RqVjjyfBeNXUSi0yzsR9EErETu7zoavbpjvA+zUVzeenVAIbbE l+OtMuNocI3JaHBujSX/DR21GWpFUNsLcCdTvrKvddjcADHrQbLltCtu+1Xk0ntLpUBP CCSgZPqbIrTm5PCj5V5Q8W0E9aWffKMkYwduu7+S0EmO8TNGWMU+FYCLFvyU5rZA5f+F PdHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=TdpsaGQQt2Y4RqxqF4yAo63jfWsUC4HuA7va+4pi9tU=; fh=8UDfi8xBJ790SZyvmkQ8i9XlHyHv9fuRECSK+7qBwQM=; b=CafwJUg7FKrlD/kO8k4rMKkrSMgW0ygAnobkRkhah3vEiK9Xig9qmPuRBcKAib0sr2 eBB67sI5G06oCi8zI8PaO+DXf6G5qW80wZhS690PJgs/0DFZn26jmgblzdhRY8m39e+u dGq4PvLRFzDRxeDeOxg3c2esh+6/LVpkqWGFmkf+hsM6ADpMWSLw0fsKs6NmwEKNfog7 qCEsa3t+YOUfuOqF7OV2iTfTi7TaZSs0dIGCfTu1ogXWA0+jITToRXUuW43VFt2Xvkir rqPFucmbig+V4mMHM0/O45zqfN/7Dz+OOa57RLWNSV974pERtW79YmsW9ogT9ViZ3OEr v24g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=SGchQVlV; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ku4-20020a170903288400b001bbbbb61c67si2171902plb.542.2023.08.10.17.07.07; Thu, 10 Aug 2023 17:07:19 -0700 (PDT) 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=20221208 header.b=SGchQVlV; 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 S229549AbjHJW67 (ORCPT + 99 others); Thu, 10 Aug 2023 18:58:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbjHJW67 (ORCPT ); Thu, 10 Aug 2023 18:58:59 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BE5E272C for ; Thu, 10 Aug 2023 15:58:58 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fe2d620d17so13915e9.0 for ; Thu, 10 Aug 2023 15:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691708336; x=1692313136; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TdpsaGQQt2Y4RqxqF4yAo63jfWsUC4HuA7va+4pi9tU=; b=SGchQVlV2GHHQcGnMheJD42brf+UWBoWStKxi7jCpOHhHaPzrkK7lH43eMadTOilqC YgyWOToZg4a2UbuPNYAu+G5zhOem0mTsBbAXbCbfyLHelUKNYd6Ax/d6m90r9RNMHEfD petT6B8PFavaemF4lMKo+i69tR+o6yQ1fK0cEe1lsLUYqTGBd0gbHAqjoL3s2RZ4X+b7 K4jb0qcck8mSYyQRuwL5CcddxcJjGkoBhZ+SGfWmA4I8jDcQFhpR+PsYaVPG7Js/7XVT PwRYb/Ht+sKlNSoCUqfaj1PBMelKYt/DF+4vB5FACo5PXuBcXJZtVexjQRhicLgMQSSH /Oig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691708336; x=1692313136; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TdpsaGQQt2Y4RqxqF4yAo63jfWsUC4HuA7va+4pi9tU=; b=I7SUH0tH7FS/7dVcjEuf/2usINxOhmoNi3F+NEmipN5tv57+5JbfFfWHLfRCYLDJgT KmD+v68ZPUpfF/kBWDzLbVVxMwvQ/ar9kHx0PzwX7jZIcIFjcN9RmRQDdzlwSV12iW1t bDj7qwSJE17EcRU7PEk8IOI00Gemfg+kEwWgbGNcwH26sXL3+w1Ag0WO9EvDW50C44Mj EpU83/F7JvOf+a1Li9THW4Ffewk281Try/NeRa4y/cgPeooAdVH5VIPFNIEeK+Ct8wqV SyIH2E3yJ1RHjNePMC8o4kC5mFUuoBwSbCEX50nIfsBopne6nr2nKhCelDBdqK3f2pDB LRUg== X-Gm-Message-State: AOJu0YxcF0aOxIC1u2iRuyEEw3gZEvCYOoiXwuAqKaTGzLeQTvn0Lo/T 6aQ4qYtw/TrLXtglv+/q7sug1rZfRH6A4uzLDIhLMw== X-Received: by 2002:a7b:cc93:0:b0:3f1:70d1:21a6 with SMTP id p19-20020a7bcc93000000b003f170d121a6mr54523wma.0.1691708336474; Thu, 10 Aug 2023 15:58:56 -0700 (PDT) MIME-Version: 1.0 References: <20230809155438.22470-1-rf@opensource.cirrus.com> <20230809155438.22470-6-rf@opensource.cirrus.com> In-Reply-To: <20230809155438.22470-6-rf@opensource.cirrus.com> From: Rae Moar Date: Thu, 10 Aug 2023 17:58:44 -0500 Message-ID: Subject: Re: [PATCH v3 5/7] kunit: kunit-test: Add test cases for logging very long lines To: Richard Fitzgerald Cc: brendan.higgins@linux.dev, davidgow@google.com, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, patches@opensource.cirrus.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 9, 2023 at 10:54=E2=80=AFAM Richard Fitzgerald wrote: > > Add kunit_log_long_line_test() to test that logging a line longer than > the buffer fragment size doesn't truncate the line. > > Add extra tests to kunit_log_newline_test() for lines longer than the > buffer fragment size. > > Signed-off-by: Richard Fitzgerald Hello! This test looks good to me. I have included just a few comments below. Reviewed-by: Rae Moar Thanks! -Rae > --- > lib/kunit/kunit-test.c | 84 +++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 83 insertions(+), 1 deletion(-) > > diff --git a/lib/kunit/kunit-test.c b/lib/kunit/kunit-test.c > index 9ac81828d018..c079550c3afd 100644 > --- a/lib/kunit/kunit-test.c > +++ b/lib/kunit/kunit-test.c > @@ -609,7 +609,7 @@ static void kunit_log_newline_test(struct kunit *test= ) > { > struct kunit_suite suite; > struct kunit_log_frag *frag; > - char *p; > + char *p, *line; > > kunit_info(test, "Add newline\n"); > if (test->log) { > @@ -635,6 +635,33 @@ static void kunit_log_newline_test(struct kunit *tes= t) > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p); > KUNIT_EXPECT_NOT_NULL_MSG(test, strstr(p, "x12345678\n"), > "Newline not appended when fragment is full. Log = is:\n'%s'", p); > + kunit_kfree(test, p); > + I really like the thoroughness of this test. However, I do wonder if this newline test could be broken into at least 2 parts as the test is quite long with all these additions. I spoke on this in a previous patch and just wanted to touch on it here as well. > + /* String that is much longer than a fragment */ > + line =3D kunit_kzalloc(test, sizeof(frag->buf) * 6, GFP_K= ERNEL); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, line); > + memset(line, 'x', (sizeof(frag->buf) * 6) - 1); > + kunit_log_append(suite.log, "%s", line); > + p =3D get_concatenated_log(test, suite.log, NULL); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p); > + KUNIT_EXPECT_EQ(test, p[strlen(p) - 1], '\n'); > + KUNIT_EXPECT_NULL(test, strstr(p, "\n\n")); > + kunit_kfree(test, p); > + I would also consider adding comments between these three cases to describe their differences and maybe what the desired behavior would be. > + kunit_log_append(suite.log, "%s\n", line); > + p =3D get_concatenated_log(test, suite.log, NULL); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p); > + KUNIT_EXPECT_EQ(test, p[strlen(p) - 1], '\n'); > + KUNIT_EXPECT_NULL(test, strstr(p, "\n\n")); > + kunit_kfree(test, p); > + > + line[strlen(line) - 1] =3D '\n'; > + kunit_log_append(suite.log, "%s", line); > + p =3D get_concatenated_log(test, suite.log, NULL); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p); > + KUNIT_EXPECT_EQ(test, p[strlen(p) - 1], '\n'); > + KUNIT_EXPECT_NULL(test, strstr(p, "\n\n")); > + kunit_kfree(test, p); > } else { > kunit_skip(test, "only useful when debugfs is enabled"); > } > @@ -799,6 +826,60 @@ static void kunit_log_frag_sized_line_test(struct ku= nit *test) > #endif > } > > +static void kunit_log_long_line_test(struct kunit *test) > +{ > +#ifdef CONFIG_KUNIT_DEBUGFS > + struct kunit_suite suite; > + struct kunit_log_frag *frag; > + struct rnd_state rnd; > + char *line, *p, *pn; > + size_t line_buf_size, len; > + int num_frags, i; > + > + suite.log =3D kunit_kzalloc(test, sizeof(*suite.log), GFP_KERNEL)= ; > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, suite.log); > + INIT_LIST_HEAD(suite.log); > + frag =3D kunit_kmalloc(test, sizeof(*frag), GFP_KERNEL); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, frag); > + kunit_init_log_frag(frag); > + KUNIT_EXPECT_EQ(test, frag->buf[0], '\0'); > + list_add_tail(&frag->list, suite.log); > + > + /* Create a very long string to be logged */ > + line_buf_size =3D sizeof(frag->buf) * 6; > + line =3D kunit_kmalloc(test, line_buf_size, GFP_KERNEL); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, line); > + line[0] =3D '\0'; > + > + prandom_seed_state(&rnd, 3141592653589793238ULL); I was a little worried about including a randomized string but since it does not need to be reproduced here it should be fine. I also haven't seen any issues with the tests with the randomized strings being nondeterministic. > + len =3D 0; > + do { > + static const char fill[] =3D > + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv= wxyz"; > + > + i =3D prandom_u32_state(&rnd) % (sizeof(fill) - 1); > + len =3D strlcat(line, &fill[i], line_buf_size); > + } while (len < line_buf_size); > + > + kunit_log_append(suite.log, "%s\n", line); > + > + p =3D get_concatenated_log(test, suite.log, &num_frags); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p); > + KUNIT_EXPECT_GT(test, num_frags, 1); > + > + kunit_info(test, "num_frags:%d total len:%zu\n", num_frags, strle= n(p)); > + > + /* Don't compare the trailing '\n' */ > + pn =3D strrchr(p, '\n'); > + KUNIT_EXPECT_NOT_ERR_OR_NULL(test, pn); > + *pn =3D '\0'; > + KUNIT_EXPECT_EQ(test, strlen(p), strlen(line)); > + KUNIT_EXPECT_STREQ(test, p, line); > +#else > + kunit_skip(test, "only useful when debugfs is enabled"); > +#endif > +} > + > static struct kunit_case kunit_log_test_cases[] =3D { > KUNIT_CASE(kunit_log_init_frag_test), > KUNIT_CASE(kunit_log_test), > @@ -806,6 +887,7 @@ static struct kunit_case kunit_log_test_cases[] =3D { > KUNIT_CASE(kunit_log_extend_test_1), > KUNIT_CASE(kunit_log_extend_test_2), > KUNIT_CASE(kunit_log_frag_sized_line_test), > + KUNIT_CASE(kunit_log_long_line_test), > {} > }; > > -- > 2.30.2 >