Skip to content

Commit

Permalink
rewrite min-global-align to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jul 30, 2024
1 parent 595316b commit c9d378c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
14 changes: 14 additions & 0 deletions src/tools/run-make-support/src/assertion_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ pub fn assert_not_contains<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N)
}
}

/// Assert that `haystack` contains `needle` a `count` number of times.
#[track_caller]
pub fn assert_count_is<H: AsRef<str>, N: AsRef<str>>(count: usize, haystack: H, needle: N) {
let haystack = haystack.as_ref();
let needle = needle.as_ref();
if count != haystack.matches(needle).count() {
eprintln!("=== HAYSTACK ===");
eprintln!("{}", haystack);
eprintln!("=== NEEDLE ===");
eprintln!("{}", needle);
panic!("needle did not appear {count} times in haystack");
}
}

/// Assert that all files in `dir1` exist and have the same content in `dir2`
pub fn assert_dirs_are_equal(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
let dir2 = dir2.as_ref();
Expand Down
2 changes: 1 addition & 1 deletion src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub use path_helpers::{
pub use scoped_run::{run_in_tmpdir, test_while_readonly};

pub use assertion_helpers::{
assert_contains, assert_dirs_are_equal, assert_equals, assert_not_contains,
assert_contains, assert_count_is, assert_dirs_are_equal, assert_equals, assert_not_contains,
};

pub use string::{
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ run-make/link-cfg/Makefile
run-make/long-linker-command-lines-cmd-exe/Makefile
run-make/long-linker-command-lines/Makefile
run-make/macos-deployment-target/Makefile
run-make/min-global-align/Makefile
run-make/native-link-modifier-bundle/Makefile
run-make/native-link-modifier-whole-archive/Makefile
run-make/no-alloc-shim/Makefile
Expand Down
22 changes: 0 additions & 22 deletions tests/run-make/min-global-align/Makefile

This file was deleted.

27 changes: 27 additions & 0 deletions tests/run-make/min-global-align/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// This tests ensure that global variables respect the target minimum alignment.
// The three bools `STATIC_BOOL`, `STATIC_MUT_BOOL`, and `CONST_BOOL` all have
// type-alignment of 1, but some targets require greater global alignment.
// See https://github.com/rust-lang/rust/pull/44440

//@ only-linux
// Reason: this test is target-independent, considering compilation is targeted
// towards linux architectures only.

use run_make_support::{assert_count_is, llvm_components_contain, rfs, rustc};

fn main() {
// Most targets are happy with default alignment -- take i686 for example.
if llvm_components_contain("x86") {
rustc().target("i686-unknown-linux-gnu").emit("llvm-ir").input("min_global_align.rs").run();
assert_count_is(3, rfs::read_to_string("min_global_align.ll"), "align 1");
}
// SystemZ requires even alignment for PC-relative addressing.
if llvm_components_contain("systemz") {
rustc()
.target("s390x-unknown-linux-gnu")
.emit("llvm-ir")
.input("min_global_align.rs")
.run();
assert_count_is(3, rfs::read_to_string("min_global_align.ll"), "align 2");
}
}

0 comments on commit c9d378c

Please sign in to comment.