Skip to content

Commit

Permalink
Improve test checks - more failures
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Young <sean@mess.org>
  • Loading branch information
seanyoung committed May 4, 2024
1 parent 6ab552c commit ba41680
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion irp/src/build_bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ impl<'a> Builder<'a> {
self.decoder_state_ty,
self.decoder_state,
e.offset as u32,
name,
&format!("{name}_ptr"),
)
.unwrap(),
e.value.unwrap(),
Expand Down
10 changes: 7 additions & 3 deletions irp/tests/bpf_decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ fn decode_all() {

let mut decodes = bpf_decode(&dfa, &options, &protocol.name, &msg);

let mut ok = true;
// if nothing decoded, we fail to decode
let mut ok = !decodes.is_empty();

while let Some(code) = decodes.pop() {
let mut received = code;
Expand Down Expand Up @@ -160,7 +161,7 @@ fn decode_all() {
failing_protocols.len()
);

assert!((52..=61).contains(&fails));
assert_eq!(failing_protocols.len(), 39);
}

fn bpf_decode(dfa: &DFA, options: &Options, name: &str, message: &Message) -> Vec<u64> {
Expand Down Expand Up @@ -250,7 +251,10 @@ fn bpf_decode(dfa: &DFA, options: &Options, name: &str, message: &Message) -> Ve
)
};

println!("executing {raw} {vars}");
println!(
"executing {}{raw} {vars}",
if i.is_even() { '-' } else { '+' }
);

let ret = vm.execute_program(mbuff, &context.sample).unwrap();
assert_eq!(ret, 0);
Expand Down
14 changes: 11 additions & 3 deletions irp/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use irp::{Decoder, Event, InfraredData, Irp, Message, Options, Protocol, Vartabl
use irptransmogrifier::{create_jvm, IrpTransmogrifierRender};
use itertools::Itertools;
use rand::Rng;
use std::{collections::HashMap, path::PathBuf};
use std::{
collections::{HashMap, HashSet},
path::PathBuf,
};

#[test]
fn test() {
Expand Down Expand Up @@ -423,16 +426,17 @@ fn compare_encode_to_transmogrifier() {

#[test]
fn decode_all() {
let protocols = Protocol::parse(&PathBuf::from(
let mut protocols = Protocol::parse(&PathBuf::from(
"tests/IrpTransmogrifier/src/main/resources/IrpProtocols.xml",
))
.unwrap();

let mut total_tests = 0;
let mut fails = 0;
let mut failed_protocols: HashSet<&str> = HashSet::new();
let mut rng = rand::thread_rng();

for mut protocol in protocols {
for protocol in &mut protocols {
println!("trying {}", protocol.name);

if protocol.name == "NEC-Shirriff" {
Expand Down Expand Up @@ -496,6 +500,7 @@ fn decode_all() {
let mut decodes = Vec::new();

for data in InfraredData::from_u32_slice(&msg.raw) {
// TODO: fix DFA decoding here
decoder.nfa_input(data, &nfa, |ev, res| decodes.push((ev, res)));
}

Expand Down Expand Up @@ -538,6 +543,8 @@ fn decode_all() {

if params == res {
ok = true;
} else {
failed_protocols.insert(&protocol.name);
}
}

Expand All @@ -563,6 +570,7 @@ fn decode_all() {
}

println!("tests: {total_tests} fails: {fails}");
println!("Failed protocols: {failed_protocols:?}");

assert_eq!(fails, 0);
}
Expand Down

0 comments on commit ba41680

Please sign in to comment.