github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/smbios/vm_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  //go:build !race
     6  // +build !race
     7  
     8  package smbios
     9  
    10  import (
    11  	"testing"
    12  
    13  	"github.com/mvdan/u-root-coreutils/pkg/qemu"
    14  	"github.com/mvdan/u-root-coreutils/pkg/testutil"
    15  	"github.com/mvdan/u-root-coreutils/pkg/vmtest"
    16  )
    17  
    18  func TestIntegration(t *testing.T) {
    19  	vmtest.GolangTest(t, []string{"github.com/mvdan/u-root-coreutils/pkg/smbios"}, &vmtest.Options{
    20  		QEMUOpts: qemu.Options{
    21  			Devices: []qemu.Device{
    22  				qemu.ArbitraryArgs{"-smbios", "type=2,manufacturer=u-root"},
    23  			},
    24  		},
    25  	})
    26  }
    27  
    28  func TestFromSysfs(t *testing.T) {
    29  	testutil.SkipIfNotRoot(t)
    30  
    31  	info, err := FromSysfs()
    32  	if err != nil || info == nil {
    33  		t.Errorf("FromSysfs() = %q, '%v', want nil", info, err)
    34  	}
    35  }
    36  
    37  func TestGetBIOSInfo(t *testing.T) {
    38  	testutil.SkipIfNotRoot(t)
    39  
    40  	info, err := FromSysfs()
    41  	if err != nil {
    42  		t.Errorf("FromSysfs as a requirement failed.")
    43  	}
    44  
    45  	smbiosinfo, err := info.GetBIOSInfo()
    46  	if err != nil || smbiosinfo == nil {
    47  		t.Errorf("GetBiosInfo() = %q, '%v'", smbiosinfo, err)
    48  	}
    49  }
    50  
    51  func TestGetSystemInfo(t *testing.T) {
    52  	testutil.SkipIfNotRoot(t)
    53  
    54  	info, err := FromSysfs()
    55  	if err != nil {
    56  		t.Errorf("FromSysfs as a requirement failed.")
    57  	}
    58  
    59  	systeminfo, err := info.GetSystemInfo()
    60  	if err != nil || systeminfo == nil {
    61  		t.Errorf("GetSystemInfo() = %q, '%v'", systeminfo, err)
    62  	}
    63  }
    64  
    65  func TestGetChassisInfo(t *testing.T) {
    66  
    67  	testutil.SkipIfNotRoot(t)
    68  
    69  	info, err := FromSysfs()
    70  	if err != nil {
    71  		t.Errorf("FromSysfs as a requirement failed.")
    72  	}
    73  
    74  	chassisinfo, err := info.GetChassisInfo()
    75  	if err != nil || chassisinfo == nil {
    76  		t.Errorf("GetChassisInfo() = %q, '%v'", chassisinfo, err)
    77  	}
    78  }
    79  
    80  func TestGetProcessorInfo(t *testing.T) {
    81  
    82  	testutil.SkipIfNotRoot(t)
    83  
    84  	info, err := FromSysfs()
    85  	if err != nil {
    86  		t.Errorf("FromSysfs as a requirement failed.")
    87  	}
    88  
    89  	processorinfo, err := info.GetProcessorInfo()
    90  	if err != nil || processorinfo == nil {
    91  		t.Errorf("GetProcessorInfo() = %q, '%v'", processorinfo, err)
    92  	}
    93  }
    94  
    95  func TestGetMemoryDevices(t *testing.T) {
    96  	testutil.SkipIfNotRoot(t)
    97  
    98  	info, err := FromSysfs()
    99  	if err != nil {
   100  		t.Errorf("FromSysfs as a requirement failed.")
   101  	}
   102  
   103  	memorydevices, err := info.GetMemoryDevices()
   104  	if err != nil || memorydevices == nil {
   105  		t.Errorf("GetMemoryDevices() = %q, '%v'", memorydevices, err)
   106  	}
   107  }