Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp15073imm; Tue, 16 Oct 2018 16:56:25 -0700 (PDT) X-Google-Smtp-Source: ACcGV63VDi8uSB+Tbl3LHxY7ZGrbQwxm1yzRrf9eEXDe1aQ8HGNhYrpRy3qQiXRqHucRF1Ew/oTe X-Received: by 2002:a17:902:27a8:: with SMTP id d37-v6mr23738817plb.318.1539734185054; Tue, 16 Oct 2018 16:56:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539734185; cv=none; d=google.com; s=arc-20160816; b=fabjkIo1JdYOeQgW69WXQQ7yh5JinL8Rl7ozmvfWirXHl0vdu80cTr0PmWcpP4qdE1 kRNr2u68kFfEA2BdF7t6zNNidhzrm1C5Cnw1F3uNWCmi5WKV/ofI1sFuTV2ex+Cjr5AH zRd1H3YfYPuAfJGPwC9MSuSFJpeav9tl4MTP+od5/t0HVDM7xUW6Ej9t+iFJbLBEmXCb pYctWnLWkCZNzcbJg2S3MX0ZbTDvK/x+Xokf6zwhEvWcy5W1k8atjNVnqeflhlAG+69o W7C/x5DJYYAIVfbBqWUu996hzLyEX0rRQ0g9yRDhZxjXiNzcgxJD9KfnPWVXhfuEmOVL ACNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=qCMB3fmL8RW2FIsxtQnM0B4a1KuW981wvpeU2rLEEcQ=; b=HbJpEsMJEDu7oUYLXNYnCT9p8yrQEOiMmTb0XxPXzk2KcGQg2mCHHGnbhg6PfPlR7t GB1q59vWUGz6428hf1IIiFKq08MUREQ9FYUT2atE3b/HT5ULoDyPjk2b4HkTxPKwzX5i 2VsgOQ3XYvb9jumawy2HY8DED2fgvy17UPyIpLvZVRLEjetiC2oUbdjoHC8uQK6riT25 ZUL+F6NbOvsU542Xz6T7gEH1AFFCHp0rPG3lvsXEExU/bE7AuoYQlaywt6mAnfXDVQa4 teoen02ZeH66nmop7xonBI+pONlj58NJ14pz41wfMgO2v65v+bsd2PpzXxNBkzcZTEdj CGsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ubrWuUTt; 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 70-v6si9077217plc.301.2018.10.16.16.56.09; Tue, 16 Oct 2018 16:56:25 -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=ubrWuUTt; 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 S1727649AbeJQHrE (ORCPT + 99 others); Wed, 17 Oct 2018 03:47:04 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:45793 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727605AbeJQHrC (ORCPT ); Wed, 17 Oct 2018 03:47:02 -0400 Received: by mail-qk1-f201.google.com with SMTP id s123-v6so25526135qkf.12 for ; Tue, 16 Oct 2018 16:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=qCMB3fmL8RW2FIsxtQnM0B4a1KuW981wvpeU2rLEEcQ=; b=ubrWuUTt+zLu0Ttoi9FT1FxFTtzIg0tY/UoZu25xt9iDVBIuAa9bDH/YNOArK3efUq Ul+yBUWzSlLCAT1S2u8XiehSp1PdWTJJgxl/W2+BSa6BBURSNMpxJJ3+jcj73YySSq1I 5+C3SrLZ8lWF+pfw0Dqkgw+aD8nn9wubggiCTnkiQhcavMEAkkq6mNZ6hs4m1WH8cIts x/tyRHU1drdYAW5nWdlBPtOTVvJfZ2Cy1A4Kd9pccZKJol8DTRo6BQx6W6jpWK0IQ27R 7bZVu4RyDxk4k/UdGU2gLJW7gB7IbvC/bkRNJ8BSBe1YIgxt56QkuKZOhR9K7kCzfrFL eWfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=qCMB3fmL8RW2FIsxtQnM0B4a1KuW981wvpeU2rLEEcQ=; b=FP0lBa3phW2klkQrMGE+7RXm0tjslClsmk+uv8tlPFTWbSFhnQAbnZKlTVRHscb/Cv Cd9ZqM9HfjiJRjd4urpUPBCtfx09BBuH/P/J41j4iCTPSAW67hBGSAah0nayEIXniVig aCSkkhtGU44oL7bXvywUSNDya9kYTfFH4uVDqAE0a92wemOq+3Rkqaomk1cYHWiEePUw i7/TAFLk6afD2kWEa1/+wvpzc7yU6liSZthEY6jA/ZARcaWo2LHeCOeU4i0CWx+eJWOp zjo3oVHwgT6CURj/FvulyfOB2P5Kl35wJluyL2b84V2IS0+kxZADQdk5fQohNwxAPceb i3SQ== X-Gm-Message-State: ABuFfoh2d3hhP3/r033Ekpuq5wIMVo7nTxgXPhnqkF0+2tHvAwna0v6O 0dZywio3O+Pe2uyKWvngeAM9VYUa+mH1ulKlN470PQ== X-Received: by 2002:a0c:8a17:: with SMTP id 23mr19940884qvt.49.1539734053222; Tue, 16 Oct 2018 16:54:13 -0700 (PDT) Date: Tue, 16 Oct 2018 16:51:00 -0700 In-Reply-To: <20181016235120.138227-1-brendanhiggins@google.com> Message-Id: <20181016235120.138227-12-brendanhiggins@google.com> Mime-Version: 1.0 References: <20181016235120.138227-1-brendanhiggins@google.com> X-Mailer: git-send-email 2.19.1.331.ge82ca0e54c-goog Subject: [RFC v1 11/31] kunit: test: added concept of post conditions From: Brendan Higgins To: gregkh@linuxfoundation.org, keescook@google.com, mcgrof@kernel.org, shuah@kernel.org Cc: joel@jms.id.au, mpe@ellerman.id.au, joe@perches.com, brakmo@fb.com, rostedt@goodmis.org, Tim.Bird@sony.com, khilman@baylibre.com, julia.lawall@lip6.fr, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, jdike@addtoit.com, richard@nod.at, linux-um@lists.infradead.org, Brendan Higgins 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 Adds a way to specify that certain conditions must be met at the end of a test case. Signed-off-by: Brendan Higgins --- include/kunit/test.h | 6 ++++++ kunit/test.c | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/kunit/test.h b/include/kunit/test.h index 58dbe2aee423f..be2b11117d1de 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -158,6 +158,11 @@ struct test_initcall { void (*exit)(struct test_initcall *this); }; +struct test_post_condition { + struct list_head node; + void (*validate)(struct test_post_condition *condition); +}; + /** * struct test - represents a running instance of a test. * @priv: for user to store arbitrary data. Commonly used to pass data created @@ -177,6 +182,7 @@ struct test { bool success; /* Protected by lock. */ bool death_test; /* Protected by lock. */ struct list_head resources; /* Protected by lock. */ + struct list_head post_conditions; void (*set_death_test)(struct test *test, bool death_test); void (*vprintk)(const struct test *test, const char *level, diff --git a/kunit/test.c b/kunit/test.c index 9737465fb0568..6ea60059b4918 100644 --- a/kunit/test.c +++ b/kunit/test.c @@ -125,8 +125,9 @@ static void __noreturn test_abort(struct test *test) int test_init_test(struct test *test, const char *name) { - spin_lock_init(&test->lock); INIT_LIST_HEAD(&test->resources); + INIT_LIST_HEAD(&test->post_conditions); + spin_lock_init(&test->lock); test->name = name; test->set_death_test = test_set_death_test; test->vprintk = test_vprintk; @@ -186,6 +187,16 @@ static void test_run_case_cleanup(struct test *test, struct test_module *module, struct test_case *test_case) { + struct test_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 (module->exit) module->exit(test); -- 2.19.1.331.ge82ca0e54c-goog