Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5793029pxu; Thu, 22 Oct 2020 11:08:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbd3UcI1loToas5BDbUBfr2tI3rGoU6IY5Vxk93T/8e9T+O/GOTgCLyXFUUblrbraskNzf X-Received: by 2002:a17:906:9483:: with SMTP id t3mr3690781ejx.390.1603390131865; Thu, 22 Oct 2020 11:08:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603390131; cv=none; d=google.com; s=arc-20160816; b=erRodcCQh0IX8gTYD9DwixFpYkYW72xboQ6jjRmVjvCHUiau7+Y6LDiAFNwS94u0ui Na25T/cWLBhdt42vBuBOB3F4p76g9A2P5lpGSOpEVZ2k6HcfoJQxfocwpmuH6KrW6mOp HeOaso9UeL20ONnBeN0wuroLp9oDLWRgtbfHUH0+qXtVeTs52jegMTWI9cO8Yk2+VHhv XOlx5LPViCdiLAjffD9Xw1VS6MGvikqqYVelqcfM3bY9zwV7f6IZ7XWEUp725y4TVsis R2prXyPqqZU4zS51NSQyMMxiSABh8TQ013eZbeYXjI9KhJdFk9CQzkT5ybURaw18uldv b7zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KZFvf3Ldb3rFeZOwf1If8ODWGX8g/S9h9Con/ZQJhTY=; b=ZjTOnOoFa3/fkfA8XRU3bLrTmPERpCuea1iemanEtbr08xXeSlQDkd5XYadhEP9thd w9C0ePleFDM8C3QxmMnfT4IOVj23LxyfNJ+K+EBtvUBhct1ccrhUQKQ3F5Ly++pHmeW8 xJAh7lqniRVfR7NY8I/pteI64p4rAiFITXlyL2qXMy+4nAio/2JtPk/kQTnisXMFFEZ+ pACpQE79KU0bQkWUkdODqpwdCJfs+MBsU1o6VI1uCmaMBvtS1PtIs5bAOh2IGZUdom5Y Oug6npOP2IppFrusRUgqvDjqiiqaHSbpPPdnpibmTA4aNbzfWl1cmBvqQv/swsDKH9ru Mzqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=JtM0iJmE; 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 i23si1558204edg.229.2020.10.22.11.08.28; Thu, 22 Oct 2020 11:08:51 -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=JtM0iJmE; 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 S2901734AbgJVQ07 (ORCPT + 99 others); Thu, 22 Oct 2020 12:26:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2896986AbgJVQ06 (ORCPT ); Thu, 22 Oct 2020 12:26:58 -0400 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F45FC0613CF for ; Thu, 22 Oct 2020 09:26:57 -0700 (PDT) Received: by mail-il1-x144.google.com with SMTP id y17so2278367ilg.4 for ; Thu, 22 Oct 2020 09:26:57 -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; bh=KZFvf3Ldb3rFeZOwf1If8ODWGX8g/S9h9Con/ZQJhTY=; b=JtM0iJmE6RRrEXd+MT7jIZKLx0kAkZLPovF2TeerZFALAeroqqLSOZx4PrKi7hUI4g 0yuWHR4xm/tThpgwo+RNiM8gVwLCvPyEsTLFQfRu3ZKkWLKShfIOoAGQ4n9o/cl3CEYA 4BwklKnalgc8nHYmDPIvBgR/l97VhTaCwKmwt/58IfI/RFBlrcarYyAr+JOTWMMDI12X 9i6zmQSr6okD6AsOvbYBJft619i0VdbZWL7pfDFqzj8y/o9fBMiVqZ2VlTYB6rmSHWxj 170s+EUHyq4tNm5nmLaFUONUYWPbAvnHKBxNj38eR3E6eZdNIaUjFI4CDB8F6Z/WK6g4 fM4g== 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; bh=KZFvf3Ldb3rFeZOwf1If8ODWGX8g/S9h9Con/ZQJhTY=; b=HzhtZebf67I7SoGOLxhEK101LDn8RXL9m4/S40KHy90tVBLCSGEdQicjWvitZ9/oWf 1LSfY+bTStB72Bl3IhThWY00Hs7VVqu3blLd4cs3X1UTnQJ/Ks/QRvOEMO7RCbtl5WTx W/eKHuwiQgiYD6xFxAlj4UxIUKn/GvhcZU/2BXoFvPdhazAKa8DEpYy/U1UViJ6LXQya 3N8iUC9tbThvZ4q/hdk2YN8lSLSCbjjWeLpp3SAnDDAE7mAZ5TSG69h3luCV8UQR8Wdv jWYKSwc1XJSxcpj0GkhuWr+32zd5raSGTtElVo9YJpgeO1vK4a1cIXc4z10ZR2lSzqMy QeHQ== X-Gm-Message-State: AOAM530RemGKdaSs4h82lXODtINopqGVM2MpIsAJj8W7YC6BbXpSBqc1 PTRBIDokJK7IGJeewLi3f0lQk5hvUt8xDMSA8VMczA== X-Received: by 2002:a92:cf44:: with SMTP id c4mr1547289ilr.110.1603384016294; Thu, 22 Oct 2020 09:26:56 -0700 (PDT) MIME-Version: 1.0 References: <20201019224556.3536790-1-dlatypov@google.com> <20201022150648.GH4077@smile.fi.intel.com> In-Reply-To: <20201022150648.GH4077@smile.fi.intel.com> From: Daniel Latypov Date: Thu, 22 Oct 2020 09:26:45 -0700 Message-ID: Subject: Re: [PATCH] lib: add basic KUnit test for lib/math To: Andy Shevchenko Cc: David Gow , Brendan Higgins , Linux Kernel Mailing List , "open list:KERNEL SELFTEST FRAMEWORK" , Shuah Khan Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 22, 2020 at 8:06 AM Andy Shevchenko wrote: > > On Wed, Oct 21, 2020 at 10:47:50AM -0700, Daniel Latypov wrote: > > On Tue, Oct 20, 2020 at 8:40 PM David Gow wrote: > > > On Tue, Oct 20, 2020 at 6:46 AM Daniel Latypov wrote: > > > > > > > > Add basic test coverage for files that don't require any config options: > > > > * gcd.c > > > > * lcm.c > > > > * int_sqrt.c > > > > * reciprocal_div.c > > > > (Ignored int_pow.c since it's a simple textbook algorithm.) > > > > > > > I don't see a particular reason why int_pow.c being a simple algorithm > > > means it shouldn't be tested. I'm not saying it has to be tested by > > > this particular change -- and I doubt the test would be > > > earth-shatteringly interesting -- but there's no real reason against > > > testing it. > > > > Agreed on principle, but int_pow() feels like a special case. > > I've written it the exact same way (modulo variable names+types) > > several times in personal projects. > > Even the spacing matched exactly in a few of those... > > But if you would like to *teach* somebody by this exemplary piece of code, you > better do it close to ideal. > > > > > These tests aren't particularly interesting, but > > > > * they're chosen as easy to understand examples of how to write tests > > > > * provides a place to add tests for any new files in this dir > > > > * written so adding new test cases to cover edge cases should be easy > > > > > > I think these tests can stand on their own merits, rather than just as > > > examples (though I do think they do make good additional examples for > > > how to test these sorts of functions). > > > So, I'd treat this as an actual test of the maths functions (and > > > you've got what seems to me a decent set of test cases for that, > > > though there are a couple of comments below) first, and any use it > > > gains as an example is sort-of secondary to that (anything that makes > > > it a better example is likely to make it a better test anyway). > > > > > > In any case, modulo the comments below, this seems good to me. > > > > Ack. > > I'll wait on Andy's input before deciding whether or not to push out a > > v2 with the changes. > > You need to put detailed comments in the code to have it as real example how to > create the KUnit test. But hey, it will mean that documentation sucks. So, Out of curiosity * By "it will mean that documentation sucks," do you mean that the documentation will rot faster if people are using the existing in-tree tests as their entrypoint? * What level of detailed comments? On the level of kunit-example-test.c? * More concretely, then we'd have a comment block linking to the example and then describing table driven unit testing? * And then maybe another block about invariants instead of the perhaps too-terse /* gcd(a,b) == gcd(b,a) */ ? > please update documentation to cover issues that you found and which motivated > you to create these test cases. > > Summarize this, please create usable documentation first. Sounds good. I'm generally wary people not reading the docs, and of documentation examples becoming bitrotted faster than actual code. But so far KUnit seems to be doing relatively well on both fronts. usage.rst is currently the best place for this, but it felt like it would quickly become a dumping ground for miscellaneous tips and tricks. I'll spend some time thinking if we want a new file or not, based on how much I want to write about the things this test demonstrated (EXPECT_*MSG, table driven tests, testing invariants, etc). In offline discussions with David, the idea had come up with having a set of (relatively) simple tests in tree that the documentation could point to as examples of these things. That would keep the line count in usage.rst down a bit. (But then it would necessitate more tests like this math_test.c) > > -- > With Best Regards, > Andy Shevchenko > >