From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 873EFC76191 for ; Mon, 15 Jul 2019 21:26:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5D4322145D for ; Mon, 15 Jul 2019 21:26:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OKadg9ad" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732478AbfGOVZ7 (ORCPT ); Mon, 15 Jul 2019 17:25:59 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:44647 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730268AbfGOVZ6 (ORCPT ); Mon, 15 Jul 2019 17:25:58 -0400 Received: by mail-pf1-f196.google.com with SMTP id t16so8001903pfe.11 for ; Mon, 15 Jul 2019 14:25: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=L1iVnKb9KyH2VdRaa+1X1AxuS2MqitxfIlVlkn/kOv8=; b=OKadg9adfR8FnEoQT6HdGl96SBZxASHai1a3d6JJ7kS2KeuZ1gp/Sww0dZ4FNnRfmX dsWE9zqYktoShjIU+eYZsCRcFIJfFws6QoK2qlbR+qOq4rr/hOZP2M3LcnN2q482/I73 uk9eNSjzCb/KkfhP4BJ2nmSyKV5xwGPcSeH7IrIsnT+SSVepNWQYB1x9JIyW2ECp5yWy v4jcSyoBZJSrmeWQFBgJn1mNjyDuuQcjVCEz7vy2pTS+5CwXEpnaX+c+7wd+NdqiTuWs jLfiDc8e4oMqUtNtGi1qAx20ReiWP9Qgxngtq/5EbA2D41xPwKDuHWOLS0EUq/G9lFRU uKpQ== 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=L1iVnKb9KyH2VdRaa+1X1AxuS2MqitxfIlVlkn/kOv8=; b=fvNVx3aNEE7qxQ2XYRB8E8guc3ktPS0CPE3Fmw8Yd60Q971POCGweH7Ja5Bzb0hdsK svoPVoYqPmo9PlTbm4C03pELHob9tXxILFtCUkaVhHBV4zBmci7apIvPrwHTuqwnuUdW ojna604rXFx2BIHfu2dAxD9cBA7ZVtSNx6b07zOYcpcavYKRRwXvyVgyZqSsQUttYOnI ZNihn11biaAZTXh5lFWmNDRNGgIAWgOelO5DNsU/OqCKq0aBupLOrAersPIQcGC9+zf2 AwbVMR2BM2tvElbU3/ugtjE1a48zrlsjifc6iXwpUCgnpDbqRAWnmapqgHaHGxAaGaUU B7lw== X-Gm-Message-State: APjAAAXtgmSR4V0j0OfSYSMyz6xmSR4hX4Vlbcohl/hxgO7b+mdoiTH2 uAi8iytAxqtEzAp7arlXjk61wOm1UPVXttWbYe6Gtw== X-Google-Smtp-Source: APXvYqxYpwH7M9Tn69WNYt23pvYEmwOFSLt2yT+zRsvwVW6B093wD7DIpVEsyGIo3whwBHoCVELofo1GZGIk7QmjTys= X-Received: by 2002:a63:205f:: with SMTP id r31mr29138784pgm.159.1563225956600; Mon, 15 Jul 2019 14:25:56 -0700 (PDT) MIME-Version: 1.0 References: <20190712081744.87097-1-brendanhiggins@google.com> <20190712081744.87097-2-brendanhiggins@google.com> <20190715201054.C69AA2086C@mail.kernel.org> In-Reply-To: <20190715201054.C69AA2086C@mail.kernel.org> From: Brendan Higgins Date: Mon, 15 Jul 2019 14:25:45 -0700 Message-ID: Subject: Re: [PATCH v9 01/18] kunit: test: add KUnit test runner core To: Stephen Boyd Cc: Frank Rowand , Greg KH , Josh Poimboeuf , Kees Cook , Kieran Bingham , Luis Chamberlain , Peter Zijlstra , Rob Herring , shuah , "Theodore Ts'o" , Masahiro Yamada , devicetree , dri-devel , kunit-dev@googlegroups.com, "open list:DOCUMENTATION" , linux-fsdevel@vger.kernel.org, linux-kbuild , Linux Kernel Mailing List , "open list:KERNEL SELFTEST FRAMEWORK" , linux-nvdimm , linux-um@lists.infradead.org, Sasha Levin , "Bird, Timothy" , Amir Goldstein , Dan Carpenter , Daniel Vetter , Jeff Dike , Joel Stanley , Julia Lawall , Kevin Hilman , Knut Omang , Logan Gunthorpe , Michael Ellerman , Petr Mladek , Randy Dunlap , Richard Weinberger , David Rientjes , Steven Rostedt , wfg@linux.intel.com 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 On Mon, Jul 15, 2019 at 1:10 PM Stephen Boyd wrote: > > Quoting Brendan Higgins (2019-07-12 01:17:27) > > Add core facilities for defining unit tests; this provides a common way > > to define test cases, functions that execute code which is under test > > and determine whether the code under test behaves as expected; this also > > provides a way to group together related test cases in test suites (here > > we call them test_modules). > > > > Just define test cases and how to execute them for now; setting > > expectations on code will be defined later. > > > > Signed-off-by: Brendan Higgins > > Reviewed-by: Greg Kroah-Hartman > > Reviewed-by: Logan Gunthorpe > > Reviewed-by: Luis Chamberlain > > Reviewed-by: Stephen Boyd > > Minor nits below. > > > diff --git a/kunit/test.c b/kunit/test.c > > new file mode 100644 > > index 0000000000000..571e4c65deb5c > > --- /dev/null > > +++ b/kunit/test.c > > @@ -0,0 +1,189 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Base unit test (KUnit) API. > > + * > > + * Copyright (C) 2019, Google LLC. > > + * Author: Brendan Higgins > > + */ > > + > > +#include > > +#include > > + > > +static void kunit_set_failure(struct kunit *test) > > +{ > > + WRITE_ONCE(test->success, false); > > +} > > + > [...] > > + > > +void kunit_init_test(struct kunit *test, const char *name) > > +{ > > + test->name = name; > > + test->success = true; > > +} > > + > > +/* > > + * Performs all logic to run a test case. > > + */ > > +static void kunit_run_case(struct kunit_suite *suite, > > + struct kunit_case *test_case) > > +{ > > + struct kunit test; > > + int ret = 0; > > + > > + kunit_init_test(&test, test_case->name); > > + > > + if (suite->init) { > > + ret = suite->init(&test); > > Can you push the ret definition into this if scope? That way we can > avoid default initialize to 0 for it. Sure! I would actually prefer that from a cosmetic standpoint. I just thought that mixing declarations and code was against the style guide. > > + if (ret) { > > + kunit_err(&test, "failed to initialize: %d\n", ret); > > + kunit_set_failure(&test); > > Do we need to 'test_case->success = test.success' here too? Or is the > test failure extracted somewhere else? Er, yes. That's kind of embarrassing. Good catch. > > + return; > > + } > > + } > > + > > + test_case->run_case(&test); > > + > > + if (suite->exit) > > + suite->exit(&test); > > + > > + test_case->success = test.success; Thanks!