Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp247459ybd; Tue, 25 Jun 2019 20:41:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqw66C8oRWK0PnyCVT4CoyBm0CtzWiB29kK1csFgmJy0UAFxPvuZhqvmpKuphkL7KagioPSv X-Received: by 2002:a17:90a:cb18:: with SMTP id z24mr1749238pjt.108.1561520480511; Tue, 25 Jun 2019 20:41:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561520480; cv=none; d=google.com; s=arc-20160816; b=tpVJ+hUL2Myfg6mEMXdIgmymCrzsTtmkpdMl8GXvxGlVhrhYYdjALaD/SAfZ2U64ui MRVvV2n9yOB0eSpyMOt2Ak/RrtvDYrA90YOtoM1ek+nmj+D/zWsBsQ8kknodSOTW/3FZ boE2xidFKrUTmqPjj+ZeD9ReQ+SmReH823QH72rVpQAvYDWWBBUYJC0IqD5jTzPK14X1 +15qJrAsNe7chhx5smeZAzvcIR8oNhK1lFYiygZApwsXYZ61TB24qmQiPUs3YJ1kmREm JXwrHka3MqkpZJTYQ8U1DwokIFVTsbh+fBrcnwbxzW72twbcjvdNe/Ci6WfTl+bJE5Hx RdHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:user-agent:cc:subject :from:to:references:in-reply-to:content-transfer-encoding :mime-version:dkim-signature; bh=GxPjzAYcmvYpmc+3dUDolABfqgv+d/tTMTr6YT4T2OQ=; b=1JzQDQ5T8+jV2DXK8rpJV+CQdTBRNIhTMZaYzSU0gWHLsxHt6FTMMDYayS+m2+kze7 5STjDGU/Aqg/zt0j+ivhmcchp/f9aSrWyIqmFXwcKNcjiQU7R/sIbmT7Ep4nAsR/0W+s sCtENoQIuUkeAgkvXXpcM/jfb05I43n0TGOv3An7Y9obZfcHKAB8hWT3kvy4HEFOjUjm mU6Gt+wwBhnXVry7yKH8Q1hQ/TwUeWKPLpYAWVMf7RmHk2H23Vxjtjy+lAgPJQ9iKsBD xmIap2lBM6GLidFDSsICBZmCzIisibfM5QnCDqx8GgDfspNosgwqFURTEgZ3DkhGQtkL H5Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TozaXDPs; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a24si14767807pgw.395.2019.06.25.20.41.04; Tue, 25 Jun 2019 20:41:20 -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=@kernel.org header.s=default header.b=TozaXDPs; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726558AbfFZDlD (ORCPT + 99 others); Tue, 25 Jun 2019 23:41:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:51194 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726077AbfFZDlC (ORCPT ); Tue, 25 Jun 2019 23:41:02 -0400 Received: from kernel.org (unknown [104.132.0.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B238520883; Wed, 26 Jun 2019 03:41:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561520460; bh=YjnOrrgSNhT6RWlqKXwtbjuCaQYM6DgeF+J68o3kqsE=; h=In-Reply-To:References:To:From:Subject:Cc:Date:From; b=TozaXDPsvQQt/kVas3URc54NSndgjkoC4JTDYWEqG70XXqn3fWJpPNfLyDu06hZCO ksLT9uE8zoDvTnwOTaGmRz8VF+Rm9bpa8KzXo9tWm3/qM5QRpGdRrtfc1krtZGPl7s UrIkXsoPp/B2GQ3tBVMxOkqmDHBq+Vr71I5oFTqc= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: References: <20190617082613.109131-1-brendanhiggins@google.com> <20190617082613.109131-2-brendanhiggins@google.com> <20190620001526.93426218BE@mail.kernel.org> To: Brendan Higgins From: Stephen Boyd Subject: Re: [PATCH v5 01/18] kunit: test: add KUnit test runner core 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 User-Agent: alot/0.8.1 Date: Tue, 25 Jun 2019 20:40:59 -0700 Message-Id: <20190626034100.B238520883@mail.kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Brendan Higgins (2019-06-25 13:28:25) > On Wed, Jun 19, 2019 at 5:15 PM Stephen Boyd wrote: > > > > Quoting Brendan Higgins (2019-06-17 01:25:56) > > > diff --git a/kunit/test.c b/kunit/test.c > > > new file mode 100644 > > > index 0000000000000..d05d254f1521f > > > --- /dev/null > > > +++ b/kunit/test.c > > > @@ -0,0 +1,210 @@ > > > +// SPDX-License-Identifier: GPL-2.0 > > > +/* > > > + * Base unit test (KUnit) API. > > > + * > > > + * Copyright (C) 2019, Google LLC. > > > + * Author: Brendan Higgins > > > + */ > > > + > > > +#include > > > +#include > > > + > > > +static bool kunit_get_success(struct kunit *test) > > > +{ > > > + unsigned long flags; > > > + bool success; > > > + > > > + spin_lock_irqsave(&test->lock, flags); > > > + success =3D test->success; > > > + spin_unlock_irqrestore(&test->lock, flags); > > > > I still don't understand the locking scheme in this code. Is the > > intention to make getter and setter APIs that are "safe" by adding in a > > spinlock that is held around getting and setting various members in the > > kunit structure? >=20 > Yes, your understanding is correct. It is possible for a user to write > a test such that certain elements may be updated in different threads; > this would most likely happen in the case where someone wants to make > an assertion or an expectation in a thread created by a piece of code > under test. Although this should generally be avoided, it is possible, > and there are occasionally good reasons to do so, so it is > functionality that we should support. >=20 > Do you think I should add a comment to this effect? No, I think the locking should be removed. >=20 > > In what situation is there more than one thread reading or writing the > > kunit struct? Isn't it only a single process that is going to be >=20 > As I said above, it is possible that the code under test may spawn a > new thread that may make an expectation or an assertion. It is not a > super common use case, but it is possible. Sure, sounds super possible and OK. >=20 > > operating on this structure? And why do we need to disable irqs? Are we > > expecting to be modifying the unit tests from irq contexts? >=20 > There are instances where someone may want to test a driver which has > an interrupt handler in it. I actually have (not the greatest) example > here. Now in these cases, I expect someone to use a mock irqchip or > some other fake mechanism to trigger the interrupt handler and not > actual hardware; technically speaking in this case, it is not going to > be accessed from a "real" irq context; however, the code under test > should think that it is in an irq context; given that, I figured it is > best to just treat it as a real irq context. Does that make sense? Can you please describe the scenario in which grabbing the lock here, updating a single variable, and then releasing the lock right after does anything useful vs. not having the lock? I'm looking for a two CPU scenario like below, but where it is a problem. There could be three CPUs, or even one CPU and three threads if you want to describe the extra thread scenario. Here's my scenario where it isn't needed: CPU0 CPU1 ---- ---- kunit_run_test(&test) test_case_func() .... [mock hardirq] kunit_set_success(&test) [hardirq ends] ... complete(&test_done) wait_for_completion(&test_done) kunit_get_success(&test) We don't need to care about having locking here because success or failure only happens in one place and it's synchronized with the completion. >=20 > > > + > > > + return success; > > > +} > > > + > > > +static void kunit_set_success(struct kunit *test, bool success) > > > +{ > > > + unsigned long flags; > > > + > > > + spin_lock_irqsave(&test->lock, flags); > > > + test->success =3D success; > > > + spin_unlock_irqrestore(&test->lock, flags); > > > +}