Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1456114ybg; Wed, 29 Jul 2020 14:58:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWFkwJg6/Ojzmx+q+6Zlqz6FRF9QIPr5XwEaDmDypk2+IqQfq3cNfVypZ8b1MwX8aPrjnr X-Received: by 2002:a17:906:d8f:: with SMTP id m15mr391901eji.494.1596059903932; Wed, 29 Jul 2020 14:58:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596059903; cv=none; d=google.com; s=arc-20160816; b=eCa+AuuKDqfdCVN0ViT7aQKKyxHf3nij+bxZJdJpi/VPI7XJf35wZox8D7nMLSLImH wS5U9YS8yzj3/CcBfLvZ+Df+NvdoI6eNTi7Qj+fMujP6bn/6K6C4uTSAezL23TYHkbOM ddaxJRLXvK4EfyYUQFE4qNkWH9qlS3q+b2MYcusOGWzZ6kntStzse5erTQURpSuktb6X 1olMuNPVg3pJq7QGP2ejrwKymujnznvR3hCqYR8vB2M33lCRhaaSD4LVoW1WOTHP/5XB Y8d2R4DxiBwd2DqHC73IWT2DmoouvelxkSUoFeSsQZyg5bnogR3UyrFrhfil0NIFawUY fiyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=d/ukW0X/5BiKbJEKr2oeHvITKKVidatQzqB3tkKKQNg=; b=NNDyoW7IUXu5dcBJO78nXEJTDyRvckdq460Zlx2hHO/qGAXeMkzk/C1dNfRkmjb7Xb pU5XL8M3ww3LmMzTXStzalTH9+527vR/u4i9V1qFPa6dCLFLNd4KjE63ND1NPlNsSNdx CXq+quZ+7x/+Ri8AlQY7d5pIYE6aYwcmgC41ChKJvOonpLviAB62+TGXD4bABAh65gs6 jRkfHGESYvrAdVsSAGP4bohJDudDyj4WTPzwkGfCtOGNhAK0Ydr/dvBDh7WTUcVAHfai F4Ambvk38/FGfzkch/5vJjM9oxaT8C/uaHzDxbANCnkv8KfVWrU/pKmD1d/CXnoBpEOr o2DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@massaru-org.20150623.gappssmtp.com header.s=20150623 header.b=rJaH5wiX; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a16si1902396ejs.361.2020.07.29.14.58.01; Wed, 29 Jul 2020 14:58:23 -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=@massaru-org.20150623.gappssmtp.com header.s=20150623 header.b=rJaH5wiX; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727071AbgG2V5z (ORCPT + 99 others); Wed, 29 Jul 2020 17:57:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726365AbgG2V5y (ORCPT ); Wed, 29 Jul 2020 17:57:54 -0400 Received: from mail-yb1-xb43.google.com (mail-yb1-xb43.google.com [IPv6:2607:f8b0:4864:20::b43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E373C061794 for ; Wed, 29 Jul 2020 14:57:54 -0700 (PDT) Received: by mail-yb1-xb43.google.com with SMTP id a15so13342393ybs.8 for ; Wed, 29 Jul 2020 14:57:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=massaru-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=d/ukW0X/5BiKbJEKr2oeHvITKKVidatQzqB3tkKKQNg=; b=rJaH5wiXRvUWjGwEt7fJ1cni+QUEQC+KArZY6p9dqwr+4i9DiQKMSTcR2iiDPSaH8u fs+PexYNdlCvXC5wsnATdxceiAcJXPGlFX2e9AmEodp+cXu385RH3dMPBV1cVaFZ8sWv DQ823qFab2ZxTt4iFeEC9dVOjJgenL7Ch/RIR1u/PCbMpZXEOui01nlr3cARdxjtAy9L CzpjWgxyXcgh931rMjLjrAVgbhTDVmK0kglNHoNPDvJhLXtUMjjdo47t8tApp/WMUli+ +Veo/yRPfOpoJnwAamAlxDyucbmT1wpFRznchCnqhxMgKido4q6VF/LK607lXukFaMP1 AX0w== 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=d/ukW0X/5BiKbJEKr2oeHvITKKVidatQzqB3tkKKQNg=; b=uMjltdQE70CRLabbwbvZNyoTZlnwxvpuixujVJYteooGYPHZkJarHywABzi0Jlwhau RohpyXYX+vluyOB7KkDCpuKsyOsnbH9StH5WIYqKshcmnGCE9s5ta29GY46orOQp5IUx ucGJKHJltQEF/CjNg62MCo+zUl+znwHBwXVLvDi+8iBtJQsCk6BNAzfAJE991MD4g63V EsgyBbxGvNPH/iOviuQDmN1RuwOG306nTyoq5kCNYOJ7Kkf118btJ2yfCfuDtfMncbHK 5NHdy8gzmUXPyYHyDwCR/PzrEQrXfHCre0l8UpDKsjvivDxmJAOy1UA1saNH7LI0JtY6 Mzsw== X-Gm-Message-State: AOAM532KYXwSzKZzZ+PmPr35GCC1axfbqsllB+ImINJCWNBPUbcL4nWm TQ5PtOM4Kt9kQm/QZPs6HJSvgy3BsoxF9bcmqhjlWg== X-Received: by 2002:a25:361b:: with SMTP id d27mr66842yba.348.1596059873438; Wed, 29 Jul 2020 14:57:53 -0700 (PDT) MIME-Version: 1.0 References: <20200729201146.537433-1-vitor@massaru.org> <20200729203908.GD2655@hirez.programming.kicks-ass.net> In-Reply-To: <20200729203908.GD2655@hirez.programming.kicks-ass.net> From: Vitor Massaru Iha Date: Wed, 29 Jul 2020 18:57:17 -0300 Message-ID: Subject: Re: [PATCH] lib: kunit: add test_min_heap test conversion to KUnit To: peterz@infradead.org Cc: KUnit Development , "open list:KERNEL SELFTEST FRAMEWORK" , Linux Kernel Mailing List , Brendan Higgins , Shuah Khan , linux-kernel-mentees@lists.linuxfoundation.org, irogers@google.com, mingo@kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Peter, On Wed, Jul 29, 2020 at 5:39 PM wrote: > > On Wed, Jul 29, 2020 at 05:11:46PM -0300, Vitor Massaru Iha wrote: > > This adds the conversion of the runtime tests of test_min_heap, > > from `lib/test_min_heap.c` to KUnit tests. > > > > Please apply this commit first (linux-kselftest/kunit-fixes): > > 3f37d14b8a3152441f36b6bc74000996679f0998 kunit: kunit_config: Fix parsing of CONFIG options with space > > > > Signed-off-by: Vitor Massaru Iha > > --- > > lib/Kconfig.debug | 29 ++++-- > > lib/Makefile | 2 +- > > lib/{test_min_heap.c => min_heap_kunit.c} | 117 ++++++++++++---------- > > 3 files changed, 83 insertions(+), 65 deletions(-) > > rename lib/{test_min_heap.c => min_heap_kunit.c} (60%) > > So where's the win? What's KUnit, why should I care and more lines. KUnit is a unit testing and mocking framework for the Linux kernel. [0] In Kconfig.debug you only have some more information about KUnit. If the number of lines is a parameter that should be considered, I can change sections like this - if (last > values[0]) { - pr_err("error: expected %d <= %d\n", last, - values[0]); - err++; - } + KUNIT_EXPECT_FALSE_MSG(context, + last > values[0], + "expected %d <= %d\n", + last, values[0]); To this: - if (last > values[0]) { - pr_err("error: expected %d <= %d\n", last, - values[0]); - err++; - } + KUNIT_EXPECT_FALSE_MSG(context, last > values[0], "expected %d <= %d\n", last, values[0]); And from this: +static struct kunit_case __refdata min_heap_test_cases[] = { + KUNIT_CASE(test_heapify_all_true), + KUNIT_CASE(test_heapify_all_false), + KUNIT_CASE(test_heap_push_true), + KUNIT_CASE(test_heap_push_false), + KUNIT_CASE(test_heap_pop_push_true), + KUNIT_CASE(test_heap_pop_push_false), + {} To this: +static struct kunit_case __refdata min_heap_test_cases[] = { + KUNIT_CASE(test_min_heap), + {} I did the latter this way to be more informative, but if the goal is to reduce lines of code, this is possible. The results can be seen this way: This is an excerpt from the test.log with the result in TAP format: [snip] ok 5 - example # Subtest: min-heap 1..6 ok 1 - test_heapify_all_true ok 2 - test_heapify_all_false ok 3 - test_heap_push_true ok 4 - test_heap_push_false ok 5 - test_heap_pop_push_true ok 6 - test_heap_pop_push_false [snip] And this from kunit-tool: [snip] [18:43:32] ============================================================ [18:43:32] ======== [PASSED] min-heap ======== [18:43:32] [PASSED] test_heapify_all_true [18:43:32] [PASSED] test_heapify_all_false [18:43:32] [PASSED] test_heap_push_true [18:43:32] [PASSED] test_heap_push_false [18:43:32] [PASSED] test_heap_pop_push_true [18:43:32] [PASSED] test_heap_pop_push_false [18:43:32] ============================================================ [18:43:32] Testing complete. 20 tests run. 0 failed. 0 crashed. [18:43:32] Elapsed time: 9.758s total, 0.001s configuring, 6.012s building, 0.000s running [snip] BR, Vitor [0] https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html#what-is-kunit