Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5978053rwb; Tue, 1 Aug 2023 10:24:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlHn0ggVZpRtC9kjSf+eG57rSep0PKhw2alTTdwezj3/dv7BCLzCOp097Og8KYldrlQKmpTk X-Received: by 2002:a05:6808:1706:b0:3a1:e85f:33c3 with SMTP id bc6-20020a056808170600b003a1e85f33c3mr14252132oib.50.1690910677772; Tue, 01 Aug 2023 10:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690910677; cv=none; d=google.com; s=arc-20160816; b=GteDYbs3+GjPyAZco+8BIbdaaC7b+CN//pk6Qf/r92NJCtVsA2HBuHRB8Z75KA/Pka s1XYrhhhHCTCLr9+iwqSvM7DDg6SQQYQe0dcQHFZy6Gp7l6pSFggIfyNjknN36gyYS7L gtOjJg8Sj4axOWY/PvUxHtVYSsNcfbfXXlzhx1uGtmkA4qYr3QlojCTceaq7oPQD3l7A 78kN6Oa1cArddjSTuFa1rcP06/2Jx0hVCBDhfSQEjxwzdP5/NrL70G0UhO3esEp+mw9Q GsNFuV/JLBjNRhDPftxwJCXeF8JE8qCf8v54yOa4d/bCG2aa1+32hnBcPXcQab8YluxB uGgw== 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:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=dXgNoIC2PvO/RdQx7w9iCucEs/VxyEwm+OaXP/sJCPQ=; fh=PlWkUiTuMH63B5Szhluv/DbtzJsl2Yeck/J71n84QbI=; b=gu8XSjt0PappL3nGPA6f8gAXg9St73bWWy/xx/Kcdps/uuxg01b9NFvYY1aVYzI0zY WRNJQg46vKshgxkz4cA+jMLl/NY+88E5fzmMBFyWLgOW9BtDD7SgOz3nGMY/CDkSDrHY REa7FP85xHWuTzFDnAI/IKRXG8tec7bIt6x5GydNIg5e/zmf0PY+6KeuZMtJyyvZeOh3 62VbH9BdwznLcMqdQqOcK34jgu/IzAHEv4pDzy1jJJ2b67tX5xRZrrh1SKNO8hjBvVKX aGnSlz560HA7H01N8mY0CM4t0vWow9PxwR6RqyukVYxFACAO88746gxYPuBwLwWIUYBr hxtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=VFMh5LS5; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k192-20020a636fc9000000b00563dc438e52si9221837pgc.518.2023.08.01.10.24.25; Tue, 01 Aug 2023 10:24:37 -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=@gmail.com header.s=20221208 header.b=VFMh5LS5; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234881AbjHAOor (ORCPT + 99 others); Tue, 1 Aug 2023 10:44:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233969AbjHAOoq (ORCPT ); Tue, 1 Aug 2023 10:44:46 -0400 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B08B1BC3; Tue, 1 Aug 2023 07:44:45 -0700 (PDT) Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-c5f98fc4237so4687844276.2; Tue, 01 Aug 2023 07:44:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690901084; x=1691505884; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=dXgNoIC2PvO/RdQx7w9iCucEs/VxyEwm+OaXP/sJCPQ=; b=VFMh5LS5z3t+hG68vt3INAW1bmqD8uEWGh7LMqvkYjF7v6fZ/vZkLNxUe9mYT6pjMm 65JazsVmxiH3X6IUyXQFHXLVz1mH5F9dIW1GbdgUBwb00JFth2efdOU1NR0w5eWdYAbk 8ObzV3Kxly5ZAa4OdMnlE63neLzSJNFjgC2BEhwZ+VvaplEEoAq9BndXYlcuCt02GY2O dIA1d7QrDoL+fMV2YirfEhivh/yO2ytwgD9bMR+qpktysNaz9wuFliMgI2WtaFFTvffP so94wlh17sCKXLmDLTg085cPWzJwdjluHA9d4clhAb0ERK26knfENhZXdyArYbUvkQoT 2dcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690901084; x=1691505884; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dXgNoIC2PvO/RdQx7w9iCucEs/VxyEwm+OaXP/sJCPQ=; b=EswM2fgvEh/JA3eAaUC1r/Etp1zki3Q0/MiUV5FiWBRerFch+oG/Ma8v8P9Y4Q2G7S kkvW2pvYpym8ZFMUVlWz1QLjLhW2zo+GAOXuv6CTYrQNTZnk3OgqmUQFS1XImJ3zcGty +HBLdToCZjw8ttRLuSjigTo4Y1fQ4c7rcAU2wCDfVqEXoWFOtdWprFgx7T8zD1VK8mEt rF7tGLjKas8wpKXryrJnwTvYiqOpXtJ8Zf1tJE+s462r9YPyszZZrzsnLHQuelCFnaja VZoNLpAZJY2AvG7Mvbl5jUVQ9ecTbCu7G8ddh3gYDEKqdtGm8vJB9o/m+BCp8kZXtldp L8rg== X-Gm-Message-State: ABy/qLa47cDlQiEqL1OKN2KvlzQFXqM30Pt93RwMeTVwoxBkjqrIRUyW cJH6UZDcXcTa9XOSI3G039AmHVGwT6lVVOqlqqA= X-Received: by 2002:a25:ac9b:0:b0:d15:bd9f:cac0 with SMTP id x27-20020a25ac9b000000b00d15bd9fcac0mr9856536ybi.39.1690901084347; Tue, 01 Aug 2023 07:44:44 -0700 (PDT) MIME-Version: 1.0 References: <20230720-rustbind-v1-0-c80db349e3b5@google.com> <20230720-rustbind-v1-2-c80db349e3b5@google.com> In-Reply-To: <20230720-rustbind-v1-2-c80db349e3b5@google.com> From: Miguel Ojeda Date: Tue, 1 Aug 2023 16:44:32 +0200 Message-ID: Subject: Re: [PATCH 2/3] rust: macros: add macro to easily run KUnit tests To: David Gow , =?UTF-8?B?Sm9zw6kgRXhww7NzaXRv?= Cc: Brendan Higgins , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , Benno Lossin , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , 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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 20, 2023 at 8:40=E2=80=AFAM David Gow wro= te: > > The only difference with user-space tests is that instead of using > `#[cfg(test)]`, `#[kunit_tests(kunit_test_suit_name)]` is used. I may be missing something, but this does not appear to map the `assert*!`s to the KUnit APIs, is that correct? (i.e. like we do for `rustdoc`-tests). I made an assertion fail, and it seems to use the standard library macros, thus panicking and ending up in `BUG()` (rather than a failed test): rust_kernel: panicked at 'assertion failed: `(left =3D=3D right)` left: `true`, right: `false`', rust/kernel/kunit.rs:329:1 ------------[ cut here ]------------ kernel BUG at rust/helpers.c:34! Then the test times out eventually and things break: # rust_test_kunit_kunit_tests: try timed out ------------[ cut here ]------------ refcount_t: addition on 0; use-after-free. > + // Add `#[cfg(CONFIG_KUNIT)]` before the module declaration. > + let config_kunit =3D "#[cfg(CONFIG_KUNIT)]".to_owned().parse().unwra= p(); > + tokens.insert( > + 0, > + TokenTree::Group(Group::new(Delimiter::None, config_kunit)), > + ); I wonder about compile-time here with this approach. As far as I understand, having the `cfg` explicitly outside the proc macro would avoid invoking it. Do we know the potential compile-time impact, especially when we will have many tests? ventually it would be ideal to have an approach closer to the `rustdoc` one, where the compiler finds the tests for us and we generate the needed code in the build system, i.e. outside a proc macro. Cheers, Miguel