diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-11-20 18:24:56 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-11-21 08:46:20 +0100 |
| commit | 9071fc0e22cf194e6e048dff403155cbb0205a1f (patch) | |
| tree | ff0f3eda72167f09c89750417b761f24e53ed143 /pkg/ifuzz | |
| parent | 5405d2e2ed019de7452677eacfc7de9562a8ea12 (diff) | |
pkg/ifuzz/ifuzzimpl: move ModeInsns into tests
ModeInsns is only used in tests. Move it there.
Diffstat (limited to 'pkg/ifuzz')
| -rw-r--r-- | pkg/ifuzz/ifuzz_test.go | 25 | ||||
| -rw-r--r-- | pkg/ifuzz/ifuzzimpl/ifuzzimpl.go | 16 |
2 files changed, 15 insertions, 26 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 +} diff --git a/pkg/ifuzz/ifuzzimpl/ifuzzimpl.go b/pkg/ifuzz/ifuzzimpl/ifuzzimpl.go index 71485172c..3de38ea59 100644 --- a/pkg/ifuzz/ifuzzimpl/ifuzzimpl.go +++ b/pkg/ifuzz/ifuzzimpl/ifuzzimpl.go @@ -64,20 +64,4 @@ const ( TypeLast ) -// ModeInsns returns list of all instructions for the given mode. -func ModeInsns(cfg *Config) []Insn { - insnset := Arches[cfg.Arch] - if cfg.Mode < 0 || cfg.Mode >= ModeLast { - panic("bad mode") - } - insns := insnset.GetInsns(cfg.Mode, TypeUser) - if cfg.Priv { - insns = append(insns, insnset.GetInsns(cfg.Mode, TypePriv)...) - if cfg.Exec { - insns = append(insns, insnset.GetInsns(cfg.Mode, TypeExec)...) - } - } - return insns -} - var SpecialNumbers = [...]uint64{0, 1 << 15, 1 << 16, 1 << 31, 1 << 32, 1 << 47, 1 << 47, 1 << 63} |
