util/intelp2m/parser/template: Add unit test
Change-Id: I1612a7d18bf53479cbe53ca0ba761b67e795c16b Signed-off-by: Maxim Polyakov <max.senia.poliak@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/67135 Reviewed-by: Alicja Michalska <ahplka19@gmail.com> Reviewed-by: David Hendricks <david.hendricks@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
6b43e4ba33
commit
6abf66c8f3
3 changed files with 43 additions and 3 deletions
|
|
@ -117,7 +117,7 @@ func (parser *ParserData) padInfoExtract() int {
|
|||
var function, id string
|
||||
var dw0, dw1 uint32
|
||||
var template = map[int]template{
|
||||
config.TempInteltool: useInteltoolLogTemplate,
|
||||
config.TempInteltool: UseInteltoolLogTemplate,
|
||||
config.TempGpioh : useGpioHTemplate,
|
||||
config.TempSpec : useYourTemplate,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"unicode"
|
||||
)
|
||||
|
||||
const INTSEL_MASK uint32 = 0xffffff00
|
||||
|
||||
type template func(string, *string, *string, *uint32, *uint32) int
|
||||
|
||||
// extractPadFuncFromComment
|
||||
|
|
@ -38,7 +40,7 @@ func tokenCheck(c rune) bool {
|
|||
// *dw1 : DW1 register value
|
||||
// return
|
||||
// error status
|
||||
func useInteltoolLogTemplate(line string, function *string,
|
||||
func UseInteltoolLogTemplate(line string, function *string,
|
||||
id *string, dw0 *uint32, dw1 *uint32) int {
|
||||
|
||||
var val uint64
|
||||
|
|
@ -57,7 +59,7 @@ func useInteltoolLogTemplate(line string, function *string,
|
|||
*function += "/" + fields[i]
|
||||
}
|
||||
// clear RO Interrupt Select (INTSEL)
|
||||
*dw1 &= 0xffffff00
|
||||
*dw1 &= INTSEL_MASK
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
|
|
|||
38
util/intelp2m/parser/template_test.go
Normal file
38
util/intelp2m/parser/template_test.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package parser_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"review.coreboot.org/coreboot.git/util/intelp2m/parser"
|
||||
)
|
||||
|
||||
func TestTemp(t *testing.T) {
|
||||
t.Run("TEMPLATE/INTELTOOL-LINE", func(t *testing.T) {
|
||||
const (
|
||||
ref_fn string = "SLP_S0#"
|
||||
ref_id string = "GPP_B12"
|
||||
ref_dw0 uint32 = 0x44000600
|
||||
ref_dw1 uint32 = 0x0000003c
|
||||
)
|
||||
var (
|
||||
fn, id string
|
||||
dw0, dw1 uint32
|
||||
)
|
||||
line := fmt.Sprintf("0x0520: 0x%08x%08x %s %s", ref_dw1, ref_dw0, ref_id, ref_fn)
|
||||
_ = parser.UseInteltoolLogTemplate(line, &fn, &id, &dw0, &dw1)
|
||||
if fn != ref_fn {
|
||||
t.Errorf("function from '%s':\nExpects: '%s'\nActually: '%s'\n\n",
|
||||
line, ref_fn, fn)
|
||||
} else if id != ref_id {
|
||||
t.Errorf("id from '%s':\nExpects: '%s'\nActually: '%s'\n\n",
|
||||
line, ref_id, id)
|
||||
} else if dw0 != ref_dw0 {
|
||||
t.Errorf("dw0 from '%s':\nExpects: '0x%08x'\nActually: '0x%08x'\n\n",
|
||||
line, ref_dw0, dw0)
|
||||
} else if dw1 != (ref_dw1 & parser.INTSEL_MASK) {
|
||||
t.Errorf("dw1 from '%s':\nExpects: '0x%08x'\nActually: '0x%08x'\n\n",
|
||||
line, (ref_dw1 & parser.INTSEL_MASK), dw1)
|
||||
}
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue