cbfs: Remove remnants of ext-win-*
[coreboot2.git] / util / intelp2m / platforms / test / suite.go
blob8ec4886357529b6d9ff9e0f112b6d3831506f662
1 package test
3 import (
4 "fmt"
5 "testing"
7 "review.coreboot.org/coreboot.git/util/intelp2m/config"
10 type (
11 Pad struct {
12 ID string
13 DW0 uint32
14 DW1 uint32
15 Ownership uint8
17 Macro struct {
18 Short string
19 Long string
21 TestCase struct {
22 Pad
23 Macro
25 PlatformSpecificIf interface {
26 GenMacro(string, uint32, uint32, uint8) string
28 Suite []TestCase
31 func (p Pad) toShortMacro(platform PlatformSpecificIf) string {
32 config.FldStyleSet("none")
33 config.NonCheckingFlagSet(true)
34 return platform.GenMacro(p.ID, p.DW0, p.DW1, p.Ownership)
37 func (p Pad) toLongMacro(platform PlatformSpecificIf) string {
38 config.FldStyleSet("cb")
39 config.NonCheckingFlagSet(false)
40 return platform.GenMacro(p.ID, p.DW0, p.DW1, p.Ownership)
43 func (m *Macro) checkFor(platform PlatformSpecificIf, pad Pad) error {
44 var format string = "%s macro\nExpects: '%s'\nActually: '%s'\n\n"
45 if actually := pad.toLongMacro(platform); m.Long != "" && m.Long != actually {
46 return fmt.Errorf(format, "LONG", m.Long, actually)
48 if actually := pad.toShortMacro(platform); m.Short != "" && m.Short != actually {
49 return fmt.Errorf(format, "SHORT", m.Short, actually)
51 return nil
54 func (suite Suite) Run(t *testing.T, label string, platform PlatformSpecificIf) {
55 t.Run(label, func(t *testing.T) {
56 for _, testcase := range suite {
57 if err := testcase.Macro.checkFor(platform, testcase.Pad); err != nil {
58 t.Errorf("Test failed for pad %s\n%v", testcase.Pad.ID, err)