github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/boot/zimage/zimage_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 zimage 6 7 import ( 8 "os" 9 "reflect" 10 "testing" 11 ) 12 13 var testData = &ZImage{ 14 Header: Header{ 15 Magic: 0x16f2818, 16 Start: 0x0, 17 End: 0xd5638, 18 Endianess: 0x4030201, 19 TableMagic: 0x45454545, 20 TableAddr: 0x25bc, 21 }, 22 Table: []TableEntry{ 23 { 24 Tag: 0x5a534c4b, 25 Data: []uint32{0xd55f5, 0x2b83c}, 26 }, 27 }, 28 } 29 30 func TestParse(t *testing.T) { 31 f, err := os.Open("testdata/zImage") 32 if err != nil { 33 t.Fatal(err) 34 } 35 defer f.Close() 36 37 z, err := Parse(f) 38 if err != nil { 39 t.Fatal(err) 40 } 41 42 if !reflect.DeepEqual(z, testData) { 43 t.Errorf(`Parse("testdata/zImage") = %#v; want %#v`, z, testData) 44 } 45 } 46 47 func TestKernelSizes(t *testing.T) { 48 piggySizeAddr, kernelBSSSize, err := testData.GetKernelSizes() 49 if err != nil { 50 t.Fatal(err) 51 } 52 if piggySizeAddr != 0xd55f5 { 53 t.Errorf("want piggySizeAddr=0xd55f5, got piggySizeAddr=%#x", piggySizeAddr) 54 } 55 if kernelBSSSize != 0x2b83c { 56 t.Errorf("want kernelBSSSize=0x2b83c, got kernelBSSSize=%#x", kernelBSSSize) 57 } 58 }