github.com/linuxboot/fiano@v1.2.0/pkg/visitors/count_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 visitors
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  func TestCount(t *testing.T) {
    12  	f := parseImage(t)
    13  
    14  	count := &Count{}
    15  	if err := count.Run(f); err != nil {
    16  		t.Fatal(err)
    17  	}
    18  
    19  	tests := []struct {
    20  		mapPtr       *map[string]int
    21  		firmwareType string
    22  		atLeast      int
    23  	}{
    24  		{&count.FirmwareTypeCount, "BIOSRegion", 1},
    25  		{&count.FirmwareTypeCount, "File", 2},
    26  		{&count.FirmwareTypeCount, "FirmwareVolume", 2},
    27  		{&count.FirmwareTypeCount, "Section", 2},
    28  		{&count.FileTypeCount, "EFI_FV_FILETYPE_APPLICATION", 2},
    29  		{&count.FileTypeCount, "EFI_FV_FILETYPE_DRIVER", 2},
    30  		{&count.FileTypeCount, "EFI_FV_FILETYPE_DXE_CORE", 1},
    31  		{&count.FileTypeCount, "EFI_FV_FILETYPE_FFS_PAD", 1},
    32  		{&count.FileTypeCount, "EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE", 1},
    33  		{&count.FileTypeCount, "EFI_FV_FILETYPE_FREEFORM", 1},
    34  		{&count.FileTypeCount, "EFI_FV_FILETYPE_PEIM", 1},
    35  		{&count.FileTypeCount, "EFI_FV_FILETYPE_PEI_CORE", 1},
    36  		{&count.FileTypeCount, "EFI_FV_FILETYPE_RAW", 1},
    37  		{&count.FileTypeCount, "EFI_FV_FILETYPE_SECURITY_CORE", 1},
    38  		{&count.SectionTypeCount, "EFI_SECTION_DXE_DEPEX", 2},
    39  		{&count.SectionTypeCount, "EFI_SECTION_FIRMWARE_VOLUME_IMAGE", 1},
    40  		{&count.SectionTypeCount, "EFI_SECTION_GUID_DEFINED", 1},
    41  		{&count.SectionTypeCount, "EFI_SECTION_PE32", 2},
    42  		{&count.SectionTypeCount, "EFI_SECTION_RAW", 2},
    43  		{&count.SectionTypeCount, "EFI_SECTION_USER_INTERFACE", 2},
    44  		{&count.SectionTypeCount, "EFI_SECTION_VERSION", 2},
    45  	}
    46  
    47  	for _, tt := range tests {
    48  		t.Run(tt.firmwareType, func(t *testing.T) {
    49  			if _, ok := (*tt.mapPtr)[tt.firmwareType]; !ok {
    50  				t.Fatalf("expected %q to be in the count", tt.firmwareType)
    51  			}
    52  			if (*tt.mapPtr)[tt.firmwareType] < tt.atLeast {
    53  				t.Fatalf("expected to count at least %d of type %q, got %d",
    54  					tt.atLeast, tt.firmwareType, (*tt.mapPtr)[tt.firmwareType])
    55  			}
    56  
    57  		})
    58  	}
    59  }