Skip to content

Commit e98d81f

Browse files
yannhamclaude
andcommitted
test(ffi): assert cdylib exists and is readable before ELF inspection
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e6a7b10 commit e98d81f

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

libdd-otel-thread-ctx-ffi/tests/elf_properties.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,34 @@ fn cdylib_path() -> PathBuf {
2121
PathBuf::from(env!("CDYLIB_PROFILE_DIR")).join("liblibdd_otel_thread_ctx_ffi.so")
2222
}
2323

24+
fn check_cdylib_exists(path: &PathBuf) {
25+
assert!(
26+
path.exists(),
27+
"cdylib not found at {}: \
28+
ensure `cargo build -p libdd-otel-thread-ctx-ffi` has been run for this profile",
29+
path.display()
30+
);
31+
assert!(
32+
std::fs::File::open(path).is_ok(),
33+
"cdylib exists at {} but could not be opened for reading",
34+
path.display()
35+
);
36+
}
37+
2438
fn readelf(args: &[&str], path: &PathBuf) -> String {
2539
let out = Command::new("readelf")
2640
.args(args)
2741
.arg(path)
2842
.output()
29-
.expect("failed to run readelf — is binutils installed?");
43+
.expect("failed to run readelf. Is binutils installed?");
3044
String::from_utf8_lossy(&out.stdout).into_owned()
3145
}
3246

3347
#[test]
3448
#[cfg_attr(miri, ignore)]
3549
fn otel_thread_ctx_v1_in_dynsym() {
3650
let path = cdylib_path();
51+
check_cdylib_exists(&path);
3752
let output = readelf(&["-W", "--dyn-syms"], &path);
3853
let line = output
3954
.lines()
@@ -49,6 +64,7 @@ fn otel_thread_ctx_v1_in_dynsym() {
4964
#[cfg_attr(miri, ignore)]
5065
fn otel_thread_ctx_v1_tlsdesc_reloc() {
5166
let path = cdylib_path();
67+
check_cdylib_exists(&path);
5268
let output = readelf(&["-W", "--relocs"], &path);
5369
let found = output.lines().any(|l| {
5470
l.contains(SYMBOL) && (l.contains("R_X86_64_TLSDESC") || l.contains("R_AARCH64_TLSDESC"))

0 commit comments

Comments
 (0)