mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 10:49:34 +02:00
BitFields - updated tests
This commit is contained in:
parent
a6d692e19d
commit
54ac180e1a
4 changed files with 63 additions and 15 deletions
|
@ -140,7 +140,29 @@ public class UnionDataTypeTest extends AbstractGTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBitFieldUnionLength() throws Exception {
|
public void testBitFieldUnion() throws Exception {
|
||||||
|
|
||||||
|
int cnt = union.getNumComponents();
|
||||||
|
for (int i = 0; i < cnt; i++) {
|
||||||
|
union.delete(0);
|
||||||
|
}
|
||||||
|
// NOTE: bitOffset ignored for union
|
||||||
|
union.insertBitField(0, 4, 12, IntegerDataType.dataType, 2, "bf1", "bf1Comment");
|
||||||
|
union.insert(0, ShortDataType.dataType);
|
||||||
|
|
||||||
|
//@formatter:off
|
||||||
|
CompositeTestUtils.assertExpectedComposite(this, "/TestUnion\n" +
|
||||||
|
"Unaligned\n" +
|
||||||
|
"Union TestUnion {\n" +
|
||||||
|
" 0 short 2 null \"\"\n" +
|
||||||
|
" 0 int:2(0) 1 bf1 \"bf1Comment\"\n" +
|
||||||
|
"}\n" +
|
||||||
|
"Size = 2 Actual Alignment = 1", union);
|
||||||
|
//@formatter:on
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAlignedBitFieldUnion() throws Exception {
|
||||||
|
|
||||||
int cnt = union.getNumComponents();
|
int cnt = union.getNumComponents();
|
||||||
for (int i = 0; i < cnt; i++) {
|
for (int i = 0; i < cnt; i++) {
|
||||||
|
@ -148,16 +170,17 @@ public class UnionDataTypeTest extends AbstractGTest {
|
||||||
}
|
}
|
||||||
union.insertBitField(0, 4, 12, IntegerDataType.dataType, 2, "bf1", "bf1Comment");
|
union.insertBitField(0, 4, 12, IntegerDataType.dataType, 2, "bf1", "bf1Comment");
|
||||||
union.insert(0, ShortDataType.dataType);
|
union.insert(0, ShortDataType.dataType);
|
||||||
|
union.setInternallyAligned(true);
|
||||||
|
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
CompositeTestUtils.assertExpectedComposite(this, "/TestUnion\n" +
|
CompositeTestUtils.assertExpectedComposite(this, "/TestUnion\n" +
|
||||||
"Unaligned\n" +
|
"Aligned\n" +
|
||||||
"Union TestUnion {\n" +
|
"Union TestUnion {\n" +
|
||||||
" 0 short 2 null \"\"\n" +
|
" 0 short 2 null \"\"\n" +
|
||||||
" 1 byte:2(4) 1 bf1 \"bf1Comment\"\n" +
|
" 0 int:2(0) 1 bf1 \"bf1Comment\"\n" +
|
||||||
"}\n" +
|
"}\n" +
|
||||||
"Size = 4 Actual Alignment = 1", union);
|
"Size = 4 Actual Alignment = 4", union);
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -203,8 +203,8 @@ public interface Composite extends DataType {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a new bitfield at the specified ordinal position in this composite.
|
* Inserts a new bitfield at the specified ordinal position in this composite.
|
||||||
* Within an aligned composites the specified byteWidth and bitOffset will be ignored
|
* Within aligned composites and unions the specified byteWidth and bitOffset will be
|
||||||
* while bitOffset is always ignored for unions.
|
* ignored.
|
||||||
* The component length will be computed based upon the specified parameters and will
|
* The component length will be computed based upon the specified parameters and will
|
||||||
* be reduced from byteWidth to its minimal size for the new component.
|
* be reduced from byteWidth to its minimal size for the new component.
|
||||||
* <p>
|
* <p>
|
||||||
|
|
|
@ -39,6 +39,7 @@ public class StructureDBTest extends AbstractGTest {
|
||||||
dataMgr = new StandAloneDataTypeManager("dummyDTM");
|
dataMgr = new StandAloneDataTypeManager("dummyDTM");
|
||||||
|
|
||||||
// default data organization is little-endian
|
// default data organization is little-endian
|
||||||
|
// default BitFieldPackingImpl uses gcc conventions with type alignment enabled
|
||||||
|
|
||||||
dataMgr.startTransaction("Test");
|
dataMgr.startTransaction("Test");
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ public class UnionDBTest extends AbstractGTest {
|
||||||
dataMgr = new StandAloneDataTypeManager("dummydataMgr");
|
dataMgr = new StandAloneDataTypeManager("dummydataMgr");
|
||||||
|
|
||||||
// default data organization is little-endian
|
// default data organization is little-endian
|
||||||
|
// default BitFieldPackingImpl uses gcc conventions
|
||||||
|
|
||||||
dataMgr.startTransaction("Test");
|
dataMgr.startTransaction("Test");
|
||||||
|
|
||||||
|
@ -156,12 +157,13 @@ public class UnionDBTest extends AbstractGTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBitFieldUnionLength() throws Exception {
|
public void testBitFieldUnion() throws Exception {
|
||||||
|
|
||||||
int cnt = union.getNumComponents();
|
int cnt = union.getNumComponents();
|
||||||
for (int i = 0; i < cnt; i++) {
|
for (int i = 0; i < cnt; i++) {
|
||||||
union.delete(0);
|
union.delete(0);
|
||||||
}
|
}
|
||||||
|
// NOTE: bitOffset ignored for union
|
||||||
union.insertBitField(0, 4, 12, IntegerDataType.dataType, 2, "bf1", "bf1Comment");
|
union.insertBitField(0, 4, 12, IntegerDataType.dataType, 2, "bf1", "bf1Comment");
|
||||||
union.insert(0, ShortDataType.dataType);
|
union.insert(0, ShortDataType.dataType);
|
||||||
|
|
||||||
|
@ -170,9 +172,31 @@ public class UnionDBTest extends AbstractGTest {
|
||||||
"Unaligned\n" +
|
"Unaligned\n" +
|
||||||
"Union TestUnion {\n" +
|
"Union TestUnion {\n" +
|
||||||
" 0 short 2 null \"\"\n" +
|
" 0 short 2 null \"\"\n" +
|
||||||
" 1 byte:2(4) 1 bf1 \"bf1Comment\"\n" +
|
" 0 int:2(0) 1 bf1 \"bf1Comment\"\n" +
|
||||||
"}\n" +
|
"}\n" +
|
||||||
"Size = 4 Actual Alignment = 1", union);
|
"Size = 2 Actual Alignment = 1", union);
|
||||||
|
//@formatter:on
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAlignedBitFieldUnion() throws Exception {
|
||||||
|
|
||||||
|
int cnt = union.getNumComponents();
|
||||||
|
for (int i = 0; i < cnt; i++) {
|
||||||
|
union.delete(0);
|
||||||
|
}
|
||||||
|
union.insertBitField(0, 4, 12, IntegerDataType.dataType, 2, "bf1", "bf1Comment");
|
||||||
|
union.insert(0, ShortDataType.dataType);
|
||||||
|
union.setInternallyAligned(true);
|
||||||
|
|
||||||
|
//@formatter:off
|
||||||
|
CompositeTestUtils.assertExpectedComposite(this, "/TestUnion\n" +
|
||||||
|
"Aligned\n" +
|
||||||
|
"Union TestUnion {\n" +
|
||||||
|
" 0 short 2 null \"\"\n" +
|
||||||
|
" 0 int:2(0) 1 bf1 \"bf1Comment\"\n" +
|
||||||
|
"}\n" +
|
||||||
|
"Size = 4 Actual Alignment = 4", union);
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue