aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/ifuzz/ifuzz_test.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-11-20 18:24:56 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-11-21 08:46:20 +0100
commit9071fc0e22cf194e6e048dff403155cbb0205a1f (patch)
treeff0f3eda72167f09c89750417b761f24e53ed143 /pkg/ifuzz/ifuzz_test.go
parent5405d2e2ed019de7452677eacfc7de9562a8ea12 (diff)
pkg/ifuzz/ifuzzimpl: move ModeInsns into tests
ModeInsns is only used in tests. Move it there.
Diffstat (limited to 'pkg/ifuzz/ifuzz_test.go')
-rw-r--r--pkg/ifuzz/ifuzz_test.go25
1 files changed, 15 insertions, 10 deletions
diff --git a/pkg/ifuzz/ifuzz_test.go b/pkg/ifuzz/ifuzz_test.go
index 70177b5ef..d62048304 100644
--- a/pkg/ifuzz/ifuzz_test.go
+++ b/pkg/ifuzz/ifuzz_test.go
@@ -28,13 +28,7 @@ func testMode(t *testing.T, arch string) {
for mode := ifuzzimpl.Mode(0); mode < ifuzzimpl.ModeLast; mode++ {
for priv := 0; priv < 2; priv++ {
for exec := 0; exec < 2; exec++ {
- cfg := &Config{
- Arch: arch,
- Mode: mode,
- Priv: priv != 0,
- Exec: exec != 0,
- }
- insns := ifuzzimpl.ModeInsns(cfg)
+ insns := allInsns(arch, mode, priv != 0, exec != 0)
t.Logf("mode=%v priv=%v exec=%v: %v instructions", mode, priv, exec, len(insns))
for _, insn := range insns {
all[insn] = true
@@ -68,14 +62,13 @@ func testDecode(t *testing.T, arch string) {
for repeat := 0; repeat < 10; repeat++ {
for mode := ifuzzimpl.Mode(0); mode < ifuzzimpl.ModeLast; mode++ {
- cfg := &Config{
- Arch: arch,
+ cfg := &ifuzzimpl.Config{
Mode: mode,
Priv: true,
Exec: true,
}
failed := false
- for _, insn := range ifuzzimpl.ModeInsns(cfg) {
+ for _, insn := range allInsns(arch, mode, true, true) {
text0 := insn.Encode(cfg, r)
text := text0
repeat:
@@ -127,3 +120,15 @@ func testDecode(t *testing.T, arch string) {
}
}
}
+
+func allInsns(arch string, mode ifuzzimpl.Mode, priv, exec bool) []ifuzzimpl.Insn {
+ insnset := ifuzzimpl.Arches[arch]
+ insns := insnset.GetInsns(mode, ifuzzimpl.TypeUser)
+ if priv {
+ insns = append(insns, insnset.GetInsns(mode, ifuzzimpl.TypePriv)...)
+ if exec {
+ insns = append(insns, insnset.GetInsns(mode, ifuzzimpl.TypeExec)...)
+ }
+ }
+ return insns
+}