github.com/system-transparency/u-root@v6.0.1-0.20190919065413-ed07a650de4c+incompatible/pkg/acpi/sdt_test.go (about) 1 // Copyright 2019 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 acpi 6 7 import ( 8 "os" 9 "reflect" 10 "testing" 11 ) 12 13 // TestSDT tests basic functions, so that we can verify the marshal/unmarshal 14 // is idempotent. 15 func TestSDT(t *testing.T) { 16 Debug = t.Logf 17 if os.Getuid() != 0 { 18 t.Logf("NOT root, skipping") 19 t.Skip() 20 } 21 _, r, err := GetRSDP() 22 if err != nil { 23 t.Fatalf("TestSDT GetRSDP: got %v, want nil", err) 24 } 25 t.Logf("%q", r) 26 s, err := UnMarshalSDT(r) 27 if err != nil { 28 t.Fatalf("TestSDT: got %q, want nil", err) 29 } 30 t.Logf("%q::%s", s, ShowTable(s)) 31 sraw, err := ReadRaw(r.Base()) 32 if err != nil { 33 t.Fatalf("TestSDT: readraw got %q, want nil", err) 34 } 35 t.Logf("%q", sraw) 36 b, err := s.Marshal() 37 if err != nil { 38 t.Fatalf("Marshaling SDT: got %q, want nil", err) 39 } 40 t.Logf("%q", b) 41 // The sdt marshaling, because we need it to, also marshals the tables. Just check 42 // the header bytes. 43 b = b[:len(sraw.AllData())] 44 if !reflect.DeepEqual(sraw.AllData(), b) { 45 for i, c := range sraw.AllData() { 46 t.Logf("%d: raw %#02x b %#02x", i, c, b[i]) 47 } 48 t.Fatalf("TestSDT: input and output []byte differ: in %q, out %q: want same", sraw, b) 49 } 50 } 51 52 // TestNewSDT tests to ensure that NewSDT returns a correct empty SDT and marshals 53 // to a HeaderLength byte array. 54 func TestNewSDT(t *testing.T) { 55 s, err := NewSDT() 56 if err != nil { 57 t.Fatal(err) 58 } 59 if len(s.data) != HeaderLength { 60 t.Fatalf("NewSDT: got size %d, want %d", len(s.data), HeaderLength) 61 } 62 }