1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 type fileTest
struct {
15 sections
[]*SectionHeader
18 var fileTests
= []fileTest
{
20 "testdata/386-plan9-exec",
21 FileHeader
{Magic386
, 0x324, 0x14, 4, 0x1000, 32},
23 {"text", 0x4c5f, 0x20},
24 {"data", 0x94c, 0x4c7f},
25 {"syms", 0x2c2b, 0x55cb},
26 {"spsz", 0x0, 0x81f6},
27 {"pcsz", 0xf7a, 0x81f6},
31 "testdata/amd64-plan9-exec",
32 FileHeader
{MagicAMD64
, 0x618, 0x13, 8, 0x200000, 40},
34 {"text", 0x4213, 0x28},
35 {"data", 0xa80, 0x423b},
36 {"syms", 0x2c8c, 0x4cbb},
37 {"spsz", 0x0, 0x7947},
38 {"pcsz", 0xca0, 0x7947},
43 func TestOpen(t
*testing
.T
) {
44 for i
:= range fileTests
{
47 f
, err
:= Open(tt
.file
)
52 if !reflect
.DeepEqual(f
.FileHeader
, tt
.hdr
) {
53 t
.Errorf("open %s:\n\thave %#v\n\twant %#v\n", tt
.file
, f
.FileHeader
, tt
.hdr
)
57 for i
, sh
:= range f
.Sections
{
58 if i
>= len(tt
.sections
) {
61 have
:= &sh
.SectionHeader
62 want
:= tt
.sections
[i
]
63 if !reflect
.DeepEqual(have
, want
) {
64 t
.Errorf("open %s, section %d:\n\thave %#v\n\twant %#v\n", tt
.file
, i
, have
, want
)
67 tn
:= len(tt
.sections
)
70 t
.Errorf("open %s: len(Sections) = %d, want %d", tt
.file
, fn
, tn
)
75 func TestOpenFailure(t
*testing
.T
) {
76 filename
:= "file.go" // not a Plan 9 a.out file
77 _
, err
:= Open(filename
) // don't crash
79 t
.Errorf("open %s: succeeded unexpectedly", filename
)