diff mbox series

[12/12] lib/oeqa/selftest/cases/riscvtunes.py: test Rust target features

Message ID 20261118204853.2155173-13-tgamblin@baylibre.com
State New
Headers show
Series riscv: add new ISA extensions, profiles, and selftests | expand

Commit Message

Trevor Gamblin Nov. 18, 2026, 8:48 p.m. UTC
Add test_riscv_rust_target_features(), which generates the Rust target
spec for hello-rs with the 'riscv64gc' and 'rva23u64' tunes, then checks
that its 'features' pass each extension in TUNE_FEATURES to LLVM in
order. Also check that riscv64gc's feature set remains unchanged.

AI-Generated: Uses Claude Opus 5.5

Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
---
 meta/lib/oeqa/selftest/cases/riscvtunes.py | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/riscvtunes.py b/meta/lib/oeqa/selftest/cases/riscvtunes.py
index daee22a51e..b2ff2cc739 100644
--- a/meta/lib/oeqa/selftest/cases/riscvtunes.py
+++ b/meta/lib/oeqa/selftest/cases/riscvtunes.py
@@ -4,6 +4,9 @@ 
 # SPDX-License-Identifier: MIT
 #
 
+import json
+import os
+
 from oe.tune import riscv_isa_to_tune
 from oeqa.selftest.case import OESelftestTestCase
 from oeqa.utils.commands import bitbake, get_bb_var, get_bb_vars
@@ -146,3 +149,26 @@  class RiscvTunesTests(OESelftestTestCase):
                 # small, and compiled with TUNE_CCARGS. It has no do_build, and
                 # populate_sysroot also writes an sstate object.
                 bitbake('libgcc-initial -c populate_sysroot')
+
+    def test_riscv_rust_target_features(self):
+        """
+        Check that the Rust target spec passes every extension in the tune's
+        TUNE_FEATURES on to LLVM, in TUNE_FEATURES order.
+        """
+        for tune in ['riscv64gc', 'rva23u64']:
+            with self.subTest(tune=tune):
+                self.write_config(self._machine_config() + 'DEFAULTTUNE = "%s"\n' % tune)
+                # hello-rs is a small cargo recipe in meta-selftest, and
+                # do_rust_gen_targets runs right after do_patch, so neither
+                # the toolchain nor Rust has to be built
+                bitbake('hello-rs -c rust_gen_targets')
+                v = get_bb_vars(['WORKDIR', 'RUST_TARGET_SYS', 'TUNE_FEATURES'], 'hello-rs')
+                with open(os.path.join(v['WORKDIR'], 'rust-targets', v['RUST_TARGET_SYS'] + '.json')) as f:
+                    features = json.load(f)['features'].split(',')
+
+                # Everything but the base ISA and its width
+                expected = ['+' + e for e in v['TUNE_FEATURES'].split() if e not in ('rv', '64', 'i')]
+                self.assertEqual(features, expected)
+                if tune == 'riscv64gc':
+                    # The features of the existing tunes must not change
+                    self.assertEqual(features, ['+m', '+a', '+f', '+d', '+c', '+zicsr', '+zifencei'])