Maxim Polyakov has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/68673 )
Change subject: util/intelp2m/fields: Add unit tests ......................................................................
util/intelp2m/fields: Add unit tests
Change-Id: I6330855b1c7463a3093b38c54e6cc06c3409009a Signed-off-by: Maxim Polyakov max.senia.poliak@gmail.com --- A util/intelp2m/fields/cb/cb_test.go A util/intelp2m/fields/fsp/fsp_test.go A util/intelp2m/fields/raw/raw_test.go A util/intelp2m/fields/test/suite.go 4 files changed, 204 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/73/68673/1
diff --git a/util/intelp2m/fields/cb/cb_test.go b/util/intelp2m/fields/cb/cb_test.go new file mode 100644 index 0000000..d90036b --- /dev/null +++ b/util/intelp2m/fields/cb/cb_test.go @@ -0,0 +1,48 @@ +package cb_test + +import ( + "testing" + + "review.coreboot.org/coreboot.git/util/intelp2m/fields/cb" + "review.coreboot.org/coreboot.git/util/intelp2m/fields/test" +) + +// sliding-one + +func TestCorebootFields(t *testing.T) { + referenceSlice := []string{ + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO) | PAD_RESET(PLTRST), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO) | PAD_RESET(DEEP), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO) | (1 << 29), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO) | (1 << 28), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO) | PAD_TRIG(OFF), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO) | PAD_TRIG(EDGE_SINGLE), PAD_CFG1_TOL_1V8),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO) | PAD_RX_POL(INVERT), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO) | PAD_IRQ_ROUTE(IOAPIC), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO) | PAD_IRQ_ROUTE(SCI), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO) | PAD_IRQ_ROUTE(SMI), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO) | PAD_IRQ_ROUTE(NMI), PAD_IOSSTATE(HIZCRx1)),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO), PAD_IOSSTATE(Tx1RxDCRx1)),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO), PAD_IOSSTATE(Tx0RxDCRx1)),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO), PAD_IOSSTATE(Tx0RxDCRx0)),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO), PAD_PULL(INVALID)),", // Error invalid TERM value = 8 + "_PAD_CFG_STRUCT(, PAD_FUNC(NF4), PAD_PULL(DN_20K)),", + "_PAD_CFG_STRUCT(, PAD_FUNC(NF2), PAD_PULL(DN_5K)),", + "_PAD_CFG_STRUCT(, PAD_FUNC(NF1), PAD_PULL(INVALID)),", // Error invalid TERM value = 1 + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO) | PAD_BUF(RX_DISABLE), PAD_IOSTERM(ENPD)),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO) | PAD_BUF(TX_DISABLE), PAD_IOSTERM(DISPUPD)),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO) | (1 << 1), 0),", + "_PAD_CFG_STRUCT(, PAD_FUNC(GPIO) | 1, 0),", + } + test.SlidingOneTestSuiteCreate(referenceSlice).Run(t, "SLIDING-ONE-TEST", cb.FieldMacros{}) +} diff --git a/util/intelp2m/fields/fsp/fsp_test.go b/util/intelp2m/fields/fsp/fsp_test.go new file mode 100644 index 0000000..90bbc0e --- /dev/null +++ b/util/intelp2m/fields/fsp/fsp_test.go @@ -0,0 +1,46 @@ +package fsp_test + +import ( + "testing" + + "review.coreboot.org/coreboot.git/util/intelp2m/fields/fsp" + "review.coreboot.org/coreboot.git/util/intelp2m/fields/test" +) + +func TestFSPFields(t *testing.T) { + referenceSlice := []string{ + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioPlatformReset, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioHostDeepReset, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLvlEdgDis, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntEdge, GpioResetPwrGood, GpioTolerance1v8 | GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInInvOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntApic | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntSci | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntSmi | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntNmi | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, INVALID, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeNative4, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermWpd20K, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeNative2, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermWpd5K, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeNative1, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, INVALID, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirIn, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutLow, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + "{ GPIO_SKL_H_, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInOut, GpioOutHigh, GpioIntDis | GpioIntLevel, GpioResetPwrGood, GpioTermNone, GpioPadConfigLock } },", + } + test.SlidingOneTestSuiteCreate(referenceSlice).Run(t, "SLIDING-ONE-TEST", fsp.FieldMacros{}) +} diff --git a/util/intelp2m/fields/raw/raw_test.go b/util/intelp2m/fields/raw/raw_test.go new file mode 100644 index 0000000..8cab698 --- /dev/null +++ b/util/intelp2m/fields/raw/raw_test.go @@ -0,0 +1,46 @@ +package raw_test + +import ( + "testing" + + "review.coreboot.org/coreboot.git/util/intelp2m/fields/raw" + "review.coreboot.org/coreboot.git/util/intelp2m/fields/test" +) + +func TestRAWFields(t *testing.T) { + referenceSlice := []string{ + "_PAD_CFG_STRUCT(, 0x80000000, 0x80000000),", + "_PAD_CFG_STRUCT(, 0x40000000, 0x40000000),", + "_PAD_CFG_STRUCT(, 0x20000000, 0x20000000),", + "_PAD_CFG_STRUCT(, 0x10000000, 0x10000000),", + "_PAD_CFG_STRUCT(, 0x08000000, 0x08000000),", + "_PAD_CFG_STRUCT(, 0x04000000, 0x04000000),", + "_PAD_CFG_STRUCT(, 0x02000000, 0x02000000),", + "_PAD_CFG_STRUCT(, 0x01000000, 0x01000000),", + "_PAD_CFG_STRUCT(, 0x00800000, 0x00800000),", + "_PAD_CFG_STRUCT(, 0x00400000, 0x00400000),", + "_PAD_CFG_STRUCT(, 0x00200000, 0x00200000),", + "_PAD_CFG_STRUCT(, 0x00100000, 0x00100000),", + "_PAD_CFG_STRUCT(, 0x00080000, 0x00080000),", + "_PAD_CFG_STRUCT(, 0x00040000, 0x00040000),", + "_PAD_CFG_STRUCT(, 0x00020000, 0x00020000),", + "_PAD_CFG_STRUCT(, 0x00010000, 0x00010000),", + "_PAD_CFG_STRUCT(, 0x00008000, 0x00008000),", + "_PAD_CFG_STRUCT(, 0x00004000, 0x00004000),", + "_PAD_CFG_STRUCT(, 0x00002000, 0x00002000),", + "_PAD_CFG_STRUCT(, 0x00001000, 0x00001000),", + "_PAD_CFG_STRUCT(, 0x00000800, 0x00000800),", + "_PAD_CFG_STRUCT(, 0x00000400, 0x00000400),", + "_PAD_CFG_STRUCT(, 0x00000200, 0x00000200),", + "_PAD_CFG_STRUCT(, 0x00000100, 0x00000100),", + "_PAD_CFG_STRUCT(, 0x00000080, 0x00000080),", + "_PAD_CFG_STRUCT(, 0x00000040, 0x00000040),", + "_PAD_CFG_STRUCT(, 0x00000020, 0x00000020),", + "_PAD_CFG_STRUCT(, 0x00000010, 0x00000010),", + "_PAD_CFG_STRUCT(, 0x00000008, 0x00000008),", + "_PAD_CFG_STRUCT(, 0x00000004, 0x00000004),", + "_PAD_CFG_STRUCT(, 0x00000002, 0x00000002),", + "_PAD_CFG_STRUCT(, 0x00000001, 0x00000001),", + } + test.SlidingOneTestSuiteCreate(referenceSlice).Run(t, "SLIDING-ONE-TEST", raw.FieldMacros{}) +} diff --git a/util/intelp2m/fields/test/suite.go b/util/intelp2m/fields/test/suite.go new file mode 100644 index 0000000..a61062e --- /dev/null +++ b/util/intelp2m/fields/test/suite.go @@ -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 +}