Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2391122yba; Thu, 25 Apr 2019 15:54:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqz21xHh8hS5ysicthjS+nBzerZ3vfvykUXdQ8RlB4U2DUGY8We8RnFSoEaL6KCYsmIN4GQS X-Received: by 2002:a17:902:9302:: with SMTP id bc2mr26146381plb.108.1556232842006; Thu, 25 Apr 2019 15:54:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556232841; cv=none; d=google.com; s=arc-20160816; b=hKUa45S1Jrll5kf6eAHQHjRP0Rq/kI4bwouG+0dAb2VlAuwQ5oC3Tky0eajoAEKVmS BCUftIjHAQoURYRyEPk8idnhD7JpPl3TdeMdpQKh40PGmuETm5XyVYEKsY5eBkIhYAWm qQ2/9jylokOtby9+zoWnoSUsX7WvFLmyD9uXVOMM0XDTUhSyu4A6vxiadcSVw6ZYe9Yn iLTrSlUWyIcQEKh9Tfd8qtMh1MClYp5ntjXVX8gSqY9nhUBYV3KiI7v/fRYNi9Ly7LVN nBMO5Oyvyyi4ZyMgf7d17oBwdqjJ5TVdDtDAdGQpyqxSvTDKMXwRcX2yUtZl0yW8r8QC b6Fg== 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=dPZ7rdZkRKHvl7tQSBXYLFpo+EXi1n//LfsmoJY/Z2s=; b=eoopeUmc3F0Pt+VNwEkOOgrjtoj3A7cTBayuIBcSM4flwE/4l6DKWPjE47pYwXSyMb ULmaIqI9vu/RQutdYa9U35mPH1aToy/n0BChRigfXY7SUpaPPcL/PJynDj3fCaB3YY02 xLVfHAjuxcaM7/r02HEdiOleGpU+6MzShtldXwlkHtyaEa2BxfbLekocviW4jDPT/IC0 +3NtTUPVdUfhhN+jQPN2uoK5uEYnFyloDii0vSlTfGJpM8kJnyBpYQ1LvOR1pzIlTZsW bNuSEuGEITk8Z3w2CcU2ZgikY3RnkB6Et+tICPXXpafklDczPN88LZDClDDvpnbRvEaI QTOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=aYdwRc1H; 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 c68si9869843pfa.56.2019.04.25.15.53.43; Thu, 25 Apr 2019 15:54:01 -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=aYdwRc1H; 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 S1731356AbfDYVjb (ORCPT + 99 others); Thu, 25 Apr 2019 17:39:31 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:33090 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727179AbfDYVj1 (ORCPT ); Thu, 25 Apr 2019 17:39:27 -0400 Received: by mail-oi1-f196.google.com with SMTP id e5so1336860oii.0 for ; Thu, 25 Apr 2019 14:39:27 -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=dPZ7rdZkRKHvl7tQSBXYLFpo+EXi1n//LfsmoJY/Z2s=; b=aYdwRc1HggUO9HL2nIeKqe+hn+Sk6MTVGTkf+pkSUW1w1acF2uKUF+Q1q50U9Y3aaC iV8DLA3o0UHQQwh7u2LDLZ2dULCvFPACLRWcICRHJwk55EGTGEhuesSmDrJKY+GZ+pBQ zxW7c7nFWIsSTuM66KbhGr6p5ywsTb9yBASdwUTfB4mCZRAEjeV3MwJixtVF/8dJKYwg Aa9JBZbSh5KailXw7X/dDBSWpnyer/ZCPxUVQrjc2WwJPc6O+oT4RbnwacyHBj7h51vC 7yoslX52WmthkJmI8/w4rDSzwtqIPzANAeLWsPayMNzRiiKdK9ZXi0LV1FkrRZkUS4wq xI5g== 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=dPZ7rdZkRKHvl7tQSBXYLFpo+EXi1n//LfsmoJY/Z2s=; b=It/P21BbgUhYDZFTfZkoHHX99wvi3i/3cDevnNAN98BI26xzZ/SdB7n7SQZAJ+23sY vLTsIf81axWrCiAqSkQh0l+ME6EB3OjMRRtHXe264jQiJgTJgyomeeFoyj1Jz7kWr/jw VTpmnzVzhzQbCiArV3XNUBMizzwikt64shxwiLBB1yMvF3HtAjNr5fHISViD9KVbxz1O wbB0rQlNf3kHjVUgAJyMfykPAOlUvLRFp23+G0qwgNUjPTDVq1uf3f0zkKZrwuhJOSUi JXebvhF1fQGhbZBKcxJajBWQDfEgsc0PIu1MolvjHABFaBmcg0hh+uqH74BJ7kGUAUVX RS3A== X-Gm-Message-State: APjAAAXol+YRSC0SyqWxmEejtD/2ru9ymLy/3IcC1uWcFOOndScgTtwg Jby/umRwFdPJrHZ28bKBJAAZntHRGTt5yhB/2Wirrg== X-Received: by 2002:aca:4586:: with SMTP id s128mr4542736oia.148.1556228366758; Thu, 25 Apr 2019 14:39:26 -0700 (PDT) MIME-Version: 1.0 References: <20190404220652.19765-1-brendanhiggins@google.com> <20190404220652.19765-12-brendanhiggins@google.com> <20190424190019.wvljyeo3y7gd24p5@gabell> In-Reply-To: <20190424190019.wvljyeo3y7gd24p5@gabell> From: Brendan Higgins Date: Thu, 25 Apr 2019 14:39:15 -0700 Message-ID: Subject: Re: [PATCH v1 11/17] kunit: test: add test managed resource tests To: Masayoshi Mizuma Cc: Jonathan Corbet , Frank Rowand , Kees Cook , Kieran Bingham , Luis Chamberlain , Rob Herring , shuah@kernel.org, yamada.masahiro@socionext.com, Petr Mladek , linux-doc@vger.kernel.org, Amir Goldstein , dri-devel , Sasha Levin , linux-kselftest@vger.kernel.org, linux-nvdimm , Kevin Hilman , Knut Omang , wfg@linux.intel.com, Joel Stanley , Jeff Dike , Dan Carpenter , devicetree , linux-kbuild@vger.kernel.org, "Bird, Timothy" , Avinash Kondareddy , linux-um@lists.infradead.org, Steven Rostedt , Julia Lawall , kunit-dev@googlegroups.com, Richard Weinberger , Greg KH , Linux Kernel Mailing List , Daniel Vetter , Michael Ellerman , linux-fsdevel@vger.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 On Wed, Apr 24, 2019 at 12:00 PM Masayoshi Mizuma wrote: > > On Thu, Apr 04, 2019 at 03:06:46PM -0700, Brendan Higgins wrote: > > From: Avinash Kondareddy > > > > Tests how tests interact with test managed resources in their lifetime. > > > > Signed-off-by: Avinash Kondareddy > > Signed-off-by: Brendan Higgins > > --- > > kunit/test-test.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 122 insertions(+) > > > > diff --git a/kunit/test-test.c b/kunit/test-test.c > > index 4bd7a34d0a6cb..54add8ca418a0 100644 > > --- a/kunit/test-test.c > > +++ b/kunit/test-test.c > > @@ -135,3 +135,125 @@ static struct kunit_module kunit_try_catch_test_module = { > > .test_cases = kunit_try_catch_test_cases, > > }; > > module_test(kunit_try_catch_test_module); > > + > > +/* > > + * Context for testing test managed resources > > + * is_resource_initialized is used to test arbitrary resources > > + */ > > +struct kunit_test_resource_context { > > + struct kunit test; > > + bool is_resource_initialized; > > +}; > > + > > +static int fake_resource_init(struct kunit_resource *res, void *context) > > +{ > > + struct kunit_test_resource_context *ctx = context; > > + > > + res->allocation = &ctx->is_resource_initialized; > > + ctx->is_resource_initialized = true; > > + return 0; > > +} > > + > > +static void fake_resource_free(struct kunit_resource *res) > > +{ > > + bool *is_resource_initialized = res->allocation; > > + > > + *is_resource_initialized = false; > > +} > > + > > +static void kunit_resource_test_init_resources(struct kunit *test) > > +{ > > + struct kunit_test_resource_context *ctx = test->priv; > > + > > + kunit_init_test(&ctx->test, "testing_test_init_test"); > > + > > + KUNIT_EXPECT_TRUE(test, list_empty(&ctx->test.resources)); > > +} > > + > > +static void kunit_resource_test_alloc_resource(struct kunit *test) > > +{ > > + struct kunit_test_resource_context *ctx = test->priv; > > + struct kunit_resource *res; > > + kunit_resource_free_t free = fake_resource_free; > > + > > + res = kunit_alloc_resource(&ctx->test, > > + fake_resource_init, > > + fake_resource_free, > > + ctx); > > + > > > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, res); > > KUNIT_EXPECT_NOT_ERR_OR_NULL(test, res); See my reply to your email on the 14/17 patch.