gitee.com/mirrors_u-root/u-root@v7.0.0+incompatible/pkg/uefivars/boot/efiDppACPI_test.go (about) 1 // Copyright 2020 the u-root 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 // SPDX-License-Identifier: BSD-3-Clause 6 // 7 8 package boot 9 10 import ( 11 "testing" 12 ) 13 14 //func ParseDppAcpiExDevPath(h EfiDevicePathProtocolHdr, b []byte) (*DppAcpiExDevPath, error) 15 func TestParseDppAcpiExDevPath(t *testing.T) { 16 in := []byte{ 17 0, 0, 0, 1, 18 0, 0, 0, 2, 19 0, 0, 0, 3, 20 } 21 //not sure what's supposed to go into these fields, so use made-up values 22 in = append(in, cstr("HIDSTR")...) 23 in = append(in, cstr("UIDSTR")...) 24 in = append(in, cstr("CIDSTR")...) 25 hdr := EfiDevicePathProtocolHdr{ 26 ProtoType: 2, 27 ProtoSubType: 2, 28 Length: uint16(len(in) + 4), 29 } 30 31 p, err := ParseDppAcpiExDevPath(hdr, in) 32 if err != nil { 33 t.Error(err) 34 } else { 35 want := "ACPI_EX(0x00000001,0x00000002,0x00000003,HIDSTR,UIDSTR,CIDSTR)" 36 got := p.String() 37 if got != want { 38 t.Errorf("want %s, got %s", want, got) 39 } 40 gotp := p.ProtoSubTypeStr() 41 wantp := "Expanded Device Path" 42 if gotp != wantp { 43 t.Errorf("want %s, got %s", wantp, gotp) 44 } 45 } 46 } 47 48 func cstr(s string) []byte { return append([]byte(s), 0) } 49 50 //func ParseDppAcpiDevPath(h EfiDevicePathProtocolHdr, b []byte) (*DppAcpiDevPath, error) 51 func TestParseDppAcpiDevPath(t *testing.T) { 52 in := []byte{ 53 0, 0, 0, 1, 54 0, 0, 0, 2, 55 } 56 hdr := EfiDevicePathProtocolHdr{ 57 ProtoType: 2, 58 ProtoSubType: 4, 59 Length: uint16(len(in) + 4), 60 } 61 p, err := ParseDppAcpiDevPath(hdr, in) 62 if err != nil { 63 t.Error(err) 64 } else { 65 want := "ACPI(0x00000001,0x00000002)" 66 got := p.String() 67 if got != want { 68 t.Errorf("want %s, got %s", want, got) 69 } 70 gotp := p.ProtoSubTypeStr() 71 wantp := "NVDIMM" 72 if gotp != wantp { 73 t.Errorf("want %s, got %s", wantp, gotp) 74 } 75 } 76 }