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=-12.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT 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 8BB4EC43464 for ; Fri, 18 Sep 2020 18:32:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3474C22208 for ; Fri, 18 Sep 2020 18:32:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="jDjmNJ3K" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726343AbgIRScB (ORCPT ); Fri, 18 Sep 2020 14:32:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726316AbgIRScA (ORCPT ); Fri, 18 Sep 2020 14:32:00 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3EDAC0613D1 for ; Fri, 18 Sep 2020 11:31:59 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id y6so6372470ybi.11 for ; Fri, 18 Sep 2020 11:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=6j9u1FoP2f0YImnHuabzWtMZNqpaUUCvlMhNCAR76JU=; b=jDjmNJ3KSjUg3aa2pfGH6CUYyYGAFArBEZZ1q/Tv+a+dfnBIYuV1XXDlylS5aE4y8U WO1UYuqBLmyj+k5wRntFsQ3bEH1WCZspbUxL/burLyyD4Dn6XJPB4d8VpnCEySdG7IXY ZYa6j5yEnprmhDU1vuXUvpDL1zB2Z/1tE1BKrfSynNYOXnQa4+0HBNBTSQ/5XIehuaUf ad7PyGX8YJF27WDgEWiVnDYzUHW5HmB5swPoT58rXdtoEdH24gFbi3eFxGQkBE8oWQxw wW5YFTniST+xPuOrdLrBU8QCD5dGYujxkpwLXxwfA/loh9zuRC2JJw8vFZoRGRbJalCB rfyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=6j9u1FoP2f0YImnHuabzWtMZNqpaUUCvlMhNCAR76JU=; b=fBPoAK0IbW3zogTYbNk7WwdejgOSa5oL6THqMpgbFx2EJE8VGzxAf7UUWtdCkW5Ttb uF2RWi6CuTGwq2DqRHH8kblYikbNRhBz3ThBp+UhoKQXcZWlUrVBmD7foOXQ6HPb1BXG OJGpnqcQPXeS6vvCWJ2wvBlKG+MdNqKj04Fa5l/lwzFkw5Hv2gDaU+K1WNiI8OdtkdJH 9CQkeK8j+j733YISHPV0K6hIIajzrSK0ehQHfPCpFNPNlKUgFWhYC77FT3hkF106egpY HpdNeCcu+4i2v7mz1OA2iLyz7nHIM63wcqf0BrsJXZ+kDLjXqgTR6MZ7sbAuzMnIg6M1 6bEA== X-Gm-Message-State: AOAM530fpbDKgYEP2sFfpT9a6LpitXf8WpGvXQMb71PBIp0bveKFHVmS AxDj2bmtj9nOeTzwmY42yKDiizHMDj6rAQ== X-Google-Smtp-Source: ABdhPJwSKO0Xmi7ZdVdGxwSqjplGIFXXa2v0SvgpaWFgjL3kkLAAaO0/pZnF0v65UTjDjem62JeMBrGHZTNwNw== X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:a28c:fdff:fee3:28c6]) (user=dlatypov job=sendgmr) by 2002:a25:6a06:: with SMTP id f6mr12076185ybc.334.1600453918948; Fri, 18 Sep 2020 11:31:58 -0700 (PDT) Date: Fri, 18 Sep 2020 11:31:05 -0700 In-Reply-To: <20200918183114.2571146-1-dlatypov@google.com> Message-Id: <20200918183114.2571146-4-dlatypov@google.com> Mime-Version: 1.0 References: <20200918183114.2571146-1-dlatypov@google.com> X-Mailer: git-send-email 2.28.0.681.g6f77f65b4e-goog Subject: [RFC v1 03/12] kunit: test: add concept of post conditions From: Daniel Latypov To: Brendan Higgins , David Gow , Shuah Khan Cc: kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , Luis Chamberlain , Alan Maguire , Stephen Boyd , Daniel Latypov Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Brendan Higgins Add a way to specify that certain conditions must be met at the end of a test case. Signed-off-by: Brendan Higgins Signed-off-by: Daniel Latypov --- include/kunit/test.h | 6 ++++++ lib/kunit/test.c | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/kunit/test.h b/include/kunit/test.h index 687782fa44d9..0eb3abb00da4 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -190,6 +190,11 @@ struct kunit_suite { char *log; }; +struct kunit_post_condition { + struct list_head node; + void (*validate)(struct kunit_post_condition *condition); +}; + /** * struct kunit - represents a running instance of a test. * @@ -223,6 +228,7 @@ struct kunit { * protect it with some type of lock. */ struct list_head resources; /* Protected by lock. */ + struct list_head post_conditions; }; void kunit_init_test(struct kunit *test, const char *name, char *log); diff --git a/lib/kunit/test.c b/lib/kunit/test.c index 670d1cc9c105..4e8c74c89073 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -228,6 +228,7 @@ void kunit_init_test(struct kunit *test, const char *name, char *log) { spin_lock_init(&test->lock); INIT_LIST_HEAD(&test->resources); + INIT_LIST_HEAD(&test->post_conditions); test->name = name; test->log = log; if (test->log) @@ -269,6 +270,16 @@ static void kunit_case_internal_cleanup(struct kunit *test) static void kunit_run_case_cleanup(struct kunit *test, struct kunit_suite *suite) { + struct kunit_post_condition *condition, *condition_safe; + + list_for_each_entry_safe(condition, + condition_safe, + &test->post_conditions, + node) { + condition->validate(condition); + list_del(&condition->node); + } + if (suite->exit) suite->exit(test); -- 2.28.0.681.g6f77f65b4e-goog