| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package xmlspec |
| 6 |
|
| 7 |
import ( |
| 8 |
"flag" |
| 9 |
"regexp" |
| 10 |
"strings" |
| 11 |
"testing" |
| 12 |
) |
| 13 |
|
| 14 |
var remoteData = flag.Bool("remote", false, "use remote data") |
| 15 |
|
| 16 |
func getData(t *testing.T) []*InstructionParsed { |
| 17 |
if *remoteData { |
| 18 |
xmlDir, err := GetArm64XMLSpec(t.TempDir(), ExpectedURL, ExpectedVersion) |
| 19 |
if err != nil { |
| 20 |
t.Fatalf("GetArm64XMLSpec failed: %v", err) |
| 21 |
} |
| 22 |
return ParseXMLFiles(xmlDir) |
| 23 |
} |
| 24 |
return ParseXMLFiles("testdata") |
| 25 |
} |
| 26 |
|
| 27 |
func TestParseXMLFiles(t *testing.T) { |
| 28 |
insts := getData(t) |
| 29 |
|
| 30 |
t.Logf("Number of instructions: %d\n", len(insts)) |
| 31 |
} |
| 32 |
|
| 33 |
func TestProcessXMLFiles(t *testing.T) { |
| 34 |
insts := getData(t) |
| 35 |
ProcessXMLFiles(insts) |
| 36 |
specialInsts := map[string]bool{ |
| 37 |
"HISTSEG -- A64": true, |
| 38 |
"REVB, REVH, REVW -- A64": true, |
| 39 |
"SXTB, SXTH, SXTW -- A64": true, |
| 40 |
"URECPE -- A64": true, |
| 41 |
"URSQRTE -- A64": true, |
| 42 |
"UXTB, UXTH, UXTW -- A64": true, |
| 43 |
} |
| 44 |
outer: |
| 45 |
for _, inst := range insts { |
| 46 |
if inst == nil { |
| 47 |
continue |
| 48 |
} |
| 49 |
if specialInsts[inst.Title] { |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
continue |
| 54 |
} |
| 55 |
isAlias := false |
| 56 |
for _, doc := range inst.DocVars { |
| 57 |
if doc.Key == "alias_mnemonic" { |
| 58 |
isAlias = true |
| 59 |
break |
| 60 |
} |
| 61 |
} |
| 62 |
if isAlias { |
| 63 |
|
| 64 |
|
| 65 |
continue |
| 66 |
} |
| 67 |
|
| 68 |
for _, iclass := range inst.Classes.Iclass { |
| 69 |
if !iclass.RegDiagram.Parsed { |
| 70 |
continue |
| 71 |
} |
| 72 |
for _, encoding := range iclass.Encodings { |
| 73 |
if !encoding.Parsed { |
| 74 |
continue outer |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
encodedBoxes := make(map[string]bool) |
| 80 |
for _, encoding := range iclass.Encodings { |
| 81 |
if encoding.Alias { |
| 82 |
|
| 83 |
|
| 84 |
continue |
| 85 |
} |
| 86 |
for _, operand := range encoding.Operands { |
| 87 |
for _, elem := range operand.Elems { |
| 88 |
encodedIn := elem.encodedIn |
| 89 |
encodedBoxes[encodedIn] = true |
| 90 |
if strings.Contains(encodedIn, ":") { |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
re := regexp.MustCompile(`\((.*?) :: (.*?)( :: (.*?))?\)`) |
| 98 |
matches := re.FindStringSubmatch(encodedIn) |
| 99 |
if len(matches) == 3 { |
| 100 |
encodedBoxes[matches[1]] = true |
| 101 |
encodedBoxes[matches[2]] = true |
| 102 |
} else if len(matches) == 5 { |
| 103 |
encodedBoxes[matches[1]] = true |
| 104 |
encodedBoxes[matches[2]] = true |
| 105 |
encodedBoxes[matches[4]] = true |
| 106 |
} |
| 107 |
} |
| 108 |
if strings.Contains(encodedIn, "[") { |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
re := regexp.MustCompile(`(.*)\[.*?\]`) |
| 114 |
matches := re.FindStringSubmatch(encodedIn) |
| 115 |
if len(matches) == 2 { |
| 116 |
encodedBoxes[matches[1]] = true |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
for name := range iclass.RegDiagram.varBin { |
| 123 |
if !encodedBoxes[name] { |
| 124 |
t.Errorf("Box %s not encoded in %s", name, inst.file) |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
} |