Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

Commit

Permalink
Merge pull request #191 from bgamari/ioreg-fixes
Browse files Browse the repository at this point in the history
A few ioreg! fixes
  • Loading branch information
bgamari committed Oct 19, 2014
2 parents 837496c + f2f46b3 commit c0e15b5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ioreg/builder/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'a> Iterator<RegOrPadding<'a>> for PaddedRegsIterator<'a> {
let ref reg = self.sorted_regs[self.index];
if reg.offset > self.last_offset {
let pad_length = reg.offset - self.last_offset;
self.last_offset = reg.offset + reg.size();
self.last_offset = reg.offset;
Some(Pad(pad_length))
} else {
self.index += 1;
Expand Down
34 changes: 34 additions & 0 deletions src/ioreg/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,38 @@ mod test {
assert_eq!(get_value(&test, 0), 0x1 | 0x3<<8)
}
)

ioregs!(GAP_TEST = {
0x0 => reg32 reg1 {
0..31 => field,
}
0x10 => reg32 reg2 {
0..31 => field,
}
0x14 => reg32 reg3 {
0..31 => field,
}
0x20 => reg32 reg4 {
0..31 => field,
}
})

describe!(
before_each {
let test: GAP_TEST = zeroed_safe();
let base = &test as *const GAP_TEST;
}
it "has zero base offset" {
let addr = &test.reg1 as *const GAP_TEST_reg1;
assert_eq!(addr.to_uint() - base.to_uint(), 0x0)
}
it "computes the correct first gap" {
let addr = &test.reg2 as *const GAP_TEST_reg2;
assert_eq!(addr.to_uint() - base.to_uint(), 0x10)
}
it "computes the correct second gap" {
let addr = &test.reg4 as *const GAP_TEST_reg4;
assert_eq!(addr.to_uint() - base.to_uint(), 0x20)
}
)
}

0 comments on commit c0e15b5

Please sign in to comment.