Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4635207pxu; Tue, 13 Oct 2020 03:30:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzY1/X/luBJ7rDzING26/V7vw0/0mIDHPo4wHVvjHb6ywCj+Y4ANYiY5Kv/CKkbyvC6bDIx X-Received: by 2002:aa7:c68b:: with SMTP id n11mr18583579edq.340.1602585046713; Tue, 13 Oct 2020 03:30:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602585046; cv=none; d=google.com; s=arc-20160816; b=ZPmGjCM5o6dtxFv7UTusOMCQX0NuUXYuX+YDsNfWryEefLqWY8e8LYI5fHSpOi1hBT 33rUtj33j5uqdmhwP2Y/OP4rquX7MZMaTtEKCfXMLfbpmuIEjUhuhuU5YDd29owXuk8y Sa5N1udOtDZefn/2GMZEsFcB2PZrLRm6PiU7YKBP+Z3hnNf13jwL2cimVfFgxVILX8bQ BrhCRJvR2+SHOw9w+QMWVRQDLzqyuEG+y6bISeI8kDQp0BONPrJq2d9c15ZzaLt1jPG9 WCnkuOZbIlD4HYvJYUvJPBTsePcBAIixppFxFfXU029a+0qi/8x+OhuKes49/hQH+qbR g4mA== 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=gM5ubYzG27vt0QdpAC5kBFMLhscZEvN14dCPbrDfOfM=; b=rXHwPBS1zTV1f9aQtgFog14XrlQ6RHS4xnf5C80MdGcU8d5iqGeEHELdOWkEXvQeBa ePJIKau3rIabAPhT73yrf8/xeebDwN+J/qFIMdG+8q+9jaVCgDNRmhVl/mkB6HH/xo1k sz5XtUB401oeA9JkhVURXQD2VH6P6wRA6oSR2BrErvQySJfO4eZOxdt22UEcVcRMTZ7y AJL63en60DLsmNsC3yBouBdm2rgyk6tamEFF3hFO6kYgO6MvnFeck/OnnhSDbDogm421 DjPDjUTXUsxTjIJ+gkxC4YBP0zlkfJ4SN1OIHApeeO2A7rpC94sIymtBzUwvz9tO1bov 0Z2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Mcm5WR1/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w8si13515682edu.395.2020.10.13.03.30.24; Tue, 13 Oct 2020 03:30:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Mcm5WR1/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1731308AbgJLUtE (ORCPT + 99 others); Mon, 12 Oct 2020 16:49:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731019AbgJLUtE (ORCPT ); Mon, 12 Oct 2020 16:49:04 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4394BC0613D1 for ; Mon, 12 Oct 2020 13:49:04 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id o8so9327129pll.4 for ; Mon, 12 Oct 2020 13:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=gM5ubYzG27vt0QdpAC5kBFMLhscZEvN14dCPbrDfOfM=; b=Mcm5WR1/rQDht3VQR4YSx4CH89Q/TShAdVSst9OT9WGLFyecwLeG9ZQsJizhDKIzJG gmDEXDFimGC3KgVfdTT675Dm1PB8EIkRSt5zKrLNEK8JB69aNyAICuNyyjHoDYZoewVw x8os1FDsXxWYFhNc1conb8HlirSVg355+Lv41izx/a9lgYuctKBXrK0posDd1792Rr4q OB5w/lYd9FEVSK4uOW6smNTEhdOy3mFVmeFgRvvlOkTCS4jBWgU1gtD4GSy/UU0+u/VT hVvakyAV2lVJFPB6yDClobSS0BsFnBzOSy3Kj5NHPoG0FwKjpQj4/8PBxml5yNS74KMf 6b+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=gM5ubYzG27vt0QdpAC5kBFMLhscZEvN14dCPbrDfOfM=; b=GzzhVqkV3+INnyGuzfch35SbCLPJo59hK1V1Svpya6+dcSac9BkQuFisIVPrB4Cjrv jO+erbhPKOr+IGmQeurkOFdII3FYf3tgoqiMMCgEeNMRjJRW8exzXbmttyPKO5Vujojs 17+aePLif6zdNAkZ+BPB70z1WpARabErg7pjXq7gKWN42V3MrhDv0xePx8KMFCNKwFIQ v8nsPFUl8mppRYqvVRejKDGoKXmkXb2aYrPUnP3CLrVarcd4bwtfdvdM7UL2WhwxLHAq 4/hlr/UsgupoELrYrBeroLWQuW4rkR0Ibmk4yLz51IR43LNPrmqoIBtf8KMwm/uTC13h T77A== X-Gm-Message-State: AOAM531+ocwwMjb1oNwJJknWoclFHM0kRQhJ271jrPL4QjVq7JYTrbpo sKQ/XGRbORWOlgr6XS4A2wwSGIUZMQaL3G4pn9vpGg== X-Received: by 2002:a17:902:ba8c:b029:d2:aa93:c8b4 with SMTP id k12-20020a170902ba8cb02900d2aa93c8b4mr25677253pls.80.1602535743355; Mon, 12 Oct 2020 13:49:03 -0700 (PDT) MIME-Version: 1.0 References: <20200817043028.76502-1-98.arpi@gmail.com> <20200821113710.GA26290@alley> <4e26f696-3b50-d781-00fd-7fc6fdc2c3eb@rasmusvillemoes.dk> In-Reply-To: From: Brendan Higgins Date: Mon, 12 Oct 2020 13:48:52 -0700 Message-ID: Subject: Re: [PATCH] lib: Convert test_printf.c to KUnit To: Rasmus Villemoes Cc: Petr Mladek , Arpitha Raghunandan <98.arpi@gmail.com>, Shuah Khan , Andy Shevchenko , Steven Rostedt , Sergey Senozhatsky , KUnit Development , "open list:KERNEL SELFTEST FRAMEWORK" , Linux Kernel Mailing List , linux-kernel-mentees@lists.linuxfoundation.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 12, 2020 at 1:13 PM Brendan Higgins wrote: > > On Fri, Aug 21, 2020 at 5:19 AM Rasmus Villemoes > wrote: > > Sorry about the late reply. I saw activity on this before and thought > it was under control. I only saw the unresolved state now looking > through patchwork. > > > On 21/08/2020 13.37, Petr Mladek wrote: > > > On Mon 2020-08-17 09:06:32, Rasmus Villemoes wrote: > > >> On 17/08/2020 06.30, Arpitha Raghunandan wrote: > > >>> Converts test lib/test_printf.c to KUnit. > > >>> More information about KUnit can be found at > > >>> https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html. > > >>> KUnit provides a common framework for unit tests in the kernel. > > >> > > >> So I can continue to build a kernel with some appropriate CONFIG set= to > > >> y, boot it under virt-me, run dmesg and see if I broke printf? That'= s > > >> what I do now, and I don't want to have to start using some enterpri= sy > > >> framework. > > > > > > I had the same concern. I have tried it. > > > > Thanks for doing that and reporting the results. > > > > > #> modprobe printf_kunit > > > > > > produced the following in dmesg: > > > > > > [ 60.931175] printf_kunit: module verification failed: signature an= d/or required key missing - tainting kernel > > > [ 60.942209] TAP version 14 > > > [ 60.945197] # Subtest: printf-kunit-test > > > [ 60.945200] 1..1 > > > [ 60.951092] ok 1 - selftest > > > [ 60.953414] ok 1 - printf-kunit-test > > > > > > I could live with the above. Then I tried to break a test by the foll= owing change: > > > > > > > > > diff --git a/lib/printf_kunit.c b/lib/printf_kunit.c > > > index 68ac5f9b8d28..1689dadd70a3 100644 > > > --- a/lib/printf_kunit.c > > > +++ b/lib/printf_kunit.c > > > @@ -395,7 +395,7 @@ ip4(struct kunit *kunittest) > > > sa.sin_port =3D cpu_to_be16(12345); > > > sa.sin_addr.s_addr =3D cpu_to_be32(0x7f000001); > > > > > > - test(kunittest, "127.000.000.001|127.0.0.1", "%pi4|%pI4", &sa= .sin_addr, &sa.sin_addr); > > > + test(kunittest, "127-000.000.001|127.0.0.1", "%pi4|%pI4", &sa= .sin_addr, &sa.sin_addr); > > > test(kunittest, "127.000.000.001|127.0.0.1", "%piS|%pIS", &sa= , &sa); > > > sa.sin_addr.s_addr =3D cpu_to_be32(0x01020304); > > > test(kunittest, "001.002.003.004:12345|1.2.3.4:12345", "%piSp= |%pISp", &sa, &sa); > > > > > > > > > It produced:: > > > > > > [ 56.786858] TAP version 14 > > > [ 56.787493] # Subtest: printf-kunit-test > > > [ 56.787494] 1..1 > > > [ 56.788612] # selftest: EXPECTATION FAILED at lib/printf_kunit= .c:76 > > > Expected memcmp(test_buffer, expect, written) =3D= =3D 0, but > > > memcmp(test_buffer, expect, written) =3D=3D 1 > > > 0 =3D=3D 0 > > > vsnprintf(buf, 256, "%pi4|%pI4", ...) wrote '127.000.0= 00.001|127.0.0.1', expected '127-000.000.001|127.0.0.1' > > > [ 56.795433] # selftest: EXPECTATION FAILED at lib/printf_kunit= .c:76 > > > Expected memcmp(test_buffer, expect, written) =3D= =3D 0, but > > > memcmp(test_buffer, expect, written) =3D=3D 1 > > > 0 =3D=3D 0 > > > vsnprintf(buf, 20, "%pi4|%pI4", ...) wrote '127.000.00= 0.001|127', expected '127-000.000.001|127' > > > [ 56.800909] # selftest: EXPECTATION FAILED at lib/printf_kunit= .c:108 > > > Expected memcmp(p, expect, elen+1) =3D=3D 0, but > > > memcmp(p, expect, elen+1) =3D=3D 1 > > > 0 =3D=3D 0 > > > kvasprintf(..., "%pi4|%pI4", ...) returned '127.000.00= 0.001|127.0.0.1', expected '127-000.000.001|127.0.0.1' > > > [ 56.806497] not ok 1 - selftest > > > [ 56.806497] not ok 1 - printf-kunit-test > > > > > > while the original code would have written the following error messag= es: > > > > > > [ 95.859225] test_printf: loaded. > > > [ 95.860031] test_printf: vsnprintf(buf, 256, "%pi4|%pI4", ...) wro= te '127.000.000.001|127.0.0.1', expected '127-000.000.001|127.0.0.1' > > > [ 95.862630] test_printf: vsnprintf(buf, 6, "%pi4|%pI4", ...) wrote= '127.0', expected '127-0' > > > [ 95.864118] test_printf: kvasprintf(..., "%pi4|%pI4", ...) returne= d '127.000.000.001|127.0.0.1', expected '127-000.000.001|127.0.0.1' > > > [ 95.866589] test_printf: failed 3 out of 388 tests > > > > > > > > > Even the error output is acceptable for me. > > > > Urgh. Yeah, perhaps, but the original is much more readable; it really > > doesn't matter that a memcmp() fails to compare equal to 0, that's > > merely how we figured out that the output was wrong. > > We can go back to the original error reporting format, just as long as > you don't mind the "ok" lines interspersed throughout (this is part of > an attempt to standardize around the KTAP reporting format[1]. > > > I am just curious why > > > the 2nd failure is different: > > > > > > + original code: vsnprintf(buf, 6, "%pi4|%pI4", ...) wrote '127.0'= , expected '127-0' > > > + kunit code: vsnprintf(buf, 20, "%pi4|%pI4", ...) wrote '127.000.= 000.001|127', expected '127-000.000.001|127' > > > > That's by design. If you read the code, there's a comment that says we > > do every test case four times: With a buffer that is large enough to do > > the whole output, with a 0 size buffer (that's essential to allowing > > kasprintf to know how much to allocate), with kvasprintf - but also > > with a buffer size that's guaranteed to ensure the output gets truncate= d > > somewhere. And that size is chosen randomly - I guess one could test > > every single buffer size between 0 and elen+1, but that's overkill. > > > > Now I should probably have made the tests deterministic in the sense of > > getting a random seed for a PRNG, printing that seed and allowing a > > module parameter to set the seed in order to repeat the exact same > > tests. But so far I haven't really seen any bugs caught by test_printf > > which would have been easier to fix with that. > > > > The reason I added that "chop it off somewhere randomly" was, IIRC, due > > to some %p extensions that behaved rather weirdly depending on whether > > there was enough room left or not, but I fixed those bugs before > > creating test_printf (and they were in turn the reason for creating > > test_printf). See for example 41416f2330, where %pE at the beginning of > > the format string would work ok, but if anything preceded it and the > > buffer was too small we'd crash. > > > > > > > > I am also a bit scared by the following note at > > > https://www.kernel.org/doc/html/latest/dev-tools/kunit/start.html#run= ning-tests-without-the-kunit-wrapper > > > > > > "KUnit is not designed for use in a production system, and it=E2= =80=99s > > > possible that tests may reduce the stability or security of the > > > system." > > > > > > What does it mean thay it might reduce stability or security? > > > Is it because the tests might cause problems? > > > Or because the kunit framework modifies functionality of the running > > > system all the time? > > Oh yeah, that's just because we are afraid that tests might cause > problems. KUnit by itself does nothing to affect the stability or > security of the system. And I forgot the link to KTAP[1]. I am really batting a thousand here. [1] https://lore.kernel.org/linux-kselftest/CY4PR13MB1175B804E31E502221BC81= 63FD830@CY4PR13MB1175.namprd13.prod.outlook.com/