Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp88166ybd; Tue, 25 Jun 2019 17:08:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqyw5hopTZ5Q7dTxSKslYwzhXkJ8JLOqHDPfgiD+IC2AqHRZu+BaBnHAnFYLCDbZvajhaOVn X-Received: by 2002:a17:902:aa83:: with SMTP id d3mr1551279plr.74.1561507735122; Tue, 25 Jun 2019 17:08:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561507735; cv=none; d=google.com; s=arc-20160816; b=tNUvnyCQ2DuLghYP7KQEMHhJPhmlmugq/lAvHfYNtPZ9PiCs6ErhOQif1WOICziVnj cbDMwVnF6l+v1H7VnDza1CD7R8cCmwvOszHsvK1Z3fHO88ezMsVogvD2MONHy+6NTQ4R P/6hbnBtMyvP7Yu5BTseqmufIsu5Yw+2aTsqkJZUOsml7W5FXb/Sodo4I5vXilIvAwRY Es4pKpdpXXEdaBH03H3ohXnWf+z84wUutVePLj2xksswXmpKadRVybNt91i5E/Jjez3o 8doQ+yakyWlEuVJq29ZYd9p/aDWhq/7mHJwRJF+vmTmcppK5TkO2520pa9Xp4Xslm4ok WW1A== 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=0CKSZbZdZTCXDsFevmx6xy0jVDdxhx+j1rEEB3vl63s=; b=R3P1D4Ol+aru7hjDYz9EY5rMtzblri39FTRd9HQhqa5T1KGt4ZSxK/KVoUhehr7dx5 lQWrHROVF5cguX35IJe97xzgsNgMFHSsOQcSYhyKSDWh0ocAe63KbwtuYwBxcYXC4mko lsJ/kEOJtxJ/ffYveIO/ZL2MfQaNjGZoDnpdMu8PmJBZ0Nhoo1deOMUjXnQicuzBh3hL Um4Wbc8RveLwyGRzzJAqNM87Qw1ehcZUeSf64jDL/0MBnf805HdX8fjeli+kjKmtZJ8P WXSNAp93X6zt1IdGfRGZ0MaIRmGqtfgM7voSPeJU2EYYmCYUwBlweaz/U8g1KpchgH6y 3G2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Udp0DSI1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id 68si9819395pge.235.2019.06.25.17.08.38; Tue, 25 Jun 2019 17:08:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Udp0DSI1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726412AbfFZAHq (ORCPT + 99 others); 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-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