Skip to content

Commit 1bade18

Browse files
test(ctermid): add host differential coverage (bd-lphwb7)
1 parent 2a72f22 commit 1bade18

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

crates/frankenlibc-abi/tests/stdlib_abi_test.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2879,6 +2879,39 @@ fn ctermid_writes_into_caller_buffer() {
28792879
assert_eq!(value, "/dev/tty");
28802880
}
28812881

2882+
#[test]
2883+
fn ctermid_matches_host_for_static_and_caller_storage() {
2884+
// SAFETY: null requests ctermid's static storage in each implementation.
2885+
let fl_static = unsafe { ctermid(ptr::null_mut()) };
2886+
// SAFETY: null requests the host libc's static storage.
2887+
let host_static = unsafe { libc::ctermid(ptr::null_mut()) };
2888+
assert!(!fl_static.is_null());
2889+
assert!(!host_static.is_null());
2890+
// SAFETY: both ctermid calls returned valid NUL-terminated strings.
2891+
assert_eq!(
2892+
unsafe { CStr::from_ptr(fl_static).to_bytes_with_nul() },
2893+
unsafe { CStr::from_ptr(host_static).to_bytes_with_nul() }
2894+
);
2895+
// SAFETY: repeated null calls are valid and must retain static storage.
2896+
assert_eq!(unsafe { ctermid(ptr::null_mut()) }, fl_static);
2897+
// SAFETY: repeated null calls are valid and must retain host static storage.
2898+
assert_eq!(unsafe { libc::ctermid(ptr::null_mut()) }, host_static);
2899+
2900+
let mut fl_buffer = [0_i8; 32];
2901+
let mut host_buffer = [0_i8; 32];
2902+
// SAFETY: both buffers are writable and large enough for ctermid output.
2903+
let fl_out = unsafe { ctermid(fl_buffer.as_mut_ptr()) };
2904+
// SAFETY: both buffers are writable and large enough for ctermid output.
2905+
let host_out = unsafe { libc::ctermid(host_buffer.as_mut_ptr()) };
2906+
assert_eq!(fl_out, fl_buffer.as_mut_ptr());
2907+
assert_eq!(host_out, host_buffer.as_mut_ptr());
2908+
// SAFETY: both calls wrote NUL-terminated output to their supplied buffers.
2909+
assert_eq!(
2910+
unsafe { CStr::from_ptr(fl_buffer.as_ptr()).to_bytes_with_nul() },
2911+
unsafe { CStr::from_ptr(host_buffer.as_ptr()).to_bytes_with_nul() }
2912+
);
2913+
}
2914+
28822915
#[test]
28832916
fn get_nprocs_helpers_match_sysconf_values() {
28842917
let online = get_nprocs();
@@ -4090,7 +4123,10 @@ fn random_r_accepts_valid_tracked_state_and_result() {
40904123
// srandom_r reseeds the bound generator; the same seed replays exactly.
40914124
assert_eq!(srandom_r(123, buf.cast()), 0);
40924125
assert_eq!(random_r(buf.cast(), result), 0);
4093-
assert_eq!(*result, first, "srandom_r(123) must replay the seed sequence");
4126+
assert_eq!(
4127+
*result, first,
4128+
"srandom_r(123) must replay the seed sequence"
4129+
);
40944130

40954131
frankenlibc_abi::malloc_abi::free(result.cast());
40964132
frankenlibc_abi::malloc_abi::free(statebuf.cast());

0 commit comments

Comments
 (0)