github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/ifuzz/x86_test.go (about) 1 // Copyright 2024 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package ifuzz 5 6 import ( 7 "encoding/hex" 8 "strings" 9 "testing" 10 11 "github.com/google/syzkaller/pkg/ifuzz/iset" 12 ) 13 14 type regTestCase struct { 15 text string 16 mode iset.Mode 17 } 18 19 // Regression test for x86 instruction decoding. 20 // nolint: lll 21 func TestDecodeRegression(t *testing.T) { 22 testData := []regTestCase{ 23 {"46 f7 25 04 49 a3 2c b9 14 01 01 c0 b8 c3 de 66 3f ba 1f 38 8b 0f 0f 30 2e 6e 2e 74 1c 0f 01 30 b9 80 00 00 c0 0f 32 35 00 08 00 00 0f 30 d9 be 45 00 00 00 c7 44 24 00 0b 00 00 00 c7 44 24 02 0e ff ff ff ff 2c 24 c4 23 e9 6c 6e b9 d3", iset.ModeLong64}, 24 {"0f 30 f0 f7 94 c3 00 0f c7 5f e8 9a 0d 00 ed 00", iset.ModeProt16}, 25 } 26 insnset := iset.Arches[ArchX86] 27 for _, test := range testData { 28 text, err := hex.DecodeString(strings.ReplaceAll(test.text, " ", "")) 29 if err != nil { 30 t.Fatalf("invalid hex string") 31 } 32 for len(text) != 0 { 33 size, err := insnset.Decode(test.mode, text) 34 if size == 0 || err != nil { 35 t.Errorf("failed to decode text: % x", text) 36 break 37 } 38 text = text[size:] 39 } 40 } 41 }