-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation tests for riscv64asm GNU/Plan9 decoder, including objdump test and external test. Change-Id: Id7442704ea7e10c22ca4a799cdfc9f7d043f85c3 Reviewed-on: https://go-review.googlesource.com/c/arch/+/602916 Reviewed-by: Meng Zhuo <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: David Chase <[email protected]> Reviewed-by: Mark Ryan <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
- Loading branch information
Showing
7 changed files
with
1,530 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package riscv64asm | ||
|
||
import ( | ||
"bufio" | ||
"encoding/hex" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func testDecode(t *testing.T, syntax string) { | ||
input := filepath.Join("testdata", syntax+"cases.txt") | ||
f, err := os.Open(input) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer f.Close() | ||
scanner := bufio.NewScanner(f) | ||
for scanner.Scan() { | ||
line := strings.TrimSpace(scanner.Text()) | ||
if line == "" || strings.HasPrefix(line, "#") { | ||
continue | ||
} | ||
f := strings.SplitN(line, "\t", 2) | ||
i := strings.Index(f[0], "|") | ||
|
||
if i < 0 { | ||
t.Errorf("parsing %q: missing | separator", f[0]) | ||
continue | ||
} | ||
if i%2 != 0 { | ||
t.Errorf("parsing %q: misaligned | separator", f[0]) | ||
} | ||
code, err := hex.DecodeString(f[0][:i] + f[0][i+1:]) | ||
if err != nil { | ||
t.Errorf("parsing %q: %v", f[0], err) | ||
continue | ||
} | ||
asm0 := strings.Replace(f[1], " ", " ", -1) | ||
asm := strings.TrimSpace(asm0) | ||
inst, decodeErr := Decode(code) | ||
if decodeErr != nil && decodeErr != errUnknown { | ||
if asm == "illegalins" && decodeErr == errShort { | ||
continue | ||
} | ||
// Some rarely used system instructions are not supported | ||
// Following logicals will filter such unknown instructions | ||
t.Errorf("parsing %x: %s", code, decodeErr) | ||
continue | ||
} | ||
|
||
var out string | ||
switch syntax { | ||
case "gnu": | ||
out = GNUSyntax(inst) | ||
case "plan9": | ||
out = GoSyntax(inst, 0, nil, nil) | ||
default: | ||
t.Errorf("unknown syntax %q", syntax) | ||
continue | ||
} | ||
|
||
if asm != out { | ||
t.Errorf("Decode(%s) [%s] = %s want %s", f[0], syntax, out, asm) | ||
} | ||
} | ||
} | ||
|
||
func TestDecodeGNUSyntax(t *testing.T) { | ||
testDecode(t, "gnu") | ||
} | ||
|
||
func TestDecodeGoSyntax(t *testing.T) { | ||
testDecode(t, "plan9") | ||
} |
Oops, something went wrong.