From patchwork Thu Nov 10 16:41:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 18204 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp251317wru; Thu, 10 Nov 2022 08:43:39 -0800 (PST) X-Google-Smtp-Source: AMsMyM6bV/782i4R/2hTMGiVS+ZhHM6GjTJvIra4AErCg1NOqFkKMDFex9EpZKxU8rp4TW0qKfJY X-Received: by 2002:a17:906:26ce:b0:7ae:3f79:4d0a with SMTP id u14-20020a17090626ce00b007ae3f794d0amr2836976ejc.120.1668098619676; Thu, 10 Nov 2022 08:43:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668098619; cv=none; d=google.com; s=arc-20160816; b=s/04cKlzD7m3b6qvTz/Ut5mGyAvIpM4x8no8Vwl4XlW2pPnUP/NeKDLm56FYJrgL5r +iV/4upHyqPFmCHTKMnbnBHFfZ3BrvXjlLXf3wJXqM/7a1SrQxbCsowNEmtWK+KHfuni wmY1jHRqCWuN0lKo7I7NaO0htXOiFJd779YlK5Yw2N9tV8GobJWkrsKyrRVW5Tojw8aM 5hbcIsZjC0GrrOXO4o0YYBk88BtnzJgkA3apwOTWB1LZSd3Y/8PIerh32kCv6yGnTn3t IjNhOoBtJHLcezppshoNUcLcoYnBvHi19MIJWplY4qAeBitGDNxrm1bRmdiVL5aMmyph JhBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DL8biA4l58Uib7Zi0kvMfO+1q1DrZjakq6c9suKK+gg=; b=NrbNcYF1O6wa+B9ZGxxmVU22jVy2OCkRK4E3xc4wqYLy+X3VXtDgpfLCnZY81B41f1 Rem1ChCYOsvHgpPig4M0Adzx6IvteqtfcHhH3kS0tfgbvHMrkeWEHDVdeiygrwtD8lM9 3/gE43lKQGw0L+9zZePd9ORfogTBT+71GgvkHpMS3EWZC+b19dEDS+uC8wxpSl3B57Uv xe0han4xEKlpq83AUTpf3NYqosNybJT/8iKekhoIt0vP/1tLHWqQhrxY5QKOFGEID1dA L1Dee6x1EXYpTClmLu4PB/UO8lVjPoYjrUup7o36Ppnx2V24SJ0Ubl92Hrw7uHc9izW+ PT4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kFHRJ3LL; 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=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kq2-20020a170906abc200b0078ddc074afdsi13759996ejb.577.2022.11.10.08.43.12; Thu, 10 Nov 2022 08:43:39 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=kFHRJ3LL; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232069AbiKJQmm (ORCPT + 99 others); Thu, 10 Nov 2022 11:42:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232035AbiKJQmd (ORCPT ); Thu, 10 Nov 2022 11:42:33 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 923BD419BA; Thu, 10 Nov 2022 08:42:32 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4E06EB82248; Thu, 10 Nov 2022 16:42:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E61E9C433D6; Thu, 10 Nov 2022 16:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668098550; bh=QKUPnCuSt4qJQagjKlcEHWgf/R6XA/d08OIKtNrfC4A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kFHRJ3LLht4uHqTvA2yMYuD/T2ka6ewc6LmTvqWp/68elWBdnjquvKyqAxmYBXycR JyriAUY2Fen5o1iJDBbRbKP3Gh/RwSX5mD/geMGKy5yU936R9Jfif7tnxrHPIwXXZi /Nrvl41iIzXpoTwzDxD7UpP6SpynDlu2ttxQzbpJ8r9tMGEO2zIQGAysutNJ5qpalX HiURkpjwPpoALI/3J8kEr8nggzmSlt8QAOW7jc4BKbV5MuMVqAqj2W44PU2eBH7jFn TGii7XSktwWnUtD+PnjNYXPrxGMzDYfrZv+KXdjsKOGnr3N5N8XBdhBbh/C5JXm1Pp GoZG9rfnKihnA== From: Miguel Ojeda To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH v1 04/28] rust: samples: add `rust_print` example Date: Thu, 10 Nov 2022 17:41:16 +0100 Message-Id: <20221110164152.26136-5-ojeda@kernel.org> In-Reply-To: <20221110164152.26136-1-ojeda@kernel.org> References: <20221110164152.26136-1-ojeda@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749128178067926160?= X-GMAIL-MSGID: =?utf-8?q?1749128178067926160?= Add example to exercise the printing macros (`pr_*!`) introduced in the previous patches. Signed-off-by: Miguel Ojeda Reviewed-by: Finn Behrens Reviewed-by: Wei Liu Tested-by: Sergio González Collado --- samples/rust/Kconfig | 10 +++++++ samples/rust/Makefile | 1 + samples/rust/rust_print.rs | 54 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 samples/rust/rust_print.rs diff --git a/samples/rust/Kconfig b/samples/rust/Kconfig index 841e0906e943..b0f74a81c8f9 100644 --- a/samples/rust/Kconfig +++ b/samples/rust/Kconfig @@ -20,6 +20,16 @@ config SAMPLE_RUST_MINIMAL If unsure, say N. +config SAMPLE_RUST_PRINT + tristate "Printing macros" + help + This option builds the Rust printing macros sample. + + To compile this as a module, choose M here: + the module will be called rust_print. + + If unsure, say N. + config SAMPLE_RUST_HOSTPROGS bool "Host programs" help diff --git a/samples/rust/Makefile b/samples/rust/Makefile index 1daba5f8658a..03086dabbea4 100644 --- a/samples/rust/Makefile +++ b/samples/rust/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_SAMPLE_RUST_MINIMAL) += rust_minimal.o +obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs diff --git a/samples/rust/rust_print.rs b/samples/rust/rust_print.rs new file mode 100644 index 000000000000..09f737790f3f --- /dev/null +++ b/samples/rust/rust_print.rs @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Rust printing macros sample. + +use kernel::pr_cont; +use kernel::prelude::*; + +module! { + type: RustPrint, + name: b"rust_print", + author: b"Rust for Linux Contributors", + description: b"Rust printing macros sample", + license: b"GPL", +} + +struct RustPrint; + +impl kernel::Module for RustPrint { + fn init(_module: &'static ThisModule) -> Result { + pr_info!("Rust printing macros sample (init)\n"); + + pr_emerg!("Emergency message (level 0) without args\n"); + pr_alert!("Alert message (level 1) without args\n"); + pr_crit!("Critical message (level 2) without args\n"); + pr_err!("Error message (level 3) without args\n"); + pr_warn!("Warning message (level 4) without args\n"); + pr_notice!("Notice message (level 5) without args\n"); + pr_info!("Info message (level 6) without args\n"); + + pr_info!("A line that"); + pr_cont!(" is continued"); + pr_cont!(" without args\n"); + + pr_emerg!("{} message (level {}) with args\n", "Emergency", 0); + pr_alert!("{} message (level {}) with args\n", "Alert", 1); + pr_crit!("{} message (level {}) with args\n", "Critical", 2); + pr_err!("{} message (level {}) with args\n", "Error", 3); + pr_warn!("{} message (level {}) with args\n", "Warning", 4); + pr_notice!("{} message (level {}) with args\n", "Notice", 5); + pr_info!("{} message (level {}) with args\n", "Info", 6); + + pr_info!("A {} that", "line"); + pr_cont!(" is {}", "continued"); + pr_cont!(" with {}\n", "args"); + + Ok(RustPrint) + } +} + +impl Drop for RustPrint { + fn drop(&mut self) { + pr_info!("Rust printing macros sample (exit)\n"); + } +}