mirror of
https://github.com/golang/go
synced 2024-11-17 20:44:47 -07:00
added unit test
This commit is contained in:
parent
c101b2e639
commit
5aa10d0491
1
src/debug/dwarf/testdata/typedef.c
vendored
1
src/debug/dwarf/testdata/typedef.c
vendored
@ -8,6 +8,7 @@ gcc -gdwarf-2 -m64 -c typedef.c && gcc -gdwarf-2 -m64 -o typedef.elf typedef.o
|
|||||||
|
|
||||||
OS X Mach-O:
|
OS X Mach-O:
|
||||||
gcc -gdwarf-2 -m64 -c typedef.c -o typedef.macho
|
gcc -gdwarf-2 -m64 -c typedef.c -o typedef.macho
|
||||||
|
gcc -gdwarf-4 -m64 -c typedef.c -o typedef.macho4
|
||||||
*/
|
*/
|
||||||
#include <complex.h>
|
#include <complex.h>
|
||||||
|
|
||||||
|
BIN
src/debug/dwarf/testdata/typedef.macho4
vendored
Normal file
BIN
src/debug/dwarf/testdata/typedef.macho4
vendored
Normal file
Binary file not shown.
@ -228,3 +228,54 @@ func TestUnsupportedTypes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBitOffsetsELF(t *testing.T) { testBitOffsets(t, elfData(t, "testdata/typedef.elf")) }
|
||||||
|
|
||||||
|
func TestBitOffsetsMachO(t *testing.T) {
|
||||||
|
testBitOffsets(t, machoData(t, "testdata/typedef.macho"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBitOffsetsMachO4(t *testing.T) {
|
||||||
|
testBitOffsets(t, machoData(t, "testdata/typedef.macho4"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBitOffsetsELFDwarf4(t *testing.T) {
|
||||||
|
testBitOffsets(t, elfData(t, "testdata/typedef.elf4"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testBitOffsets(t *testing.T, d *Data) {
|
||||||
|
r := d.Reader()
|
||||||
|
for {
|
||||||
|
e, err := r.Next()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("r.Next:", err)
|
||||||
|
}
|
||||||
|
if e == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if e.Tag == TagStructType {
|
||||||
|
typ, err := d.Type(e.Offset)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("d.Type:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t1 := typ.(*StructType)
|
||||||
|
|
||||||
|
for _, field := range t1.Field {
|
||||||
|
// We're only testing for bitfields
|
||||||
|
if field.BitSize == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure BitOffset is not zero
|
||||||
|
if field.BitOffset == 0 {
|
||||||
|
t.Errorf("bit offset of field %s in %s %s is not set", field.Name, t1.Kind, t1.StructName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if e.Tag != TagCompileUnit {
|
||||||
|
r.SkipChildren()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user