adjust test

This commit is contained in:
Zeke Lu 2022-09-27 12:15:39 +08:00
parent d4592cb718
commit fb1fd51f6e
2 changed files with 24 additions and 22 deletions

View file

@ -47,25 +47,3 @@ func TestNames(t *testing.T) {
}
}
}
func TestNobitsSection(t *testing.T) {
const testdata = "testdata/gcc-amd64-linux-exec"
f, err := Open(testdata)
if err != nil {
t.Fatalf("could not read %s: %v", testdata, err)
}
defer f.Close()
bss := f.Section(".bss")
bssData, err := bss.Data()
if err != nil {
t.Fatalf("error reading .bss section: %v", err)
}
if g, w := uint64(len(bssData)), bss.Size; g != w {
t.Errorf(".bss section length mismatch: got %d, want %d", g, w)
}
for i := range bssData {
if bssData[i] != 0 {
t.Fatalf("unexpected non-zero byte at offset %d: %#x", i, bssData[i])
}
}
}

View file

@ -944,6 +944,30 @@ func TestNoSectionOverlaps(t *testing.T) {
}
}
func TestNobitsSection(t *testing.T) {
const testdata = "testdata/gcc-amd64-linux-exec"
f, err := Open(testdata)
if err != nil {
t.Fatalf("could not read %s: %v", testdata, err)
}
defer f.Close()
wantError := "unexpected read from SHT_NOBITS section"
bss := f.Section(".bss")
_, err = bss.Data()
if err == nil || err.Error() != wantError {
t.Fatalf("bss.Data() got error %q, want error %q", err, wantError)
}
r := bss.Open()
p := make([]byte, 1)
_, err = r.Read(p)
if err == nil || err.Error() != wantError {
t.Fatalf("r.Read(p) got error %q, want error %q", err, wantError)
}
}
// TestLargeNumberOfSections tests the case that a file has greater than or
// equal to 65280 (0xff00) sections.
func TestLargeNumberOfSections(t *testing.T) {