Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d54bd6473f |
Generated
+1
@@ -75,6 +75,7 @@ dependencies = [
|
|||||||
"alkane-artifacts",
|
"alkane-artifacts",
|
||||||
"alkane-core",
|
"alkane-core",
|
||||||
"sha2",
|
"sha2",
|
||||||
|
"tempfile",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
+13
-12
@@ -2,10 +2,11 @@
|
|||||||
# Measure line coverage from BOTH the unit tests AND the headless UI self-test.
|
# Measure line coverage from BOTH the unit tests AND the headless UI self-test.
|
||||||
#
|
#
|
||||||
# The self-test (ALKANE_SELFTEST=1) builds the real wxWidgets table, renders every
|
# The self-test (ALKANE_SELFTEST=1) builds the real wxWidgets table, renders every
|
||||||
# fixture through the real widgets, and checks each cell against the model -- it
|
# fixture through the real widgets, and checks each cell against the model.
|
||||||
# exercises most of ui.rs. Because it runs as a separate binary invocation, a plain
|
# It covers the fixture-rendering path, while interactive event handlers need
|
||||||
# `cargo llvm-cov` (which only runs the #[test]s) never counts it, so ui.rs shows
|
# separate tests. Because it runs as a separate binary invocation, a plain
|
||||||
# ~4% even though it is integration-tested. This combines both runs' coverage.
|
# `cargo llvm-cov` (which only runs the #[test]s) never counts it. This
|
||||||
|
# combines both runs' coverage.
|
||||||
#
|
#
|
||||||
# Usage: ci/coverage.sh [extra `cargo llvm-cov report` args, e.g. --summary-only]
|
# Usage: ci/coverage.sh [extra `cargo llvm-cov report` args, e.g. --summary-only]
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@@ -16,8 +17,12 @@ export WX_RS_WXCONFIG="${WX_RS_WXCONFIG:-$HOME/.cache/wx-3.3.3-linux/bin/wx-conf
|
|||||||
# default; override with CARGO_LLVM_COV_FLAGS if you need something else.
|
# default; override with CARGO_LLVM_COV_FLAGS if you need something else.
|
||||||
read -ra CARGO_FLAGS <<<"${CARGO_LLVM_COV_FLAGS:---offline}"
|
read -ra CARGO_FLAGS <<<"${CARGO_LLVM_COV_FLAGS:---offline}"
|
||||||
|
|
||||||
# A display for the self-test's real widgets.
|
# A display is required for the self-test; skipping it would publish an
|
||||||
need_xvfb() { command -v xvfb-run >/dev/null 2>&1; }
|
# incomplete coverage number as if the measured test set had run.
|
||||||
|
if ! command -v xvfb-run >/dev/null 2>&1; then
|
||||||
|
echo "coverage.sh: xvfb-run is required for the UI self-test" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
cargo llvm-cov clean --workspace
|
cargo llvm-cov clean --workspace
|
||||||
|
|
||||||
@@ -27,12 +32,8 @@ cargo llvm-cov --no-report "${CARGO_FLAGS[@]}" \
|
|||||||
-p alkane-artifacts -p alkane-flash -p alkane-cli
|
-p alkane-artifacts -p alkane-flash -p alkane-cli
|
||||||
|
|
||||||
# 2. Headless UI self-test, under the same instrumentation, its coverage appended.
|
# 2. Headless UI self-test, under the same instrumentation, its coverage appended.
|
||||||
if need_xvfb; then
|
xvfb-run -a env GDK_BACKEND=x11 ALKANE_SELFTEST=1 \
|
||||||
xvfb-run -a env GDK_BACKEND=x11 ALKANE_SELFTEST=1 \
|
cargo llvm-cov run --no-report "${CARGO_FLAGS[@]}" --bin alkane-toolkit
|
||||||
cargo llvm-cov run --no-report "${CARGO_FLAGS[@]}" --bin alkane-toolkit
|
|
||||||
else
|
|
||||||
echo "coverage.sh: xvfb-run not found; skipping the self-test run (unit tests only)" >&2
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 3. Merged report, our source only (vendored asic-rs + the patched wx-rs bridge
|
# 3. Merged report, our source only (vendored asic-rs + the patched wx-rs bridge
|
||||||
# are out of scope).
|
# are out of scope).
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ alkane-core = { path = "../alkane-core" }
|
|||||||
alkane-artifacts = { path = "../alkane-artifacts" }
|
alkane-artifacts = { path = "../alkane-artifacts" }
|
||||||
sha2.workspace = true
|
sha2.workspace = true
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
|
tempfile = "3"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
use alkane_artifacts::VerifiedArtifact;
|
use alkane_artifacts::VerifiedArtifact;
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use std::io::{Read, Seek, SeekFrom};
|
use std::io::{Read, Seek, SeekFrom, Write};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
pub struct PartitionSpec {
|
pub struct PartitionSpec {
|
||||||
@@ -90,6 +90,34 @@ fn digest_bytes(hex: &str) -> Result<[u8; 32], FlashError> {
|
|||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn stage_verified_artifact(
|
||||||
|
artifact: &mut VerifiedArtifact,
|
||||||
|
size: u64,
|
||||||
|
expected: [u8; 32],
|
||||||
|
) -> Result<std::fs::File, FlashError> {
|
||||||
|
let mut staged = tempfile::tempfile().map_err(|e| FlashError::ArtifactIo(e.to_string()))?;
|
||||||
|
artifact
|
||||||
|
.reader()
|
||||||
|
.seek(SeekFrom::Start(0))
|
||||||
|
.map_err(|e| FlashError::ArtifactIo(e.to_string()))?;
|
||||||
|
let mut source = DigestReader {
|
||||||
|
inner: artifact.reader(),
|
||||||
|
remaining: size,
|
||||||
|
digest: Sha256::new(),
|
||||||
|
};
|
||||||
|
std::io::copy(&mut source, &mut staged).map_err(|e| FlashError::ArtifactIo(e.to_string()))?;
|
||||||
|
if source.remaining != 0 || <[u8; 32]>::from(source.digest.finalize()) != expected {
|
||||||
|
return Err(FlashError::ArtifactChanged);
|
||||||
|
}
|
||||||
|
staged
|
||||||
|
.flush()
|
||||||
|
.map_err(|e| FlashError::ArtifactIo(e.to_string()))?;
|
||||||
|
staged
|
||||||
|
.seek(SeekFrom::Start(0))
|
||||||
|
.map_err(|e| FlashError::ArtifactIo(e.to_string()))?;
|
||||||
|
Ok(staged)
|
||||||
|
}
|
||||||
|
|
||||||
struct DigestReader<'a> {
|
struct DigestReader<'a> {
|
||||||
inner: &'a mut dyn Read,
|
inner: &'a mut dyn Read,
|
||||||
remaining: u64,
|
remaining: u64,
|
||||||
@@ -145,6 +173,10 @@ pub fn write_verified<W: Writer, R: IndependentReadback>(
|
|||||||
artifact
|
artifact
|
||||||
.revalidate()
|
.revalidate()
|
||||||
.map_err(|_| FlashError::ArtifactChanged)?;
|
.map_err(|_| FlashError::ArtifactChanged)?;
|
||||||
|
let expected = digest_bytes(&artifact.record().sha256)?;
|
||||||
|
// The source path may change while backup or transport I/O runs. Copy and
|
||||||
|
// verify it before any device write; the anonymous file is removed on drop.
|
||||||
|
let mut staged = stage_verified_artifact(artifact, size, expected)?;
|
||||||
let backup = writer
|
let backup = writer
|
||||||
.backup(partition)
|
.backup(partition)
|
||||||
.map_err(|e| FlashError::Write(e.to_string()))?;
|
.map_err(|e| FlashError::Write(e.to_string()))?;
|
||||||
@@ -154,13 +186,8 @@ pub fn write_verified<W: Writer, R: IndependentReadback>(
|
|||||||
{
|
{
|
||||||
return Err(FlashError::BackupIncomplete);
|
return Err(FlashError::BackupIncomplete);
|
||||||
}
|
}
|
||||||
let expected = digest_bytes(&artifact.record().sha256)?;
|
|
||||||
artifact
|
|
||||||
.reader()
|
|
||||||
.seek(SeekFrom::Start(0))
|
|
||||||
.map_err(|e| FlashError::ArtifactIo(e.to_string()))?;
|
|
||||||
let mut stream = DigestReader {
|
let mut stream = DigestReader {
|
||||||
inner: artifact.reader(),
|
inner: &mut staged,
|
||||||
remaining: size,
|
remaining: size,
|
||||||
digest: Sha256::new(),
|
digest: Sha256::new(),
|
||||||
};
|
};
|
||||||
@@ -203,6 +230,7 @@ mod tests {
|
|||||||
max_read: Option<u64>,
|
max_read: Option<u64>,
|
||||||
writes: usize,
|
writes: usize,
|
||||||
contents: Vec<u8>,
|
contents: Vec<u8>,
|
||||||
|
mutate_source_on_write: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Writer for MockWriter {
|
impl Writer for MockWriter {
|
||||||
@@ -231,6 +259,9 @@ mod tests {
|
|||||||
_: u64,
|
_: u64,
|
||||||
) -> Result<(), Self::Error> {
|
) -> Result<(), Self::Error> {
|
||||||
self.writes += 1;
|
self.writes += 1;
|
||||||
|
if let Some(path) = &self.mutate_source_on_write {
|
||||||
|
std::fs::write(path, b"PK\x03\x04changed").map_err(|_| "mutation failed")?;
|
||||||
|
}
|
||||||
if let Some(limit) = self.max_read {
|
if let Some(limit) = self.max_read {
|
||||||
image
|
image
|
||||||
.take(limit)
|
.take(limit)
|
||||||
@@ -285,6 +316,7 @@ mod tests {
|
|||||||
max_read: None,
|
max_read: None,
|
||||||
writes: 0,
|
writes: 0,
|
||||||
contents: Vec::new(),
|
contents: Vec::new(),
|
||||||
|
mutate_source_on_write: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,4 +427,20 @@ mod tests {
|
|||||||
assert_eq!(writer.writes, 1);
|
assert_eq!(writer.writes, 1);
|
||||||
std::fs::remove_file(path).unwrap();
|
std::fs::remove_file(path).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn writes_verified_snapshot_when_source_changes_during_transport() {
|
||||||
|
let (path, mut image) = artifact("mutated-during-write");
|
||||||
|
let mut writer = writer();
|
||||||
|
writer.mutate_source_on_write = Some(path.clone());
|
||||||
|
let mut readback = MockReadback {
|
||||||
|
channel: "serial",
|
||||||
|
digest: digest_bytes(SHA).unwrap(),
|
||||||
|
};
|
||||||
|
let receipt = write_verified(&partition(), &mut image, &mut writer, &mut readback).unwrap();
|
||||||
|
assert_eq!(receipt.image_sha256, digest_bytes(SHA).unwrap());
|
||||||
|
assert_eq!(writer.contents, IMAGE);
|
||||||
|
assert_eq!(std::fs::read(&path).unwrap(), b"PK\x03\x04changed");
|
||||||
|
std::fs::remove_file(path).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user