Message ID | 20230720-rustbind-v1-0-c80db349e3b5@google.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2935800vqt; Thu, 20 Jul 2023 00:09:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlE9Vmsj0NV4aw/SW9xo6jiHj6N88l/ZJfztMEzYV/CZQJsy0FDhdR0ZwqW5LtBVnEu0arls X-Received: by 2002:a17:907:8693:b0:973:d076:67ab with SMTP id qa19-20020a170907869300b00973d07667abmr5462776ejc.42.1689836962535; Thu, 20 Jul 2023 00:09:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689836962; cv=none; d=google.com; s=arc-20160816; b=yTk5FqvPkRu2BOcNeKNokGexb1ltf6LmIH3Ed9b8w/i16T+ebQczYXEe85R1ZPocBX EnYV5bUqchdGvPUYlxlt/v5oOYyjqZ0qj1sp6Lq2+yk4SRVDxoTZPmOc3aGt4ruuNgMN Dy9DvmE+/fQM84cd+L360nHDCBN0I4bUySpiaZh4IFVOZy0MdwNwnEdWu1j+lI13j+x4 7nPC/0Svj7SgekUqPxG4XC6TOwQKJz6Z5wpA9IHvTP93EdtmPCQ9b16tNpmt2PoEg1Np HcsuaBXoD/TBgg5XUYG1Me05mugg5DIHyKKDQdoYaFMnwzMMkENHyvrdIR2G0gZ2VJJp E3pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :message-id:mime-version:date:dkim-signature; bh=NqyBwYcbKCWrE+16W+dtidCOefNt3yC66lUvAXJt1+s=; fh=tt14ALlvSCOaeGq2WOiQl00uBX8L7oEnWR0UCRJ1Mu8=; b=nhISlYYunjDPa/uSnXpJrJPrICT2lJ+LwXaeHZ4iAsd4VJmbn7TAt1S8LqiCG+z4Is YRwbpeL+PEBaEq+1+xlXDqQkjMxr2wn4vmnSK6gpfKFec3aYkBg2ya3HJ1rS5cZ2YPe5 dbeoDtlcsEah87T8O03tkIjHIvQU/28wRqQ+MkXzpHRrsrJFbUC/6sfsr7eyo67iaAsR P0HhknNRVEJgSpRtVA82sUVjN79ZR17oqQvyCRxh3gAxlCuaSBJhpHM5Q38PosSlqqtn x+a98jQ3jGTMGNZwHqtVKwwncdJMZX+vo0pL/NofIfG2QcNLkRqxKtQfx0cr9zTtXhNm hnGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=IlTKnP6H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bn5-20020a170906c0c500b009932d8a227asi281060ejb.277.2023.07.20.00.08.56; Thu, 20 Jul 2023 00:09:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=IlTKnP6H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231249AbjGTGk4 (ORCPT <rfc822;assdfgzxcv4@gmail.com> + 99 others); Thu, 20 Jul 2023 02:40:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231223AbjGTGkj (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 20 Jul 2023 02:40:39 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B8392D4E for <linux-kernel@vger.kernel.org>; Wed, 19 Jul 2023 23:40:03 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-577323ba3d5so25778737b3.0 for <linux-kernel@vger.kernel.org>; Wed, 19 Jul 2023 23:40:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689835196; x=1690439996; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:from:to:cc:subject:date:message-id:reply-to; bh=NqyBwYcbKCWrE+16W+dtidCOefNt3yC66lUvAXJt1+s=; b=IlTKnP6Hl3Uub4PdrzLciuVSeDE8WsRXahT7kfpq0odCgAnJWCMHF979FftsDo5mMe SoAunJVXgM3wrjDRvaR7UCvHnidfSONnnormq22bhHGlj4n1M88NakgAfG1o44iJDWIC GjQQPGWkYthFqwnfYEAxYf//QexU1tgz2GwPAD4d7rulKOIx5o7dlACHv+Xn6iRBiK2H BVP+hxhLpvvYvcaSlzQOaACvy56RrzNES6NqJO1v+CPq7iWAOPjCRgGeTHfHuVnKhMUO ESKFVjhglV1S/+YlnMJIxRe1Ymnn2soaXjiJnIwFYFm8d0zpu5vFCREpJidLH6bmzEtn fyzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689835196; x=1690439996; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=NqyBwYcbKCWrE+16W+dtidCOefNt3yC66lUvAXJt1+s=; b=lZTUTElUrUygyLeqgTqr41JVPPorL+LdDtwc06CcVEick37nNah/HNoJX2ucIL7Ooj bNa2dSL9+QBe5jC6zitI8V+u0U33w7WXuV0JO+e+nfSmLKdIQ5X3oNOM/rSR68Dz4Ixo ZFp7KNg6XnMuHOYFstDGxnzDLuUCcANF59WsKExKTlHUbiVEH/1Ds0ECI+vvBpwJA+3o HYc0FI2EA4UU4XBc55YoqEwOZg/gOVTEmi8tr2rVf2RALQCrkM+WRpx7hV6GSDWmCBIx e8arp6otLpLZda/hQb6ckMgkQFGDE9hukBm4oJTUbsUBCX41nW5nbmDIk9gYOvnZJ6wX ZzpQ== X-Gm-Message-State: ABy/qLab8pDkTDJrblyRB/s+ZnJdPXoHu0BtPoJgif51LHsc6qdV33ae XDnii4UVc3aCAds5pymvD6islFhLDMn0gA== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a05:690c:dd2:b0:577:6462:24c3 with SMTP id db18-20020a05690c0dd200b00577646224c3mr84157ywb.4.1689835195982; Wed, 19 Jul 2023 23:39:55 -0700 (PDT) Date: Thu, 20 Jul 2023 14:38:51 +0800 Mime-Version: 1.0 X-Mailer: b4 0.13-dev-099c9 Message-ID: <20230720-rustbind-v1-0-c80db349e3b5@google.com> Subject: [PATCH 0/3] rust: kunit: Support KUnit tests with a user-space like syntax From: David Gow <davidgow@google.com> To: Brendan Higgins <brendan.higgins@linux.dev>, Miguel Ojeda <ojeda@kernel.org>, Alex Gaynor <alex.gaynor@gmail.com>, Wedson Almeida Filho <wedsonaf@gmail.com>, Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>, Benno Lossin <benno.lossin@proton.me> Cc: David Gow <davidgow@google.com>, " =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= " <jose.exposito89@gmail.com>, " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " <bjorn3_gh@protonmail.com>, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771922482668251079 X-GMAIL-MSGID: 1771922482668251079 |
Series |
rust: kunit: Support KUnit tests with a user-space like syntax
|
|
Message
David Gow
July 20, 2023, 6:38 a.m. UTC
This series was originally written by José Expósito, and can be found
here:
https://github.com/Rust-for-Linux/linux/pull/950
Add support for writing KUnit tests in Rust. While Rust doctests are
already converted to KUnit tests and run, they're really better suited
for examples, rather than as first-class unit tests.
This series implements a series of direct Rust bindings for KUnit tests,
as well as a new macro which allows KUnit tests to be written using a
close variant of normal Rust unit test syntax. The only change required
is replacing '#[cfg(test)]' with '#[kunit_tests(kunit_test_suite_name)]'
An example test would look like:
#[kunit_tests(rust_kernel_hid_driver)]
mod tests {
use super::*;
use crate::{c_str, driver, hid, prelude::*};
use core::ptr;
struct SimpleTestDriver;
impl Driver for SimpleTestDriver {
type Data = ();
}
#[test]
fn rust_test_hid_driver_adapter() {
let mut hid = bindings::hid_driver::default();
let name = c_str!("SimpleTestDriver");
static MODULE: ThisModule = unsafe { ThisModule::from_ptr(ptr::null_mut()) };
let res = unsafe {
<hid::Adapter<SimpleTestDriver> as driver::DriverOps>::register(&mut hid, name, &MODULE)
};
assert_eq!(res, Err(ENODEV)); // The mock returns -19
}
}
Changes since the GitHub PR:
- Rebased on top of kselftest/kunit
- Add const_mut_refs feature
This may conflict with https://lore.kernel.org/lkml/20230503090708.2524310-6-nmi@metaspace.dk/
- Add rust/macros/kunit.rs to the KUnit MAINTAINERS entry
Signed-off-by: David Gow <davidgow@google.com>
---
José Expósito (3):
rust: kunit: add KUnit case and suite macros
rust: macros: add macro to easily run KUnit tests
rust: kunit: allow to know if we are in a test
MAINTAINERS | 1 +
rust/kernel/kunit.rs | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++
rust/kernel/lib.rs | 1 +
rust/macros/kunit.rs | 149 ++++++++++++++++++++++++++++++++++++++++++
rust/macros/lib.rs | 29 +++++++++
5 files changed, 361 insertions(+)
---
base-commit: 64bd4641310c41a1ecf07c13c67bc0ed61045dfd
change-id: 20230720-rustbind-477964954da5
Best regards,