| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package smbios_test |
| 16 |
|
| 17 |
import ( |
| 18 |
"os" |
| 19 |
"runtime" |
| 20 |
"testing" |
| 21 |
|
| 22 |
"github.com/digitalocean/go-smbios/smbios" |
| 23 |
) |
| 24 |
|
| 25 |
func TestStreamIntegration(t *testing.T) { |
| 26 |
if goos := runtime.GOOS; goos != "linux" { |
| 27 |
t.Skipf("skipping on non-Linux platform: %q", goos) |
| 28 |
} |
| 29 |
|
| 30 |
rc, ep, err := smbios.Stream() |
| 31 |
if err != nil { |
| 32 |
if os.IsPermission(err) { |
| 33 |
t.Skipf("skipping, permission denied while reading SMBIOS stream: %v", err) |
| 34 |
} |
| 35 |
|
| 36 |
return |
| 37 |
} |
| 38 |
defer rc.Close() |
| 39 |
|
| 40 |
d := smbios.NewDecoder(rc) |
| 41 |
ss, err := d.Decode() |
| 42 |
if err != nil { |
| 43 |
t.Fatalf("failed to decode structures: %v", err) |
| 44 |
} |
| 45 |
|
| 46 |
major, minor, rev := ep.Version() |
| 47 |
addr, size := ep.Table() |
| 48 |
|
| 49 |
|
| 50 |
if major < 2 { |
| 51 |
t.Fatalf("unexpected major version: %d", major) |
| 52 |
} |
| 53 |
if addr == 0 { |
| 54 |
t.Fatal("expected non-zero table address") |
| 55 |
} |
| 56 |
if size == 0 { |
| 57 |
t.Fatal("expected non-zero table size") |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
t.Logf("SMBIOS %d.%d.%d - table: address: %#x, size: %d\n", |
| 62 |
major, minor, rev, addr, size) |
| 63 |
|
| 64 |
|
| 65 |
var foundBIOS, foundEOT bool |
| 66 |
for _, s := range ss { |
| 67 |
switch s.Header.Type { |
| 68 |
case 0: |
| 69 |
foundBIOS = true |
| 70 |
t.Logf("BIOS: %#v", s) |
| 71 |
case 127: |
| 72 |
foundEOT = true |
| 73 |
t.Logf(" EOT: %#v", s) |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
if !foundBIOS { |
| 78 |
t.Fatal("did not find BIOS information") |
| 79 |
} |
| 80 |
if !foundEOT { |
| 81 |
t.Fatal("did not find end of table") |
| 82 |
} |
| 83 |
} |