Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/uefi/meregion: add TestFindFPTSignature test case #444

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 TestFindFPTSignature(t *testing.T) {
var empty16 = make([]byte, 16)
var empty12 = make([]byte, 12)
var empty = make([]byte, 128)

var firstRow = append(MEFPTSignature, empty12...)

Check failure on line 68 in pkg/uefi/meregion_test.go

View workflow job for this annotation

GitHub Actions / lint (1.21, ubuntu-latest)

undefined: MEFPTSignature (typecheck)

Check failure on line 68 in pkg/uefi/meregion_test.go

View workflow job for this annotation

GitHub Actions / lint (1.22, ubuntu-latest)

undefined: MEFPTSignature (typecheck)
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", r, test.res)
}
if test.res == -1 && e == nil {
t.Errorf("expected error")
}
})
}
}
Loading