From patchwork Thu Sep 11 21:44:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 297 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757627124; bh=ikC2HriTfmvWvMDUxe00+Ufl60DdaIWWD1H1rZmQ6w0=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=db40ynoIb84YU0WNwsLkEoh/6zOEYN2oOIP/99n8w2d+rw1e85lugoRwJNFcgXkuB tIsFmPjyTLmdPsGK9nDdyAnJQtp1RrGedhafmyc16jNn2Tt0ZSNsz4wb7iWAG1z/mJ GlsJAUDzQJcBwBM53ZAP3QCpsBfaims/9Nmkw6FT7Dm7E1w0Z/cnvPJ4FrayKi/nww 8Mz49Qpnx710zSNFA6u8zwTSx4UVcVSiodlgLHIb+He/8kwoHO+BQnlaQ+Vb30X3OL PMFNP+LUNL2KUAAW7FFD9Y5/oA+kjAGKIjhyd6bF00YBnYgIgvrm2pzFdQBxDsUcqE RO+ijwgaCp5wA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B334267B0F for ; Thu, 11 Sep 2025 15:45:24 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id wZoOkMm49qQu for ; Thu, 11 Sep 2025 15:45:24 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757627124; bh=ikC2HriTfmvWvMDUxe00+Ufl60DdaIWWD1H1rZmQ6w0=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=db40ynoIb84YU0WNwsLkEoh/6zOEYN2oOIP/99n8w2d+rw1e85lugoRwJNFcgXkuB tIsFmPjyTLmdPsGK9nDdyAnJQtp1RrGedhafmyc16jNn2Tt0ZSNsz4wb7iWAG1z/mJ GlsJAUDzQJcBwBM53ZAP3QCpsBfaims/9Nmkw6FT7Dm7E1w0Z/cnvPJ4FrayKi/nww 8Mz49Qpnx710zSNFA6u8zwTSx4UVcVSiodlgLHIb+He/8kwoHO+BQnlaQ+Vb30X3OL PMFNP+LUNL2KUAAW7FFD9Y5/oA+kjAGKIjhyd6bF00YBnYgIgvrm2pzFdQBxDsUcqE RO+ijwgaCp5wA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A3C0467A59 for ; Thu, 11 Sep 2025 15:45:24 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757627122; bh=WNRo2Y64QY4uU87H9GCMOmPVnokwl4otJajtOpPG/ZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=emkNeozRDeOz8fNEEZ3k7YO8YnmwmLNX7WwuW+rEn/6y5bBRzYnLpETVCWrucfeTq PujkZa6xhgQ/5Ax28clez3b090F8MQiBVTke8Fpwvvl0eQtb3hCRKsRBrAxGk4MpzP +r1b/IvTD6c3/IwPg3af2PpbBGL+q1WxXKpXtKUk+x4h6gr0VdM1topj16CdqIDTwI 9qJJS2FfJh3W1W1Nk6EfOELxOJSF6M4k70zJh0JTKvvKW+tL0S2G1MVMFROJLJqCmj Hd4zFpeLRr/ihsE1Z2kT8AK/7IiwR2D5q44QQ372t/F93ieni9Xs5+nQx3d6vsdmGW 6ZUKY/Xy+E9bw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 62A04679D6; Thu, 11 Sep 2025 15:45:22 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id nKiXP6C9kq6w; Thu, 11 Sep 2025 15:45:22 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757627117; bh=xmwOeXstxRAHeVhRBK8M74DkM+3njJYSVvarR5aaMlA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F4KpMiLk4PuV/z9bJL8r/KHJ0g9kQHpuwt9vmSxXNkVFQ76tlM41YnAGonYp0DjJs xDcOtR8Ada2tNLPapwG3ItdS9FnbH9Ig5kg6gDmHZJHRgZMCN0mI8Mk2nzQ4pxga7A dhNR6WnfLOEB32vEq5/ZOy0VnGQbFEKMXU+MJrllKO5bCYYMWonfgS2n+WGucOqq8T mxmHgk7QWobp0dpdidsfma5rngcVRTcykFf6fjd5LHA1n9MQ+0N7hSyc0ICOCrteVY /9fd6P7D7P0WH7njI8YG0hHU9JiPOKiZ6LPiyKzRS3ya57mVwVaRVrND9c/vds9wHt FXhQE2lbW12Hg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 146C167B06; Thu, 11 Sep 2025 15:45:17 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 11 Sep 2025 15:44:16 -0600 Message-ID: <20250911214425.3687188-13-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250911214425.3687188-1-sjg@u-boot.org> References: <20250911214425.3687188-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: JRBLKHYRZRCNIG2W36KUFDHCCTV2BJY4 X-Message-ID-Hash: JRBLKHYRZRCNIG2W36KUFDHCCTV2BJY4 X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 12/14] test: ulib: Add a test for the rust example List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Provide a test which is similar to the ulib example, to make sure that the Rust programs can be built correctly. Signed-off-by: Simon Glass --- test/py/tests/test_ulib.py | 65 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/test/py/tests/test_ulib.py b/test/py/tests/test_ulib.py index 76d40e1385c..9b8b7097db4 100644 --- a/test/py/tests/test_ulib.py +++ b/test/py/tests/test_ulib.py @@ -1,6 +1,8 @@ # SPDX-License-Identifier: GPL-2.0+ # Copyright (c) 2025, Canonical Ltd. +"""Test U-Boot library functionality""" + import os import subprocess import pytest @@ -74,6 +76,31 @@ def check_demo_output(ubman, out): assert lines[i] == expected, \ f"Line {i}: expected '{expected}', got '{lines[i]}'" +def check_rust_demo_output(_ubman, out): + """Check output from the Rust ulib demo programs exactly line by line""" + lines = out.split('\n') + + # Read the actual system version from /proc/version + with open('/proc/version', 'r', encoding='utf-8') as f: + proc_version = f.read().strip() + + # Check individual parts of the output + assert len(lines) == 13, f"Expected 13 lines, got {len(lines)}" + + assert lines[0] == 'U-Boot Library Demo Helper\r' + assert lines[1] == '==========================\r' + assert lines[2].startswith('U-Boot version: ') and lines[2].endswith('\r') + assert lines[3] == '\r' + assert lines[4] == 'System version:\r' + assert lines[5] == f' {proc_version}\r' + assert lines[6] == '\r' + assert lines[7] == 'Read 1 line(s) using U-Boot library functions.\r' + assert lines[8] == 'helper: Adding 42 + 13 = 55\r' + assert lines[9] == 'Helper function result: 55\r' + assert lines[10] == '=================================\r' + assert lines[11] == 'Demo complete (hi from rust)\r' + assert lines[12] == '' + @pytest.mark.boardspec('sandbox') def test_ulib_demos(ubman): """Test both ulib demo programs (dynamic and static).""" @@ -107,6 +134,44 @@ def test_ulib_demos(ubman): out_dynamic = utils.run_and_log(ubman, [demo], env=env) check_demo_output(ubman, out_dynamic) +@pytest.mark.boardspec('sandbox') +def test_ulib_rust_demos(ubman): + """Test both Rust ulib demo programs (dynamic and static).""" + + build = ubman.config.build_dir + src = ubman.config.source_dir + examples = os.path.join(src, 'examples', 'rust') + test_program = os.path.join(build, 'test', 'ulib', 'ulib_test') + + # Skip test if ulib_test doesn't exist (clang) + if not os.path.exists(test_program): + pytest.skip('ulib_test not found - library build may be disabled') + + # Check if cargo is available + try: + utils.run_and_log(ubman, ['cargo', '--version']) + except (subprocess.CalledProcessError, FileNotFoundError): + pytest.skip('cargo not found - Rust toolchain required') + + # Build the Rust demo programs - clean first to ensure fresh build + cmd = ['make', 'clean'] + utils.run_and_log(ubman, cmd, cwd=examples) + + cmd = ['make', f'UBOOT_BUILD={os.path.abspath(build)}', f'srctree={src}'] + utils.run_and_log(ubman, cmd, cwd=examples) + + # Test static demo program + demo_static = os.path.join(examples, 'demo_static') + out_static = utils.run_and_log(ubman, [demo_static]) + check_rust_demo_output(ubman, out_static) + + # Test dynamic demo program (with proper LD_LIBRARY_PATH) + demo = os.path.join(examples, 'demo') + env = os.environ.copy() + env['LD_LIBRARY_PATH'] = os.path.abspath(build) + out_dynamic = utils.run_and_log(ubman, [demo], env=env) + check_rust_demo_output(ubman, out_dynamic) + @pytest.mark.boardspec('sandbox') def test_ulib_api_header(ubman): """Test that the u-boot-api.h header is generated correctly."""