88//! - `otel_thread_ctx_v1` is accessed via TLSDESC relocations (R_X86_64_TLSDESC or
99//! R_AARCH64_TLSDESC), as required by the OTel thread-level context sharing spec.
1010//!
11- //! The cdylib path is injected at compile time via `build.rs` from `OUT_DIR`.
11+ //! The cdylib path is derived at runtime from the test executable location:
12+ //! the test binary lives in `target/<[triple/]profile>/deps/`, so the cdylib
13+ //! is one level up at `target/<[triple/]profile>/liblibdd_otel_thread_ctx_ffi.so`.
1214
1315#![ cfg( target_os = "linux" ) ]
1416
@@ -18,22 +20,43 @@ use std::process::Command;
1820const SYMBOL : & str = "otel_thread_ctx_v1" ;
1921
2022fn cdylib_path ( ) -> PathBuf {
21- PathBuf :: from ( env ! ( "CDYLIB_PROFILE_DIR" ) ) . join ( "liblibdd_otel_thread_ctx_ffi.so" )
23+ // test binary: target/<[triple/]profile>/deps/<name>
24+ // cdylib: target/<[triple/]profile>/liblibdd_otel_thread_ctx_ffi.so
25+ let exe = std:: env:: current_exe ( ) . expect ( "failed to read current executable path" ) ;
26+ exe. parent ( ) // deps/
27+ . and_then ( |p| p. parent ( ) ) // <profile>/
28+ . expect ( "unexpected test executable path structure" )
29+ . join ( "liblibdd_otel_thread_ctx_ffi.so" )
30+ }
31+
32+ fn check_cdylib_exists ( path : & PathBuf ) {
33+ assert ! (
34+ path. exists( ) ,
35+ "cdylib not found at {}: \
36+ ensure `cargo build -p libdd-otel-thread-ctx-ffi` has been run for this profile",
37+ path. display( )
38+ ) ;
39+ assert ! (
40+ std:: fs:: File :: open( path) . is_ok( ) ,
41+ "cdylib exists at {} but could not be opened for reading" ,
42+ path. display( )
43+ ) ;
2244}
2345
2446fn readelf ( args : & [ & str ] , path : & PathBuf ) -> String {
2547 let out = Command :: new ( "readelf" )
2648 . args ( args)
2749 . arg ( path)
2850 . output ( )
29- . expect ( "failed to run readelf — is binutils installed?" ) ;
51+ . expect ( "failed to run readelf. Is binutils installed?" ) ;
3052 String :: from_utf8_lossy ( & out. stdout ) . into_owned ( )
3153}
3254
3355#[ test]
3456#[ cfg_attr( miri, ignore) ]
3557fn otel_thread_ctx_v1_in_dynsym ( ) {
3658 let path = cdylib_path ( ) ;
59+ check_cdylib_exists ( & path) ;
3760 let output = readelf ( & [ "-W" , "--dyn-syms" ] , & path) ;
3861 let line = output
3962 . lines ( )
@@ -49,6 +72,7 @@ fn otel_thread_ctx_v1_in_dynsym() {
4972#[ cfg_attr( miri, ignore) ]
5073fn otel_thread_ctx_v1_tlsdesc_reloc ( ) {
5174 let path = cdylib_path ( ) ;
75+ check_cdylib_exists ( & path) ;
5276 let output = readelf ( & [ "-W" , "--relocs" ] , & path) ;
5377 let found = output. lines ( ) . any ( |l| {
5478 l. contains ( SYMBOL ) && ( l. contains ( "R_X86_64_TLSDESC" ) || l. contains ( "R_AARCH64_TLSDESC" ) )
0 commit comments