Debian Codegraph @

smbios/stream_integration_test.go

raw symbols SCIP
1 // Copyright 2017-2018 DigitalOcean.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
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 // Assume SMBIOS version 2+, assume non-zero table address and size.
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 // Show some info in the test output.
61 t.Logf("SMBIOS %d.%d.%d - table: address: %#x, size: %d\n",
62 major, minor, rev, addr, size)
63
64 // Assume we find BIOS and end of table types.
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 }