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=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 53BA8C433E7 for ; Mon, 12 Oct 2020 22:21:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 060AD20797 for ; Mon, 12 Oct 2020 22:21:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Axk4HR41" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388955AbgJLWV1 (ORCPT ); Mon, 12 Oct 2020 18:21:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388897AbgJLWVX (ORCPT ); Mon, 12 Oct 2020 18:21:23 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB0EDC0613D2 for ; Mon, 12 Oct 2020 15:21:22 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id 9so13495439pfj.22 for ; Mon, 12 Oct 2020 15:21:22 -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=sDgp3qm/ugpnk+z4x4KeSqXwj6auWLovvv5/S95lj9Y=; b=Axk4HR416fA3as2M3/r8vuSuAGnjGbuBaZzegYEm/GTKv1tcPQr8q2WH8B2+LpC8BO qg2DOsdhHq6ud7scQepygkoKHbXbboap7Oq1Bh9w1d876C5PsiLTzo0RZe4RAAqUKx/u 1wX9K4giNMW86G0q+du0mTTEQsu1JkdoBYpifVsxh0PuMo7mUFf6WX8QNsSS8KBtVSUL vyYcn10QQyRKQEIGun2X6fklJ3WJK0fhUSiVobhIs2H/DxM53feTvT9ZcOtCrU0UvVyk 8rtvXCA/TtmAXsCbwJ4Dbe5dLCn/IXeBCIiyNJEY3J6G6LMpcC3Og9g7xBKVigQgtm8p 6cIg== 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=sDgp3qm/ugpnk+z4x4KeSqXwj6auWLovvv5/S95lj9Y=; b=m1gn8t1EdmgSghZlVrSfRMYmd7KrbSLx/l6mKAIkvuNH5KGuxHylTf/m1hdQ1cR8Fj mfNmIP3e32gGOU+WEPdNynF+RuFYW0GAV5qYJnJ7cnlWx4ibRawaowSkLbAiHVtz4aUd yyZrV+pATkzg0CDSHF92rHCTbOF9bNzW53juRcU7GXJmJ4X8NkMxIClsrd2bH25p3Bm7 N9VfuBAo3pvu20uk4CWIBGbDt0bxdeA5BdD6bMpLkNxEcB9uafh13+o17bLIdK0a8xJE H1WUut2VRfH2upg7w/KWUNLGqp9ms4G3NLG+3zSnJGqA8bwYOnLxi8Rw8bX/hBSZ2Nxx BFJw== X-Gm-Message-State: AOAM532ymFoH0ZizgQeHKL82mb6Yijk6zc2Zw0FHTA0QSAGDoAX16P6a YO51kMO3dMJo3bGgLNldeuMZMyzVnvqCnQ== X-Google-Smtp-Source: ABdhPJy5Re8npscP33jZwoNk9byPUI4959EUf0fhcKlQrlm7ua/psQRY2kWt6pP/1eU4PO7HtGUOYK5rf5EyEg== Sender: "dlatypov via sendgmr" X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:a28c:fdff:fee3:28c6]) (user=dlatypov job=sendgmr) by 2002:a63:f744:: with SMTP id f4mr14710149pgk.34.1602541282218; Mon, 12 Oct 2020 15:21:22 -0700 (PDT) Date: Mon, 12 Oct 2020 15:20:41 -0700 In-Reply-To: <20201012222050.999431-1-dlatypov@google.com> Message-Id: <20201012222050.999431-4-dlatypov@google.com> Mime-Version: 1.0 References: <20201012222050.999431-1-dlatypov@google.com> X-Mailer: git-send-email 2.28.0.1011.ga647a8990f-goog Subject: [RFC v2 03/12] kunit: test: add concept of post conditions From: Daniel Latypov To: dlatypov@google.com Cc: alan.maguire@oracle.com, brendanhiggins@google.com, davidgow@google.com, keescook@chromium.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, mcgrof@kernel.org, sboyd@kernel.org, skhan@linuxfoundation.org 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.1011.ga647a8990f-goog