forked from microsoft/onefuzz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from microsoft/main
Fork Sync: Update from parent repository
- Loading branch information
Showing
5 changed files
with
112 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/agent/onefuzz-file-format/tests/files/binary-coverage.v0.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[ | ||
{ | ||
"module": "/setup/main.exe", | ||
"blocks": [ | ||
{ | ||
"offset": 1, | ||
"count": 0 | ||
}, | ||
{ | ||
"offset": 300, | ||
"count": 1 | ||
}, | ||
{ | ||
"offset": 5000, | ||
"count": 0 | ||
} | ||
] | ||
}, | ||
{ | ||
"module": "/setup/lib/some.dll", | ||
"blocks": [ | ||
{ | ||
"offset": 123, | ||
"count": 0 | ||
}, | ||
{ | ||
"offset": 456, | ||
"count": 10 | ||
} | ||
] | ||
} | ||
] |
15 changes: 15 additions & 0 deletions
15
src/agent/onefuzz-file-format/tests/files/binary-coverage.v1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"/setup/main.exe": { | ||
"blocks": { | ||
"1": 0, | ||
"12c": 1, | ||
"1388": 0 | ||
} | ||
}, | ||
"/setup/lib/some.dll": { | ||
"blocks": { | ||
"7b": 0, | ||
"1c8": 10 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
use pretty_assertions::assert_eq; | ||
|
||
use anyhow::Result; | ||
use coverage::binary::{BinaryCoverage, Count, FilePath, ModuleBinaryCoverage, Offset}; | ||
use onefuzz_file_format::coverage::binary::{v0, v1}; | ||
|
||
fn expected_binary_coverage() -> Result<BinaryCoverage> { | ||
let main_exe_path = FilePath::new("/setup/main.exe")?; | ||
let some_dll_path = FilePath::new("/setup/lib/some.dll")?; | ||
|
||
let mut main_exe = ModuleBinaryCoverage::default(); | ||
main_exe.offsets.insert(Offset(1), Count(0)); | ||
main_exe.offsets.insert(Offset(300), Count(1)); | ||
main_exe.offsets.insert(Offset(5000), Count(0)); | ||
|
||
let mut some_dll = ModuleBinaryCoverage::default(); | ||
some_dll.offsets.insert(Offset(123), Count(0)); | ||
some_dll.offsets.insert(Offset(456), Count(10)); | ||
|
||
let mut binary = BinaryCoverage::default(); | ||
binary.modules.insert(some_dll_path, some_dll); | ||
binary.modules.insert(main_exe_path, main_exe); | ||
|
||
Ok(binary) | ||
} | ||
|
||
#[test] | ||
fn test_binary_coverage_formats() -> Result<()> { | ||
let expected = expected_binary_coverage()?; | ||
|
||
let v0_text = include_str!("files/binary-coverage.v0.json"); | ||
let v0_json: v0::BinaryCoverageJson = serde_json::from_str(v0_text)?; | ||
let from_v0 = BinaryCoverage::try_from(v0_json)?; | ||
assert_eq!(from_v0, expected); | ||
|
||
let v1_text = include_str!("files/binary-coverage.v1.json"); | ||
let v1_json: v1::BinaryCoverageJson = serde_json::from_str(v1_text)?; | ||
let from_v1 = BinaryCoverage::try_from(v1_json)?; | ||
assert_eq!(from_v1, expected); | ||
|
||
Ok(()) | ||
} |