Add tests for heapviz tool.
This commit is contained in:
7
.github/workflows/cargo_fmt.yml
vendored
7
.github/workflows/cargo_fmt.yml
vendored
@@ -5,6 +5,7 @@ on:
|
|||||||
- 'examples/*.rs'
|
- 'examples/*.rs'
|
||||||
- 'libraries/**/*.rs'
|
- 'libraries/**/*.rs'
|
||||||
- 'src/**/*.rs'
|
- 'src/**/*.rs'
|
||||||
|
- 'tools/**/*.rs'
|
||||||
- 'patches/**'
|
- 'patches/**'
|
||||||
- '**/Cargo.toml'
|
- '**/Cargo.toml'
|
||||||
- '.cargo/config'
|
- '.cargo/config'
|
||||||
@@ -46,3 +47,9 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
command: fmt
|
command: fmt
|
||||||
args: --manifest-path libraries/crypto/Cargo.toml --all -- --check
|
args: --manifest-path libraries/crypto/Cargo.toml --all -- --check
|
||||||
|
|
||||||
|
- name: Cargo format tools/heapviz
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: fmt
|
||||||
|
args: --manifest-path tools/heapviz/Cargo.toml --all -- --check
|
||||||
|
|||||||
32
.github/workflows/heapviz_test.yml
vendored
Normal file
32
.github/workflows/heapviz_test.yml
vendored
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
---
|
||||||
|
name: Heapviz tool tests
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- 'tools/heapviz/**'
|
||||||
|
pull_request:
|
||||||
|
types: [opened, synchronize, reopened]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
cbor_test:
|
||||||
|
runs-on: ubuntu-18.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Check heapviz tool
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: check
|
||||||
|
args: --manifest-path tool/heapviz/Cargo.toml
|
||||||
|
|
||||||
|
- name: Unit testing of heapviz tool (debug mode)
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
args: --manifest-path tool/heapviz/Cargo.toml
|
||||||
|
|
||||||
|
- name: Unit testing of heapviz tool (release mode)
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
args: --manifest-path tool/heapviz/Cargo.toml --release
|
||||||
@@ -23,11 +23,16 @@ cd ../..
|
|||||||
cd libraries/crypto
|
cd libraries/crypto
|
||||||
cargo fmt --all -- --check
|
cargo fmt --all -- --check
|
||||||
cd ../..
|
cd ../..
|
||||||
|
cd tools/heapviz
|
||||||
|
cargo fmt --all -- --check
|
||||||
|
cd ../..
|
||||||
|
|
||||||
echo "Building sha256sum tool..."
|
echo "Building sha256sum tool..."
|
||||||
cargo build --manifest-path third_party/tock/tools/sha256sum/Cargo.toml
|
cargo build --manifest-path third_party/tock/tools/sha256sum/Cargo.toml
|
||||||
echo "Checking that heapviz tool builds properly..."
|
echo "Checking that heapviz tool builds properly..."
|
||||||
cargo build --manifest-path tools/heapviz/Cargo.toml
|
cargo build --manifest-path tools/heapviz/Cargo.toml
|
||||||
|
echo "Testing heapviz tool..."
|
||||||
|
cargo test --manifest-path tools/heapviz/Cargo.toml
|
||||||
|
|
||||||
echo "Checking that CTAP2 builds properly..."
|
echo "Checking that CTAP2 builds properly..."
|
||||||
cargo check --release --target=thumbv7em-none-eabi
|
cargo check --release --target=thumbv7em-none-eabi
|
||||||
|
|||||||
@@ -9,5 +9,6 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.33.1"
|
clap = "2.33.1"
|
||||||
|
lazy_static = "1.4.0"
|
||||||
ncurses = "5.99.0"
|
ncurses = "5.99.0"
|
||||||
regex = "1"
|
regex = "1"
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
|
use lazy_static::lazy_static;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader, Read, Write};
|
use std::io::{BufRead, BufReader, Read, Write};
|
||||||
@@ -59,6 +60,7 @@ fn parse_cli() -> Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// An allocation or deallocation event.
|
/// An allocation or deallocation event.
|
||||||
|
#[cfg_attr(test, derive(Debug, PartialEq))]
|
||||||
struct Event {
|
struct Event {
|
||||||
/// Whether this even is an allocation (true) or a deallocation (false).
|
/// Whether this even is an allocation (true) or a deallocation (false).
|
||||||
is_alloc: bool,
|
is_alloc: bool,
|
||||||
@@ -68,16 +70,14 @@ struct Event {
|
|||||||
len: usize,
|
len: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn parse_event(line: &str) -> Option<Event> {
|
||||||
let config = parse_cli();
|
|
||||||
|
|
||||||
// The following regex matches lines looking like the following from OpenSK's output. Such lines
|
// The following regex matches lines looking like the following from OpenSK's output. Such lines
|
||||||
// are printed to the console when the `--debug-allocations` feature is enabled in the deploy
|
// are printed to the console when the `--debug-allocations` feature is enabled in the deploy
|
||||||
// script.
|
// script.
|
||||||
//
|
//
|
||||||
// ```
|
// ```
|
||||||
// alloc[256, 1] = 0x2002410c (2 ptrs, 384 bytes)
|
// alloc[256, 1] = 0x2002401c (2 ptrs, 384 bytes)
|
||||||
// dealloc[256, 1] = 0x2002410c (1 ptrs, 512 bytes)
|
// dealloc[64, 1] = 0x2002410c (1 ptrs, 512 bytes)
|
||||||
// ```
|
// ```
|
||||||
//
|
//
|
||||||
// The two integers between square brackets after the (de)alloc keywords represent the length
|
// The two integers between square brackets after the (de)alloc keywords represent the length
|
||||||
@@ -90,20 +90,31 @@ fn main() {
|
|||||||
// - The keyword to know whether this operation is an allocation or a deallocation.
|
// - The keyword to know whether this operation is an allocation or a deallocation.
|
||||||
// - The length of the allocated block.
|
// - The length of the allocated block.
|
||||||
// - The starting address of the allocated block.
|
// - The starting address of the allocated block.
|
||||||
let re = Regex::new(r"^(alloc|dealloc)\[(\d+), \d+\] = 0x([0-9a-f]+) \(\d+ ptrs, \d+ bytes\)$")
|
lazy_static! {
|
||||||
|
static ref RE: Regex =
|
||||||
|
Regex::new(r"^(alloc|dealloc)\[(\d+), \d+\] = 0x([0-9a-f]+) \(\d+ ptrs, \d+ bytes\)$")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
let mut events = Vec::new();
|
RE.captures(line).map(|caps| {
|
||||||
for line in BufReader::new(config.logfile).lines() {
|
|
||||||
if let Some(caps) = re.captures(&line.unwrap()) {
|
|
||||||
let typ = caps.get(1).unwrap().as_str();
|
let typ = caps.get(1).unwrap().as_str();
|
||||||
let len = caps.get(2).unwrap().as_str().parse::<usize>().unwrap();
|
let len = caps.get(2).unwrap().as_str().parse::<usize>().unwrap();
|
||||||
let start = usize::from_str_radix(&caps.get(3).unwrap().as_str(), 16).unwrap();
|
let start = usize::from_str_radix(&caps.get(3).unwrap().as_str(), 16).unwrap();
|
||||||
events.push(Event {
|
Event {
|
||||||
is_alloc: typ == "alloc",
|
is_alloc: typ == "alloc",
|
||||||
start,
|
start,
|
||||||
len,
|
len,
|
||||||
});
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let config = parse_cli();
|
||||||
|
|
||||||
|
let mut events = Vec::new();
|
||||||
|
for line in BufReader::new(config.logfile).lines() {
|
||||||
|
if let Some(event) = parse_event(&line.unwrap()) {
|
||||||
|
events.push(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,3 +176,42 @@ fn main() {
|
|||||||
|
|
||||||
ncurses::endwin();
|
ncurses::endwin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_event_alloc() {
|
||||||
|
assert_eq!(
|
||||||
|
parse_event("alloc[256, 1] = 0x2002401c (2 ptrs, 384 bytes)"),
|
||||||
|
Some(Event {
|
||||||
|
is_alloc: true,
|
||||||
|
start: 0x2002401c,
|
||||||
|
len: 256,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_event_dealloc() {
|
||||||
|
assert_eq!(
|
||||||
|
parse_event("dealloc[64, 1] = 0x2002410c (1 ptrs, 512 bytes)"),
|
||||||
|
Some(Event {
|
||||||
|
is_alloc: false,
|
||||||
|
start: 0x2002410c,
|
||||||
|
len: 64,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_event_none() {
|
||||||
|
assert_eq!(
|
||||||
|
parse_event(
|
||||||
|
"NRF52 HW INFO: Variant: AAD0, Part: N52840, Package: QI, Ram: K256, Flash: K1024"
|
||||||
|
),
|
||||||
|
None
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user