diff --git a/.config/target-matrix.json b/.config/target-matrix.json index 1305130c..6eed71b3 100644 --- a/.config/target-matrix.json +++ b/.config/target-matrix.json @@ -210,7 +210,7 @@ "runner": "ubuntu-24.04-riscv", "contract": "nightly", "components": "", - "timeout_minutes": 60, + "timeout_minutes": 120, "verify_plan": false, "cache": false, "compile": "native", diff --git a/scripts/ci/native-platform.sh b/scripts/ci/native-platform.sh index 670e7902..abb2ae31 100755 --- a/scripts/ci/native-platform.sh +++ b/scripts/ci/native-platform.sh @@ -52,7 +52,7 @@ require_host() { run_amx() { local flags test_name - flags=$(sed -n 's/^flags[[:space:]]*: //p' /proc/cpuinfo | head -n 1) + flags=$(awk '/^flags[[:space:]]*:/ { sub(/^[^:]*:[[:space:]]*/, ""); print; exit }' /proc/cpuinfo) [[ " $flags " == *" amx_tile "* ]] || fail "intel-spr runner does not expose AMX-TILE" export CARGO_PROFILE_TEST_DEBUG=0 @@ -74,6 +74,7 @@ run_native_runtime() { export RSCRYPTO_TEST_MODE=commit if [[ "$platform" == rise-riscv ]]; then export RSCRYPTO_CI_RESOURCE_PROFILE=constrained + export CARGO_PROFILE_TEST_DEBUG=0 apply_ci_resource_profile elif [[ "$platform" == ibm-s390x ]]; then export CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_RUSTFLAGS="-C target-feature=+vector" diff --git a/scripts/test/test-rsa-linux-asm.sh b/scripts/test/test-rsa-linux-asm.sh index 1eded9bd..f2e11055 100755 --- a/scripts/test/test-rsa-linux-asm.sh +++ b/scripts/test/test-rsa-linux-asm.sh @@ -8,7 +8,7 @@ fail() { [[ "$(uname -s)" == Linux && "$(uname -m)" == x86_64 ]] \ || fail "requires a Linux x86-64 host" -flags=$(sed -n 's/^flags[[:space:]]*: //p' /proc/cpuinfo | head -n 1) +flags=$(awk '/^flags[[:space:]]*:/ { sub(/^[^:]*:[[:space:]]*/, ""); print; exit }' /proc/cpuinfo) [[ " $flags " == *" bmi2 "* && " $flags " == *" adx "* ]] \ || fail "requires BMI2 and ADX" diff --git a/tests/rsa_allocations.rs b/tests/rsa_allocations.rs index b54afe9c..c34280b2 100644 --- a/tests/rsa_allocations.rs +++ b/tests/rsa_allocations.rs @@ -2,7 +2,7 @@ use core::{ alloc::{GlobalAlloc, Layout}, - sync::atomic::{AtomicUsize, Ordering}, + cell::Cell, }; use std::alloc::System; @@ -12,18 +12,30 @@ use rscrypto::{ RsaPssProfile, RsaPublicKey, RsaPublicKeyPolicy, RsaSignatureProfile, RsaX509PublicKey, }; -static ALLOCATIONS: AtomicUsize = AtomicUsize::new(0); +std::thread_local! { + static ALLOCATIONS: Cell> = const { Cell::new(None) }; +} const ID_RSASSA_PSS_OID: &[u8] = &[0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0a]; struct CountingAlloc; +fn record_allocation() { + match ALLOCATIONS.try_with(|allocations| { + if let Some(count) = allocations.get() { + allocations.set(Some(count.strict_add(1))); + } + }) { + Ok(()) | Err(_) => {} + } +} + // SAFETY: CountingAlloc preserves the global allocator contract because: // 1. Every allocation operation delegates to `System` with the original `Layout`. // 2. Returned pointers and deallocations are exactly those produced/accepted by `System`. -// 3. The only added behavior is an atomic counter update independent of allocation memory. +// 3. The only added behavior is a thread-local counter update independent of allocation memory. unsafe impl GlobalAlloc for CountingAlloc { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - ALLOCATIONS.fetch_add(1, Ordering::Relaxed); + record_allocation(); // SAFETY: Delegating allocation to `System` because: // 1. `layout` is forwarded unchanged from the caller. // 2. `System` is the platform allocator and defines the allocation contract. @@ -38,7 +50,7 @@ unsafe impl GlobalAlloc for CountingAlloc { } unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { - ALLOCATIONS.fetch_add(1, Ordering::Relaxed); + record_allocation(); // SAFETY: Delegating reallocation to `System` because: // 1. `ptr` and `layout` identify an allocation owned by this allocator. // 2. `new_size` is forwarded unchanged from the caller. @@ -378,11 +390,13 @@ fn public_operation_input() -> Vec { } fn reset_allocations() { - ALLOCATIONS.store(0, Ordering::SeqCst); + ALLOCATIONS.set(Some(0)); } fn allocation_count() -> usize { - ALLOCATIONS.load(Ordering::SeqCst) + ALLOCATIONS + .replace(None) + .expect("allocation counting must be enabled before reading it") } #[test]