| 1 | package generator_test |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | |
| 7 | "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" |
| 8 | "review.coreboot.org/coreboot.git/util/intelp2m/generator" |
| 9 | "review.coreboot.org/coreboot.git/util/intelp2m/generator/testsuites" |
| 10 | parsertest "review.coreboot.org/coreboot.git/util/intelp2m/parser/test" |
| 11 | ) |
| 12 | |
| 13 | func do(t *testing.T, reference string) { |
| 14 | actually, err := generator.Run(parsertest.Suite) |
| 15 | if err != nil { |
| 16 | t.Errorf("failed to run generator: %v", err) |
| 17 | } |
| 18 | |
| 19 | expects := strings.SplitAfter(reference, "\n") |
| 20 | for i := range actually { |
| 21 | if expects[i] != actually[i] { |
| 22 | t.Errorf("row number %d:\n\tExpects: <%s>\n\tActually <%s>", |
| 23 | i, expects[i], actually[i]) |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | func TestGenerator(t *testing.T) { |
| 29 | t.Run("GENERATOR/I0-NO-COMMENTS", func(t *testing.T) { |
| 30 | p2m.SettingsReset() |
| 31 | p2m.Config.AutoCheck = false |
| 32 | do(t, testsuites.ReferenceI0NoComments) |
| 33 | }) |
| 34 | |
| 35 | t.Run("GENERATOR/I1-WITH-COMMENTS", func(t *testing.T) { |
| 36 | p2m.SettingsReset() |
| 37 | p2m.Config.AutoCheck = false |
| 38 | p2m.Config.GenLevel = 1 |
| 39 | do(t, testsuites.ReferenceI1Comments) |
| 40 | }) |
| 41 | |
| 42 | t.Run("GENERATOR/I2-AUTO-CHECK", func(t *testing.T) { |
| 43 | p2m.SettingsReset() |
| 44 | p2m.Config.GenLevel = 2 |
| 45 | do(t, testsuites.ReferenceI2AutoCheck) |
| 46 | }) |
| 47 | |
| 48 | t.Run("GENERATOR/I3-UNCHECK", func(t *testing.T) { |
| 49 | p2m.SettingsReset() |
| 50 | p2m.Config.AutoCheck = false |
| 51 | p2m.Config.IgnoredFields = true |
| 52 | p2m.Config.GenLevel = 3 |
| 53 | do(t, testsuites.ReferenceI3Uncheck) |
| 54 | }) |
| 55 | |
| 56 | t.Run("GENERATOR/I4-EXCLUDE-UNUSED-CB-FIELDS", func(t *testing.T) { |
| 57 | p2m.SettingsReset() |
| 58 | p2m.Config.IgnoredFields = true |
| 59 | p2m.Config.Field = p2m.CbFlds |
| 60 | p2m.Config.GenLevel = 4 |
| 61 | do(t, testsuites.ReferenceI4ExcludeUnusedCbFlds) |
| 62 | }) |
| 63 | } |