diff --git a/rust/ittapi/src/string.rs b/rust/ittapi/src/string.rs index 9760892..39fb198 100644 --- a/rust/ittapi/src/string.rs +++ b/rust/ittapi/src/string.rs @@ -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()); + } } }