From 181298bc5737f0b787198ba1a68cc35579dc2576 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Mon, 21 Jul 2025 04:04:59 -0700 Subject: [PATCH 1/8] ci: set `cache-workspace-crates: true` for `rust-cache` since most workspace crates rarely change --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c593ae4da6..c3be01a62e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,6 +41,8 @@ jobs: # cached, what gets used as part of the key, and what additional handling # happens to make the cache reliable and smaller. - uses: Swatinem/rust-cache@v2 + with: + cache-workspace-crates: true # Run after `rust-cache` so that this is cached. - run: rustup component add rustfmt rustc-dev From 5e1797d284b079dcb4c36600f0bae4e15f8132b5 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sat, 19 Jul 2025 02:00:51 -0700 Subject: [PATCH 2/8] tests: use the Rust test runner instead of our manually generated one This way, things like `#[cfg]` and `#[should_panic]` work. This seems simpler than trying to parse the `#[cfg]`s from Python and keeping the old way. This generates a much simpler `lib.rs` instead of a `main.rs` that tries to be its own simple test runner. Rust's test runner doesn't distinguish between expected and unexpected failures (it should counts an expected failure as a success), so we lose this output information, but an expected failure really is a success so this should be fine. --- scripts/test_translator.py | 105 ++++++------------ tests/README.md | 4 +- tests/arrays/src/test_arrays.rs | 6 + tests/asm.aarch64/src/test_asm.rs | 1 + tests/asm.arm/src/test_asm.rs | 1 + tests/asm.x86_64/src/test_asm.rs | 1 + tests/builtins/src/test_builtins.rs | 6 + tests/casts/src/test_casts.rs | 3 + tests/comments/src/test_comments.rs | 1 + tests/conditionals/src/test_conditionals.rs | 5 + tests/enums/src/test_enums.rs | 7 ++ tests/example/src/test_add.rs | 2 + tests/example/src/test_file_xfail.rs | 1 + tests/example/src/test_fn_xfail.rs | 3 +- tests/example/src/test_sub.rs | 2 + tests/floats/src/test_no_wrapping_neg.rs | 2 + tests/gotos/src/test_dfa_multiple_three.rs | 1 + tests/gotos/src/test_duffs.rs | 1 + tests/gotos/src/test_early_returns.rs | 1 + .../gotos/src/test_idiomatic_control_flow.rs | 2 + tests/gotos/src/test_irreducible.rs | 1 + tests/gotos/src/test_stmt_expr.rs | 1 + tests/gotos/src/test_translation_only.rs | 1 + tests/ints/src/test_arithmetic.rs | 1 + tests/ints/src/test_compound_assignment.rs | 1 + tests/ints/src/test_const.rs | 1 + tests/ints/src/test_implicit_ints.rs | 2 + tests/ints/src/test_ints.rs | 2 + tests/ints/src/test_sieve_of_eratosthenes.rs | 1 + tests/ints/src/test_volatile.rs | 1 + tests/items/src/test_fn_attrs.rs | 1 + tests/items/src/test_functions.rs | 1 + tests/items/src/test_linking.rs | 1 + tests/items/src/test_noop.rs | 2 + tests/items/src/test_varargs.rs | 8 ++ tests/longdouble/src/test_long_double.rs | 3 + tests/loops/src/test_goto.rs | 3 + tests/loops/src/test_loops.rs | 1 + tests/loops/src/test_switch.rs | 1 + tests/macros/src/test_define.rs | 3 + tests/misc/src/test_exprs.rs | 1 + tests/misc/src/test_lvalues.rs | 1 + tests/misc/src/test_memory.rs | 2 + tests/misc/src/test_quicksort.rs | 3 + tests/misc/src/test_shadowing.rs | 2 + tests/misc/src/test_sizeofs.rs | 1 + tests/misc/src/test_typedef.rs | 1 + tests/misc/src/test_uninitialized.rs | 2 + tests/modules/src/test_modules.rs | 1 + tests/pointers/src/test_pointers.rs | 3 + tests/simd.x86_64/src/test_x86.rs | 5 + tests/statics/src/test_sections.rs | 2 + tests/statics/src/test_storage.rs | 1 + tests/statics/src/test_thread_locals.rs | 1 + tests/structs/src/test_anonymous_decls.rs | 1 + tests/structs/src/test_bitfields.rs | 8 ++ tests/structs/src/test_flex_array_members.rs | 1 + tests/structs/src/test_forward.rs | 1 + tests/structs/src/test_self_referential.rs | 1 + tests/structs/src/test_struct_with_exp.rs | 1 + tests/structs/src/test_structs.rs | 3 + tests/structs/src/test_variable_offsetof.rs | 1 + tests/unions/src/test_unions.rs | 1 + 63 files changed, 161 insertions(+), 74 deletions(-) diff --git a/scripts/test_translator.py b/scripts/test_translator.py index 0ec02b8636..70138a7b80 100755 --- a/scripts/test_translator.py +++ b/scripts/test_translator.py @@ -216,6 +216,8 @@ def __init__(self, path: str, test_functions: Optional[List[TestFunction]] = Non class TestDirectory: + rs_test_files: list[TestFile] + def __init__(self, full_path: str, files: 're.Pattern', keep: List[str], log_level: str) -> None: self.c_files = [] self.rs_test_files = [] @@ -272,7 +274,6 @@ def __init__(self, full_path: str, files: 're.Pattern', keep: List[str], log_lev elif (filename.startswith("test_") and ext == ".rs" and files.search(filename)): rs_test_file = self._read_rust_test_file(path) - self.rs_test_files.append(rs_test_file) def _read_c_file(self, path: str) -> Optional[CFile]: @@ -453,7 +454,6 @@ def run(self) -> List[TestOutcome]: rust_file_builder.add_mod(RustMod(extensionless_rust_file, RustVisibility.Public)) - match_arms = [] rustc_extra_args = ["-C", "target-cpu=native"] # Build one binary that can call all the tests @@ -464,6 +464,8 @@ def run(self) -> List[TestOutcome]: _, file_name = os.path.split(test_file.path) extensionless_file_name, _ = os.path.splitext(file_name) + if test_file.pass_expected: + rust_file_builder.add_mod(RustMod(extensionless_file_name, RustVisibility.Private)) if not test_file.pass_expected: try: @@ -486,32 +488,11 @@ def run(self) -> List[TestOutcome]: continue - for test_function in test_file.test_functions: - rust_file_builder.add_mod(RustMod(extensionless_file_name, - RustVisibility.Public)) - left = "Some(\"{}::{}\")".format(extensionless_file_name, - test_function.name) - right = "{}::{}()".format(extensionless_file_name, - test_function.name) - match_arms.append((left, right)) - - match_arms.append(("e", - "panic!(\"Tried to run unknown test: {:?}\", e)")) - - test_main_body = [ - RustMatch("std::env::args().nth(1).as_ref().map(AsRef::::as_ref)", match_arms), - ] - test_main = RustFunction("main", - visibility=RustVisibility.Public, - body=[str(stmt) for stmt in test_main_body]) - - rust_file_builder.add_function(test_main) + lib_file = rust_file_builder.build(self.full_path + "/src/lib.rs") - main_file = rust_file_builder.build(self.full_path + "/src/main.rs") + self.generated_files["rust_src"].append(lib_file) - self.generated_files["rust_src"].append(main_file) - - # Try and build test binary + # Build with pb.local.cwd(self.full_path): args = ["build"] @@ -524,9 +505,9 @@ def run(self) -> List[TestOutcome]: retcode, stdout, stderr = cargo[args].run(retcode=None) if retcode != 0: - _, main_file_path_short = os.path.split(main_file.path) + _, lib_file_path_short = os.path.split(lib_file.path) - self.print_status(Colors.FAIL, "FAILED", "compile {}".format(main_file_path_short)) + self.print_status(Colors.FAIL, "FAILED", "compile {}".format(lib_file_path_short)) sys.stdout.write('\n') sys.stdout.write(stderr) @@ -534,55 +515,35 @@ def run(self) -> List[TestOutcome]: return outcomes - for test_file in self.rs_test_files: - if not test_file.pass_expected: - continue - - _, file_name = os.path.split(test_file.path) - extensionless_file_name, _ = os.path.splitext(file_name) - - for test_function in test_file.test_functions: - args = ["run", "{}::{}".format(extensionless_file_name, test_function.name)] - - if c.BUILD_TYPE == 'release': - args.append('--release') - - with pb.local.cwd(self.full_path): - retcode, stdout, stderr = cargo[args].run(retcode=None) - - logging.debug("stdout:%s\n", stdout) - - test_str = file_name + ' - ' + test_function.name - - if retcode == 0: - if test_function.pass_expected: - self.print_status(Colors.OKGREEN, "OK", " test " + test_str) - sys.stdout.write('\n') - - outcomes.append(TestOutcome.Success) - else: - self.print_status(Colors.FAIL, "FAILED", "test " + test_str) - sys.stdout.write('\n') + # Test + with pb.local.cwd(self.full_path): + args = ["test"] - outcomes.append(TestOutcome.UnexpectedSuccess) + if c.BUILD_TYPE == 'release': + args.append('--release') - elif retcode != 0: - if test_function.pass_expected: - self.print_status(Colors.FAIL, "FAILED", "test " + test_str) - sys.stdout.write('\n') - sys.stdout.write(stderr) + if self.target: + args += ["--target", self.target] - outcomes.append(TestOutcome.UnexpectedFailure) - else: - self.print_status(Colors.OKBLUE, "FAILED", "test " + test_str) - sys.stdout.write('\n') + retcode, stdout, stderr = cargo[args].run(retcode=None) + + if retcode != 0: + _, lib_file_path_short = os.path.split(lib_file.path) - outcomes.append(TestOutcome.Failure) + self.print_status(Colors.FAIL, "FAILED", "test {}".format(lib_file_path_short)) + sys.stdout.write('\n') + sys.stdout.write(stdout) + else: + sys.stdout.write("\n".join(line for line in stdout.split("\n") if "... ok" in line or "... FAILED" in line)) + + # Don't distinguish between expected and unexpected failures. + # `#[should_panic]` is used for that instead of `// xfail` now. + # Also, `cargo test -- --format json` is unstable, so it's easier to just parse very simply. + for _ in range(stdout.count("... ok")): + outcomes.append(TestOutcome.Success) + for _ in range(stdout.count("... FAILED")): + outcomes.append(TestOutcome.UnexpectedFailure) - if not outcomes: - display_text = " No rust file(s) matching " + self.files.pattern - display_text += " within this folder\n" - self.print_status(Colors.OKBLUE, "N/A", display_text) return outcomes def cleanup(self) -> None: diff --git a/tests/README.md b/tests/README.md index 82c4bc9d5c..6044cbe5ef 100644 --- a/tests/README.md +++ b/tests/README.md @@ -23,6 +23,7 @@ extern "C" { // The length can be any value const BUFFER_SIZE: usize = 1024; +#[test] pub fn test_example() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; @@ -42,7 +43,8 @@ The C code can do one of two things: modify some sort of buffer or return a valu To completely skip the translation of a C file, you must add the comment `//! skip_translation` at the top of the file. That will prevent the case from showing up as red in the console output. -You can also mark a Rust file as unexpected to compile, by adding `//! xfail` to the top of the file, or just expect an individual test function to fail to run by adding `// xfail` prior to the function definition. +You can also mark a Rust file as unexpected to compile by adding `//! xfail` to the top of the file. +For an individual test function, use the normal Rust `#[should_panic]` for `#[test]`s. Adding `//! extern_crate_X` to the top of a test file will ensure `extern crate X;` gets added to the main binary driver. diff --git a/tests/arrays/src/test_arrays.rs b/tests/arrays/src/test_arrays.rs index 05fce1c6f1..82479cf867 100644 --- a/tests/arrays/src/test_arrays.rs +++ b/tests/arrays/src/test_arrays.rs @@ -27,18 +27,21 @@ const BUFFER_SIZE: usize = 49; const BUFFER_SIZE2: usize = 2; const BUFFER_SIZEV: usize = 88; +#[test] pub fn test_sized_array_impls() { unsafe { assert_eq!(rust_test_sized_array(), test_sized_array()); } } +#[test] pub fn test_global_incomplete_array() { unsafe { assert_eq!(rust_check_some_ints(), check_some_ints()); } } +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; @@ -59,6 +62,7 @@ pub fn test_buffer() { } } +#[test] pub fn test_buffer2() { let mut buffer = [0; BUFFER_SIZE2]; let mut rust_buffer = [0; BUFFER_SIZE2]; @@ -73,6 +77,7 @@ pub fn test_buffer2() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_variable_arrays() { let mut buffer = [0; BUFFER_SIZEV]; let mut rust_buffer = [0; BUFFER_SIZEV]; @@ -93,6 +98,7 @@ pub fn test_variable_arrays() { } } +#[test] pub fn test_alloca_arrays() { let mut buffer = [0; BUFFER_SIZEV]; let mut rust_buffer = [0; BUFFER_SIZEV]; diff --git a/tests/asm.aarch64/src/test_asm.rs b/tests/asm.aarch64/src/test_asm.rs index e7bbb841e6..da5e9798d8 100644 --- a/tests/asm.aarch64/src/test_asm.rs +++ b/tests/asm.aarch64/src/test_asm.rs @@ -10,6 +10,7 @@ extern "C" { const BUFFER_SIZE: usize = 6; +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/asm.arm/src/test_asm.rs b/tests/asm.arm/src/test_asm.rs index 84a118ce7a..e50ca091b0 100644 --- a/tests/asm.arm/src/test_asm.rs +++ b/tests/asm.arm/src/test_asm.rs @@ -8,6 +8,7 @@ extern "C" { const BUFFER_SIZE: usize = 1; +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/asm.x86_64/src/test_asm.rs b/tests/asm.x86_64/src/test_asm.rs index ce566a5cfd..883ccfb151 100644 --- a/tests/asm.x86_64/src/test_asm.rs +++ b/tests/asm.x86_64/src/test_asm.rs @@ -10,6 +10,7 @@ extern "C" { const BUFFER_SIZE: usize = 6; +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/builtins/src/test_builtins.rs b/tests/builtins/src/test_builtins.rs index 8826e282be..37fe75f1fa 100644 --- a/tests/builtins/src/test_builtins.rs +++ b/tests/builtins/src/test_builtins.rs @@ -21,6 +21,7 @@ extern "C" { const BUFFER_SIZE: usize = 1024; const BUFFER_SIZE2: usize = 10; +#[test] pub fn test_atomics() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; @@ -35,6 +36,7 @@ pub fn test_atomics() { } } +#[test] pub fn test_new_atomics() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; @@ -50,6 +52,7 @@ pub fn test_new_atomics() { } } +#[test] pub fn test_mem_fns() { let const_string = "I am ten!\0"; let mut buffer = [0; BUFFER_SIZE2]; @@ -66,6 +69,7 @@ pub fn test_mem_fns() { } } +#[test] pub fn test_ffs() { for i in 0..256 { let ffs_ret = unsafe { ffs(i) }; @@ -85,6 +89,7 @@ pub fn test_ffs() { } } +#[test] pub fn test_clang9_intrinsics() { let pinf = 1.0 / 0.0; let ninf = -1.0 / 0.0; @@ -121,6 +126,7 @@ pub fn test_clang9_intrinsics() { } } +#[test] pub fn test_assume_aligned() { let null = std::ptr::null_mut(); diff --git a/tests/casts/src/test_casts.rs b/tests/casts/src/test_casts.rs index cc17ad3cf8..364e36903b 100644 --- a/tests/casts/src/test_casts.rs +++ b/tests/casts/src/test_casts.rs @@ -18,6 +18,7 @@ extern "C" { const BUFFER_SIZE: usize = 1; +#[test] pub fn test_compiles() { unsafe { cast_stuff(); @@ -25,6 +26,7 @@ pub fn test_compiles() { } } +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; @@ -37,6 +39,7 @@ pub fn test_buffer() { assert_eq!(buffer, rust_buffer); } +#[test] pub fn test_identity() { for i in 0..10 { let id = unsafe { identity(i) }; diff --git a/tests/comments/src/test_comments.rs b/tests/comments/src/test_comments.rs index 8e854c4562..de324b7509 100644 --- a/tests/comments/src/test_comments.rs +++ b/tests/comments/src/test_comments.rs @@ -1,5 +1,6 @@ use crate::comments::{rust_test_fn, CONSTANT, CONSTANT1}; +#[test] pub fn test_comments() { let val = unsafe { rust_test_fn() }; assert_eq!(6, val); diff --git a/tests/conditionals/src/test_conditionals.rs b/tests/conditionals/src/test_conditionals.rs index db05d537b0..f45871a433 100644 --- a/tests/conditionals/src/test_conditionals.rs +++ b/tests/conditionals/src/test_conditionals.rs @@ -26,6 +26,7 @@ const BUFFER_SIZE: usize = 4; const BUFFER_SIZE2: usize = 30; const BUFFER_SIZE3: usize = 6; +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; @@ -40,6 +41,7 @@ pub fn test_buffer() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_buffer2() { let mut buffer = [0; BUFFER_SIZE2]; let mut rust_buffer = [0; BUFFER_SIZE2]; @@ -56,6 +58,7 @@ pub fn test_buffer2() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_binary_conditionals() { let mut buffer = [0; BUFFER_SIZE3]; let mut rust_buffer = [0; BUFFER_SIZE3]; @@ -70,6 +73,7 @@ pub fn test_binary_conditionals() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_unused_conditional() { unsafe { assert_eq!(unused_conditional1(), rust_unused_conditional1()); @@ -78,6 +82,7 @@ pub fn test_unused_conditional() { } } +#[test] pub fn test_else_if_chain(){ unsafe { assert_eq!(entry4(0) , rust_entry4(0)); diff --git a/tests/enums/src/test_enums.rs b/tests/enums/src/test_enums.rs index 5a98e07179..205d597e03 100644 --- a/tests/enums/src/test_enums.rs +++ b/tests/enums/src/test_enums.rs @@ -33,11 +33,13 @@ const BUFFER_SIZE4: usize = 1; const BUFFER_SIZE5: usize = 6; const BUFFER_SIZE6: usize = 1; +#[test] pub fn test_variants() { assert_eq!(A as u32, 0); assert_eq!(B as u32, 1); } +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; @@ -52,6 +54,7 @@ pub fn test_buffer() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_buffer2() { let mut buffer = [0; BUFFER_SIZE2]; let mut rust_buffer = [0; BUFFER_SIZE2]; @@ -66,6 +69,7 @@ pub fn test_buffer2() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_buffer3() { let mut buffer = [0; BUFFER_SIZE3]; let mut rust_buffer = [0; BUFFER_SIZE3]; @@ -80,6 +84,7 @@ pub fn test_buffer3() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_buffer4() { let mut buffer = [0; BUFFER_SIZE4]; let mut rust_buffer = [0; BUFFER_SIZE4]; @@ -94,6 +99,7 @@ pub fn test_buffer4() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_buffer5() { let mut buffer = [0; BUFFER_SIZE5]; let mut rust_buffer = [0; BUFFER_SIZE5]; @@ -108,6 +114,7 @@ pub fn test_buffer5() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_buffer6() { let mut buffer = [0; BUFFER_SIZE6]; let mut rust_buffer = [0; BUFFER_SIZE6]; diff --git a/tests/example/src/test_add.rs b/tests/example/src/test_add.rs index 4ebdebd44f..2344f4e5f1 100644 --- a/tests/example/src/test_add.rs +++ b/tests/example/src/test_add.rs @@ -6,6 +6,7 @@ extern "C" { fn add(left: c_uint, right: c_uint) -> c_uint; } +#[test] pub fn test_addition() { let sum = unsafe { add(1, 2) }; let rust_sum = unsafe { rust_add(1, 2) }; @@ -14,6 +15,7 @@ pub fn test_addition() { assert_eq!(rust_sum, 3); } +#[test] pub fn test_overflow() { let max_uint = c_uint::max_value(); let sum = unsafe { add(max_uint, 3) }; diff --git a/tests/example/src/test_file_xfail.rs b/tests/example/src/test_file_xfail.rs index 29a3b31590..fe5832a3fe 100644 --- a/tests/example/src/test_file_xfail.rs +++ b/tests/example/src/test_file_xfail.rs @@ -1,6 +1,7 @@ //! xfail // This test file is expected not to compile for whatever reason +#[test] pub fn test_foo() { Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam non mauris laoreet, vestibulum lectus sit amet, tincidunt ipsum. Aliquam feugiat diff --git a/tests/example/src/test_fn_xfail.rs b/tests/example/src/test_fn_xfail.rs index c6e8d0c2e0..6306f788e5 100644 --- a/tests/example/src/test_fn_xfail.rs +++ b/tests/example/src/test_fn_xfail.rs @@ -1,6 +1,7 @@ // This failure is specific to this test, other passing tests may be present -// xfail +#[test] +#[should_panic] pub fn test_xfails() { panic!("Not meant to pass"); } diff --git a/tests/example/src/test_sub.rs b/tests/example/src/test_sub.rs index e0f31b4f86..a41e650eb3 100644 --- a/tests/example/src/test_sub.rs +++ b/tests/example/src/test_sub.rs @@ -6,6 +6,7 @@ extern "C" { fn sub(left: c_uint, right: c_uint) -> c_uint; } +#[test] pub fn test_subtraction() { let diff = unsafe { sub(5, 2) }; let rust_diff = unsafe { rust_sub(5, 2) }; @@ -14,6 +15,7 @@ pub fn test_subtraction() { assert_eq!(rust_diff, 3); } +#[test] pub fn test_underflow() { let max_uint = c_uint::max_value(); let diff = unsafe { sub(2, 3) }; diff --git a/tests/floats/src/test_no_wrapping_neg.rs b/tests/floats/src/test_no_wrapping_neg.rs index 094f7b748e..c5f462b240 100644 --- a/tests/floats/src/test_no_wrapping_neg.rs +++ b/tests/floats/src/test_no_wrapping_neg.rs @@ -8,6 +8,7 @@ extern "C" { fn double_inc_dec() -> c_double; } +#[test] pub fn test_buffer() { unsafe { assert_eq!(no_wrapping_neg(), -1.); @@ -15,6 +16,7 @@ pub fn test_buffer() { } } +#[test] pub fn test_inc_dec_op() { unsafe { assert_eq!(float_inc_dec(), -0.79999995); diff --git a/tests/gotos/src/test_dfa_multiple_three.rs b/tests/gotos/src/test_dfa_multiple_three.rs index ba73bcce42..03128bf019 100644 --- a/tests/gotos/src/test_dfa_multiple_three.rs +++ b/tests/gotos/src/test_dfa_multiple_three.rs @@ -2,6 +2,7 @@ use crate::dfa_binary_multiple_three::rust_multiple_three; use std::ffi::CString; +#[test] pub fn test_multiple_three() { let n1 = CString::new(format!("{:b}", 4529465 * 3 + 0)).unwrap(); let n2 = CString::new(format!("{:b}", 65424738 * 3 + 1)).unwrap(); diff --git a/tests/gotos/src/test_duffs.rs b/tests/gotos/src/test_duffs.rs index 70927ceb8d..3e3b01328a 100644 --- a/tests/gotos/src/test_duffs.rs +++ b/tests/gotos/src/test_duffs.rs @@ -1,5 +1,6 @@ use crate::duffs::rust_copy; +#[test] pub fn test_multiple_three() { let mut from = [1, 2, 3, 8, 2, 9, 8, 1, 8, 4, 5, 6, 2, 89, 0, 2, 3, 4, 56, 8]; let mut to = [0; 20]; diff --git a/tests/gotos/src/test_early_returns.rs b/tests/gotos/src/test_early_returns.rs index 1d7dac88e7..f386a8af47 100644 --- a/tests/gotos/src/test_early_returns.rs +++ b/tests/gotos/src/test_early_returns.rs @@ -1,5 +1,6 @@ use crate::early_returns::rust_early_returns; +#[test] pub fn test_early_returns() { unsafe { assert_eq!(rust_early_returns(2), 2); diff --git a/tests/gotos/src/test_idiomatic_control_flow.rs b/tests/gotos/src/test_idiomatic_control_flow.rs index 5615e14463..61d9dbb481 100644 --- a/tests/gotos/src/test_idiomatic_control_flow.rs +++ b/tests/gotos/src/test_idiomatic_control_flow.rs @@ -1,6 +1,7 @@ use crate::idiomatic_nested_loops::rust_break_multiple; use crate::idiomatic_switch::rust_idiomatic_switch; +#[test] pub fn test_idiomatic_switch() { unsafe { assert_eq!(rust_idiomatic_switch(-1), 1); @@ -10,6 +11,7 @@ pub fn test_idiomatic_switch() { } } +#[test] pub fn test_break_multiple_loops() { unsafe { assert_eq!(rust_break_multiple(0), 4); diff --git a/tests/gotos/src/test_irreducible.rs b/tests/gotos/src/test_irreducible.rs index 67dc1b69ed..e15eba2b56 100644 --- a/tests/gotos/src/test_irreducible.rs +++ b/tests/gotos/src/test_irreducible.rs @@ -6,6 +6,7 @@ extern "C" { fn irreducible(_: c_int) -> c_int; } +#[test] pub fn test_irreducible() { unsafe { for i in 0..20 { diff --git a/tests/gotos/src/test_stmt_expr.rs b/tests/gotos/src/test_stmt_expr.rs index 75361946c9..c3fbc1efc5 100644 --- a/tests/gotos/src/test_stmt_expr.rs +++ b/tests/gotos/src/test_stmt_expr.rs @@ -2,6 +2,7 @@ use crate::stmt_expr::rust_stmt_expr_func; use std::ffi::c_int; +#[test] pub fn test_stmt_expr_relooper() { unsafe { assert_eq!(rust_stmt_expr_func(0), 14); diff --git a/tests/gotos/src/test_translation_only.rs b/tests/gotos/src/test_translation_only.rs index 52eb2a2470..139af7c1f4 100644 --- a/tests/gotos/src/test_translation_only.rs +++ b/tests/gotos/src/test_translation_only.rs @@ -5,4 +5,5 @@ use crate::label_break_trigger::rust_triggers_label_break; // This test case just makes sure that the functions imported actually were // translated. Compilation suffices. +#[test] pub fn test_nothing() {} diff --git a/tests/ints/src/test_arithmetic.rs b/tests/ints/src/test_arithmetic.rs index 7b0c56e503..dc3397271a 100644 --- a/tests/ints/src/test_arithmetic.rs +++ b/tests/ints/src/test_arithmetic.rs @@ -8,6 +8,7 @@ extern "C" { const BUFFER_SIZE: usize = 100; +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/ints/src/test_compound_assignment.rs b/tests/ints/src/test_compound_assignment.rs index a6e700d3c5..e8ae6c23fa 100644 --- a/tests/ints/src/test_compound_assignment.rs +++ b/tests/ints/src/test_compound_assignment.rs @@ -9,6 +9,7 @@ extern "C" { const BUFFER_SIZE: usize = 13; +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/ints/src/test_const.rs b/tests/ints/src/test_const.rs index ed5f71b493..41e8e440ee 100644 --- a/tests/ints/src/test_const.rs +++ b/tests/ints/src/test_const.rs @@ -8,6 +8,7 @@ extern "C" { const BUFFER_SIZE: usize = 2; +#[test] pub fn test_const() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/ints/src/test_implicit_ints.rs b/tests/ints/src/test_implicit_ints.rs index 1c64c1948b..d89ebeae83 100644 --- a/tests/ints/src/test_implicit_ints.rs +++ b/tests/ints/src/test_implicit_ints.rs @@ -10,6 +10,7 @@ extern "C" { fn implicit_int(); } +#[test] pub fn test_identity() { unsafe { assert_eq!(identity(1), 1); @@ -18,6 +19,7 @@ pub fn test_identity() { } +#[test] pub fn test_implicit_int() { unsafe { implicit_int(); diff --git a/tests/ints/src/test_ints.rs b/tests/ints/src/test_ints.rs index 78be57dd98..e273785093 100644 --- a/tests/ints/src/test_ints.rs +++ b/tests/ints/src/test_ints.rs @@ -11,6 +11,7 @@ extern "C" { const BUFFER_SIZE: usize = 10; +#[test] pub fn test_size_t_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; @@ -25,6 +26,7 @@ pub fn test_size_t_buffer() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_chars_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/ints/src/test_sieve_of_eratosthenes.rs b/tests/ints/src/test_sieve_of_eratosthenes.rs index 11c030956e..6abc1ed565 100644 --- a/tests/ints/src/test_sieve_of_eratosthenes.rs +++ b/tests/ints/src/test_sieve_of_eratosthenes.rs @@ -8,6 +8,7 @@ extern "C" { const BUFFER_SIZE: usize = 102; +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/ints/src/test_volatile.rs b/tests/ints/src/test_volatile.rs index 18b83ddd63..c761936a5a 100644 --- a/tests/ints/src/test_volatile.rs +++ b/tests/ints/src/test_volatile.rs @@ -8,6 +8,7 @@ extern "C" { const BUFFER_SIZE: usize = 9; +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/items/src/test_fn_attrs.rs b/tests/items/src/test_fn_attrs.rs index 8f4b6d3cc3..518a3d1c09 100644 --- a/tests/items/src/test_fn_attrs.rs +++ b/tests/items/src/test_fn_attrs.rs @@ -1,5 +1,6 @@ use crate::fn_attrs::{rust_ensure_use, rust_inline_extern, rust_noinline_nonstatic}; +#[test] pub fn test_fn_attrs() { // There's no way to directly test that a function is inlined or not // so instead we're checking the source itself diff --git a/tests/items/src/test_functions.rs b/tests/items/src/test_functions.rs index d2ed4f8ddf..91c53aa08f 100644 --- a/tests/items/src/test_functions.rs +++ b/tests/items/src/test_functions.rs @@ -5,6 +5,7 @@ extern "C" { fn coreutils_static_assert(); } +#[test] pub fn test_coreutils_static_assert() { unsafe { coreutils_static_assert(); diff --git a/tests/items/src/test_linking.rs b/tests/items/src/test_linking.rs index 502955052a..c5795d93cb 100644 --- a/tests/items/src/test_linking.rs +++ b/tests/items/src/test_linking.rs @@ -8,6 +8,7 @@ extern "C" { fn w() -> c_int; } +#[test] pub fn test_linking() { let mut ret = unsafe { l() }; diff --git a/tests/items/src/test_noop.rs b/tests/items/src/test_noop.rs index d418715cbe..21ec513641 100644 --- a/tests/items/src/test_noop.rs +++ b/tests/items/src/test_noop.rs @@ -10,6 +10,7 @@ extern "C" { fn nofnargs() -> c_int; } +#[test] pub fn test_noop() { unsafe { noop(); @@ -17,6 +18,7 @@ pub fn test_noop() { } } +#[test] pub fn test_nofnargs() { let ret = unsafe { nofnargs() }; let rust_ret = unsafe { rust_nofnargs() }; diff --git a/tests/items/src/test_varargs.rs b/tests/items/src/test_varargs.rs index 9e9079b5be..8c32664c74 100644 --- a/tests/items/src/test_varargs.rs +++ b/tests/items/src/test_varargs.rs @@ -29,6 +29,7 @@ extern "C" { // This test ensures we are able to define and call vararg prototypes // that get linked in (IE printf) +#[test] pub fn test_call_printf() { unsafe { call_printf(); @@ -37,6 +38,7 @@ pub fn test_call_printf() { } // Make sure we can pass through va_list arguments +#[test] pub fn test_call_vprintf() { let fmt_str = CString::new("%d, %f\n").unwrap(); unsafe { @@ -46,6 +48,7 @@ pub fn test_call_vprintf() { } // Test out a small varargs function definition +#[test] pub fn test_my_printf() { let fmt_str = CString::new("%d, %f, %s\n").unwrap(); let test_str = CString::new("test").unwrap(); @@ -55,6 +58,7 @@ pub fn test_my_printf() { } } +#[test] pub fn test_simple_vacopy() { let fmt_str = CString::new("%d, %f\n").unwrap(); unsafe { @@ -63,6 +67,7 @@ pub fn test_simple_vacopy() { } } +#[test] pub fn test_valist_struct_member() { let fmt_str = CString::new("%d, %f\n").unwrap(); unsafe { @@ -71,6 +76,7 @@ pub fn test_valist_struct_member() { } } +#[test] pub fn test_valist_struct_pointer_member() { let fmt_str = CString::new("%d, %f\n").unwrap(); unsafe { @@ -79,6 +85,7 @@ pub fn test_valist_struct_pointer_member() { } } +#[test] pub fn test_restart_valist() { let fmt_str = CString::new("%d, %f\n").unwrap(); unsafe { @@ -87,6 +94,7 @@ pub fn test_restart_valist() { } } +#[test] pub fn test_sample_stddev() { unsafe { let c_res = sample_stddev(4, 25.0, 27.3, 26.9, 25.7); diff --git a/tests/longdouble/src/test_long_double.rs b/tests/longdouble/src/test_long_double.rs index f9e5767af4..a18ab576b6 100644 --- a/tests/longdouble/src/test_long_double.rs +++ b/tests/longdouble/src/test_long_double.rs @@ -5,6 +5,7 @@ use crate::long_double::{ }; use f128::f128; +#[test] pub fn test_long_double_ops() { let input_result = f128::parse("-4.40000000000000013322676295501878485").unwrap(); let ret_result = f128::parse("-5.40000000000000013322676295501878485").unwrap(); @@ -15,6 +16,7 @@ pub fn test_long_double_ops() { assert_eq!(rust_ret, ret_result); } +#[test] pub fn test_long_double_casts() { let input = f128::parse("4.41234567890123413322676295501878485").unwrap(); @@ -31,6 +33,7 @@ pub fn test_long_double_casts() { assert_eq!(rust_ret, 4u32); } +#[test] pub fn test_global_f128s() { unsafe { assert_eq!(rust_ld1, f128::new(1.0f64)); diff --git a/tests/loops/src/test_goto.rs b/tests/loops/src/test_goto.rs index 2e1f24b2db..65730fc8fc 100644 --- a/tests/loops/src/test_goto.rs +++ b/tests/loops/src/test_goto.rs @@ -17,6 +17,7 @@ const BUFFER_SIZE: usize = 4; const BUFFER_SIZE2: usize = 12; const BUFFER_SIZE3: usize = 6; +#[test] pub fn test_goto_linear() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; @@ -30,6 +31,7 @@ pub fn test_goto_linear() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_goto_loop() { let mut buffer = [0; BUFFER_SIZE2]; let mut rust_buffer = [0; BUFFER_SIZE2]; @@ -43,6 +45,7 @@ pub fn test_goto_loop() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_goto_switch() { let mut buffer = [0; BUFFER_SIZE3]; let mut rust_buffer = [0; BUFFER_SIZE3]; diff --git a/tests/loops/src/test_loops.rs b/tests/loops/src/test_loops.rs index 5255df2889..60e8b70edb 100644 --- a/tests/loops/src/test_loops.rs +++ b/tests/loops/src/test_loops.rs @@ -8,6 +8,7 @@ extern "C" { const BUFFER_SIZE: usize = 70; +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/loops/src/test_switch.rs b/tests/loops/src/test_switch.rs index 686c38d22c..e5ed70ae4d 100644 --- a/tests/loops/src/test_switch.rs +++ b/tests/loops/src/test_switch.rs @@ -6,6 +6,7 @@ extern "C" { fn switch_val(_: c_int) -> c_int; } +#[test] pub fn test_switch() { let val = unsafe { switch_val(1) }; let rust_val = unsafe { rust_switch_val(1) }; diff --git a/tests/macros/src/test_define.rs b/tests/macros/src/test_define.rs index a416e57c21..9a38fd724a 100644 --- a/tests/macros/src/test_define.rs +++ b/tests/macros/src/test_define.rs @@ -8,17 +8,20 @@ extern "C" { fn reference_define() -> c_uint; } +#[test] pub fn test_define() { let rust_x = unsafe { rust_reference_define() }; assert_eq!(rust_x, TEST_CONST1 + TEST_CONST2 + TEST_PARENS as c_int); } +#[test] pub fn test_zstd_define() { let max = unsafe { rust_test_zstd() } as i32; assert!(max == ZSTD_WINDOWLOG_MAX_32 || max == ZSTD_WINDOWLOG_MAX_64); } +#[test] pub fn test_macro_stmt_expr() { let ret = unsafe { rust_stmt_expr_inc() }; diff --git a/tests/misc/src/test_exprs.rs b/tests/misc/src/test_exprs.rs index a16e8ad0a1..04555acbda 100644 --- a/tests/misc/src/test_exprs.rs +++ b/tests/misc/src/test_exprs.rs @@ -8,6 +8,7 @@ extern "C" { const BUFFER_SIZE: usize = 60; +#[test] pub fn test_exprs() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/misc/src/test_lvalues.rs b/tests/misc/src/test_lvalues.rs index bd105c96e0..d381f6108e 100644 --- a/tests/misc/src/test_lvalues.rs +++ b/tests/misc/src/test_lvalues.rs @@ -8,6 +8,7 @@ extern "C" { const BUFFER_SIZE: usize = 6; +#[test] pub fn test_lvalue() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/misc/src/test_memory.rs b/tests/misc/src/test_memory.rs index c0e47aa163..2285b25ae5 100644 --- a/tests/misc/src/test_memory.rs +++ b/tests/misc/src/test_memory.rs @@ -12,6 +12,7 @@ extern "C" { const BUFFER_SIZE: usize = 3; const BUFFER_SIZE2: usize = 5; +#[test] pub fn test_malloc() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; @@ -26,6 +27,7 @@ pub fn test_malloc() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_memset() { let mut buffer = [0; BUFFER_SIZE2]; let mut rust_buffer = [0; BUFFER_SIZE2]; diff --git a/tests/misc/src/test_quicksort.rs b/tests/misc/src/test_quicksort.rs index 588c49a46e..d5a09a0ecc 100644 --- a/tests/misc/src/test_quicksort.rs +++ b/tests/misc/src/test_quicksort.rs @@ -10,6 +10,7 @@ extern "C" { fn quickSort(_: *mut c_int, _: c_int, _: c_int); } +#[test] pub fn test_swap() { let (mut a, mut b) = (1, 2); @@ -26,6 +27,7 @@ pub fn test_swap() { assert_eq!(b, 2); } +#[test] pub fn test_partition() { let mut buffer = [6, 1, 5, 6, 2, 0, 9, 2, 0, 5]; let mut rust_buffer = buffer.clone(); @@ -40,6 +42,7 @@ pub fn test_partition() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_quicksort() { let mut buffer = [6, 1, 5, 6, 2, 0, 9, 2, 0, 5]; let mut rust_buffer = buffer.clone(); diff --git a/tests/misc/src/test_shadowing.rs b/tests/misc/src/test_shadowing.rs index ea04274e9b..442fa8dd13 100644 --- a/tests/misc/src/test_shadowing.rs +++ b/tests/misc/src/test_shadowing.rs @@ -10,6 +10,7 @@ extern "C" { const BUFFER_SIZE: usize = 10; +#[test] pub fn test_twice() { for i in 0..20 { let double = unsafe { twice(i) }; @@ -19,6 +20,7 @@ pub fn test_twice() { } } +#[test] pub fn test_shadowing() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/misc/src/test_sizeofs.rs b/tests/misc/src/test_sizeofs.rs index b962fd43f0..262235100b 100644 --- a/tests/misc/src/test_sizeofs.rs +++ b/tests/misc/src/test_sizeofs.rs @@ -10,6 +10,7 @@ extern "C" { const BUFFER_SIZE: usize = 60; +#[test] pub fn test_sizeofs() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/misc/src/test_typedef.rs b/tests/misc/src/test_typedef.rs index 1f9b2da9f9..812e209f4d 100644 --- a/tests/misc/src/test_typedef.rs +++ b/tests/misc/src/test_typedef.rs @@ -7,6 +7,7 @@ extern "C" { fn entry() -> c_int; } +#[test] pub fn test_typedef() { let ret = unsafe { entry() }; let rust_ret = unsafe { rust_entry() }; diff --git a/tests/misc/src/test_uninitialized.rs b/tests/misc/src/test_uninitialized.rs index b3515049ce..005aac15ac 100644 --- a/tests/misc/src/test_uninitialized.rs +++ b/tests/misc/src/test_uninitialized.rs @@ -7,6 +7,7 @@ extern "C" { const BUFFER_SIZE: usize = 1; +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; @@ -21,6 +22,7 @@ pub fn test_buffer() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_types() { assert_eq!(foo as u32, 1); assert_eq!(bar as u32, 2); diff --git a/tests/modules/src/test_modules.rs b/tests/modules/src/test_modules.rs index 0ef191f90b..04a205cda0 100644 --- a/tests/modules/src/test_modules.rs +++ b/tests/modules/src/test_modules.rs @@ -6,4 +6,5 @@ extern "C" { fn modules(); } +#[test] pub fn test_modules() {} diff --git a/tests/pointers/src/test_pointers.rs b/tests/pointers/src/test_pointers.rs index b3a712471d..ab428a1964 100644 --- a/tests/pointers/src/test_pointers.rs +++ b/tests/pointers/src/test_pointers.rs @@ -21,6 +21,7 @@ const BUFFER_SIZE: usize = 5; const BUFFER_SIZE2: usize = 31; const BUFFER_SIZE3: usize = 18; +#[test] pub fn test_init() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; @@ -35,6 +36,7 @@ pub fn test_init() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_arith() { let mut buffer = [0; BUFFER_SIZE2]; let mut rust_buffer = [0; BUFFER_SIZE2]; @@ -52,6 +54,7 @@ pub fn test_arith() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_fn_ptrs() { let mut buffer = [0; BUFFER_SIZE3]; let mut rust_buffer = [0; BUFFER_SIZE3]; diff --git a/tests/simd.x86_64/src/test_x86.rs b/tests/simd.x86_64/src/test_x86.rs index fe535d03c6..1765e67c35 100644 --- a/tests/simd.x86_64/src/test_x86.rs +++ b/tests/simd.x86_64/src/test_x86.rs @@ -109,6 +109,7 @@ impl Debug for ShuffleVectors { } } +#[test] pub fn test_unpack_128_2x128() { assert!(is_x86_feature_detected!("sse2"), "{}", UNSAFETY_ERROR); @@ -139,6 +140,7 @@ pub fn test_unpack_128_2x128() { } } +#[test] pub fn test_zero_initializers() { assert!(is_x86_feature_detected!("sse"), "{}", UNSAFETY_ERROR); assert!(is_x86_feature_detected!("sse2"), "{}", UNSAFETY_ERROR); @@ -150,6 +152,7 @@ pub fn test_zero_initializers() { } } +#[test] pub fn test_shuffle_vectors() { assert!(is_x86_feature_detected!("sse4.2"), "{}", UNSAFETY_ERROR); assert!(is_x86_feature_detected!("ssse3"), "{}", UNSAFETY_ERROR); @@ -184,6 +187,7 @@ impl Debug for VectorInitLists { } } +#[test] pub fn test_vector_init_lists() { assert!(is_x86_feature_detected!("sse"), "{}", UNSAFETY_ERROR); assert!(is_x86_feature_detected!("sse2"), "{}", UNSAFETY_ERROR); @@ -198,6 +202,7 @@ pub fn test_vector_init_lists() { assert_eq!(c2, r2); } +#[test] pub fn test_static_init_lists() { assert!(is_x86_feature_detected!("sse"), "{}", UNSAFETY_ERROR); assert!(is_x86_feature_detected!("sse2"), "{}", UNSAFETY_ERROR); diff --git a/tests/statics/src/test_sections.rs b/tests/statics/src/test_sections.rs index 814fae5402..c773463458 100644 --- a/tests/statics/src/test_sections.rs +++ b/tests/statics/src/test_sections.rs @@ -3,6 +3,7 @@ use crate::attributes::{rust_no_attrs, rust_used_static, rust_used_static2, rust use crate::sections::*; use std::ffi::c_uint; +#[test] pub fn test_sectioned_statics() { unsafe { assert_eq!(rust_section_me, c_uint::max_value()); @@ -27,6 +28,7 @@ pub fn test_sectioned_statics() { } } +#[test] pub fn test_sectioned_used_static() { if cfg!(not(target_os = "macos")) { // This static variable is private and unused (but with the used attribute) diff --git a/tests/statics/src/test_storage.rs b/tests/statics/src/test_storage.rs index 18804910cf..51c6ff650b 100644 --- a/tests/statics/src/test_storage.rs +++ b/tests/statics/src/test_storage.rs @@ -8,6 +8,7 @@ extern "C" { const BUFFER_SIZE: usize = 11; +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/statics/src/test_thread_locals.rs b/tests/statics/src/test_thread_locals.rs index 4113750655..836a4a779a 100644 --- a/tests/statics/src/test_thread_locals.rs +++ b/tests/statics/src/test_thread_locals.rs @@ -49,6 +49,7 @@ fn run_test() { } } +#[test] pub fn test_thread_locals() { run_test(); run_test(); diff --git a/tests/structs/src/test_anonymous_decls.rs b/tests/structs/src/test_anonymous_decls.rs index 36b1f26e3a..e45fb6b751 100644 --- a/tests/structs/src/test_anonymous_decls.rs +++ b/tests/structs/src/test_anonymous_decls.rs @@ -1,5 +1,6 @@ use crate::anonymous_decls::rust_k; +#[test] pub fn test_anonymous_decl() { unsafe { assert_eq!(rust_k.j.l, 0); diff --git a/tests/structs/src/test_bitfields.rs b/tests/structs/src/test_bitfields.rs index 09dfc6dab4..5fdd763eb8 100644 --- a/tests/structs/src/test_bitfields.rs +++ b/tests/structs/src/test_bitfields.rs @@ -26,6 +26,7 @@ extern "C" { static ma_results: [u8; 17]; } +#[test] pub fn test_three_byte_date() { let c_size_of = unsafe { size_of_three_byte_date() }; @@ -86,6 +87,7 @@ pub fn test_three_byte_date() { assert_eq!(tbd.year(), 2); } +#[test] pub fn test_padded_bitfield() { let c_size_of = unsafe { size_of_padded_bitfield() }; @@ -113,6 +115,7 @@ pub fn test_padded_bitfield() { assert_eq!(rust_pb.x(), c_x); } +#[test] pub fn test_static_bitfield() { // On C static unsafe { @@ -147,6 +150,7 @@ pub fn test_static_bitfield() { // Test creating arrays of bitfield structs // as well as pointers to non bitfields +#[test] pub fn test_bf_arrays_and_pointers() { let c_size_of = unsafe { size_of_mixed_bitfields() }; @@ -179,6 +183,7 @@ pub fn test_bf_arrays_and_pointers() { } // This a sample struct which was generated by csmith +#[test] pub fn test_from_csmith() { let c_size_of = unsafe { size_of_from_csmith() }; @@ -195,6 +200,7 @@ pub fn test_from_csmith() { assert_eq!(fc.f6(), 7); } +#[test] pub fn test_returned_bitfield_ptr() { let ptr = unsafe { rust_modify_bf_ptr(); @@ -209,12 +215,14 @@ pub fn test_returned_bitfield_ptr() { // Previously there was an issue where the end // padding was one byte instead of two for this // struct +#[test] pub fn test_size_of_two_eight_bits() { let c_size_of = unsafe { size_of_two_eight_bits() }; assert_eq!(size_of::(), c_size_of); } +#[test] pub fn test_multiple_assignments() { unsafe { multiple_assignments(); diff --git a/tests/structs/src/test_flex_array_members.rs b/tests/structs/src/test_flex_array_members.rs index e3383fd43d..a679bd2dc4 100644 --- a/tests/structs/src/test_flex_array_members.rs +++ b/tests/structs/src/test_flex_array_members.rs @@ -8,6 +8,7 @@ extern "C" { const BUFFER_SIZE: usize = 12; +#[test] pub fn test_flex_array_members() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/structs/src/test_forward.rs b/tests/structs/src/test_forward.rs index 22debac4b3..c0d8cb7955 100644 --- a/tests/structs/src/test_forward.rs +++ b/tests/structs/src/test_forward.rs @@ -8,6 +8,7 @@ extern "C" { const BUFFER_SIZE: usize = 1; +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/structs/src/test_self_referential.rs b/tests/structs/src/test_self_referential.rs index 45a21bf5c5..64be0ace10 100644 --- a/tests/structs/src/test_self_referential.rs +++ b/tests/structs/src/test_self_referential.rs @@ -5,4 +5,5 @@ extern "C" { fn whatever(np: *mut Node); } +#[test] pub fn test_buffer2() {} diff --git a/tests/structs/src/test_struct_with_exp.rs b/tests/structs/src/test_struct_with_exp.rs index fa2dd890ec..c0d36613f0 100644 --- a/tests/structs/src/test_struct_with_exp.rs +++ b/tests/structs/src/test_struct_with_exp.rs @@ -8,6 +8,7 @@ extern "C" { const BUFFER_SIZE: usize = 1; +#[test] pub fn test_struct_with_exp() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; diff --git a/tests/structs/src/test_structs.rs b/tests/structs/src/test_structs.rs index f511fb027f..91d1013018 100644 --- a/tests/structs/src/test_structs.rs +++ b/tests/structs/src/test_structs.rs @@ -13,6 +13,7 @@ extern "C" { const BUFFER_SIZE: usize = 9; const ALIGNMENT_BUFFER_SIZE: usize = 276; +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; @@ -27,12 +28,14 @@ pub fn test_buffer() { assert_eq!(buffer, expected_buffer); } +#[test] pub fn test_alignment() { let c_alignment = unsafe { alignment_of_aligned8_struct() }; assert_eq!(align_of::(), c_alignment); } +#[test] pub fn test_alignments() { let mut buffer = [0; ALIGNMENT_BUFFER_SIZE]; let mut rust_buffer = [0; ALIGNMENT_BUFFER_SIZE]; diff --git a/tests/structs/src/test_variable_offsetof.rs b/tests/structs/src/test_variable_offsetof.rs index 4f6bdf534f..97f83ad6c1 100644 --- a/tests/structs/src/test_variable_offsetof.rs +++ b/tests/structs/src/test_variable_offsetof.rs @@ -8,6 +8,7 @@ extern "C" { fn get_offset2(_: size_t) -> size_t; } +#[test] pub fn test_get_offset() { for idx in 0..3 { let rust_ret = unsafe { rust_get_offset(idx) }; diff --git a/tests/unions/src/test_unions.rs b/tests/unions/src/test_unions.rs index 6b8eb7c771..0a2733b3e8 100644 --- a/tests/unions/src/test_unions.rs +++ b/tests/unions/src/test_unions.rs @@ -8,6 +8,7 @@ extern "C" { const BUFFER_SIZE: usize = 19; +#[test] pub fn test_buffer() { let mut buffer = [0; BUFFER_SIZE]; let mut rust_buffer = [0; BUFFER_SIZE]; From 1d7346cf65d3b0951100595513182cfdda2e18a4 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Mon, 21 Jul 2025 04:33:28 -0700 Subject: [PATCH 3/8] ci: update `run_ci_checks.sh` with the `uv` changes already made in `ci.yml` --- scripts/run_ci_checks.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/run_ci_checks.sh b/scripts/run_ci_checks.sh index df3a59d679..f12cb351f7 100755 --- a/scripts/run_ci_checks.sh +++ b/scripts/run_ci_checks.sh @@ -48,7 +48,9 @@ test() { # so changing `RUSTFLAGS` will not trigger a full rebuild. test-translator() { unset RUSTFLAGS - ./scripts/test_translator.py tests/ + uv venv + uv pip install -r ./scripts/requirements.txt + uv run ./scripts/test_translator.py tests/ } all() { From 13b9a195b94cdd8912da9fc9e1cb911f7e66c3c3 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sat, 19 Jul 2025 02:17:27 -0700 Subject: [PATCH 4/8] tests: format `function_pointers.c` --- tests/pointers/src/function_pointers.c | 140 ++++++++++++------------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/tests/pointers/src/function_pointers.c b/tests/pointers/src/function_pointers.c index b54ae72a1a..f5590d6b60 100644 --- a/tests/pointers/src/function_pointers.c +++ b/tests/pointers/src/function_pointers.c @@ -19,77 +19,77 @@ int varargs_intval(const char c, ...) { return c; } int varargs_fp(const int c, ...) { va_list arg; va_start(arg, c); - char_to_int *fp = va_arg(arg, char_to_int*); + char_to_int *fp = va_arg(arg, char_to_int *); return fp((char)c); } -void entry3(const unsigned sz, int buffer[const]) -{ - int i = 0; - - char_to_int *p0; - char_to_int *p1 = 0; - char_to_int *p2 = intval; - char_to_int *p3 = &intval; - p3 = intval; - p3 = &intval; - - if (!p1 && p3 && !!p3 && p3 != 0) { - buffer[i] = p3('a'); - } - i++; - - char_to_int_fp p4; - char_to_int_fp p5 = 0; - char_to_int_fp p6 = intval; - char_to_int_fp p7 = &intval; - p7 = intval; - p7 = &intval; - - if (!p5 && p7 && !!p7 && p7 != 0) { - buffer[i] = (*p7)('a'); - } - i++; - - char_to_int_fp funs[3] = { intval, negintval }; - - for (int j = 0; funs[j]; j++) { - buffer[i++] = funs[j] ? funs[j]('a'+j) : 55; - } - - // validate function pointer comparison to null - buffer[i++] = p1 == 0; - buffer[i++] = p1 != 0; - buffer[i++] = p2 == 0; - buffer[i++] = p2 != 0; - - // These should now use is_some, is_none: - int j = p4 == 0; - j = 0 == p4; - j = p4 != 0; - j = 0 != p4; - - va_char_to_int_fp p8 = varargs_intval; - buffer[i++] = p8('A'); - buffer[i++] = (*p8)('B', 'C'); - - // Test valid casts between function pointers - // with additional parameters - char_int_to_int_fp p9 = (char_int_to_int_fp)&intval, p10 = (char_int_to_int_fp)p7; - buffer[i++] = p9('D', 42); - buffer[i++] = p10('E', 1337); - - // Test K&R style function pointers - knr *p11 = (knr *)1; - knr *p12 = (knr *)intval; - knr *p13 = (knr *)&intval; - struct pointer_st s; - s.fn = (int (*)())intval; - buffer[i++] = p12('a'); - buffer[i++] = p13('a'); - buffer[i++] = (*(s).fn)(('a')); - - buffer[i++] = p2 == intval; - buffer[i++] = varargs_fp('a', intval); - buffer[i++] = varargs_fp('b', p2); +void entry3(const unsigned sz, int buffer[const]) { + int i = 0; + + char_to_int *p0; + char_to_int *p1 = 0; + char_to_int *p2 = intval; + char_to_int *p3 = &intval; + p3 = intval; + p3 = &intval; + + if (!p1 && p3 && !!p3 && p3 != 0) { + buffer[i] = p3('a'); + } + i++; + + char_to_int_fp p4; + char_to_int_fp p5 = 0; + char_to_int_fp p6 = intval; + char_to_int_fp p7 = &intval; + p7 = intval; + p7 = &intval; + + if (!p5 && p7 && !!p7 && p7 != 0) { + buffer[i] = (*p7)('a'); + } + i++; + + char_to_int_fp funs[3] = {intval, negintval}; + + for (int j = 0; funs[j]; j++) { + buffer[i++] = funs[j] ? funs[j]('a' + j) : 55; + } + + // validate function pointer comparison to null + buffer[i++] = p1 == 0; + buffer[i++] = p1 != 0; + buffer[i++] = p2 == 0; + buffer[i++] = p2 != 0; + + // These should now use is_some, is_none: + int j = p4 == 0; + j = 0 == p4; + j = p4 != 0; + j = 0 != p4; + + va_char_to_int_fp p8 = varargs_intval; + buffer[i++] = p8('A'); + buffer[i++] = (*p8)('B', 'C'); + + // Test valid casts between function pointers + // with additional parameters + char_int_to_int_fp p9 = (char_int_to_int_fp)&intval, + p10 = (char_int_to_int_fp)p7; + buffer[i++] = p9('D', 42); + buffer[i++] = p10('E', 1337); + + // Test K&R style function pointers + knr *p11 = (knr *)1; + knr *p12 = (knr *)intval; + knr *p13 = (knr *)&intval; + struct pointer_st s; + s.fn = (int (*)())intval; + buffer[i++] = p12('a'); + buffer[i++] = p13('a'); + buffer[i++] = (*(s).fn)(('a')); + + buffer[i++] = p2 == intval; + buffer[i++] = varargs_fp('a', intval); + buffer[i++] = varargs_fp('b', p2); } From e70c6a8cebbedb10723bfe16da8f7fefc1eb6c50 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Fri, 18 Jul 2025 19:14:03 -0700 Subject: [PATCH 5/8] tests: skip varargs tests on aarch64, as they don't work yet --- tests/items/src/test_varargs.rs | 19 +++++++++++++++++-- tests/items/src/varargs.c | 5 +++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/items/src/test_varargs.rs b/tests/items/src/test_varargs.rs index 8c32664c74..8c9d23469d 100644 --- a/tests/items/src/test_varargs.rs +++ b/tests/items/src/test_varargs.rs @@ -1,8 +1,11 @@ //! feature_c_variadic, +use crate::varargs::rust_call_printf; +// See #1281. Varargs don't yet work on aarch64. +#[cfg(not(target_arch = "aarch64"))] use crate::varargs::{ - rust_call_printf, rust_call_vprintf, rust_my_printf, rust_restart_valist, rust_sample_stddev, - rust_simple_vacopy, rust_valist_struct_member, rust_valist_struct_pointer_member, + rust_call_vprintf, rust_my_printf, rust_restart_valist, rust_sample_stddev, rust_simple_vacopy, + rust_valist_struct_member, rust_valist_struct_pointer_member, }; use std::ffi::c_char; @@ -11,7 +14,12 @@ use std::ffi::CString; #[link(name = "test")] extern "C" { fn call_printf(); +} +// See #1281. Varargs don't yet work on aarch64. +#[cfg(not(target_arch = "aarch64"))] +#[link(name = "test")] +extern "C" { fn call_vprintf(_: *const c_char, ...); fn my_printf(_: *const c_char, ...); @@ -38,6 +46,7 @@ pub fn test_call_printf() { } // Make sure we can pass through va_list arguments +#[cfg(not(target_arch = "aarch64"))] #[test] pub fn test_call_vprintf() { let fmt_str = CString::new("%d, %f\n").unwrap(); @@ -48,6 +57,7 @@ pub fn test_call_vprintf() { } // Test out a small varargs function definition +#[cfg(not(target_arch = "aarch64"))] #[test] pub fn test_my_printf() { let fmt_str = CString::new("%d, %f, %s\n").unwrap(); @@ -58,6 +68,7 @@ pub fn test_my_printf() { } } +#[cfg(not(target_arch = "aarch64"))] #[test] pub fn test_simple_vacopy() { let fmt_str = CString::new("%d, %f\n").unwrap(); @@ -67,6 +78,7 @@ pub fn test_simple_vacopy() { } } +#[cfg(not(target_arch = "aarch64"))] #[test] pub fn test_valist_struct_member() { let fmt_str = CString::new("%d, %f\n").unwrap(); @@ -76,6 +88,7 @@ pub fn test_valist_struct_member() { } } +#[cfg(not(target_arch = "aarch64"))] #[test] pub fn test_valist_struct_pointer_member() { let fmt_str = CString::new("%d, %f\n").unwrap(); @@ -85,6 +98,7 @@ pub fn test_valist_struct_pointer_member() { } } +#[cfg(not(target_arch = "aarch64"))] #[test] pub fn test_restart_valist() { let fmt_str = CString::new("%d, %f\n").unwrap(); @@ -94,6 +108,7 @@ pub fn test_restart_valist() { } } +#[cfg(not(target_arch = "aarch64"))] #[test] pub fn test_sample_stddev() { unsafe { diff --git a/tests/items/src/varargs.c b/tests/items/src/varargs.c index 3dc3745325..f39111214b 100644 --- a/tests/items/src/varargs.c +++ b/tests/items/src/varargs.c @@ -7,6 +7,9 @@ void call_printf(void) { printf("%d, %f\n", 10, 1.5); } +// See #1281. Varargs don't yet work on aarch64. +#ifndef __aarch64__ + void my_vprintf(const char *format, va_list ap) { vprintf(format, ap); } @@ -134,3 +137,5 @@ double sample_stddev(int count, ...) va_end(args2); return sqrt(sum_sq_diff / count); } + +#endif From bc7e031fc9143fc5b1bc272fa6d482c8c30b024e Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sat, 19 Jul 2025 02:19:01 -0700 Subject: [PATCH 6/8] tests: skip varargs in `function_pointers.c` on aarch64 --- tests/pointers/src/function_pointers.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/pointers/src/function_pointers.c b/tests/pointers/src/function_pointers.c index f5590d6b60..aaac4639ad 100644 --- a/tests/pointers/src/function_pointers.c +++ b/tests/pointers/src/function_pointers.c @@ -16,6 +16,9 @@ int negintval(const char c) { return -c; } int varargs_intval(const char c, ...) { return c; } +// See #1281. Varargs don't yet work on aarch64. +#ifndef __aarch64__ + int varargs_fp(const int c, ...) { va_list arg; va_start(arg, c); @@ -23,6 +26,8 @@ int varargs_fp(const int c, ...) { return fp((char)c); } +#endif + void entry3(const unsigned sz, int buffer[const]) { int i = 0; @@ -68,9 +73,11 @@ void entry3(const unsigned sz, int buffer[const]) { j = p4 != 0; j = 0 != p4; +#ifndef __aarch64__ va_char_to_int_fp p8 = varargs_intval; buffer[i++] = p8('A'); buffer[i++] = (*p8)('B', 'C'); +#endif // Test valid casts between function pointers // with additional parameters @@ -90,6 +97,8 @@ void entry3(const unsigned sz, int buffer[const]) { buffer[i++] = (*(s).fn)(('a')); buffer[i++] = p2 == intval; +#ifndef __aarch64__ buffer[i++] = varargs_fp('a', intval); buffer[i++] = varargs_fp('b', p2); +#endif } From a4960a9c2d2e8232bc59e10365af2e3d4b260442 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sat, 19 Jul 2025 02:33:35 -0700 Subject: [PATCH 7/8] tests: fix `test_pointers.rs`'s `expected_buffer` for aarch64 since some things are skipped --- tests/pointers/src/test_pointers.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/pointers/src/test_pointers.rs b/tests/pointers/src/test_pointers.rs index ab428a1964..7793e48477 100644 --- a/tests/pointers/src/test_pointers.rs +++ b/tests/pointers/src/test_pointers.rs @@ -61,6 +61,10 @@ pub fn test_fn_ptrs() { let expected_buffer = [ 97, 97, 97, -98, 1, 0, 0, 1, 65, 66, 68, 69, 97, 97, 97, 1, 97, 98, ]; + #[cfg(target_arch = "aarch64")] + let expected_buffer = [ + 97, 97, 97, -98, 1, 0, 0, 1, 68, 69, 97, 97, 97, 1, 0, 0, 0, 0, + ]; unsafe { entry3(BUFFER_SIZE3 as u32, buffer.as_mut_ptr()); From 4f6f8c7e82b66ea5a85dbbd7d07c5789edc53ec5 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Mon, 14 Jul 2025 05:10:39 -0400 Subject: [PATCH 8/8] ci: test on aarch64 macOS --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3be01a62e..6f91ebc133 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,10 @@ jobs: os: macOS arch: x86_64 clang-version: 17 + - runner: macos-15 + os: macOS + arch: aarch64 + clang-version: 17 fail-fast: false name: "test (${{ matrix.runner }}: ${{ matrix.os }} ${{ matrix.arch}}, Clang ${{ matrix.clang-version }})" runs-on: ${{ matrix.runner }}