github.com/system-transparency/u-root@v6.0.1-0.20190919065413-ed07a650de4c+incompatible/pkg/acpi/ibft_test.go (about) 1 // Copyright 2010-2018 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 "encoding/json" 9 "io/ioutil" 10 "reflect" 11 "testing" 12 ) 13 14 /* 15 func testTarget(t *testing.T) { 16 var tests = []struct { 17 n string 18 v *IBFTTarget 19 out []uint8 20 }{ 21 {"Empty", &IBFTTarget{Valid: "0", Boot: "1", CHAP: "0", RCHAP: "1", Index: "0", BootLUN: "8"}, []uint8{}}, 22 } 23 Debug = t.Logf 24 for _, tst := range tests { 25 26 b, err := Marshal(tst.v) 27 if err != nil { 28 t.Errorf("%s: got %v, want nil", tst.n, err) 29 } 30 t.Logf("%s: (%T, %v) -> (%v, %v)", tst.n, tst.v, tst.v, b, err) 31 } 32 } 33 */ 34 func TestIBFTSizes(t *testing.T) { 35 if len(rawIBTFHeader) != 48 { 36 t.Errorf("length of rawIBTFHeader: got %v, want 48", len(rawIBTFHeader)) 37 } 38 } 39 40 func TestIBFTMarshal(t *testing.T) { 41 i := &IBFT{ 42 Multi: "1", 43 Initiator: IBFTInitiator{ 44 Valid: "1", 45 Boot: "1", 46 SNSServer: "1.2.3.4", 47 SLPServer: "localhost", 48 PrimaryRadiusServer: "121.1.1.1", 49 SecondaryRadiusServer: "222.3.4.5", 50 Name: "myinitor", 51 }, 52 NIC0: IBFTNIC{ 53 Valid: "1", 54 Boot: "1", 55 Global: "1", 56 Index: "0", 57 IPAddress: "5.5.5.5", 58 Gateway: "7.7.7.7", 59 PrimaryDNS: "8.8.8.8", 60 SecondaryDNS: "9.9.9.9", 61 DHCP: "11.11.11.11", 62 VLAN: "10", 63 MACAddress: "00:0c:29:12:a4:2e", 64 PCIBDF: "0x18", 65 HostName: "somehost", 66 }, 67 NIC1: IBFTNIC{ 68 Valid: "1", 69 Boot: "1", 70 Global: "0", 71 Index: "1", 72 IPAddress: "15.5.5.5", 73 Gateway: "17.7.7.7", 74 PrimaryDNS: "18.8.8.8", 75 SecondaryDNS: "19.9.9.9", 76 DHCP: "121.11.11.11", 77 VLAN: "12", 78 MACAddress: "11:22:33:44:55:66", 79 PCIBDF: "0x8", 80 HostName: "otherhost", 81 }, 82 Target0: IBFTTarget{ 83 Valid: "1", 84 Boot: "1", 85 CHAP: "1", 86 RCHAP: "0", 87 Index: "1", 88 TargetIP: "1.2.3.4:88", 89 BootLUN: "1234", 90 ChapType: "0", 91 TargetName: "target", 92 CHAPName: "clown", 93 CHAPSecret: "noun", 94 ReverseCHAPName: "verb", 95 ReverseCHAPSecret: "adverb", 96 }, 97 Target1: IBFTTarget{ 98 Valid: "1", 99 Boot: "1", 100 CHAP: "1", 101 RCHAP: "1", 102 Index: "0", 103 TargetIP: "4.4.4.4:99", 104 BootLUN: "4444", 105 ChapType: "2", 106 TargetName: "bullseye", 107 CHAPName: "bozo", 108 CHAPSecret: "bee", 109 ReverseCHAPName: "barg", 110 ReverseCHAPSecret: "arg", 111 }, 112 } 113 114 Debug = t.Logf 115 if false { 116 b, err := json.MarshalIndent(i, "", "\t") 117 if err != nil { 118 t.Fatalf("Marshal: got %v, want nil", err) 119 } 120 t.Logf("%s", string(b)) 121 j := &IBFT{} 122 if err := json.Unmarshal(b, j); err != nil { 123 t.Fatalf("Unmarshal: got %v, want nil", err) 124 } 125 if !reflect.DeepEqual(i, j) { 126 t.Fatalf("Reading it in: got %q, want %q", j, i) 127 } 128 } 129 t.Logf("Send it out") 130 b, err := Marshal(i) 131 if err != nil { 132 t.Fatalf("Marshal: got %v, want nil", err) 133 } 134 t.Logf("Marshal to %v", err) 135 if len(b) != 524 { 136 t.Fatalf("Marshall: len is %d bytes and should be 2048", len(b)) 137 } 138 f, err := ioutil.TempFile("", "acpi") 139 if err != nil { 140 t.Fatal(err) 141 } 142 defer f.Close() 143 n, err := f.Write(b) 144 if err != nil { 145 t.Fatal(err) 146 } 147 t.Logf("Wrote %d bytes to %q", n, f.Name()) 148 }