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=-13.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham 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 F1978C48BD6 for ; Wed, 26 Jun 2019 00:07:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BAF1020645 for ; Wed, 26 Jun 2019 00:07:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Udp0DSI1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726425AbfFZAHq (ORCPT ); Tue, 25 Jun 2019 20:07:46 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:39355 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726329AbfFZAHp (ORCPT ); Tue, 25 Jun 2019 20:07:45 -0400 Received: by mail-pg1-f195.google.com with SMTP id 196so241219pgc.6 for ; Tue, 25 Jun 2019 17:07:45 -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=0CKSZbZdZTCXDsFevmx6xy0jVDdxhx+j1rEEB3vl63s=; b=Udp0DSI1eicbAQ93CL5kbvi8Xp/6zCCrOWD+4my5+Z2KobfpntEZptXwNDN+m1HYdl aWzrSvRzjBSRt+1Ke5gfgolTpuldTSDWCwjjFSm2u0fallCYK2AWnGnpndlL89sFN0Zl GTwNluZIxE+q2xxZzY/SPhBF2gsVikHJ199bU9KJdjOqqrHUctG5Or1EMQYsJztcsOoC DiYGphxIA91H14nI8J5aNbvthpK6V9fOCpd2OHMJOcinqK81dIeXjiZaAKjLmKAP2Jwx 0nEa6ArcVSNjpUjZHNws6GQlmspmdwUJ/ZxXDeWnV3qF6zllsbtRDaXwGrbAJh9mZIai k2MA== 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=0CKSZbZdZTCXDsFevmx6xy0jVDdxhx+j1rEEB3vl63s=; b=bF4phqKagx2dE03PPV+CW2tLbwW4dDyPmBlZ1u6UAbUu6RsNhYyR1qHEWV5wdFvxm7 a968jcwKadDkSj4LJg2j9rkeSEXy29qtiFCC8RUtORgiQBDlxkH8NENQP2ZVtpqzFYMn 9ZpX75vxwHJgvIVacZPxq3kXhUV7i2ci4bdSzuFUZ8adVThBzrPPpnsbtPySep8H3Oaz R7mY8aUcubY36O3L8RVLyQF+lT43x2lgiz+VBri6Qxm62T4whawpwJ0kJZqWiLf1QVBR 0Dh0pS/jlh1LDLxA6oZYkJ9Xzsa2q+lmyn8bb939neUCMhAlne6AEUkydgi5EadWnSEI Q2IQ== X-Gm-Message-State: APjAAAVc+IPFvRNA++7KwmqFg2BUuPWxAc7KfKDF1qFrABa48j4dFvM6 0cDsFitD2/T4vbhqCFEWoh7WVlxyWGhbyKUGVvjk4g== X-Google-Smtp-Source: APXvYqwFUlf+fXcTuEW4suwRhf8sO2Hw8q7BLLIj3tSrVcwKVl/cK8K/AXXabwkRnwCip/wX7DtGYsxR83H1S/Y9Z64= X-Received: by 2002:a17:90a:be0d:: with SMTP id a13mr657604pjs.84.1561507663974; Tue, 25 Jun 2019 17:07:43 -0700 (PDT) MIME-Version: 1.0 References: <20190617082613.109131-1-brendanhiggins@google.com> <20190617082613.109131-2-brendanhiggins@google.com> <20190625223312.GP19023@42.do-not-panic.com> In-Reply-To: <20190625223312.GP19023@42.do-not-panic.com> From: Brendan Higgins Date: Tue, 25 Jun 2019 17:07:32 -0700 Message-ID: Subject: Re: [PATCH v5 01/18] kunit: test: add KUnit test runner core To: Luis Chamberlain Cc: Frank Rowand , Greg KH , Josh Poimboeuf , Kees Cook , Kieran Bingham , Peter Zijlstra , Rob Herring , Stephen Boyd , 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 Tue, Jun 25, 2019 at 3:33 PM Luis Chamberlain wrote: > > On Mon, Jun 17, 2019 at 01:25:56AM -0700, Brendan Higgins wrote: > > +/** > > + * module_test() - used to register a &struct kunit_module with KUnit. > > + * @module: a statically allocated &struct kunit_module. > > + * > > + * Registers @module with the test framework. See &struct kunit_module for more > > + * information. > > + */ > > +#define module_test(module) \ > > + static int module_kunit_init##module(void) \ > > + { \ > > + return kunit_run_tests(&module); \ > > + } \ > > + late_initcall(module_kunit_init##module) > > Becuase late_initcall() is used, if these modules are built-in, this > would preclude the ability to test things prior to this part of the > kernel under UML or whatever architecture runs the tests. So, this > limits the scope of testing. Small detail but the scope whould be > documented. You aren't the first person to complain about this (and I am not sure it is the first time you have complained about it). Anyway, I have some follow on patches that will improve the late_initcall thing, and people seemed okay with discussing the follow on patches as part of a subsequent patchset after this gets merged. I will nevertheless document the restriction until then. > > +static void kunit_print_tap_version(void) > > +{ > > + if (!kunit_has_printed_tap_version) { > > + kunit_printk_emit(LOGLEVEL_INFO, "TAP version 14\n"); > > What is this TAP thing? Why should we care what version it is on? > Why are we printing this? It's part of the TAP specification[1]. Greg and Frank asked me to make the intermediate format conform to TAP. Seems like something else I should probable document... > > + kunit_has_printed_tap_version = true; > > + } > > +} > > + > > +static size_t kunit_test_cases_len(struct kunit_case *test_cases) > > +{ > > + struct kunit_case *test_case; > > + size_t len = 0; > > + > > + for (test_case = test_cases; test_case->run_case; test_case++) > > If we make the last test case NULL, we'd just check for test_case here, > and save ourselves an extra few bytes per test module. Any reason why > the last test case cannot be NULL? Is there anyway to make that work with a statically defined array? Basically, I want to be able to do something like: static struct kunit_case example_test_cases[] = { KUNIT_CASE(example_simple_test), KUNIT_CASE(example_mock_test), {} }; FYI, #define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name } In order to do what you are proposing, I think I need an array of pointers to test cases, which is not ideal. > > +void kunit_init_test(struct kunit *test, const char *name) > > +{ > > + spin_lock_init(&test->lock); > > + test->name = name; > > + test->success = true; > > +} > > + > > +/* > > + * Performs all logic to run a test case. > > + */ > > +static void kunit_run_case(struct kunit_module *module, > > + struct kunit_case *test_case) > > +{ > > + struct kunit test; > > + int ret = 0; > > + > > + kunit_init_test(&test, test_case->name); > > + > > + if (module->init) { > > + ret = module->init(&test); > > I believe if we used struct kunit_module *kmodule it would be much > clearer who's init this is. That's reasonable. I will fix in next revision. Cheers! [1] https://github.com/TestAnything/Specification/blob/tap-14-specification/specification.md