github.com/linuxboot/fiano@v1.2.0/pkg/amd/manifest/checksum_test.go (about)

     1  // Copyright 2019 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 manifest
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  func TestFletcherCRC32(t *testing.T) {
    12  	assertEqual := func(expected, actual uint32) {
    13  		if expected != actual {
    14  			t.Errorf("Expected: %d, but got: %d", expected, actual)
    15  		}
    16  	}
    17  	assertEqual(0xF04FC729, fletcherCRC32([]byte("abcde")))
    18  	assertEqual(0x56502D2A, fletcherCRC32([]byte("abcdef")))
    19  	assertEqual(0xEBE19591, fletcherCRC32([]byte("abcdefgh")))
    20  }
    21  
    22  func TestPSPDirectoryCheckSum(t *testing.T) {
    23  	actualCheckSum := CalculatePSPDirectoryCheckSum(pspDirectoryTableDataChunk)
    24  
    25  	table, _, err := ParsePSPDirectoryTable(pspDirectoryTableDataChunk)
    26  	if err != nil {
    27  		t.Fatalf("Failed to parse PSP Directory table, err: %v", err)
    28  	}
    29  	if table.Checksum != actualCheckSum {
    30  		t.Errorf("Incorrect checksum: 0x%X, expected: 0x%X", actualCheckSum, table.Checksum)
    31  	}
    32  }
    33  
    34  func TestBIOSDirectoryCheckSum(t *testing.T) {
    35  	actualCheckSum := CalculateBiosDirectoryCheckSum(biosDirectoryTableDataChunk)
    36  
    37  	table, _, err := ParseBIOSDirectoryTable(biosDirectoryTableDataChunk)
    38  	if err != nil {
    39  		t.Fatalf("Failed to parse PSP Directory table, err: %v", err)
    40  	}
    41  	if table.Checksum != actualCheckSum {
    42  		t.Errorf("Incorrect checksum: 0x%X, expected: 0x%X", actualCheckSum, table.Checksum)
    43  	}
    44  }