github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/ifuzz/arm64/util_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 arm64
     5  
     6  import (
     7  	"testing"
     8  )
     9  
    10  func extractBitsOne(t *testing.T, from uint32, start, size uint, expect uint32) {
    11  	ret := extractBits(from, start, size)
    12  	if ret != expect {
    13  		t.Fatalf("extractBits(%x, %d, %d) returned %x instead of %x", from, start, size, ret, expect)
    14  	}
    15  }
    16  
    17  func TestExtractBits(t *testing.T) {
    18  	extractBitsOne(t, 0, 0, 0, 0)
    19  	extractBitsOne(t, 0xffffffff, 0, 0, 0)
    20  	for i := uint(0); i <= 31; i++ {
    21  		extractBitsOne(t, 0xffffffff, i, 1, 1)
    22  	}
    23  	extractBitsOne(t, 0xf0f0f0f0, 31, 5, 0b11110)
    24  	extractBitsOne(t, 0xf0f0f0f0, 25, 4, 0b0011)
    25  	extractBitsOne(t, 0xf0f0f0f0, 21, 4, 0b1100)
    26  }