github.com/linuxboot/fiano@v1.2.0/pkg/uefi/region_test.go (about)

     1  // Copyright 2018 the LinuxBoot 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 uefi
     6  
     7  import "testing"
     8  
     9  var regionTestcases = [...]struct {
    10  	in    FlashRegion
    11  	valid bool
    12  	base  uint32
    13  	end   uint32
    14  }{
    15  	// Invalid
    16  	{
    17  		in:    FlashRegion{0, 0},
    18  		valid: false,
    19  		base:  0,
    20  		end:   0x1000,
    21  	},
    22  	{
    23  		in:    FlashRegion{1, 0},
    24  		valid: false,
    25  		base:  0x1000,
    26  		end:   0x1000,
    27  	},
    28  	// Valid
    29  	{
    30  		in:    FlashRegion{1, 1},
    31  		valid: true,
    32  		base:  0x1000,
    33  		end:   0x2000,
    34  	},
    35  	{
    36  		in:    FlashRegion{100, 200},
    37  		valid: true,
    38  		base:  0x64000,
    39  		end:   0xC9000,
    40  	},
    41  	{
    42  		in:    FlashRegion{0x0004, 0xFFFF},
    43  		valid: false,
    44  		base:  0x00004000,
    45  		end:   0x10000000,
    46  	},
    47  	{
    48  		in:    FlashRegion{0x0004, 0xFFFE},
    49  		valid: true,
    50  		base:  0x00004000,
    51  		end:   0x0FFFF000,
    52  	},
    53  	{
    54  		in:    FlashRegion{0xFFFF, 0xFFFF},
    55  		valid: false,
    56  		base:  0x0FFFF000,
    57  		end:   0x10000000,
    58  	},
    59  }
    60  
    61  func TestFlashRegionValid(t *testing.T) {
    62  	for _, tc := range regionTestcases {
    63  		if out := tc.in.Valid(); out != tc.valid {
    64  			t.Errorf("%#v.Valid() = %v; want = %v", tc.in, out, tc.valid)
    65  		}
    66  	}
    67  }
    68  
    69  func TestFlashRegionBaseOffset(t *testing.T) {
    70  	for _, tc := range regionTestcases {
    71  		if out := tc.in.BaseOffset(); out != tc.base {
    72  			t.Errorf("%#v.BaseOffset() = %d; want = %d", tc.in, out, tc.base)
    73  		}
    74  	}
    75  }
    76  
    77  func TestFlashRegionEndOffset(t *testing.T) {
    78  	for _, tc := range regionTestcases {
    79  		if out := tc.in.EndOffset(); out != tc.end {
    80  			t.Errorf("%#v.EndOffset() = %d; want = %d", tc.in, out, tc.end)
    81  		}
    82  	}
    83  }