Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions crates/allocation_hints/tests/heaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@
use allocation_hints::heaps::{Heap, Kind, bump, current_thread_id, general};
use allocation_hints::{active_hint, with_hint};

#[test]
fn general_options_round_trip() {
let options = general::Options::default()
.with_locality_segment_bytes(128 * 1024)
.with_medium_cache_max_bytes(256 * 1024);

assert_eq!(
(options.locality_segment_bytes(), options.medium_cache_max_bytes()),
(128 * 1024, 256 * 1024)
);
}

#[test]
fn option_defaults_have_exact_documented_values() {
let general = general::Options::new();
Expand Down Expand Up @@ -129,11 +117,17 @@ fn bump_option_boundaries_reject_values_outside_the_contract() {
}

#[test]
fn heap_accessors_and_debug_report_descriptor() {
let options = general::Options::new();
fn heap_accessors_and_debug_preserve_nondefault_options() {
let options = general::Options::default()
.with_locality_segment_bytes(128 * 1024)
.with_medium_cache_max_bytes(256 * 1024);
let heap = Heap::general(options);
let active = with_hint(&heap, || active_hint().unwrap());

assert_eq!(
(options.locality_segment_bytes(), options.medium_cache_max_bytes()),
(128 * 1024, 256 * 1024)
);
assert_eq!(
(heap.id().get(), heap.kind(), active.id(), active.kind(), format!("{heap:?}")),
(
Expand Down Expand Up @@ -164,16 +158,12 @@ fn default_heap_is_general_purpose() {
assert!(matches!(Heap::default().kind(), Kind::General(_)));
}

#[test]
fn thread_identity_is_nonzero() {
assert_ne!(current_thread_id().get(), 0);
}

#[test]
fn thread_identities_are_stable_per_thread_and_distinct_between_threads() {
let current = current_thread_id();
let other = std::thread::spawn(|| (current_thread_id(), current_thread_id())).join().unwrap();

assert_ne!(current.get(), 0);
assert_eq!(other.0, other.1);
assert_ne!(current, other.0);
}
Loading