浏览代码

Fix tests

Isaac Woods 4 年之前
父节点
当前提交
221d09a981
共有 7 个文件被更改,包括 116 次插入40 次删除
  1. 4 4
      aml/src/name_object.rs
  2. 4 4
      aml/src/opcode.rs
  3. 3 3
      aml/src/parser.rs
  4. 4 4
      aml/src/pkg_length.rs
  5. 2 2
      aml/src/term_object.rs
  6. 79 3
      aml/src/test_utils.rs
  7. 20 20
      aml_tester/src/main.rs

+ 4 - 4
aml/src/name_object.rs

@@ -244,11 +244,11 @@ fn is_name_char(byte: u8) -> bool {
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::{parser::Parser, test_utils::*, AmlContext, AmlError, DebugVerbosity};
+    use crate::{parser::Parser, test_utils::*, AmlError};
 
     #[test]
     fn test_name_seg() {
-        let mut context = AmlContext::new(false, DebugVerbosity::None);
+        let mut context = crate::test_utils::make_test_context();
 
         check_ok!(
             name_seg().parse(&[b'A', b'F', b'3', b'Z'], &mut context),
@@ -270,7 +270,7 @@ mod tests {
 
     #[test]
     fn test_name_path() {
-        let mut context = AmlContext::new(false, DebugVerbosity::None);
+        let mut context = crate::test_utils::make_test_context();
 
         check_err!(name_path().parse(&[], &mut context), AmlError::UnexpectedEndOfStream, &[]);
         check_ok!(name_path().parse(&[0x00], &mut context), alloc::vec![], &[]);
@@ -288,7 +288,7 @@ mod tests {
 
     #[test]
     fn test_prefix_path() {
-        let mut context = AmlContext::new(false, DebugVerbosity::None);
+        let mut context = crate::test_utils::make_test_context();
 
         check_ok!(
             name_string().parse(&[b'^', b'A', b'B', b'C', b'D'], &mut context),

+ 4 - 4
aml/src/opcode.rs

@@ -92,18 +92,18 @@ where
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::{test_utils::*, AmlError, DebugVerbosity};
+    use crate::{test_utils::*, AmlError};
 
     #[test]
     fn empty() {
-        let mut context = AmlContext::new(false, DebugVerbosity::None);
+        let mut context = crate::test_utils::make_test_context();
         check_err!(opcode(NULL_NAME).parse(&[], &mut context), AmlError::UnexpectedEndOfStream, &[]);
         check_err!(ext_opcode(EXT_DEF_FIELD_OP).parse(&[], &mut context), AmlError::UnexpectedEndOfStream, &[]);
     }
 
     #[test]
     fn simple_opcodes() {
-        let mut context = AmlContext::new(false, DebugVerbosity::None);
+        let mut context = crate::test_utils::make_test_context();
         check_ok!(opcode(DEF_SCOPE_OP).parse(&[DEF_SCOPE_OP], &mut context), (), &[]);
         check_ok!(
             opcode(DEF_NAME_OP).parse(&[DEF_NAME_OP, 0x31, 0x55, 0xf3], &mut context),
@@ -114,7 +114,7 @@ mod tests {
 
     #[test]
     fn extended_opcodes() {
-        let mut context = AmlContext::new(false, DebugVerbosity::None);
+        let mut context = crate::test_utils::make_test_context();
         check_err!(
             ext_opcode(EXT_DEF_FIELD_OP).parse(&[EXT_DEF_FIELD_OP, EXT_DEF_FIELD_OP], &mut context),
             AmlError::WrongParser,

+ 3 - 3
aml/src/parser.rs

@@ -472,11 +472,11 @@ pub(crate) macro try_with_context($context: expr, $expr: expr) {
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::{test_utils::*, DebugVerbosity};
+    use crate::test_utils::*;
 
     #[test]
     fn test_take_n() {
-        let mut context = AmlContext::new(false, DebugVerbosity::None);
+        let mut context = make_test_context();
         check_err!(take_n(1).parse(&[], &mut context), AmlError::UnexpectedEndOfStream, &[]);
         check_err!(take_n(2).parse(&[0xf5], &mut context), AmlError::UnexpectedEndOfStream, &[0xf5]);
 
@@ -487,7 +487,7 @@ mod tests {
 
     #[test]
     fn test_take_ux() {
-        let mut context = AmlContext::new(false, DebugVerbosity::None);
+        let mut context = make_test_context();
         check_err!(take_u16().parse(&[0x34], &mut context), AmlError::UnexpectedEndOfStream, &[0x34]);
         check_ok!(take_u16().parse(&[0x34, 0x12], &mut context), 0x1234, &[]);
 

+ 4 - 4
aml/src/pkg_length.rs

@@ -91,10 +91,10 @@ where
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::{test_utils::*, AmlError, DebugVerbosity};
+    use crate::{test_utils::*, AmlError};
 
     fn test_correct_pkglength(stream: &[u8], expected_raw_length: u32, expected_leftover: &[u8]) {
-        let mut context = AmlContext::new(false, DebugVerbosity::None);
+        let mut context = make_test_context();
         check_ok!(
             pkg_length().parse(stream, &mut context),
             PkgLength::from_raw_length(stream, expected_raw_length),
@@ -104,7 +104,7 @@ mod tests {
 
     #[test]
     fn test_raw_pkg_length() {
-        let mut context = AmlContext::new(false, DebugVerbosity::None);
+        let mut context = make_test_context();
         check_ok!(raw_pkg_length().parse(&[0b01000101, 0x14], &mut context), 325, &[]);
         check_ok!(raw_pkg_length().parse(&[0b01000111, 0x14, 0x46], &mut context), 327, &[0x46]);
         check_ok!(raw_pkg_length().parse(&[0b10000111, 0x14, 0x46], &mut context), 287047, &[]);
@@ -112,7 +112,7 @@ mod tests {
 
     #[test]
     fn test_pkg_length() {
-        let mut context = AmlContext::new(false, DebugVerbosity::None);
+        let mut context = make_test_context();
         check_err!(pkg_length().parse(&[], &mut context), AmlError::UnexpectedEndOfStream, &[]);
         test_correct_pkglength(&[0x00], 0, &[]);
         test_correct_pkglength(&[0x05, 0xf5, 0x7f, 0x3e, 0x54, 0x03], 5, &[0xf5, 0x7f, 0x3e, 0x54, 0x03]);

+ 2 - 2
aml/src/term_object.rs

@@ -605,11 +605,11 @@ where
 #[cfg(test)]
 mod test {
     use super::*;
-    use crate::{test_utils::*, AmlContext, DebugVerbosity};
+    use crate::test_utils::*;
 
     #[test]
     fn test_computational_data() {
-        let mut context = AmlContext::new(false, DebugVerbosity::None);
+        let mut context = make_test_context();
         check_ok!(
             computational_data().parse(&[0x00, 0x34, 0x12], &mut context),
             AmlValue::Integer(0),

+ 79 - 3
aml/src/test_utils.rs

@@ -1,8 +1,84 @@
+use crate::{AmlContext, Handler};
+use alloc::boxed::Box;
+
+struct TestHandler;
+
+impl Handler for TestHandler {
+    fn read_u8(&self, _address: usize) -> u8 {
+        unimplemented!()
+    }
+    fn read_u16(&self, _address: usize) -> u16 {
+        unimplemented!()
+    }
+    fn read_u32(&self, _address: usize) -> u32 {
+        unimplemented!()
+    }
+    fn read_u64(&self, _address: usize) -> u64 {
+        unimplemented!()
+    }
+
+    fn write_u8(&mut self, _address: usize, _value: u8) {
+        unimplemented!()
+    }
+    fn write_u16(&mut self, _address: usize, _value: u16) {
+        unimplemented!()
+    }
+    fn write_u32(&mut self, _address: usize, _value: u32) {
+        unimplemented!()
+    }
+    fn write_u64(&mut self, _address: usize, _value: u64) {
+        unimplemented!()
+    }
+
+    fn read_io_u8(&self, _port: u16) -> u8 {
+        unimplemented!()
+    }
+    fn read_io_u16(&self, _port: u16) -> u16 {
+        unimplemented!()
+    }
+    fn read_io_u32(&self, _port: u16) -> u32 {
+        unimplemented!()
+    }
+
+    fn write_io_u8(&self, _port: u16, _value: u8) {
+        unimplemented!()
+    }
+    fn write_io_u16(&self, _port: u16, _value: u16) {
+        unimplemented!()
+    }
+    fn write_io_u32(&self, _port: u16, _value: u32) {
+        unimplemented!()
+    }
+
+    fn read_pci_u8(&self, _segment: u16, _bus: u8, device: u8, _function: u8, _offset: u16) -> u8 {
+        unimplemented!()
+    }
+    fn read_pci_u16(&self, _segment: u16, _bus: u8, device: u8, _function: u8, _offset: u16) -> u16 {
+        unimplemented!()
+    }
+    fn read_pci_u32(&self, _segment: u16, _bus: u8, device: u8, _function: u8, _offset: u16) -> u32 {
+        unimplemented!()
+    }
+    fn write_pci_u8(&self, _segment: u16, _bus: u8, device: u8, _function: u8, _offset: u16, _value: u8) {
+        unimplemented!()
+    }
+    fn write_pci_u16(&self, _segment: u16, _bus: u8, device: u8, _function: u8, _offset: u16, _value: u16) {
+        unimplemented!()
+    }
+    fn write_pci_u32(&self, _segment: u16, _bus: u8, device: u8, _function: u8, _offset: u16, _value: u32) {
+        unimplemented!()
+    }
+}
+
+pub(crate) fn make_test_context() -> AmlContext {
+    AmlContext::new(Box::new(TestHandler), false, crate::DebugVerbosity::None)
+}
+
 pub(crate) macro check_err($parse: expr, $error: pat, $remains: expr) {
     match $parse {
-        Ok(result) => panic!("Expected Err, got {:#?}", result),
+        Ok((remains, _, result)) => panic!("Expected Err, got {:#?}. Remaining = {:#x?}", result, remains),
         Err((remains, _, $error)) if *remains == *$remains => (),
-        Err((remains, _, $error)) => panic!("Correct error, incorrect stream returned: {:x?}", remains),
+        Err((remains, _, $error)) => panic!("Correct error, incorrect stream returned: {:#x?}", remains),
         Err((_, _, err)) => panic!("Got wrong error: {:?}", err),
     }
 }
@@ -13,7 +89,7 @@ pub(crate) macro check_ok($parse: expr, $expected: expr, $remains: expr) {
         Ok((remains, _, ref result)) if result == &$expected => {
             panic!("Correct result, incorrect slice returned: {:x?}", remains)
         }
-        Ok(result) => panic!("Successfully parsed Ok, but it was wrong: {:#?}", result),
+        Ok((_, _, ref result)) => panic!("Successfully parsed Ok, but it was wrong: {:#?}", result),
         Err((_, _, err)) => panic!("Expected Ok, got {:#?}", err),
     }
 }

+ 20 - 20
aml_tester/src/main.rs

@@ -141,68 +141,68 @@ impl log::Log for Logger {
 struct Handler;
 
 impl aml::Handler for Handler {
-    fn read_u8(&self, address: usize) -> u8 {
+    fn read_u8(&self, _address: usize) -> u8 {
         unimplemented!()
     }
-    fn read_u16(&self, address: usize) -> u16 {
+    fn read_u16(&self, _address: usize) -> u16 {
         unimplemented!()
     }
-    fn read_u32(&self, address: usize) -> u32 {
+    fn read_u32(&self, _address: usize) -> u32 {
         unimplemented!()
     }
-    fn read_u64(&self, address: usize) -> u64 {
+    fn read_u64(&self, _address: usize) -> u64 {
         unimplemented!()
     }
 
-    fn write_u8(&mut self, address: usize, value: u8) {
+    fn write_u8(&mut self, _address: usize, _value: u8) {
         unimplemented!()
     }
-    fn write_u16(&mut self, address: usize, value: u16) {
+    fn write_u16(&mut self, _address: usize, _value: u16) {
         unimplemented!()
     }
-    fn write_u32(&mut self, address: usize, value: u32) {
+    fn write_u32(&mut self, _address: usize, _value: u32) {
         unimplemented!()
     }
-    fn write_u64(&mut self, address: usize, value: u64) {
+    fn write_u64(&mut self, _address: usize, _value: u64) {
         unimplemented!()
     }
 
-    fn read_io_u8(&self, port: u16) -> u8 {
+    fn read_io_u8(&self, _port: u16) -> u8 {
         unimplemented!()
     }
-    fn read_io_u16(&self, port: u16) -> u16 {
+    fn read_io_u16(&self, _port: u16) -> u16 {
         unimplemented!()
     }
-    fn read_io_u32(&self, port: u16) -> u32 {
+    fn read_io_u32(&self, _port: u16) -> u32 {
         unimplemented!()
     }
 
-    fn write_io_u8(&self, port: u16, value: u8) {
+    fn write_io_u8(&self, _port: u16, _value: u8) {
         unimplemented!()
     }
-    fn write_io_u16(&self, port: u16, value: u16) {
+    fn write_io_u16(&self, _port: u16, _value: u16) {
         unimplemented!()
     }
-    fn write_io_u32(&self, port: u16, value: u32) {
+    fn write_io_u32(&self, _port: u16, _value: u32) {
         unimplemented!()
     }
 
-    fn read_pci_u8(&self, segment: u16, bus: u8, device: u8, function: u8, offset: u16) -> u8 {
+    fn read_pci_u8(&self, _segment: u16, _bus: u8, device: u8, _function: u8, _offset: u16) -> u8 {
         unimplemented!()
     }
-    fn read_pci_u16(&self, segment: u16, bus: u8, device: u8, function: u8, offset: u16) -> u16 {
+    fn read_pci_u16(&self, _segment: u16, _bus: u8, device: u8, _function: u8, _offset: u16) -> u16 {
         unimplemented!()
     }
-    fn read_pci_u32(&self, segment: u16, bus: u8, device: u8, function: u8, offset: u16) -> u32 {
+    fn read_pci_u32(&self, _segment: u16, _bus: u8, device: u8, _function: u8, _offset: u16) -> u32 {
         unimplemented!()
     }
-    fn write_pci_u8(&self, segment: u16, bus: u8, device: u8, function: u8, offset: u16, value: u8) {
+    fn write_pci_u8(&self, _segment: u16, _bus: u8, device: u8, _function: u8, _offset: u16, _value: u8) {
         unimplemented!()
     }
-    fn write_pci_u16(&self, segment: u16, bus: u8, device: u8, function: u8, offset: u16, value: u16) {
+    fn write_pci_u16(&self, _segment: u16, _bus: u8, device: u8, _function: u8, _offset: u16, _value: u16) {
         unimplemented!()
     }
-    fn write_pci_u32(&self, segment: u16, bus: u8, device: u8, function: u8, offset: u16, value: u32) {
+    fn write_pci_u32(&self, _segment: u16, _bus: u8, device: u8, _function: u8, _offset: u16, _value: u32) {
         unimplemented!()
     }
 }