@@ -1462,9 +1462,10 @@ func (t test) wantedErrors(file, short string) (errs []wantedError) {
1462
1462
1463
1463
const (
1464
1464
// Regexp to match a single opcode check: optionally begin with "-" (to indicate
1465
- // a negative check), followed by a string literal enclosed in "" or ``. For "",
1465
+ // a negative check) or a positive number (to specify the expected number of
1466
+ // matches), followed by a string literal enclosed in "" or ``. For "",
1466
1467
// backslashes must be handled.
1467
- reMatchCheck = `- ?(?:\x60[^\x60]*\x60|"(?:[^"\\]|\\.)*")`
1468
+ reMatchCheck = `(-|[1-9]\d*) ?(?:\x60[^\x60]*\x60|"(?:[^"\\]|\\.)*")`
1468
1469
)
1469
1470
1470
1471
var (
@@ -1516,6 +1517,8 @@ type wantedAsmOpcode struct {
1516
1517
fileline string // original source file/line (eg: "/path/foo.go:45")
1517
1518
line int // original source line
1518
1519
opcode * regexp.Regexp // opcode check to be performed on assembly output
1520
+ expected int // expected number of matches
1521
+ actual int // actual number that matched
1519
1522
negative bool // true if the check is supposed to fail rather than pass
1520
1523
found bool // true if the opcode check matched at least one in the output
1521
1524
}
@@ -1622,9 +1625,16 @@ func (t test) wantedAsmOpcodes(fn string) asmChecks {
1622
1625
1623
1626
for _ , m := range rxAsmCheck .FindAllString (allchecks , - 1 ) {
1624
1627
negative := false
1628
+ expected := 0
1625
1629
if m [0 ] == '-' {
1626
1630
negative = true
1627
1631
m = m [1 :]
1632
+ } else if '1' <= m [0 ] && m [0 ] <= '9' {
1633
+ for '0' <= m [0 ] && m [0 ] <= '9' {
1634
+ expected *= 10
1635
+ expected += int (m [0 ] - '0' )
1636
+ m = m [1 :]
1637
+ }
1628
1638
}
1629
1639
1630
1640
rxsrc , err := strconv .Unquote (m )
@@ -1650,6 +1660,7 @@ func (t test) wantedAsmOpcodes(fn string) asmChecks {
1650
1660
ops [env ] = make (map [string ][]wantedAsmOpcode )
1651
1661
}
1652
1662
ops [env ][lnum ] = append (ops [env ][lnum ], wantedAsmOpcode {
1663
+ expected : expected ,
1653
1664
negative : negative ,
1654
1665
fileline : lnum ,
1655
1666
line : i + 1 ,
@@ -1698,7 +1709,8 @@ func (t test) asmCheck(outStr string, fn string, env buildEnv, fullops map[strin
1698
1709
// run the checks.
1699
1710
if ops , found := fullops [srcFileLine ]; found {
1700
1711
for i := range ops {
1701
- if ! ops [i ].found && ops [i ].opcode .FindString (asm ) != "" {
1712
+ if (! ops [i ].found || ops [i ].expected > 0 ) && ops [i ].opcode .FindString (asm ) != "" {
1713
+ ops [i ].actual ++
1702
1714
ops [i ].found = true
1703
1715
}
1704
1716
}
@@ -1714,6 +1726,9 @@ func (t test) asmCheck(outStr string, fn string, env buildEnv, fullops map[strin
1714
1726
if o .negative == o .found {
1715
1727
failed = append (failed , o )
1716
1728
}
1729
+ if o .expected > 0 && o .expected != o .actual {
1730
+ failed = append (failed , o )
1731
+ }
1717
1732
}
1718
1733
}
1719
1734
if len (failed ) == 0 {
@@ -1737,6 +1752,8 @@ func (t test) asmCheck(outStr string, fn string, env buildEnv, fullops map[strin
1737
1752
1738
1753
if o .negative {
1739
1754
fmt .Fprintf (& errbuf , "%s:%d: %s: wrong opcode found: %q\n " , t .goFileName (), o .line , env , o .opcode .String ())
1755
+ } else if o .expected > 0 {
1756
+ fmt .Fprintf (& errbuf , "%s:%d: %s: wrong number of opcodes: %q\n " , t .goFileName (), o .line , env , o .opcode .String ())
1740
1757
} else {
1741
1758
fmt .Fprintf (& errbuf , "%s:%d: %s: opcode not found: %q\n " , t .goFileName (), o .line , env , o .opcode .String ())
1742
1759
}
0 commit comments