Skip to content

Commit 3b3f9df

Browse files
committed
Adding simple_guest_for_fuzzing_as_string() to hyperlight_testing
Signed-off-by: Mark Rossett <[email protected]>
1 parent fdd5231 commit 3b3f9df

File tree

1 file changed

+24
-0
lines changed
  • src/hyperlight_testing/src

1 file changed

+24
-0
lines changed

src/hyperlight_testing/src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616

1717
// This crate contains testing utilities which need to be shared across multiple
1818
// crates in this project.
19+
use std::env;
1920
use std::path::PathBuf;
2021

2122
use anyhow::{anyhow, Result};
@@ -129,3 +130,26 @@ pub fn c_callback_guest_as_string() -> Result<String> {
129130
.map(|s| s.to_string())
130131
.ok_or_else(|| anyhow!("couldn't convert callback guest PathBuf to string"))
131132
}
133+
134+
/// Get a fully qualified path to a simple guest binary preferring a binary
135+
/// in the same directory as the parent executable. This will be used in
136+
/// fuzzing scenarios where pre-built binaries will be built and submitted to
137+
/// a fuzzing framework.
138+
pub fn simple_guest_for_fuzzing_as_string() -> Result<String> {
139+
let exe_dir = env::current_exe()
140+
.ok()
141+
.and_then(|path| path.parent().map(|p| p.to_path_buf()));
142+
143+
if let Some(exe_dir) = exe_dir {
144+
let guest_path = exe_dir.join("simpleguest");
145+
146+
if guest_path.exists() {
147+
return Ok(guest_path
148+
.to_str()
149+
.ok_or(anyhow!("Invalid path string"))?
150+
.to_string());
151+
}
152+
}
153+
154+
simple_guest_as_string()
155+
}

0 commit comments

Comments
 (0)