github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/smbios/smbios_test.go (about) 1 // Copyright 2016-2021 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 package smbios 6 7 import ( 8 "fmt" 9 "testing" 10 11 "github.com/mvdan/u-root-coreutils/pkg/memio" 12 ) 13 14 func TestSMBIOSBaseEFI(t *testing.T) { 15 systabPath = "testdata/smbios3_systab" 16 base, _, err := SMBIOSBase() 17 if err != nil { 18 t.Fatal(err) 19 } 20 21 var want int64 = 0x12345678 22 23 if base != want { 24 t.Errorf("SMBIOSBase(): 0x%x, want 0x%x", base, want) 25 } 26 } 27 28 func TestSMBIOSBaseLegacy(t *testing.T) { 29 tmpBuf = []byte{0, '_', 'M', 'S', '_', 0, 0, '_', 'S', 'M', '_', 0, 0, 0, 0, 0} 30 systabPath = "testdata/systab_NOT_FOUND" 31 defer func(old func(base int64, uintn memio.UintN) error) { memioRead = old }(memioRead) 32 memioRead = func(base int64, uintn memio.UintN) error { 33 dat, ok := uintn.(*memio.ByteSlice) 34 if !ok { 35 return fmt.Errorf("not supported") 36 } 37 bufLen := len(tmpBuf) 38 for i := int64(0); i < dat.Size(); i++ { 39 (*dat)[i] = tmpBuf[(base+i)%int64(bufLen)] 40 } 41 return nil 42 } 43 44 base, _, err := SMBIOSBase() 45 if err != nil { 46 t.Fatal(err) 47 } 48 49 var want int64 = 0xf0007 50 51 if base != want { 52 t.Errorf("SMBIOSBase(): 0x%x, want 0x%x", base, want) 53 } 54 } 55 56 func TestSMBIOSBaseNotFound(t *testing.T) { 57 systabPath = "testdata/systab_NOT_FOUND" 58 defer func(old func(base int64, uintn memio.UintN) error) { memioRead = old }(memioRead) 59 memioRead = func(base int64, uintn memio.UintN) error { 60 return nil 61 } 62 63 _, _, err := SMBIOSBase() 64 65 want := "could not find _SM_ or _SM3_ via /dev/mem from 0x000f0000 to 0x00100000" 66 67 if err.Error() != want { 68 t.Errorf("SMBIOSBase(): '%v', want %s", err, want) 69 } 70 }