util/intelp2m/fields: Add unit tests
Change-Id: I6330855b1c7463a3093b38c54e6cc06c3409009a Signed-off-by: Maxim Polyakov <max.senia.poliak@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/68673 Reviewed-by: Daniel Maslowski <info@orangecms.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Maximilian Brune <maximilian.brune@9elements.com>
This commit is contained in:
parent
7d1c33c9d1
commit
e95fd3e041
4 changed files with 194 additions and 0 deletions
54
util/intelp2m/fields/test/suite.go
Normal file
54
util/intelp2m/fields/test/suite.go
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"review.coreboot.org/coreboot.git/util/intelp2m/platforms/common"
|
||||
"review.coreboot.org/coreboot.git/util/intelp2m/platforms/snr"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
DW0, DW1 uint32
|
||||
Ownership uint8
|
||||
Reference string
|
||||
}
|
||||
|
||||
func (tc TestCase) Check(actuallyMacro string) error {
|
||||
if actuallyMacro != tc.Reference {
|
||||
return fmt.Errorf(`TestCase: DW0 = %d, DW1 = %d, Ownership = %d:
|
||||
Expects: '%s'
|
||||
Actually: '%s'`, tc.DW0, tc.DW1, tc.Ownership, tc.Reference, actuallyMacro)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Suite []TestCase
|
||||
|
||||
func (suite Suite) Run(t *testing.T, label string, decoderIf common.Fields) {
|
||||
t.Run(label, func(t *testing.T) {
|
||||
platform := snr.PlatformSpecific{}
|
||||
macro := common.GetInstanceMacro(platform, decoderIf)
|
||||
dw0 := macro.Register(common.PAD_CFG_DW0)
|
||||
dw1 := macro.Register(common.PAD_CFG_DW1)
|
||||
for _, tc := range suite {
|
||||
macro.Clear()
|
||||
macro.PadIdSet("").SetPadOwnership(tc.Ownership)
|
||||
dw0.ValueSet(tc.DW0)
|
||||
dw1.ValueSet(tc.DW1)
|
||||
macro.Fields.GenerateString()
|
||||
if err := tc.Check(macro.Get()); err != nil {
|
||||
t.Errorf("Test failed: %v", err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func SlidingOneTestSuiteCreate(referenceSlice []string) Suite {
|
||||
suite := make([]TestCase, len(referenceSlice))
|
||||
dw := uint32(0x80000000)
|
||||
for i, reference := range referenceSlice {
|
||||
suite[i] = TestCase{DW0: dw >> i, DW1: dw >> i, Reference: reference}
|
||||
}
|
||||
return suite
|
||||
}
|
||||
Loading…
Reference in a new issue