Compare commits
26
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1323dc1571 | ||
|
|
848a78ed5f | ||
|
|
8d092ae417 | ||
|
|
7445b05e57 | ||
|
|
faae4ee145 | ||
|
|
942801ee4b | ||
|
|
8de1bdffd4 | ||
|
|
77237023e3 | ||
|
|
fc573f075a | ||
|
|
1c364d4ff1 | ||
|
|
d54bd6473f | ||
|
|
a5b07d22ae | ||
|
|
3d17326460 | ||
|
|
56339a5eca | ||
|
|
00bb760451 | ||
|
|
5f472435a7 | ||
|
|
f22fe19a4d | ||
|
|
8ab83edc73 | ||
|
|
601da0548b | ||
|
|
4592b927ad | ||
|
|
5e347315e2 | ||
|
|
603c49a395 | ||
|
|
bc8e0535d1 | ||
|
|
cf1eaebae1 | ||
|
|
f89f220f3e | ||
|
|
c18a37eebc |
@@ -1,6 +1,6 @@
|
||||
# Alkane Toolkit
|
||||
|
||||
[](https://gitea.bluefla.re/blueflare/alkane-toolkit/actions)
|
||||
[](https://gitea.bluefla.re/blueflare/alkane-toolkit/actions)
|
||||

|
||||

|
||||

|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"bench_parse_line_near_max_addrs": 644187.0,
|
||||
"bench_parse_targets_many_ranges_near_cap": 49565223.0,
|
||||
"bench_render_cells": 3037944.0,
|
||||
"bench_sort_by_each_column": 816884.0,
|
||||
"bench_targets_to_cidrs_large_range": 443875.0,
|
||||
"bench_upsert_cold_start_population": 8871040.0,
|
||||
"bench_view_pipeline": 177652.0,
|
||||
"bench_view_pipeline_default_sort": 203830.0,
|
||||
"bench_view_pipeline_with_filter": 187371.0
|
||||
"bench_parse_line_near_max_addrs": 807160.0,
|
||||
"bench_parse_targets_many_ranges_near_cap": 54465485.0,
|
||||
"bench_render_cells": 3503112.0,
|
||||
"bench_sort_by_each_column": 486975.0,
|
||||
"bench_targets_to_cidrs_large_range": 482167.0,
|
||||
"bench_upsert_cold_start_population": 8315814.0,
|
||||
"bench_view_pipeline": 191794.0,
|
||||
"bench_view_pipeline_default_sort": 193214.0,
|
||||
"bench_view_pipeline_with_filter": 253085.0
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="160.5" height="20" role="img" aria-label="bench coverage: pending">
|
||||
<title>bench coverage: pending</title>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="128.0" height="20" role="img" aria-label="bench coverage: 7%">
|
||||
<title>bench coverage: 7%</title>
|
||||
<linearGradient id="s" x2="0" y2="100%">
|
||||
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
||||
<stop offset="1" stop-opacity=".1"/>
|
||||
</linearGradient>
|
||||
<clipPath id="r"><rect width="160.5" height="20" rx="3" fill="#fff"/></clipPath>
|
||||
<clipPath id="r"><rect width="128.0" height="20" rx="3" fill="#fff"/></clipPath>
|
||||
<g clip-path="url(#r)">
|
||||
<rect width="103.0" height="20" fill="#555"/>
|
||||
<rect x="103.0" width="57.5" height="20" fill="#9f9f9f"/>
|
||||
<rect width="160.5" height="20" fill="url(#s)"/>
|
||||
<rect x="103.0" width="25.0" height="20" fill="#e05d44"/>
|
||||
<rect width="128.0" height="20" fill="url(#s)"/>
|
||||
</g>
|
||||
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="11">
|
||||
<text x="51.5" y="15" fill="#010101" fill-opacity=".3">bench coverage</text>
|
||||
<text x="51.5" y="14">bench coverage</text>
|
||||
<text x="131.8" y="15" fill="#010101" fill-opacity=".3">pending</text>
|
||||
<text x="131.8" y="14">pending</text>
|
||||
<text x="115.5" y="15" fill="#010101" fill-opacity=".3">7%</text>
|
||||
<text x="115.5" y="14">7%</text>
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 966 B After Width: | Height: | Size: 946 B |
+7
-7
@@ -1,19 +1,19 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="147.5" height="20" role="img" aria-label="bench: -79.9% vs prev">
|
||||
<title>bench: -79.9% vs prev</title>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="141.0" height="20" role="img" aria-label="bench: +7.4% vs prev">
|
||||
<title>bench: +7.4% vs prev</title>
|
||||
<linearGradient id="s" x2="0" y2="100%">
|
||||
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
||||
<stop offset="1" stop-opacity=".1"/>
|
||||
</linearGradient>
|
||||
<clipPath id="r"><rect width="147.5" height="20" rx="3" fill="#fff"/></clipPath>
|
||||
<clipPath id="r"><rect width="141.0" height="20" rx="3" fill="#fff"/></clipPath>
|
||||
<g clip-path="url(#r)">
|
||||
<rect width="44.5" height="20" fill="#555"/>
|
||||
<rect x="44.5" width="103.0" height="20" fill="#4c1"/>
|
||||
<rect width="147.5" height="20" fill="url(#s)"/>
|
||||
<rect x="44.5" width="96.5" height="20" fill="#dfb317"/>
|
||||
<rect width="141.0" height="20" fill="url(#s)"/>
|
||||
</g>
|
||||
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="11">
|
||||
<text x="22.2" y="15" fill="#010101" fill-opacity=".3">bench</text>
|
||||
<text x="22.2" y="14">bench</text>
|
||||
<text x="96.0" y="15" fill="#010101" fill-opacity=".3">-79.9% vs prev</text>
|
||||
<text x="96.0" y="14">-79.9% vs prev</text>
|
||||
<text x="92.8" y="15" fill="#010101" fill-opacity=".3">+7.4% vs prev</text>
|
||||
<text x="92.8" y="14">+7.4% vs prev</text>
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 952 B After Width: | Height: | Size: 950 B |
+4
-4
@@ -1,5 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="141.0" height="20" role="img" aria-label="lines of code: 13.7k">
|
||||
<title>lines of code: 13.7k</title>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="141.0" height="20" role="img" aria-label="lines of code: 13.7K">
|
||||
<title>lines of code: 13.7K</title>
|
||||
<linearGradient id="s" x2="0" y2="100%">
|
||||
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
||||
<stop offset="1" stop-opacity=".1"/>
|
||||
@@ -13,7 +13,7 @@
|
||||
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="11">
|
||||
<text x="48.2" y="15" fill="#010101" fill-opacity=".3">lines of code</text>
|
||||
<text x="48.2" y="14">lines of code</text>
|
||||
<text x="118.8" y="15" fill="#010101" fill-opacity=".3">13.7k</text>
|
||||
<text x="118.8" y="14">13.7k</text>
|
||||
<text x="118.8" y="15" fill="#010101" fill-opacity=".3">13.7K</text>
|
||||
<text x="118.8" y="14">13.7K</text>
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 952 B After Width: | Height: | Size: 952 B |
+1
-1
@@ -14,7 +14,7 @@ _DUR = re.compile(r"([0-9]+(?:\.[0-9]+)?)\s*(ns|\u00b5s|us|ms|s)(?![a-zA-Z])")
|
||||
_UNIT_NS = {"ns": 1.0, "us": 1e3, "\u00b5s": 1e3, "ms": 1e6, "s": 1e9}
|
||||
_NAME = re.compile(r"^(?:test [A-Za-z0-9_:]+ \.\.\. )?(bench_[A-Za-z0-9_]+)\s*:")
|
||||
EXPECTED_BENCHES = {
|
||||
"bench_naming_transforms",
|
||||
"bench_verify_artifact", "bench_naming_transforms",
|
||||
"bench_parse_line_near_max_addrs", "bench_parse_targets_many_ranges_near_cap",
|
||||
"bench_targets_to_cidrs_large_range", "bench_view_pipeline",
|
||||
"bench_render_cells", "bench_health_diagnostics",
|
||||
|
||||
@@ -33,7 +33,7 @@ class BenchBadgeTests(unittest.TestCase):
|
||||
lines = [f"test tests::{name} ... {name}: 10ms/op"
|
||||
for name in sorted(badge.EXPECTED_BENCHES)]
|
||||
values = badge.require_suite(badge.parse_bench("\n".join(lines)))
|
||||
self.assertEqual(len(values), len(badge.EXPECTED_BENCHES))
|
||||
self.assertEqual(len(values), 12)
|
||||
with self.assertRaisesRegex(ValueError, "declared suite"):
|
||||
badge.require_suite(badge.parse_bench("\n".join(lines[:-1])))
|
||||
with self.assertRaisesRegex(ValueError, "duplicate"):
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//! Bounded, read-only SSH probes for board identification.
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::fs;
|
||||
use std::io::{self, Read};
|
||||
use std::net::IpAddr;
|
||||
@@ -20,150 +19,6 @@ pub enum Probe {
|
||||
DeviceTreeModel,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct MtdPartition {
|
||||
pub index: u32,
|
||||
pub size_bytes: u64,
|
||||
pub erase_bytes: u64,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
/// The partition identity and geometry required by an SDK flash plan.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct MtdRequirement {
|
||||
pub index: u32,
|
||||
pub name: String,
|
||||
pub size_bytes: u64,
|
||||
pub erase_bytes: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct MtdTarget {
|
||||
pub device: PathBuf,
|
||||
pub size_bytes: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum MtdMatchError {
|
||||
MissingIndex,
|
||||
AmbiguousIndex,
|
||||
NameMismatch,
|
||||
SizeMismatch,
|
||||
EraseMismatch,
|
||||
}
|
||||
|
||||
/// Resolve a character device only after comparing the observed partition
|
||||
/// with the expected identity and geometry. This does not authorize a write.
|
||||
pub fn resolve_mtd_target(
|
||||
observed: &[MtdPartition],
|
||||
expected: &MtdRequirement,
|
||||
) -> Result<MtdTarget, MtdMatchError> {
|
||||
let mut matches = observed
|
||||
.iter()
|
||||
.filter(|entry| entry.index == expected.index);
|
||||
let entry = matches.next().ok_or(MtdMatchError::MissingIndex)?;
|
||||
if matches.next().is_some() {
|
||||
return Err(MtdMatchError::AmbiguousIndex);
|
||||
}
|
||||
if entry.name != expected.name {
|
||||
return Err(MtdMatchError::NameMismatch);
|
||||
}
|
||||
if entry.size_bytes != expected.size_bytes {
|
||||
return Err(MtdMatchError::SizeMismatch);
|
||||
}
|
||||
if entry.erase_bytes != expected.erase_bytes {
|
||||
return Err(MtdMatchError::EraseMismatch);
|
||||
}
|
||||
Ok(MtdTarget {
|
||||
device: PathBuf::from(format!("/dev/mtd{}", entry.index)),
|
||||
size_bytes: entry.size_bytes,
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum MtdError {
|
||||
InvalidHeader,
|
||||
InvalidEntry(usize),
|
||||
DuplicateIndex,
|
||||
DuplicateName,
|
||||
TooManyEntries,
|
||||
}
|
||||
|
||||
/// Parse `/proc/mtd` as data. A flash plan must match both partition index
|
||||
/// and name against its board-specific layout before using a device path.
|
||||
pub fn parse_mtd_table(bytes: &[u8]) -> Result<Vec<MtdPartition>, MtdError> {
|
||||
if bytes.len() > MAX_PROBE_BYTES {
|
||||
return Err(MtdError::TooManyEntries);
|
||||
}
|
||||
let text = std::str::from_utf8(bytes).map_err(|_| MtdError::InvalidHeader)?;
|
||||
let mut lines = text.lines();
|
||||
if lines
|
||||
.next()
|
||||
.map(str::split_whitespace)
|
||||
.map(Iterator::collect::<Vec<_>>)
|
||||
!= Some(vec!["dev:", "size", "erasesize", "name"])
|
||||
{
|
||||
return Err(MtdError::InvalidHeader);
|
||||
}
|
||||
let mut entries = Vec::new();
|
||||
let mut indices = HashSet::new();
|
||||
let mut names = HashSet::new();
|
||||
for (offset, line) in lines.enumerate() {
|
||||
if line.trim().is_empty() {
|
||||
continue;
|
||||
}
|
||||
let line_number = offset + 2;
|
||||
if entries.len() >= 128 {
|
||||
return Err(MtdError::TooManyEntries);
|
||||
}
|
||||
let invalid = || MtdError::InvalidEntry(line_number);
|
||||
let start = line.find('"').ok_or_else(invalid)?;
|
||||
let end = line.rfind('"').ok_or_else(invalid)?;
|
||||
if start == end || !line[end + 1..].trim().is_empty() {
|
||||
return Err(invalid());
|
||||
}
|
||||
let fields: Vec<_> = line[..start].split_whitespace().collect();
|
||||
if fields.len() != 3 {
|
||||
return Err(invalid());
|
||||
}
|
||||
let index = fields[0]
|
||||
.strip_prefix("mtd")
|
||||
.and_then(|value| value.strip_suffix(':'))
|
||||
.and_then(|value| value.parse::<u32>().ok())
|
||||
.ok_or_else(invalid)?;
|
||||
let size_bytes = u64::from_str_radix(fields[1], 16).map_err(|_| invalid())?;
|
||||
let erase_bytes = u64::from_str_radix(fields[2], 16).map_err(|_| invalid())?;
|
||||
let name = &line[start + 1..end];
|
||||
if size_bytes == 0
|
||||
|| erase_bytes == 0
|
||||
|| name.is_empty()
|
||||
|| name.len() > 128
|
||||
|| !name
|
||||
.bytes()
|
||||
.all(|byte| byte.is_ascii_graphic() || byte == b' ')
|
||||
|| name.contains('"')
|
||||
{
|
||||
return Err(invalid());
|
||||
}
|
||||
if !indices.insert(index) {
|
||||
return Err(MtdError::DuplicateIndex);
|
||||
}
|
||||
if !names.insert(name.to_owned()) {
|
||||
return Err(MtdError::DuplicateName);
|
||||
}
|
||||
entries.push(MtdPartition {
|
||||
index,
|
||||
size_bytes,
|
||||
erase_bytes,
|
||||
name: name.to_owned(),
|
||||
});
|
||||
}
|
||||
if entries.is_empty() {
|
||||
return Err(MtdError::InvalidHeader);
|
||||
}
|
||||
Ok(entries)
|
||||
}
|
||||
|
||||
impl Probe {
|
||||
fn command(self) -> &'static str {
|
||||
match self {
|
||||
@@ -361,66 +216,4 @@ mod tests {
|
||||
Err(AccessError::Timeout)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_captured_mtd_layout_and_rejects_duplicate_targets() {
|
||||
let captured = b"dev: size erasesize name\n\
|
||||
mtd0: 02800000 00020000 \"BOOT.bin-dts-marker-kernel\"\n\
|
||||
mtd1: 02000000 00020000 \"ramfs\"\n";
|
||||
let entries = parse_mtd_table(captured).unwrap();
|
||||
assert_eq!(entries[0].index, 0);
|
||||
assert_eq!(entries[0].size_bytes, 0x0280_0000);
|
||||
assert_eq!(entries[0].erase_bytes, 0x0002_0000);
|
||||
assert_eq!(entries[0].name, "BOOT.bin-dts-marker-kernel");
|
||||
let duplicate = b"dev: size erasesize name\n\
|
||||
mtd0: 00020000 00020000 \"boot\"\n\
|
||||
mtd0: 00020000 00020000 \"root\"\n";
|
||||
assert_eq!(parse_mtd_table(duplicate), Err(MtdError::DuplicateIndex));
|
||||
assert_eq!(
|
||||
parse_mtd_table(b"mtd0: 1 1 \"boot\"\n"),
|
||||
Err(MtdError::InvalidHeader)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flash_target_requires_captured_identity_and_geometry() {
|
||||
let observed = parse_mtd_table(
|
||||
b"dev: size erasesize name\n\
|
||||
mtd0: 02800000 00020000 \"BOOT.bin-dts-marker-kernel\"\n\
|
||||
mtd1: 02000000 00020000 \"ramfs\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
let mut required = MtdRequirement {
|
||||
index: 0,
|
||||
name: "BOOT.bin-dts-marker-kernel".to_owned(),
|
||||
size_bytes: 0x0280_0000,
|
||||
erase_bytes: 0x0002_0000,
|
||||
};
|
||||
assert_eq!(
|
||||
resolve_mtd_target(&observed, &required).unwrap().device,
|
||||
Path::new("/dev/mtd0")
|
||||
);
|
||||
required.name = "ramfs".to_owned();
|
||||
assert_eq!(
|
||||
resolve_mtd_target(&observed, &required),
|
||||
Err(MtdMatchError::NameMismatch)
|
||||
);
|
||||
required.name = observed[0].name.clone();
|
||||
required.size_bytes -= 1;
|
||||
assert_eq!(
|
||||
resolve_mtd_target(&observed, &required),
|
||||
Err(MtdMatchError::SizeMismatch)
|
||||
);
|
||||
required.size_bytes = observed[0].size_bytes;
|
||||
required.erase_bytes *= 2;
|
||||
assert_eq!(
|
||||
resolve_mtd_target(&observed, &required),
|
||||
Err(MtdMatchError::EraseMismatch)
|
||||
);
|
||||
required.index = 2;
|
||||
assert_eq!(
|
||||
resolve_mtd_target(&observed, &required),
|
||||
Err(MtdMatchError::MissingIndex)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user