Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52e6093011 | ||
|
|
7fd9c8eee3 | ||
|
|
f302bbbb24 | ||
|
|
b22b494ede | ||
|
|
6c23ce847d | ||
|
|
6a466a611f | ||
|
|
1300d7e372 |
@@ -5,6 +5,10 @@ on:
|
||||
workflows: [main-release-gate, next-build]
|
||||
types: [completed]
|
||||
|
||||
concurrency:
|
||||
group: alkane-os-completed-ci-badge
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: alkane-ci
|
||||
|
||||
@@ -33,7 +33,9 @@ jobs:
|
||||
- name: CI cleanup containment checks
|
||||
run: python3 ci/test-cleanup-generated.py
|
||||
- name: Quality
|
||||
run: cargo clippy --all-targets --locked -- -D warnings
|
||||
run: |
|
||||
cargo clippy --all-targets --locked -- -D warnings
|
||||
printf '{"format":true,"clippy_warnings_denied":true}\n' > quality-current.json
|
||||
- name: Build
|
||||
run: cargo build --release --locked
|
||||
- name: Unit and workflow tests
|
||||
@@ -67,12 +69,13 @@ jobs:
|
||||
run: |
|
||||
python3 ci/metrics.py --tests-output tests-current.txt \
|
||||
--tests-coverage coverage/tests.json --bench-output bench-current.txt \
|
||||
--bench-coverage coverage/bench.json
|
||||
--bench-coverage coverage/bench.json --quality-gate quality-current.json
|
||||
- uses: https://github.com/ChristopherHX/gitea-upload-artifact@81f940d004763f986ba3582c007fd842dd5cb0d7
|
||||
with:
|
||||
name: alkane-os-metrics
|
||||
path: |
|
||||
badges/metrics.json
|
||||
quality-current.json
|
||||
coverage/tests.json
|
||||
coverage/bench.json
|
||||
bench-current.txt
|
||||
|
||||
@@ -10,7 +10,7 @@ import sys
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
DIRECTORIES = ("target", "coverage", "dist", "bench-site")
|
||||
FILES = ("tests-current.txt", "bench-current.txt")
|
||||
FILES = ("tests-current.txt", "bench-current.txt", "quality-current.json")
|
||||
|
||||
|
||||
def cleanup() -> None:
|
||||
|
||||
+50
-21
@@ -4,11 +4,22 @@
|
||||
import argparse
|
||||
import html
|
||||
import json
|
||||
import math
|
||||
import pathlib
|
||||
import re
|
||||
import tomllib
|
||||
from bench_host import identity as benchmark_host
|
||||
|
||||
EXPECTED_BENCHES = frozenset({
|
||||
"target_matrix", "power_policy", "share_verification",
|
||||
"scrypt_share_verification", "bm1366_work_encoding", "bm1362_commands",
|
||||
"bm1362_job_encoding", "bm1366_report_decode", "stratum_header",
|
||||
"stratum_submission", "stratum_authorize_format", "stratum_notify_parse",
|
||||
"stratum_control_parse", "stratum_configure_parse", "difficulty_target",
|
||||
"stratum_job_issue", "bm1366_session_cycle",
|
||||
})
|
||||
BENCH_LINE = re.compile(r"\bBENCH ([A-Za-z0-9_]+) ([0-9]+(?:\.[0-9]+)?) ns/op\Z")
|
||||
|
||||
|
||||
def coverage(path):
|
||||
data = json.loads(pathlib.Path(path).read_text())
|
||||
@@ -16,8 +27,40 @@ def coverage(path):
|
||||
|
||||
|
||||
def bench_results(path):
|
||||
text = pathlib.Path(path).read_text()
|
||||
return {name: float(ns) for name, ns in re.findall(r"BENCH (\w+) ([0-9.]+) ns/op", text)}
|
||||
results = {}
|
||||
for line in pathlib.Path(path).read_text().splitlines():
|
||||
if "BENCH " not in line:
|
||||
continue
|
||||
match = BENCH_LINE.search(line)
|
||||
if match is None:
|
||||
raise ValueError("malformed microbenchmark result")
|
||||
name, value = match.groups()
|
||||
measurement = float(value)
|
||||
if name in results or not math.isfinite(measurement) or measurement <= 0:
|
||||
raise ValueError("duplicate or invalid microbenchmark result")
|
||||
results[name] = measurement
|
||||
return results
|
||||
|
||||
|
||||
def benchmark_delta(current, baseline):
|
||||
if set(current) != EXPECTED_BENCHES:
|
||||
raise ValueError("microbenchmark set differs from the declared suite")
|
||||
if not isinstance(baseline, dict) or not set(baseline).issubset(current):
|
||||
raise ValueError("baseline contains retired or invalid benchmarks")
|
||||
if any(not isinstance(value, (int, float)) or isinstance(value, bool)
|
||||
or not math.isfinite(value) or value <= 0 for value in baseline.values()):
|
||||
raise ValueError("baseline contains invalid measurements")
|
||||
if not baseline:
|
||||
return None
|
||||
return sum((baseline[name] - current[name]) / baseline[name]
|
||||
for name in baseline) / len(baseline) * 100
|
||||
|
||||
|
||||
def quality_grade(path):
|
||||
checks = json.loads(pathlib.Path(path).read_text())
|
||||
if checks != {"format": True, "clippy_warnings_denied": True}:
|
||||
raise ValueError("format and strict Clippy must pass before publishing quality")
|
||||
return "A"
|
||||
|
||||
|
||||
def compact(number):
|
||||
@@ -34,19 +77,6 @@ def compact(number):
|
||||
return number + units[index]
|
||||
|
||||
|
||||
def quality_grade(line_coverage):
|
||||
# Main CI reaches this publisher only after warnings-denied Clippy passes.
|
||||
if line_coverage >= 90:
|
||||
return "A"
|
||||
if line_coverage >= 80:
|
||||
return "B"
|
||||
if line_coverage >= 70:
|
||||
return "C"
|
||||
if line_coverage >= 60:
|
||||
return "D"
|
||||
return "F"
|
||||
|
||||
|
||||
def svg(label, value, color):
|
||||
label, value = html.escape(label), html.escape(value)
|
||||
lw, vw = 12 + 7 * len(label), 12 + 7 * len(value)
|
||||
@@ -65,6 +95,7 @@ def main():
|
||||
parser.add_argument("--tests-coverage", required=True)
|
||||
parser.add_argument("--bench-output", required=True)
|
||||
parser.add_argument("--bench-coverage", required=True)
|
||||
parser.add_argument("--quality-gate", required=True)
|
||||
parser.add_argument("--bench-baseline", default="badges/bench-baseline.json")
|
||||
args = parser.parse_args()
|
||||
test_output = pathlib.Path(args.tests_output).read_text()
|
||||
@@ -72,13 +103,9 @@ def main():
|
||||
if tests < 1:
|
||||
raise SystemExit("no passing tests parsed")
|
||||
current = bench_results(args.bench_output)
|
||||
if not current or any(value <= 0 for value in current.values()):
|
||||
raise SystemExit("microbenchmark result missing or zero")
|
||||
base_path = pathlib.Path(args.bench_baseline)
|
||||
baseline = json.loads(base_path.read_text()) if base_path.exists() else {}
|
||||
common = [name for name in current if name in baseline and baseline[name] > 0]
|
||||
delta = (sum((baseline[name] - current[name]) / baseline[name] for name in common)
|
||||
/ len(common) * 100) if common else None
|
||||
delta = benchmark_delta(current, baseline)
|
||||
line_coverage = coverage(args.tests_coverage)
|
||||
bench_coverage = coverage(args.bench_coverage)
|
||||
loc = sum(len(path.read_text().splitlines()) for parent in (pathlib.Path("src"), pathlib.Path("ci"))
|
||||
@@ -90,7 +117,9 @@ def main():
|
||||
"bench_ns_per_op": current, "bench_improvement_pct": delta,
|
||||
"bench_host": benchmark_host(),
|
||||
"lines_of_code": loc, "dependencies": dependencies,
|
||||
"code_quality": quality_grade(line_coverage), "license": "MIT"}
|
||||
"code_quality": quality_grade(args.quality_gate),
|
||||
"quality_scope": "main CI passed cargo fmt and warnings-denied Clippy on all targets",
|
||||
"license": "MIT"}
|
||||
pathlib.Path("badges").mkdir(exist_ok=True)
|
||||
pathlib.Path("badges/metrics.json").write_text(json.dumps(metrics, indent=2) + "\n")
|
||||
badges = {
|
||||
|
||||
+28
-8
@@ -3,29 +3,49 @@
|
||||
"""Regression checks for measured benchmark and quality badges."""
|
||||
|
||||
import sys
|
||||
import json
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
from metrics import bench_results, compact, quality_grade
|
||||
from metrics import EXPECTED_BENCHES, bench_results, benchmark_delta, compact, quality_grade
|
||||
|
||||
|
||||
class MetricTests(unittest.TestCase):
|
||||
def test_quality_grade_depends_on_measured_coverage(self):
|
||||
self.assertEqual(quality_grade(92), "A")
|
||||
self.assertEqual(quality_grade(88), "B")
|
||||
self.assertEqual(quality_grade(72), "C")
|
||||
self.assertEqual(quality_grade(65), "D")
|
||||
self.assertEqual(quality_grade(40), "F")
|
||||
def test_quality_requires_both_static_checks(self):
|
||||
with TemporaryDirectory() as directory:
|
||||
path = Path(directory) / "quality.json"
|
||||
path.write_text(json.dumps({"format": True, "clippy_warnings_denied": True}))
|
||||
self.assertEqual(quality_grade(path), "A")
|
||||
path.write_text(json.dumps({"format": True, "clippy_warnings_denied": False}))
|
||||
with self.assertRaises(ValueError):
|
||||
quality_grade(path)
|
||||
|
||||
def test_benchmark_parser_and_short_si_badge(self):
|
||||
with TemporaryDirectory() as directory:
|
||||
path = Path(directory) / "bench.txt"
|
||||
path.write_text("BENCH sha 42.125 ns/op\n")
|
||||
path.write_text("test bench_sha ... BENCH sha 42.125 ns/op\n")
|
||||
self.assertEqual(bench_results(path), {"sha": 42.125})
|
||||
path.write_text("BENCH sha 42.125 ns/op\nBENCH sha 40.000 ns/op\n")
|
||||
with self.assertRaisesRegex(ValueError, "duplicate"):
|
||||
bench_results(path)
|
||||
path.write_text("BENCH sha 42.125 ns/op\nBENCH broken nan ns/op\n")
|
||||
with self.assertRaisesRegex(ValueError, "malformed"):
|
||||
bench_results(path)
|
||||
self.assertEqual(compact(1234567), "1.23M")
|
||||
|
||||
def test_benchmark_suite_and_baseline_must_be_complete(self):
|
||||
current = {name: 10.0 for name in EXPECTED_BENCHES}
|
||||
self.assertIsNone(benchmark_delta(current, {}))
|
||||
self.assertEqual(benchmark_delta(current, {"target_matrix": 20.0}), 50.0)
|
||||
with self.assertRaisesRegex(ValueError, "declared suite"):
|
||||
benchmark_delta({"target_matrix": 10.0}, {})
|
||||
with self.assertRaisesRegex(ValueError, "retired"):
|
||||
benchmark_delta(current, {"removed_bench": 20.0})
|
||||
with self.assertRaisesRegex(ValueError, "invalid measurements"):
|
||||
benchmark_delta(current, {"target_matrix": float("inf")})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
+29
-7
@@ -11,8 +11,8 @@ pub const CHIP_ADDRESS_STEP: u8 = 2;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct ModelGeometry {
|
||||
pub chips_per_chain: u8,
|
||||
pub ticket_mask: u8,
|
||||
chips_per_chain: u8,
|
||||
ticket_mask: u8,
|
||||
}
|
||||
|
||||
pub const S19J_PRO: ModelGeometry = ModelGeometry {
|
||||
@@ -29,6 +29,24 @@ pub const S19_88: ModelGeometry = ModelGeometry {
|
||||
};
|
||||
|
||||
impl ModelGeometry {
|
||||
pub const fn new(chips_per_chain: u8, ticket_mask: u8) -> Option<Self> {
|
||||
if chips_per_chain == 0 || chips_per_chain > 128 {
|
||||
return None;
|
||||
}
|
||||
Some(Self {
|
||||
chips_per_chain,
|
||||
ticket_mask,
|
||||
})
|
||||
}
|
||||
|
||||
pub const fn chips_per_chain(self) -> u8 {
|
||||
self.chips_per_chain
|
||||
}
|
||||
|
||||
pub const fn ticket_mask(self) -> u8 {
|
||||
self.ticket_mask
|
||||
}
|
||||
|
||||
/// Addresses for an observed two-address-step enumeration walk.
|
||||
pub fn chip_addresses(self) -> impl Iterator<Item = u8> {
|
||||
(0..self.chips_per_chain).map(|index| index * CHIP_ADDRESS_STEP)
|
||||
@@ -105,13 +123,10 @@ pub fn encode_job(job: &Job) -> [u8; JOB_BYTES] {
|
||||
/// BT8D for a 25 MHz input clock with BCLK_SEL=0. A model must still choose
|
||||
/// the actual target baud and confirm switching on silicon.
|
||||
pub fn bt8d_for_baud(baud: u32) -> Option<u8> {
|
||||
if baud == 0 {
|
||||
if baud == 0 || baud > 3_125_000 {
|
||||
return None;
|
||||
}
|
||||
let divider = 25_000_000_u64 / (8 * u64::from(baud));
|
||||
if divider == 0 {
|
||||
return Some(0);
|
||||
}
|
||||
u8::try_from(divider - 1).ok()
|
||||
}
|
||||
|
||||
@@ -141,6 +156,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn model_address_limits() {
|
||||
assert_eq!(ModelGeometry::new(0, 0), None);
|
||||
assert_eq!(ModelGeometry::new(129, 0), None);
|
||||
assert_eq!(
|
||||
ModelGeometry::new(128, 0).unwrap().chip_addresses().last(),
|
||||
Some(0xfe)
|
||||
);
|
||||
assert_eq!(S19J_PRO.chip_addresses().last(), Some(0xfa));
|
||||
assert_eq!(S19J.chip_addresses().last(), Some(0xd6));
|
||||
assert_eq!(S19_88.chip_addresses().last(), Some(0xae));
|
||||
@@ -187,6 +208,7 @@ mod tests {
|
||||
assert_eq!(bt8d_for_baud(3_000_000), Some(0));
|
||||
assert_eq!(bt8d_for_baud(115_200), Some(26));
|
||||
assert_eq!(bt8d_for_baud(1), None);
|
||||
assert_eq!(bt8d_for_baud(u32::MAX), Some(0));
|
||||
assert_eq!(bt8d_for_baud(3_125_001), None);
|
||||
assert_eq!(bt8d_for_baud(u32::MAX), None);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-2
@@ -120,7 +120,11 @@ impl StratumWire {
|
||||
return Err(WireError::LineTooLong);
|
||||
}
|
||||
let line = self.buffered.drain(..=end).collect();
|
||||
self.partial_started = (!self.buffered.is_empty()).then(Instant::now);
|
||||
self.partial_started = if self.buffered.is_empty() {
|
||||
None
|
||||
} else {
|
||||
self.partial_started.or_else(|| Some(Instant::now()))
|
||||
};
|
||||
return Ok(line);
|
||||
}
|
||||
if self.buffered.len() >= MAX_POOL_LINE_BYTES {
|
||||
@@ -221,7 +225,11 @@ impl StratumWire {
|
||||
return Err(WireError::LineTooLong);
|
||||
}
|
||||
let line = self.buffered.drain(..=end).collect();
|
||||
self.partial_started = (!self.buffered.is_empty()).then(Instant::now);
|
||||
self.partial_started = if self.buffered.is_empty() {
|
||||
None
|
||||
} else {
|
||||
self.partial_started.or_else(|| Some(Instant::now()))
|
||||
};
|
||||
return Ok(Some(line));
|
||||
}
|
||||
if self.buffered.len() >= MAX_POOL_LINE_BYTES {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
use alkane_os::bm1362::{
|
||||
bt8d_for_baud, chain_inactive, encode_job, read_register, read_register_all, set_chip_address,
|
||||
write_register, write_register_all, Job, S19J_PRO,
|
||||
};
|
||||
use alkane_os::bm1366::{decode_nonce_report, encode_work};
|
||||
use alkane_os::difficulty::PoolDifficulty;
|
||||
use alkane_os::miner::Bm1366Miner;
|
||||
@@ -94,6 +98,39 @@ fn bench_bm1366_work_encoding() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "microbenchmark"]
|
||||
fn bench_bm1362_commands() {
|
||||
measure("bm1362_commands", 20_000, || {
|
||||
black_box(chain_inactive());
|
||||
black_box(set_chip_address(black_box(8)));
|
||||
black_box(read_register(black_box(0x40), 0x1c));
|
||||
black_box(read_register_all(0));
|
||||
black_box(write_register(black_box(0x40), 0x18, 0x7a31));
|
||||
black_box(write_register_all(0x80, 0));
|
||||
black_box(bt8d_for_baud(black_box(115_200)));
|
||||
black_box(S19J_PRO.chip_addresses().last());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "microbenchmark"]
|
||||
fn bench_bm1362_job_encoding() {
|
||||
let job = Job {
|
||||
work_id: 8,
|
||||
num_midstates: 1,
|
||||
start_nonce: 0,
|
||||
nbits: 0x1a1f_2c34,
|
||||
ntime: 0x5e9b_3cd4,
|
||||
merkle_root: [0xa5; 32],
|
||||
previous_hash: [0x5a; 32],
|
||||
version: 0x2000_0000,
|
||||
};
|
||||
measure("bm1362_job_encoding", 20_000, || {
|
||||
black_box(encode_job(black_box(&job)));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "microbenchmark"]
|
||||
fn bench_bm1366_report_decode() {
|
||||
|
||||
@@ -90,6 +90,30 @@ fn trickled_pool_line_hits_the_absolute_deadline() {
|
||||
server.join().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buffered_complete_lines_do_not_extend_a_partial_line_deadline() {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let address = listener.local_addr().unwrap();
|
||||
let server = thread::spawn(move || {
|
||||
let (mut stream, _) = listener.accept().unwrap();
|
||||
stream.write_all(b"first\nsecond\nunfinished").unwrap();
|
||||
thread::sleep(Duration::from_secs(3));
|
||||
});
|
||||
let mut wire = StratumWire::connect(address, Duration::from_secs(2)).unwrap();
|
||||
let first = loop {
|
||||
if let Some(line) = wire.try_read_line().unwrap() {
|
||||
break line;
|
||||
}
|
||||
};
|
||||
assert_eq!(first, b"first\n");
|
||||
thread::sleep(Duration::from_millis(1300));
|
||||
assert_eq!(wire.try_read_line().unwrap(), Some(b"second\n".to_vec()));
|
||||
thread::sleep(Duration::from_millis(800));
|
||||
assert!(matches!(wire.try_read_line(), Err(WireError::Timeout)));
|
||||
assert!(wire.is_closed());
|
||||
server.join().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn idle_timeout_keeps_connection_available_for_later_messages() {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
|
||||
Reference in New Issue
Block a user