1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
package test
import (
"fmt"
"testing"
"review.coreboot.org/coreboot.git/util/intelp2m/config"
)
type (
Pad struct {
ID string
DW0 uint32
DW1 uint32
Ownership uint8
}
Macro struct {
Short string
Long string
}
TestCase struct {
Pad
Macro
}
PlatformSpecificIf interface {
GenMacro(string, uint32, uint32, uint8) string
}
Suite []TestCase
)
func (p Pad) toShortMacro(platform PlatformSpecificIf) string {
config.FldStyleSet("none")
config.NonCheckingFlagSet(true)
return platform.GenMacro(p.ID, p.DW0, p.DW1, p.Ownership)
}
func (p Pad) toLongMacro(platform PlatformSpecificIf) string {
config.FldStyleSet("cb")
config.NonCheckingFlagSet(false)
return platform.GenMacro(p.ID, p.DW0, p.DW1, p.Ownership)
}
func (m *Macro) checkFor(platform PlatformSpecificIf, pad Pad) error {
var format string = "%s macro\nExpects: '%s'\nActually: '%s'\n\n"
if actually := pad.toLongMacro(platform); m.Long != "" && m.Long != actually {
return fmt.Errorf(format, "LONG", m.Long, actually)
}
if actually := pad.toShortMacro(platform); m.Short != "" && m.Short != actually {
return fmt.Errorf(format, "SHORT", m.Short, actually)
}
return nil
}
func (suite Suite) Run(t *testing.T, label string, platform PlatformSpecificIf) {
t.Run(label, func(t *testing.T) {
for _, testcase := range suite {
if err := testcase.Macro.checkFor(platform, testcase.Pad); err != nil {
t.Errorf("Test failed for pad %s\n%v", testcase.Pad.ID, err)
}
}
})
}
|