github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/smbios/smbios_linux_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  	"testing"
     9  )
    10  
    11  func TestSMBIOSEFISMBIOS2(t *testing.T) {
    12  	systabPath = "testdata/smbios2_systab"
    13  	base, size, err := SMBIOSBaseEFI()
    14  	if err != nil {
    15  		t.Fatal(err)
    16  	}
    17  
    18  	var want int64 = 0x12345678
    19  
    20  	if base != want {
    21  		t.Errorf("SMBIOSBaseEFI(): 0x%x, want 0x%x", base, want)
    22  	}
    23  	if size != smbios2HeaderSize {
    24  		t.Errorf("SMBIOSBaseEFI(): 0x%x, want 0x%x ", size, smbios2HeaderSize)
    25  	}
    26  }
    27  
    28  func TestSMBIOSEFISMBIOS3(t *testing.T) {
    29  	systabPath = "testdata/smbios3_systab"
    30  	base, size, err := SMBIOSBaseEFI()
    31  	if err != nil {
    32  		t.Fatal(err)
    33  	}
    34  
    35  	var want int64 = 0x12345678
    36  
    37  	if base != want {
    38  		t.Errorf("SMBIOSBaseEFI(): 0x%x, want 0x%x", base, want)
    39  	}
    40  	if size != smbios3HeaderSize {
    41  		t.Errorf("SMBIOSBaseEFI(): 0x%x, want 0x%x ", size, smbios3HeaderSize)
    42  	}
    43  }
    44  
    45  func TestSMBIOSEFINotFound(t *testing.T) {
    46  	systabPath = "testdata/systab_NOT_FOUND"
    47  	_, _, err := SMBIOSBaseEFI()
    48  	if err == nil {
    49  		t.Errorf("SMBIOSBaseEFI(): nil , want error")
    50  	}
    51  }
    52  
    53  func TestSMBIOSEFIInvalid(t *testing.T) {
    54  	systabPath = "testdata/invalid_systab"
    55  	_, _, err := SMBIOSBaseEFI()
    56  	if err == nil {
    57  		t.Errorf("SMBIOSBaseEFI(): nil , want error")
    58  	}
    59  }