github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/syz-manager/covfilter_test.go (about) 1 // Copyright 2020 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 main 5 6 import ( 7 "testing" 8 9 "github.com/google/syzkaller/sys/targets" 10 ) 11 12 func TestCreateBitmap(t *testing.T) { 13 pcs := map[uint32]uint32{ 14 0x81000002: 1, 15 0x8120001d: 1, 16 } 17 target := targets.Get("test", "64") 18 order := target.HostEndian 19 bitmap := createCoverageBitmap(target, pcs) 20 start := order.Uint32(bitmap[0:]) 21 size := order.Uint32(bitmap[4:]) 22 if start != 0x81000002 || size != 0x20001b { 23 t.Fatalf("bad region 0x%x/0x%x", start, size) 24 } 25 for i, byte := range bitmap[8:] { 26 var expect uint8 27 switch i { 28 case 0: 29 expect = 0x1 30 case 0x20001 / 0x8: 31 expect = 1 << (0x20001 % 0x8) 32 } 33 if byte != expect { 34 t.Errorf("bad bitmap byte 0x%x: 0x%x, expect 0x%x", i, byte, expect) 35 } 36 } 37 pcs = map[uint32]uint32{ 38 0: 1, 39 0xffffffff: 1, 40 } 41 createCoverageBitmap(target, pcs) 42 pcs = map[uint32]uint32{ 43 0x81000000: 1, 44 0x81000100: 1, 45 } 46 createCoverageBitmap(target, pcs) 47 pcs = map[uint32]uint32{ 48 0x81000002: 1, 49 0x81000010: 1, 50 0x81000102: 1, 51 } 52 createCoverageBitmap(target, pcs) 53 } 54 55 func TestNilCoverageBitmap(t *testing.T) { 56 pcs := map[uint32]uint32(nil) 57 target := targets.Get("test", "64") 58 bitmap := createCoverageBitmap(target, pcs) 59 if bitmap != nil { 60 t.Errorf("created a bitmap on nil pcs") 61 } 62 }