rewrite min-global-align to rmake

This commit is contained in:
Oneirical 2024-07-30 14:20:16 -04:00
parent 0f442e265c
commit 5e04cefb01
5 changed files with 42 additions and 24 deletions

View File

@ -77,6 +77,20 @@ pub fn assert_not_contains_regex<H: AsRef<str>, N: AsRef<str>>(haystack: H, need
}
}
/// 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();

View File

@ -87,7 +87,7 @@ pub mod rfs {
pub use scoped_run::{run_in_tmpdir, test_while_readonly};
pub use assertion_helpers::{
assert_contains, assert_contains_regex, assert_dirs_are_equal, assert_equals,
assert_contains, assert_contains_regex, assert_count_is, assert_dirs_are_equal, assert_equals,
assert_not_contains, assert_not_contains_regex,
};

View File

@ -13,7 +13,6 @@ run-make/libtest-json/Makefile
run-make/libtest-junit/Makefile
run-make/libtest-thread-limit/Makefile
run-make/macos-deployment-target/Makefile
run-make/min-global-align/Makefile
run-make/native-link-modifier-bundle/Makefile
run-make/no-alloc-shim/Makefile
run-make/reproducible-build/Makefile

View File

@ -1,22 +0,0 @@
include ../tools.mk
# only-linux
# 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.
SRC = min_global_align.rs
LL = $(TMPDIR)/min_global_align.ll
all:
# Most targets are happy with default alignment -- take i686 for example.
ifeq ($(filter x86,$(LLVM_COMPONENTS)),x86)
$(RUSTC) --target=i686-unknown-linux-gnu --emit=llvm-ir $(SRC)
[ "$$(grep -c 'align 1' "$(LL)")" -eq "3" ]
endif
# SystemZ requires even alignment for PC-relative addressing.
ifeq ($(filter systemz,$(LLVM_COMPONENTS)),systemz)
$(RUSTC) --target=s390x-unknown-linux-gnu --emit=llvm-ir $(SRC)
[ "$$(grep -c 'align 2' "$(LL)")" -eq "3" ]
endif

View File

@ -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");
}
}