Blob Blame History Raw
From 31c8914bb530bc89ec8cda045b2e4d6537d6b750 Mon Sep 17 00:00:00 2001
From: Philip Craig <philipjcraig@gmail.com>
Date: Tue, 2 Jan 2018 12:02:46 +1000
Subject: [PATCH] Fix tests for 32 bit builds

---
 src/abbrev.rs |  3 ++-
 src/cfi.rs    |  2 ++
 src/op.rs     |  7 ++++---
 src/parser.rs |  1 +
 src/unit.rs   | 31 ++++++++++++++++++++++++++++++-
 5 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/src/abbrev.rs b/src/abbrev.rs
index 6ecc30d..da493a1 100644
--- a/src/abbrev.rs
+++ b/src/abbrev.rs
@@ -393,7 +393,8 @@ pub mod tests {
     use endianity::{EndianBuf, LittleEndian};
     use parser::Error;
     use self::test_assembler::Section;
-    use std::u64;
+    #[cfg(target_pointer_width = "32")]
+    use std::u32;
     use test_util::GimliSectionMethods;
 
     pub trait AbbrevSectionMethods {
diff --git a/src/cfi.rs b/src/cfi.rs
index ec2d0b7..4320646 100644
--- a/src/cfi.rs
+++ b/src/cfi.rs
@@ -6048,6 +6048,7 @@ mod tests {
     }
 
     #[test]
+    #[cfg(target_pointer_width = "64")]
     fn size_of_unwind_ctx() {
         use std::mem;
         assert_eq!(
@@ -6059,6 +6060,7 @@ mod tests {
     }
 
     #[test]
+    #[cfg(target_pointer_width = "64")]
     fn size_of_register_rule_map() {
         use std::mem;
         assert_eq!(
diff --git a/src/op.rs b/src/op.rs
index ab0f711..0eb30ea 100644
--- a/src/op.rs
+++ b/src/op.rs
@@ -1788,8 +1788,9 @@ mod tests {
     use leb128;
     use parser::{Error, Format, Result};
     use self::test_assembler::{Endian, Section};
-    use unit::{DebugInfoOffset, UnitOffset};
+    use std::usize;
     use test_util::GimliSectionMethods;
+    use unit::{DebugInfoOffset, UnitOffset};
 
     #[test]
     fn test_compute_pc() {
@@ -1801,7 +1802,7 @@ mod tests {
         assert_eq!(compute_pc(ebuf, ebuf, 0), Ok(*ebuf));
         assert_eq!(
             compute_pc(ebuf, ebuf, -1),
-            Err(Error::BadBranchTarget(-1i64 as u64))
+            Err(Error::BadBranchTarget(usize::MAX as u64))
         );
         assert_eq!(compute_pc(ebuf, ebuf, 5), Ok(ebuf.range_from(5..)));
         assert_eq!(
@@ -2119,7 +2120,7 @@ mod tests {
             let input = [opcode.0, 0xfc, 0xff];
             check_op_parse_failure(
                 &input[..],
-                Error::BadBranchTarget(!0u64),
+                Error::BadBranchTarget(usize::MAX as u64),
                 ADDRESS_SIZE,
                 FORMAT,
             );
diff --git a/src/parser.rs b/src/parser.rs
index 2512d1f..0df4d94 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -618,6 +618,7 @@ mod tests {
         let section = Section::with_endian(Endian::Little).L64(0x0123456789abcdef);
         let buf = section.get_contents().unwrap();
 
+        let input = &mut EndianBuf::new(&buf, LittleEndian);
         match input.read_offset(Format::Dwarf64) {
             Err(Error::UnsupportedOffset) => assert!(true),
             otherwise => panic!("Unexpected result: {:?}", otherwise),
diff --git a/src/unit.rs b/src/unit.rs
index 50f9bab..6167188 100644
--- a/src/unit.rs
+++ b/src/unit.rs
@@ -3244,6 +3244,35 @@ mod tests {
         };
     }
 
+    #[test]
+    fn test_parse_type_unit_header_32_ok() {
+        let expected_rest = &[1, 2, 3, 4, 5, 6, 7, 8, 9];
+        let mut expected_unit = TypeUnitHeader {
+            header: UnitHeader {
+                unit_length: 0,
+                version: 4,
+                debug_abbrev_offset: DebugAbbrevOffset(0x08070605),
+                address_size: 8,
+                format: Format::Dwarf32,
+                entries_buf: EndianBuf::new(expected_rest, LittleEndian),
+            },
+            offset: DebugTypesOffset(0),
+            type_signature: DebugTypeSignature(0xdeadbeefdeadbeef),
+            type_offset: UnitOffset(0x78563412),
+        };
+        let section = Section::with_endian(Endian::Little)
+            .type_unit(&mut expected_unit)
+            .append_bytes(expected_rest);
+        let buf = section.get_contents().unwrap();
+        let rest = &mut EndianBuf::new(&buf, LittleEndian);
+
+        assert_eq!(
+            parse_type_unit_header(rest, DebugTypesOffset(0)),
+            Ok(expected_unit)
+        );
+        assert_eq!(*rest, EndianBuf::new(expected_rest, LittleEndian));
+    }
+
     #[test]
     #[cfg(target_pointer_width = "64")]
     fn test_parse_type_unit_header_64_ok() {
@@ -3284,7 +3313,6 @@ mod tests {
     }
 
     #[test]
-    #[cfg(target_pointer_width = "64")]
     fn test_attribute_value() {
         let mut unit = test_parse_attribute_unit_default();
         let endian = unit.entries_buf.endian();
@@ -3324,6 +3352,7 @@ mod tests {
                 AttributeValue::Data4(([4, 3, 2, 1], endian)),
                 AttributeValue::Udata(0x01020304),
             ),
+            #[cfg(target_pointer_width = "64")]
             (
                 2,
                 constants::DW_AT_data_member_location,
-- 
2.15.1