Debian Codegraph @

util/intelp2m/platforms/common/fields/test/suite.go

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