Auto merge of #144249 - GuillaumeGomez:asm-tests, r=jieyouxu

Rename `tests/{assembly,codegen}` into `tests/{assembly,codegen}-llvm` and ignore these testsuites if configured backend doesn't match

Follow-up of https://github.com/rust-lang/rust/pull/144125.

This PR changes `compiletest` so that `asm` tests are only run if they match the current codegen backend. To better reflect it, I renamed the `tests/ui/asm` folder into `tests/ui/asm-llvm`. Like that, we can add new asm tests for other backends if we want without needing to add extra code to `compiletest`.

Next step will be to use the new code annotations added in rust-lang/rust#144125 to ignore ui tests failing in cg_gcc until it's fixed on our side.

cc `@antoyo` `@oli-obk`
r? `@Kobzol`
This commit is contained in:
bors 2025-07-22 18:39:58 +00:00
commit a7a1618e6c
793 changed files with 83 additions and 56 deletions

View file

@ -588,7 +588,7 @@ fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
&"always",
&"--stage",
&"0",
&"tests/assembly/asm",
&"tests/assembly-llvm/asm",
&"--compiletest-rustc-args",
&rustc_args,
],

View file

@ -869,7 +869,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let ltext = bx.zext(is_lt, bx.type_i8());
bx.unchecked_ssub(gtext, ltext)
} else {
// These operations are those expected by `tests/codegen/integer-cmp.rs`,
// These operations are those expected by `tests/codegen-llvm/integer-cmp.rs`,
// from <https://github.com/rust-lang/rust/pull/63767>.
let is_lt = bx.icmp(pred(mir::BinOp::Lt), lhs, rhs);
let is_ne = bx.icmp(pred(mir::BinOp::Ne), lhs, rhs);

View file

@ -75,7 +75,7 @@ fn remove_successors_from_switch<'tcx>(
let is_unreachable = |bb| unreachable_blocks.contains(&bb);
// If there are multiple targets, we want to keep information about reachability for codegen.
// For example (see tests/codegen/match-optimizes-away.rs)
// For example (see tests/codegen-llvm/match-optimizes-away.rs)
//
// pub enum Two { A, B }
// pub fn identity(x: Two) -> Two {

View file

@ -192,7 +192,7 @@ impl<T, A: Allocator> Drop for Drain<'_, T, A> {
// this branch is never taken.
// We use `#[cold]` instead of `#[inline(never)]`, because inlining this
// function into the general case (`.drain(n..m)`) is fine.
// See `tests/codegen/vecdeque-drain.rs` for a test.
// See `tests/codegen-llvm/vecdeque-drain.rs` for a test.
#[cold]
fn join_head_and_tail_wrapping<T, A: Allocator>(
source_deque: &mut VecDeque<T, A>,

View file

@ -761,7 +761,7 @@ impl<A: Allocator> RawVecInner<A> {
}
// not marked inline(never) since we want optimizers to be able to observe the specifics of this
// function, see tests/codegen/vec-reserve-extend.rs.
// function, see tests/codegen-llvm/vec-reserve-extend.rs.
#[cold]
fn finish_grow<A>(
new_layout: Layout,

View file

@ -14,7 +14,7 @@ ignore = [
"/vendor/",
# Some tests are not formatted, for various reasons.
"/tests/codegen/simd-intrinsic/", # Many types like `u8x64` are better hand-formatted.
"/tests/codegen-llvm/simd-intrinsic/", # Many types like `u8x64` are better hand-formatted.
"/tests/crashes/", # Many of these tests contain syntax errors.
"/tests/debuginfo/", # These tests are somewhat sensitive to source code layout.
"/tests/incremental/", # These tests are somewhat sensitive to source code layout.
@ -58,5 +58,5 @@ ignore = [
# Rustfmt doesn't support use closures yet
"tests/mir-opt/ergonomic-clones/closure.rs",
"tests/codegen/ergonomic-clones/closure.rs",
"tests/codegen-llvm/ergonomic-clones/closure.rs",
]

View file

@ -1342,7 +1342,12 @@ test!(Ui { path: "tests/ui", mode: "ui", suite: "ui", default: true });
test!(Crashes { path: "tests/crashes", mode: "crashes", suite: "crashes", default: true });
test!(Codegen { path: "tests/codegen", mode: "codegen", suite: "codegen", default: true });
test!(CodegenLlvm {
path: "tests/codegen-llvm",
mode: "codegen",
suite: "codegen-llvm",
default: true
});
test!(CodegenUnits {
path: "tests/codegen-units",
@ -1407,7 +1412,12 @@ test!(Pretty {
test!(RunMake { path: "tests/run-make", mode: "run-make", suite: "run-make", default: true });
test!(Assembly { path: "tests/assembly", mode: "assembly", suite: "assembly", default: true });
test!(AssemblyLlvm {
path: "tests/assembly-llvm",
mode: "assembly",
suite: "assembly-llvm",
default: true
});
/// Runs the coverage test suite at `tests/coverage` in some or all of the
/// coverage test modes.
@ -1615,7 +1625,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
let suite_path = self.path;
// Skip codegen tests if they aren't enabled in configuration.
if !builder.config.codegen_tests && suite == "codegen" {
if !builder.config.codegen_tests && mode == "codegen" {
return;
}
@ -1812,7 +1822,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
flags.push(format!(
"-Cdebuginfo={}",
if suite == "codegen" {
if mode == "codegen" {
// codegen tests typically check LLVM IR and are sensitive to additional debuginfo.
// So do not apply `rust.debuginfo-level-tests` for codegen tests.
if builder.config.rust_debuginfo_level_tests

View file

@ -411,8 +411,8 @@ const PATH_REMAP: &[(&str, &[&str])] = &[
"tests",
&[
// tidy-alphabetical-start
"tests/assembly",
"tests/codegen",
"tests/assembly-llvm",
"tests/codegen-llvm",
"tests/codegen-units",
"tests/coverage",
"tests/coverage-run-rustdoc",
@ -1049,9 +1049,9 @@ impl<'a> Builder<'a> {
test::Crashes,
test::Coverage,
test::MirOpt,
test::Codegen,
test::CodegenLlvm,
test::CodegenUnits,
test::Assembly,
test::AssemblyLlvm,
test::Incremental,
test::Debuginfo,
test::UiFullDeps,

View file

@ -65,14 +65,14 @@ ENV WASM_SCRIPT python3 /checkout/x.py --stage 2 test --host='' --target $WASM_T
tests/ui \
tests/mir-opt \
tests/codegen-units \
tests/codegen \
tests/assembly \
tests/codegen-llvm \
tests/assembly-llvm \
library/core
ENV NVPTX_TARGETS=nvptx64-nvidia-cuda
ENV NVPTX_SCRIPT python3 /checkout/x.py --stage 2 test --host='' --target $NVPTX_TARGETS \
tests/run-make \
tests/assembly
tests/assembly-llvm
ENV MUSL_TARGETS=x86_64-unknown-linux-musl \
CC_x86_64_unknown_linux_musl=x86_64-linux-musl-gcc \

View file

@ -155,9 +155,9 @@ can't know ahead of time whether a function will require a frame/base pointer.
Various tests for inline assembly are available:
- `tests/assembly/asm`
- `tests/assembly-llvm/asm`
- `tests/ui/asm`
- `tests/codegen/asm-*`
- `tests/codegen-llvm/asm-*`
Every architecture supported by inline assembly must have exhaustive tests in
`tests/assembly/asm` which test all combinations of register classes and types.
`tests/assembly-llvm/asm` which test all combinations of register classes and types.

View file

@ -25,7 +25,7 @@ rustup toolchain install nightly # enables -Z unstable-options
You can then run our test cases:
```bash
./x test --stage 1 tests/codegen/autodiff
./x test --stage 1 tests/codegen-llvm/autodiff
./x test --stage 1 tests/pretty/autodiff
./x test --stage 1 tests/ui/autodiff
./x test --stage 1 tests/ui/feature-gates/feature-gate-autodiff.rs

View file

@ -117,7 +117,7 @@ human-readable coverage report.
> directive, so they will be skipped if the profiler runtime has not been
> [enabled in `bootstrap.toml`](#recommended-configtoml-settings).
Finally, the [`tests/codegen/instrument-coverage/testprog.rs`] test compiles a simple Rust program
Finally, the [`tests/codegen-llvm/instrument-coverage/testprog.rs`] test compiles a simple Rust program
with `-C instrument-coverage` and compares the compiled program's LLVM IR to
expected LLVM IR instructions and structured data for a coverage-enabled
program, including various checks for Coverage Map-related metadata and the LLVM
@ -136,4 +136,4 @@ and `mir-opt` tests can be refreshed by running:
[`tests/coverage`]: https://github.com/rust-lang/rust/tree/master/tests/coverage
[`src/tools/coverage-dump`]: https://github.com/rust-lang/rust/tree/master/src/tools/coverage-dump
[`tests/coverage-run-rustdoc`]: https://github.com/rust-lang/rust/tree/master/tests/coverage-run-rustdoc
[`tests/codegen/instrument-coverage/testprog.rs`]: https://github.com/rust-lang/rust/blob/master/tests/mir-opt/coverage/instrument_coverage.rs
[`tests/codegen-llvm/instrument-coverage/testprog.rs`]: https://github.com/rust-lang/rust/blob/master/tests/mir-opt/coverage/instrument_coverage.rs

View file

@ -40,7 +40,7 @@ This gives you a working LLVM build.
## Testing
run
```
./x test --stage 1 tests/codegen/gpu_offload
./x test --stage 1 tests/codegen-llvm/gpu_offload
```
## Usage

View file

@ -132,7 +132,7 @@ There is also a [codegen test][codegen-test] that checks that some expected
instrumentation artifacts show up in LLVM IR.
[rmake-tests]: https://github.com/rust-lang/rust/tree/master/tests/run-make
[codegen-test]: https://github.com/rust-lang/rust/blob/master/tests/codegen/pgo-instrumentation.rs
[codegen-test]: https://github.com/rust-lang/rust/blob/master/tests/codegen-llvm/pgo-instrumentation.rs
## Additional information

View file

@ -76,7 +76,7 @@ implementation:
## Testing sanitizers
Sanitizers are validated by code generation tests in
[`tests/codegen/sanitize*.rs`][test-cg] and end-to-end functional tests in
[`tests/codegen-llvm/sanitize*.rs`][test-cg] and end-to-end functional tests in
[`tests/ui/sanitizer/`][test-ui] directory.
Testing sanitizer functionality requires the sanitizer runtimes (built when
@ -85,7 +85,7 @@ sanitizer. When sanitizer is unsupported on given target, sanitizers tests will
be ignored. This behaviour is controlled by compiletest `needs-sanitizer-*`
directives.
[test-cg]: https://github.com/rust-lang/rust/tree/master/tests/codegen
[test-cg]: https://github.com/rust-lang/rust/tree/master/tests/codegen-llvm
[test-ui]: https://github.com/rust-lang/rust/tree/master/tests/ui/sanitizer
## Enabling sanitizer on a new target

View file

@ -68,7 +68,7 @@ The following test suites are available, with links for more information:
| [`pretty`](#pretty-printer-tests) | Check pretty printing |
| [`incremental`](#incremental-tests) | Check incremental compilation behavior |
| [`debuginfo`](#debuginfo-tests) | Check debuginfo generation running debuggers |
| [`codegen`](#codegen-tests) | Check code generation |
| [`codegen-*`](#codegen-tests) | Check code generation |
| [`codegen-units`](#codegen-units-tests) | Check codegen unit partitioning |
| [`assembly`](#assembly-tests) | Check assembly output |
| [`mir-opt`](#mir-opt-tests) | Check MIR generation and optimizations |
@ -290,7 +290,7 @@ For example, `./x test tests/debuginfo -- --debugger gdb` will only test GDB com
### Codegen tests
The tests in [`tests/codegen`] test LLVM code generation. They compile the test
The tests in [`tests/codegen-llvm`] test LLVM code generation. They compile the test
with the `--emit=llvm-ir` flag to emit LLVM IR. They then run the LLVM
[FileCheck] tool. The test is annotated with various `// CHECK` comments to
check the generated code. See the [FileCheck] documentation for a tutorial and
@ -301,13 +301,13 @@ See also the [assembly tests](#assembly-tests) for a similar set of tests.
If you need to work with `#![no_std]` cross-compiling tests, consult the
[`minicore` test auxiliary](./minicore.md) chapter.
[`tests/codegen`]: https://github.com/rust-lang/rust/tree/master/tests/codegen
[`tests/codegen-llvm`]: https://github.com/rust-lang/rust/tree/master/tests/codegen-llvm
[FileCheck]: https://llvm.org/docs/CommandGuide/FileCheck.html
### Assembly tests
The tests in [`tests/assembly`] test LLVM assembly output. They compile the test
The tests in [`tests/assembly-llvm`] test LLVM assembly output. They compile the test
with the `--emit=asm` flag to emit a `.s` file with the assembly output. They
then run the LLVM [FileCheck] tool.
@ -324,7 +324,7 @@ See also the [codegen tests](#codegen-tests) for a similar set of tests.
If you need to work with `#![no_std]` cross-compiling tests, consult the
[`minicore` test auxiliary](./minicore.md) chapter.
[`tests/assembly`]: https://github.com/rust-lang/rust/tree/master/tests/assembly
[`tests/assembly-llvm`]: https://github.com/rust-lang/rust/tree/master/tests/assembly-llvm
### Codegen-units tests

View file

@ -57,8 +57,8 @@ impl TestMode {
string_enum! {
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum TestSuite {
Assembly => "assembly",
Codegen => "codegen",
AssemblyLlvm => "assembly-llvm",
CodegenLlvm => "codegen-llvm",
CodegenUnits => "codegen-units",
Coverage => "coverage",
CoverageRunRustdoc => "coverage-run-rustdoc",

View file

@ -31,7 +31,7 @@ use std::time::SystemTime;
use std::{env, fs, vec};
use build_helper::git::{get_git_modified_files, get_git_untracked_files};
use camino::{Utf8Path, Utf8PathBuf};
use camino::{Utf8Component, Utf8Path, Utf8PathBuf};
use getopts::Options;
use rayon::iter::{ParallelBridge, ParallelIterator};
use tracing::debug;
@ -799,6 +799,23 @@ fn collect_tests_from_dir(
return Ok(TestCollector::new());
}
let mut components = dir.components().rev();
if let Some(Utf8Component::Normal(last)) = components.next()
&& let Some(("assembly" | "codegen", backend)) = last.split_once('-')
&& let Some(Utf8Component::Normal(parent)) = components.next()
&& parent == "tests"
&& let Ok(backend) = CodegenBackend::try_from(backend)
&& backend != cx.config.codegen_backend
{
// We ignore asm tests which don't match the current codegen backend.
warning!(
"Ignoring tests in `{dir}` because they don't match the configured codegen \
backend (`{}`)",
cx.config.codegen_backend.as_str(),
);
return Ok(TestCollector::new());
}
// For run-make tests, a "test file" is actually a directory that contains an `rmake.rs`.
if cx.config.mode == TestMode::RunMake {
let mut collector = TestCollector::new();

View file

@ -100,8 +100,8 @@ llvm-config = "{llvm_config}"
env.host_tuple(),
"--stage",
"0",
"tests/assembly",
"tests/codegen",
"tests/assembly-llvm",
"tests/codegen-llvm",
"tests/codegen-units",
"tests/incremental",
"tests/mir-opt",

View file

@ -8,7 +8,7 @@ use std::path::Path;
use crate::walk::{filter_not_rust, walk};
const TARGET_DEFINITIONS_PATH: &str = "compiler/rustc_target/src/spec/targets/";
const ASSEMBLY_TEST_PATH: &str = "tests/assembly/targets/";
const ASSEMBLY_LLVM_TEST_PATH: &str = "tests/assembly-llvm/targets/";
const REVISION_LINE_START: &str = "//@ revisions: ";
const EXCEPTIONS: &[&str] = &[
// FIXME: disabled since it fails on CI saying the csky component is missing
@ -43,7 +43,7 @@ pub fn check(root_path: &Path, bad: &mut bool) {
let _ = targets_to_find.insert(target_name);
}
walk(&root_path.join(ASSEMBLY_TEST_PATH), |_, _| false, &mut |_, contents| {
walk(&root_path.join(ASSEMBLY_LLVM_TEST_PATH), |_, _| false, &mut |_, contents| {
for line in contents.lines() {
let Some(_) = line.find(REVISION_LINE_START) else {
continue;
@ -55,7 +55,7 @@ pub fn check(root_path: &Path, bad: &mut bool) {
for target in targets_to_find {
if !EXCEPTIONS.contains(&target.as_str()) {
tidy_error!(bad, "{ASSEMBLY_TEST_PATH}: missing assembly test for {target}")
tidy_error!(bad, "{ASSEMBLY_LLVM_TEST_PATH}: missing assembly test for {target}")
}
}
}

Some files were not shown because too many files have changed in this diff Show more