Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(366)

Delta Between Two Patch Sets: x86asm/decode_test.go

Issue 93110044: code review 93110044: x86asm: instruction decoder (Closed)
Left Patch Set: Created 9 years, 10 months ago
Right Patch Set: diff -r 66b21e781a9a https://code.google.com/p/rsc.x86/ Created 9 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « x86asm/decode.go ('k') | x86asm/inst.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package x86asm
6
7 import (
8 "encoding/hex"
9 "io/ioutil"
10 "strings"
11 "testing"
12 )
13
14 func TestDecode(t *testing.T) {
15 data, err := ioutil.ReadFile("testdata/decode.txt")
16 if err != nil {
17 t.Fatal(err)
18 }
19 all := string(data)
20 for strings.Contains(all, "\t\t") {
21 all = strings.Replace(all, "\t\t", "\t", -1)
22 }
23 for _, line := range strings.Split(all, "\n") {
24 line = strings.TrimSpace(line)
25 if line == "" || strings.HasPrefix(line, "#") {
26 continue
27 }
28 f := strings.SplitN(line, "\t", 3)
29 i := strings.Index(f[0], "|")
30 if i < 0 {
31 t.Errorf("parsing %q: missing | separator", f[0])
32 continue
33 }
34 if i%2 != 0 {
35 t.Errorf("parsing %q: misaligned | separator", f[0])
36 }
37 size := i / 2
38 code, err := hex.DecodeString(f[0][:i] + f[0][i+1:])
39 if err != nil {
40 t.Errorf("parsing %q: %v", f[0], err)
41 continue
42 }
43 syntax, asm := f[1], f[2]
44 inst, instSize, err := Decode(code, 32)
45 var out string
46 if err != nil {
47 out = "error: " + err.Error()
48 } else {
49 switch syntax {
50 case "gnu":
51 out = GNUSyntax(inst)
52 case "intel":
53 out = IntelSyntax(inst)
54 default:
55 t.Errorf("unknown syntax %q", syntax)
56 continue
57 }
58 }
59 if out != asm || instSize != size {
60 t.Errorf("Decode(%s) [%s] = %s, %d, want %s, %d", f[0], syntax, out, instSize, asm, size)
61 }
62 }
63 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b