-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathelf_interface_test.go
More file actions
68 lines (65 loc) · 1.69 KB
/
elf_interface_test.go
File metadata and controls
68 lines (65 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package elf_reader
import (
"testing"
)
func TestELFInterface(t *testing.T) {
testFile := func(filename string, expectedSectionCount uint16) {
contents := fileBytes(filename, t)
f, e := ParseELFFile(contents)
if e != nil {
t.Errorf("Failed parsing %s: %s\n", filename, e)
return
}
if f.GetSectionCount() != expectedSectionCount {
t.Errorf("Expected %d sections in %s, got %d\n",
expectedSectionCount, filename, f.GetSectionCount())
return
}
}
testFile("test_data/sleep_arm32", 30)
testFile("test_data/sleep_amd64", 29)
}
func TestGetBssContents(t *testing.T) {
testFile := func(filename string) {
contents := fileBytes(filename, t)
f, e := ParseELFFile(contents)
if e != nil {
t.Errorf("Error loading %s: %s\n", filename, e)
return
}
bssIdx := uint16(0xffff)
for i := uint16(1); i < f.GetSectionCount(); i++ {
name, e := f.GetSectionName(i)
if e != nil {
t.Errorf("Error getting name of section %d in %s: %s\n", i,
filename, e)
return
}
if name == ".bss" {
bssIdx = i
break
}
}
if bssIdx == 0xffff {
t.Errorf("Couldn't find index of .bss section in %s", filename)
return
}
_, e = f.GetSectionContent(bssIdx)
if e == nil {
t.Errorf("Didn't get expected error when reading content of " +
".bss section\n")
return
}
_, ok := e.(UninitializedDataSectionError)
if !ok {
t.Errorf("The error when reading a .bss section wasn't an " +
"UninitializedDataSectionError.\n")
return
}
t.Logf("Got expected error when reading .bss section content: %s\n", e)
}
testFile("test_data/bash32_freebsd")
testFile("test_data/sleep_amd64")
testFile("test_data/sleep_arm32")
testFile("test_data/ld-linux_arm32.so")
}