Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36D75C05027 for ; Thu, 9 Feb 2023 05:06:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229984AbjBIFGh (ORCPT ); Thu, 9 Feb 2023 00:06:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229935AbjBIFGe (ORCPT ); Thu, 9 Feb 2023 00:06:34 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62DE323C66 for ; Wed, 8 Feb 2023 21:06:32 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id bg5-20020a05600c3c8500b003e00c739ce4so617976wmb.5 for ; Wed, 08 Feb 2023 21:06:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ggQZMHFPe0aVW+wrnkt1QixZFOhWdUvTbBm/GHmH9kA=; b=PR2YnuHI1Gdu7OIlM9/bjX7PwZe5VgQDnfPXIMzNo9TUNaY5g/lL7GTnXBsqhxeKQy kqV0+7QLyM8jeogP7dN7G4BcNEeNl3mdwziNiFwRSV136+BksEULR3FzdpI64xx/g8Ic MHskupe/aCoM/8+7kHRQKPRZxX1MN6uXqL6Vnyx44ytsmWHkSrL0zgVex+LIbL1RWkg0 kmKrYNa6ZjELB+mCgFwtN6eCVSEQ6+KqF48JC01/6P49p3gJ+aKAEhV1RtoCix34u9HU XgCrAgsBMTyFI1VtTAdiDlvVX727AbCGfPRzfQKtLznLE3KPKwg9gZYAhg2cHm1N9J9B 83qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=ggQZMHFPe0aVW+wrnkt1QixZFOhWdUvTbBm/GHmH9kA=; b=eWum1Z67ey/NrejMFGQzm9X9eDlK0uMrxQbQvhcMvL4dwzK/MrhUP5hFZcrn7n1WkZ 0NvvSD7fObiqMEuXXghTPl0ZD3b/ntUXpDmDOj4jPNtA6Hi6rnPa2hShPYWij4PXO7Jd +lPFCIw1XpuJnyLAsnVf/JbBodIgy5bql0td71KHKRr4z4VslmeghIES1fgcjQvd7OvH u3nNdr0UDoefkZ7Lr4RzgTKdgzLiqnZamtJxYEpQ49xeTVWC34tdHHli+LtABhxok6/M IHgyIGeFGIUV92GkXtAAwmHkz23f+GRhS/9Z6DXsZC2wbuXuxUD/5GQV5rcepHIIgHRu 5BKA== X-Gm-Message-State: AO0yUKXRncKR4WZvWREsxUZPDNgtMNnT2OMJX3zyQwP8Y6D/xd+VLgYy IVh2sAoZnxQZxS22MH0e2i4vrygQE95t21TicfIxLQ== X-Google-Smtp-Source: AK7set8I5l3D5ZnUajff0zBFMlmYdjjUBPI+CXiSSYItTcOlnTAUfabzZu2OwOUOVww7ginlOKsegOaS4W++jfWFj7I= X-Received: by 2002:a05:600c:1d05:b0:3df:4bc8:edfb with SMTP id l5-20020a05600c1d0500b003df4bc8edfbmr401149wms.168.1675919190888; Wed, 08 Feb 2023 21:06:30 -0800 (PST) MIME-Version: 1.0 References: <20230131220355.1603527-1-rmoar@google.com> <20230131220355.1603527-4-rmoar@google.com> In-Reply-To: <20230131220355.1603527-4-rmoar@google.com> From: David Gow Date: Thu, 9 Feb 2023 13:06:17 +0800 Message-ID: Subject: Re: [PATCH v1 3/3] kunit: fix bug of extra newline characters in debugfs logs To: Rae Moar Cc: brendanhiggins@google.com, dlatypov@google.com, skhan@linuxfoundation.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="0000000000000f11e005f43d589f" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --0000000000000f11e005f43d589f Content-Type: text/plain; charset="UTF-8" On Wed, 1 Feb 2023 at 06:04, Rae Moar wrote: > > Fix bug of the extra newline characters in debugfs logs. When a > line is added to debugfs with a newline character at the end, > an extra line appears in the debugfs log. Remove these extra lines. > > Add kunit_log_newline_test to provide test coverage for this issue. > (Also, move kunit_log_test above suite definition to remove the > unnecessary declaration prior to the suite definition) > > Signed-off-by: Rae Moar > --- I've got some reservations about this patch. Firstly, could we have an example of the problem in the commit message, so we know what we're fixing? Secondly, I _really_ don't like the way this just removes newlines from log lines if there are too many. It feels like a hack, rather than a proper fix. I suspect the actual issue here is in the kunit_log macro in include/kunit/test.h: https://elixir.bootlin.com/linux/latest/source/include/kunit/test.h#L417 kunit_log_append((test_or_suite)->log, fmt "\n", ##__VA_ARGS__); \ The "\n" concatenated here is probably the issue. The printk statement doesn't add a newline, but that's because printk implicitly does if KERN_CONT is not added. So maybe the correct fix here is to use: printk(KERN_CONT lvl fmt "\n", ##__VA_ARGS__) That'd add the newline, rather than get rid of it, but at least should make the behaviour more similar between printk and the debugfs log. Equally, you could use KERN_CONT and get rid of the "\n" in both places, requiring it in log messages. Thirdly, I don't really like the way the test is skipped if debugfs isn't active. Could we skip it if test->log is not valid instead or using a compile-time #ifdef? I do like the move of kunit_log_test though. That definitely cleans things up! Cheers, -- David > lib/kunit/kunit-test.c | 36 ++++++++++++++++++++++++------------ > lib/kunit/test.c | 9 ++++++++- > 2 files changed, 32 insertions(+), 13 deletions(-) > > diff --git a/lib/kunit/kunit-test.c b/lib/kunit/kunit-test.c > index 4df0335d0d06..e9114a466f1e 100644 > --- a/lib/kunit/kunit-test.c > +++ b/lib/kunit/kunit-test.c > @@ -443,18 +443,6 @@ static struct kunit_suite kunit_resource_test_suite = { > .test_cases = kunit_resource_test_cases, > }; > > -static void kunit_log_test(struct kunit *test); > - > -static struct kunit_case kunit_log_test_cases[] = { > - KUNIT_CASE(kunit_log_test), > - {} > -}; > - > -static struct kunit_suite kunit_log_test_suite = { > - .name = "kunit-log-test", > - .test_cases = kunit_log_test_cases, > -}; > - > static void kunit_log_test(struct kunit *test) > { > struct kunit_suite suite; > @@ -481,6 +469,30 @@ static void kunit_log_test(struct kunit *test) > #endif > } > > +static void kunit_log_newline_test(struct kunit *test) > +{ > +#ifdef CONFIG_KUNIT_DEBUGFS > + kunit_info(test, "extra newline\n"); > + > + KUNIT_ASSERT_NOT_NULL_MSG(test, strstr(test->log, "extra newline\n"), > + "Missing log line, full log:\n%s", test->log); > + KUNIT_EXPECT_NULL(test, strstr(test->log, "extra newline\n\n")); > +#else > + kunit_skip(test, "only useful when debugfs is enabled"); > +#endif > +} > + > +static struct kunit_case kunit_log_test_cases[] = { > + KUNIT_CASE(kunit_log_test), > + KUNIT_CASE(kunit_log_newline_test), > + {} > +}; > + > +static struct kunit_suite kunit_log_test_suite = { > + .name = "kunit-log-test", > + .test_cases = kunit_log_test_cases, > +}; > + > static void kunit_status_set_failure_test(struct kunit *test) > { > struct kunit fake; > diff --git a/lib/kunit/test.c b/lib/kunit/test.c > index 27763f0b420c..76d9c31943bf 100644 > --- a/lib/kunit/test.c > +++ b/lib/kunit/test.c > @@ -117,6 +117,7 @@ void kunit_log_append(char *log, const char *fmt, ...) > char line[KUNIT_LOG_SIZE]; > va_list args; > int len_left; > + int line_len; > > if (!log) > return; > @@ -125,10 +126,16 @@ void kunit_log_append(char *log, const char *fmt, ...) > if (len_left <= 0) > return; > > + // Evaluate the length of the line with arguments > va_start(args, fmt); > - vsnprintf(line, sizeof(line), fmt, args); > + line_len = vsnprintf(line, sizeof(line), fmt, args); > va_end(args); > > + // If line has two newline characters, do not print > + // second newline character > + if (fmt[strlen(fmt) - 2] == '\n') > + line[line_len - 1] = '\0'; > + > strncat(log, line, len_left); > } > EXPORT_SYMBOL_GPL(kunit_log_append); > -- > 2.39.1.456.gfc5497dd1b-goog > --0000000000000f11e005f43d589f Content-Type: application/pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s" Content-Description: S/MIME Cryptographic Signature MIIPnwYJKoZIhvcNAQcCoIIPkDCCD4wCAQExDzANBglghkgBZQMEAgEFADALBgkqhkiG9w0BBwGg ggz5MIIEtjCCA56gAwIBAgIQeAMYYHb81ngUVR0WyMTzqzANBgkqhkiG9w0BAQsFADBMMSAwHgYD VQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMzETMBEGA1UEChMKR2xvYmFsU2lnbjETMBEGA1UE AxMKR2xvYmFsU2lnbjAeFw0yMDA3MjgwMDAwMDBaFw0yOTAzMTgwMDAwMDBaMFQxCzAJBgNVBAYT AkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMSowKAYDVQQDEyFHbG9iYWxTaWduIEF0bGFz IFIzIFNNSU1FIENBIDIwMjAwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCvLe9xPU9W dpiHLAvX7kFnaFZPuJLey7LYaMO8P/xSngB9IN73mVc7YiLov12Fekdtn5kL8PjmDBEvTYmWsuQS 6VBo3vdlqqXZ0M9eMkjcKqijrmDRleudEoPDzTumwQ18VB/3I+vbN039HIaRQ5x+NHGiPHVfk6Rx c6KAbYceyeqqfuJEcq23vhTdium/Bf5hHqYUhuJwnBQ+dAUcFndUKMJrth6lHeoifkbw2bv81zxJ I9cvIy516+oUekqiSFGfzAqByv41OrgLV4fLGCDH3yRh1tj7EtV3l2TngqtrDLUs5R+sWIItPa/4 AJXB1Q3nGNl2tNjVpcSn0uJ7aFPbAgMBAAGjggGKMIIBhjAOBgNVHQ8BAf8EBAMCAYYwHQYDVR0l BBYwFAYIKwYBBQUHAwIGCCsGAQ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