Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7fd9c8eee3 | ||
|
|
f302bbbb24 | ||
|
|
b22b494ede | ||
|
|
6c23ce847d | ||
|
|
6a466a611f | ||
|
|
1300d7e372 | ||
|
|
66e4f3d47a |
@@ -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:
|
||||
|
||||
+11
-14
@@ -20,6 +20,13 @@ def bench_results(path):
|
||||
return {name: float(ns) for name, ns in re.findall(r"BENCH (\w+) ([0-9.]+) ns/op", text)}
|
||||
|
||||
|
||||
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):
|
||||
value = float(number)
|
||||
units = ("", "K", "M", "G")
|
||||
@@ -34,19 +41,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 +59,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()
|
||||
@@ -90,7 +85,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 = {
|
||||
|
||||
+9
-6
@@ -3,6 +3,7 @@
|
||||
"""Regression checks for measured benchmark and quality badges."""
|
||||
|
||||
import sys
|
||||
import json
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
import unittest
|
||||
@@ -12,12 +13,14 @@ from metrics import bench_results, 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:
|
||||
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//! BM1362 frame encoding from captured command and job traffic.
|
||||
//!
|
||||
//! These pure encoders do not initialize a chain. PLL fields, voltage, and
|
||||
//! model-specific operating points still require silicon-backed validation.
|
||||
|
||||
use crate::bm13xx::{crc16, crc5};
|
||||
|
||||
pub const JOB_BYTES: usize = 88;
|
||||
pub const CHIP_ADDRESS_STEP: u8 = 2;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct ModelGeometry {
|
||||
chips_per_chain: u8,
|
||||
ticket_mask: u8,
|
||||
}
|
||||
|
||||
pub const S19J_PRO: ModelGeometry = ModelGeometry {
|
||||
chips_per_chain: 126,
|
||||
ticket_mask: 0x7f,
|
||||
};
|
||||
pub const S19J: ModelGeometry = ModelGeometry {
|
||||
chips_per_chain: 108,
|
||||
ticket_mask: 0x7f,
|
||||
};
|
||||
pub const S19_88: ModelGeometry = ModelGeometry {
|
||||
chips_per_chain: 88,
|
||||
ticket_mask: 0x3f,
|
||||
};
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
fn short_command(code: u8, address: u8, register: u8) -> [u8; 7] {
|
||||
let mut frame = [0x55, 0xaa, code, 0x05, address, register, 0];
|
||||
frame[6] = crc5(&frame[2..6]);
|
||||
frame
|
||||
}
|
||||
|
||||
fn long_command(code: u8, address: u8, register: u8, value: u32) -> [u8; 11] {
|
||||
let mut frame = [0_u8; 11];
|
||||
frame[..6].copy_from_slice(&[0x55, 0xaa, code, 0x09, address, register]);
|
||||
frame[6..10].copy_from_slice(&value.to_be_bytes());
|
||||
frame[10] = crc5(&frame[2..10]);
|
||||
frame
|
||||
}
|
||||
|
||||
pub fn chain_inactive() -> [u8; 7] {
|
||||
short_command(0x53, 0, 0)
|
||||
}
|
||||
|
||||
pub fn set_chip_address(address: u8) -> [u8; 7] {
|
||||
short_command(0x40, address, 0)
|
||||
}
|
||||
|
||||
pub fn read_register(address: u8, register: u8) -> [u8; 7] {
|
||||
short_command(0x42, address, register)
|
||||
}
|
||||
|
||||
pub fn read_register_all(register: u8) -> [u8; 7] {
|
||||
short_command(0x52, 0, register)
|
||||
}
|
||||
|
||||
pub fn write_register(address: u8, register: u8, value: u32) -> [u8; 11] {
|
||||
long_command(0x41, address, register, value)
|
||||
}
|
||||
|
||||
pub fn write_register_all(register: u8, value: u32) -> [u8; 11] {
|
||||
long_command(0x51, 0, register, value)
|
||||
}
|
||||
|
||||
/// Raw header fields in BM1362 wire order. The caller owns work-ID allocation
|
||||
/// and must supply roots and hashes in the order established by its capture.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct Job {
|
||||
pub work_id: u8,
|
||||
pub num_midstates: u8,
|
||||
pub start_nonce: u32,
|
||||
pub nbits: u32,
|
||||
pub ntime: u32,
|
||||
pub merkle_root: [u8; 32],
|
||||
pub previous_hash: [u8; 32],
|
||||
pub version: u32,
|
||||
}
|
||||
|
||||
/// Encode the 88-byte SEND_JOB form with the true-length tag observed on wire.
|
||||
pub fn encode_job(job: &Job) -> [u8; JOB_BYTES] {
|
||||
let mut frame = [0_u8; JOB_BYTES];
|
||||
frame[..6].copy_from_slice(&[0x55, 0xaa, 0x21, 0x56, job.work_id, job.num_midstates]);
|
||||
frame[6..10].copy_from_slice(&job.start_nonce.to_le_bytes());
|
||||
frame[10..14].copy_from_slice(&job.nbits.to_le_bytes());
|
||||
frame[14..18].copy_from_slice(&job.ntime.to_le_bytes());
|
||||
frame[18..50].copy_from_slice(&job.merkle_root);
|
||||
frame[50..82].copy_from_slice(&job.previous_hash);
|
||||
frame[82..86].copy_from_slice(&job.version.to_le_bytes());
|
||||
let checksum = crc16(&frame[2..86]);
|
||||
frame[86..88].copy_from_slice(&checksum.to_be_bytes());
|
||||
frame
|
||||
}
|
||||
|
||||
/// 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 || baud > 3_125_000 {
|
||||
return None;
|
||||
}
|
||||
let divider = 25_000_000_u64 / (8 * u64::from(baud));
|
||||
u8::try_from(divider - 1).ok()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn captured_command_frames() {
|
||||
assert_eq!(chain_inactive(), [0x55, 0xaa, 0x53, 5, 0, 0, 3]);
|
||||
assert_eq!(set_chip_address(0), [0x55, 0xaa, 0x40, 5, 0, 0, 0x1c]);
|
||||
assert_eq!(set_chip_address(8), [0x55, 0xaa, 0x40, 5, 8, 0, 7]);
|
||||
assert_eq!(read_register_all(0), [0x55, 0xaa, 0x52, 5, 0, 0, 0x0a]);
|
||||
assert_eq!(
|
||||
read_register(0x40, 0x1c),
|
||||
[0x55, 0xaa, 0x42, 5, 0x40, 0x1c, 0x0b]
|
||||
);
|
||||
assert_eq!(
|
||||
write_register_all(0x80, 0),
|
||||
[0x55, 0xaa, 0x51, 9, 0, 0x80, 0, 0, 0, 0, 0x1c]
|
||||
);
|
||||
assert_eq!(
|
||||
write_register(0x40, 0x18, 0x7a31),
|
||||
[0x55, 0xaa, 0x41, 9, 0x40, 0x18, 0, 0, 0x7a, 0x31, 0x11]
|
||||
);
|
||||
}
|
||||
|
||||
#[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));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn job_frame_layout() {
|
||||
let mut merkle_root = [0_u8; 32];
|
||||
let mut previous_hash = [0_u8; 32];
|
||||
for index in 0..32 {
|
||||
merkle_root[index] = 0xa0 + index as u8;
|
||||
previous_hash[index] = 0x10 + index as u8;
|
||||
}
|
||||
let frame = encode_job(&Job {
|
||||
work_id: 8,
|
||||
num_midstates: 1,
|
||||
start_nonce: 0,
|
||||
nbits: 0x1a1f_2c34,
|
||||
ntime: 0x5e9b_3cd4,
|
||||
merkle_root,
|
||||
previous_hash,
|
||||
version: 0x2000_0000,
|
||||
});
|
||||
assert_eq!(
|
||||
&frame[..18],
|
||||
&[
|
||||
0x55, 0xaa, 0x21, 0x56, 8, 1, 0, 0, 0, 0, 0x34, 0x2c, 0x1f, 0x1a, 0xd4, 0x3c, 0x9b,
|
||||
0x5e
|
||||
]
|
||||
);
|
||||
assert_eq!(&frame[18..50], &merkle_root);
|
||||
assert_eq!(&frame[50..82], &previous_hash);
|
||||
assert_eq!(&frame[82..86], &[0, 0, 0, 0x20]);
|
||||
assert_eq!(&frame[86..88], &[0xc2, 0xbd]);
|
||||
assert_eq!(
|
||||
u16::from_be_bytes([frame[86], frame[87]]),
|
||||
crc16(&frame[2..86])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn baud_dividers() {
|
||||
assert_eq!(bt8d_for_baud(0), None);
|
||||
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(3_125_001), None);
|
||||
assert_eq!(bt8d_for_baud(u32::MAX), None);
|
||||
}
|
||||
}
|
||||
+3
-27
@@ -4,6 +4,9 @@
|
||||
pub const WORK_BYTES: usize = 88;
|
||||
pub const REPORT_BYTES: usize = 11;
|
||||
|
||||
pub use crate::bm13xx::crc16;
|
||||
use crate::bm13xx::crc5;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct NonceReport {
|
||||
pub nonce: u32,
|
||||
@@ -20,33 +23,6 @@ pub enum ReportError {
|
||||
Checksum,
|
||||
}
|
||||
|
||||
pub fn crc16(bytes: &[u8]) -> u16 {
|
||||
let mut value = 0xffff_u16;
|
||||
for byte in bytes {
|
||||
value ^= u16::from(*byte) << 8;
|
||||
for _ in 0..8 {
|
||||
value = if value & 0x8000 != 0 {
|
||||
(value << 1) ^ 0x1021
|
||||
} else {
|
||||
value << 1
|
||||
};
|
||||
}
|
||||
}
|
||||
value
|
||||
}
|
||||
|
||||
fn crc5(bytes: &[u8]) -> u8 {
|
||||
let mut value = 0x1f_u8;
|
||||
for byte in bytes {
|
||||
for shift in (0..8).rev() {
|
||||
let feedback = ((value >> 4) ^ (byte >> shift)) & 1;
|
||||
value = ((value << 1) | feedback) & 0x1f;
|
||||
value ^= feedback << 2;
|
||||
}
|
||||
}
|
||||
value
|
||||
}
|
||||
|
||||
fn reverse_words(input: &[u8]) -> [u8; 32] {
|
||||
let mut output = [0_u8; 32];
|
||||
for index in 0..8 {
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//! Shared BM13xx wire checksums. This module never generates mining nonces.
|
||||
|
||||
/// CRC5 used by command and nonce-report frames, initial value 0x1f.
|
||||
pub fn crc5(bytes: &[u8]) -> u8 {
|
||||
let mut state = 0x1f_u8;
|
||||
for &byte in bytes {
|
||||
for bit in (0..8).rev() {
|
||||
let feedback = ((state >> 4) ^ (byte >> bit)) & 1;
|
||||
state = ((state << 1) | feedback) & 0x1f;
|
||||
state ^= feedback << 2;
|
||||
}
|
||||
}
|
||||
state
|
||||
}
|
||||
|
||||
/// CRC16-CCITT-FALSE used by 88-byte SEND_JOB frames.
|
||||
pub fn crc16(bytes: &[u8]) -> u16 {
|
||||
let mut state = 0xffff_u16;
|
||||
for &byte in bytes {
|
||||
state ^= u16::from(byte) << 8;
|
||||
for _ in 0..8 {
|
||||
state = if state & 0x8000 == 0 {
|
||||
state << 1
|
||||
} else {
|
||||
(state << 1) ^ 0x1021
|
||||
};
|
||||
}
|
||||
}
|
||||
state
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn captured_command_checksums() {
|
||||
let vectors: &[(&[u8], u8)] = &[
|
||||
(&[0x53, 0x05, 0, 0], 0x03),
|
||||
(&[0x40, 0x05, 0, 0], 0x1c),
|
||||
(&[0x52, 0x05, 0, 0], 0x0a),
|
||||
(&[0x40, 0x05, 8, 0], 0x07),
|
||||
(&[0x42, 0x05, 0x40, 0x1c], 0x0b),
|
||||
(&[0x51, 0x09, 0, 0x80, 0, 0, 0, 0], 0x1c),
|
||||
(&[0x41, 0x09, 0x40, 0x18, 0, 0, 0x7a, 0x31], 0x11),
|
||||
];
|
||||
for &(body, expected) in vectors {
|
||||
assert_eq!(crc5(body), expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn standard_crc16_check() {
|
||||
assert_eq!(crc16(b"123456789"), 0x29b1);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,9 @@
|
||||
//! An entry in the target matrix is a development obligation, not a claim that
|
||||
//! the pairing already mines. Hardware backends are supplied by SDK images.
|
||||
|
||||
pub mod bm1362;
|
||||
pub mod bm1366;
|
||||
pub mod bm13xx;
|
||||
pub mod difficulty;
|
||||
pub mod hal_wire;
|
||||
pub mod miner;
|
||||
|
||||
+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