Skip to content

Commit

Permalink
pkg/uefi/meregion: add TestFindFPTSignature test case
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Maslowski <[email protected]>
  • Loading branch information
orangecms committed Sep 29, 2024
1 parent dd2c9be commit 4ad1bbf
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/uefi/meregion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,35 @@ func TestMEName_UnmarshalText(t *testing.T) {
})
}
}

func TestFindFPTSignature(t *testing.T) {
var empty16 = make([]byte, 16)
var empty12 = make([]byte, 12)
var empty = make([]byte, 128)

var firstRow = append(append(MEFPTSignature, empty12...), empty16...)
var secondRow = append(empty16, firstRow...)
var elsewhere = append(empty, firstRow...)

var tests = []struct {
name string
blob []byte
res int
}{
{"beginning", firstRow, 4},
{"2nd row", secondRow, 20},
{"elsewhere", elsewhere, 132},
{"nowhere", empty, -1},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
r, e := FindMEDescriptor(test.blob)
if r != test.res {
t.Errorf("got position %d want %d (%q)", r, test.res, e)
}
if test.res == -1 && e == nil {
t.Errorf("expected error")
}
})
}
}

0 comments on commit 4ad1bbf

Please sign in to comment.