1
0
mirror of https://github.com/golang/go synced 2024-11-17 20:44:47 -07:00

added unit test

This commit is contained in:
Joe Sylve 2021-06-16 16:23:00 -05:00
parent c101b2e639
commit 5aa10d0491
3 changed files with 52 additions and 0 deletions

View File

@ -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

Binary file not shown.

View File

@ -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()
}
}
}