Skip to content

Commit

Permalink
rust: improve StringHandle test (intel#125)
Browse files Browse the repository at this point in the history
PR intel#69 identified an issue with how the C library gives out string
handles: it only does so when `INTEL_LIBITTNOTIFY64` is present in the
environment.
  • Loading branch information
abrown authored Jan 12, 2024
1 parent c38897d commit 41806ca
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions rust/ittapi/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,18 @@ impl From<&str> for StringHandle {

mod tests {
#[test]
fn with_dynamic_part_specified() {
// When INTEL_LIBITTNOTIFY64 is set in the environment, the static part of ittnotify will
// allocate; otherwise, if the dynamic part is not present, the pointer will be null.
let _env_path = scoped_env::ScopedEnv::remove("INTEL_LIBITTNOTIFY64");
fn construct_string_handle() {
let sh = super::StringHandle::new("test2");
assert!(sh.as_ptr().is_null());
// `ittapi` profiling is only enabled when the `INTEL_LIBITTNOTIFY64` environment variable
// is set, which points to the profiling collector. If set, the string handle is actually
// allocated; if not set, no allocation is performed (this is a general `ittapi` property:
// no allocation without a profiling collector). Note that string handles are thus invalid
// in the latter case--no collector--but the API safely does not provide any way to observe
// this.
if std::env::var("INTEL_LIBITTNOTIFY64").is_ok() {
assert!(!sh.as_ptr().is_null());
} else {
assert!(sh.as_ptr().is_null());
}
}
}

0 comments on commit 41806ca

Please sign in to comment.