github.com/linuxboot/fiano@v1.2.0/pkg/intel/me/me_test.go (about) 1 // Copyright 2021 the LinuxBoot 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. 4 5 package me 6 7 import ( 8 "bytes" 9 "errors" 10 "fmt" 11 "testing" 12 ) 13 14 var ( 15 validLegacyHeaderPadding = []byte{ 16 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 17 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 18 } 19 validME = []byte{ 20 0x24, 0x46, 0x50, 0x54, 0x02, 0x00, 0x00, 0x00, 21 0x20, 0x01, 0x20, 0x30, 0x00, 0x01, 0x01, 0x01, 22 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 23 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 24 // first entry 25 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 26 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 27 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 28 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 29 // second entry 30 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 31 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 32 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 33 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 34 } 35 invalidMEEntryNumber = []byte{ 36 0x24, 0x46, 0x50, 0x54, 0x07, 0x00, 0x00, 0x00, 37 0x20, 0x01, 0x20, 0x30, 0x00, 0x01, 0x01, 0x01, 38 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 39 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 40 // first entry 41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 42 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 // second entry 46 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 47 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 49 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 50 } 51 ) 52 53 func TestParseIntelME(t *testing.T) { 54 for _, tt := range []struct { 55 name string 56 data []byte 57 wantErr error 58 }{ 59 { 60 name: "Test Lagacy ME", 61 data: append(validLegacyHeaderPadding, validME...), 62 }, 63 { 64 name: "Test ME", 65 data: validME, 66 }, 67 { 68 name: "Invalid Entry number", 69 data: invalidMEEntryNumber, 70 wantErr: errors.New("EOF"), 71 }, 72 } { 73 t.Run(tt.name, func(t *testing.T) { 74 _, gotErr := ParseIntelME(bytes.NewReader(tt.data)) 75 if gotErrorString, wantErrorString := fmt.Sprint(gotErr), fmt.Sprint(tt.wantErr); gotErrorString != wantErrorString { 76 t.Errorf("ParseIntelME() got err %q; want err %q", 77 gotErrorString, 78 wantErrorString) 79 } 80 }) 81 } 82 }