/ util / intelp2m / fields / test / suite.go
suite.go
 1  package test
 2  
 3  import (
 4  	"fmt"
 5  	"testing"
 6  
 7  	"review.coreboot.org/coreboot.git/util/intelp2m/platforms/common"
 8  	"review.coreboot.org/coreboot.git/util/intelp2m/platforms/snr"
 9  )
10  
11  type TestCase struct {
12  	DW0, DW1  uint32
13  	Ownership uint8
14  	Reference string
15  }
16  
17  func (tc TestCase) Check(actuallyMacro string) error {
18  	if actuallyMacro != tc.Reference {
19  		return fmt.Errorf(`TestCase: DW0 = %d, DW1 = %d, Ownership = %d:
20  Expects:  '%s'
21  Actually: '%s'`, tc.DW0, tc.DW1, tc.Ownership, tc.Reference, actuallyMacro)
22  	}
23  	return nil
24  }
25  
26  type Suite []TestCase
27  
28  func (suite Suite) Run(t *testing.T, label string, decoderIf common.Fields) {
29  	t.Run(label, func(t *testing.T) {
30  		platform := snr.PlatformSpecific{}
31  		macro := common.GetInstanceMacro(platform, decoderIf)
32  		dw0 := macro.Register(common.PAD_CFG_DW0)
33  		dw1 := macro.Register(common.PAD_CFG_DW1)
34  		for _, tc := range suite {
35  			macro.Clear()
36  			macro.PadIdSet("").SetPadOwnership(tc.Ownership)
37  			dw0.ValueSet(tc.DW0)
38  			dw1.ValueSet(tc.DW1)
39  			macro.Fields.GenerateString()
40  			if err := tc.Check(macro.Get()); err != nil {
41  				t.Errorf("Test failed: %v", err)
42  			}
43  		}
44  	})
45  }
46  
47  func SlidingOneTestSuiteCreate(referenceSlice []string) Suite {
48  	suite := make([]TestCase, len(referenceSlice))
49  	dw := uint32(0x80000000)
50  	for i, reference := range referenceSlice {
51  		suite[i] = TestCase{DW0: dw >> i, DW1: dw >> i, Reference: reference}
52  	}
53  	return suite
54  }