Browse Source

AML: Implement tests for DefPackage parsing

Mark Poliakov 1 year ago
parent
commit
9d2fa982f8
2 changed files with 42 additions and 0 deletions
  1. 38 0
      aml/src/term_object.rs
  2. 4 0
      aml/src/test_utils.rs

+ 38 - 0
aml/src/term_object.rs

@@ -995,6 +995,44 @@ mod test {
     use super::*;
     use crate::test_utils::*;
 
+    #[test]
+    fn test_package() {
+        let mut context = make_test_context();
+
+        // The tests also check that DefPackage consumes no more input than required
+        // Empty DefPackage
+        check_ok_value!(
+            def_package().parse(&[0x12, 0x02, 0x00, 0x12, 0x34], &mut context),
+            AmlValue::Package(Vec::new()),
+            &[0x12, 0x34]
+        );
+
+        // DefPackage where NumElements == package_content.len()
+        check_ok_value!(
+            def_package()
+                .parse(&[0x12, 0x09, 0x04, 0x01, 0x0A, 0x02, 0x0A, 0x03, 0x0A, 0x04, 0x12, 0x34], &mut context),
+            AmlValue::Package(alloc::vec![
+                AmlValue::Integer(1),
+                AmlValue::Integer(2),
+                AmlValue::Integer(3),
+                AmlValue::Integer(4)
+            ]),
+            &[0x12, 0x34]
+        );
+
+        // DefPackage where NumElements > package_content.len()
+        check_ok_value!(
+            def_package().parse(&[0x012, 0x05, 0x04, 0x01, 0x0A, 0x02, 0x12, 0x34], &mut context),
+            AmlValue::Package(alloc::vec![
+                AmlValue::Integer(1),
+                AmlValue::Integer(2),
+                AmlValue::Uninitialized,
+                AmlValue::Uninitialized,
+            ]),
+            &[0x12, 0x34]
+        );
+    }
+
     #[test]
     fn test_computational_data() {
         let mut context = make_test_context();

+ 4 - 0
aml/src/test_utils.rs

@@ -119,6 +119,10 @@ pub(crate) fn crudely_cmp_values(a: &AmlValue, b: &AmlValue) -> bool {
     use crate::value::MethodCode;
 
     match a {
+        AmlValue::Uninitialized => match b {
+            AmlValue::Uninitialized => true,
+            _ => false,
+        },
         AmlValue::Boolean(a) => match b {
             AmlValue::Boolean(b) => a == b,
             _ => false,