github.com/cnboonhan/delve@v0.0.0-20230908061759-363f2388c2fb/pkg/dwarf/frame/parser_test.go (about)

     1  package frame
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/binary"
     6  	"io/ioutil"
     7  	"os"
     8  	"testing"
     9  )
    10  
    11  func TestParseCIE(t *testing.T) {
    12  	ctx := &parseContext{
    13  		buf:    bytes.NewBuffer([]byte{3, 0, 1, 124, 16, 12, 7, 8, 5, 16, 2, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 16, 64, 0, 0, 0, 0, 0}),
    14  		common: &CommonInformationEntry{Length: 12},
    15  		length: 12,
    16  	}
    17  	ctx.totalLen = ctx.buf.Len()
    18  	_ = parseCIE(ctx)
    19  
    20  	common := ctx.common
    21  
    22  	if common.Version != 3 {
    23  		t.Fatalf("Expected Version 3, but get %d", common.Version)
    24  	}
    25  	if common.Augmentation != "" {
    26  		t.Fatalf("Expected Augmentation \"\", but get %s", common.Augmentation)
    27  	}
    28  	if common.CodeAlignmentFactor != 1 {
    29  		t.Fatalf("Expected CodeAlignmentFactor 1, but get %d", common.CodeAlignmentFactor)
    30  	}
    31  	if common.DataAlignmentFactor != -4 {
    32  		t.Fatalf("Expected DataAlignmentFactor -4, but get %d", common.DataAlignmentFactor)
    33  	}
    34  	if common.ReturnAddressRegister != 16 {
    35  		t.Fatalf("Expected ReturnAddressRegister 16, but get %d", common.ReturnAddressRegister)
    36  	}
    37  	initialInstructions := []byte{12, 7, 8, 5, 16, 2, 0}
    38  	if !bytes.Equal(common.InitialInstructions, initialInstructions) {
    39  		t.Fatalf("Expected InitialInstructions %v, but get %v", initialInstructions, common.InitialInstructions)
    40  	}
    41  }
    42  
    43  func BenchmarkParse(b *testing.B) {
    44  	f, err := os.Open("testdata/frame")
    45  	if err != nil {
    46  		b.Fatal(err)
    47  	}
    48  	defer f.Close()
    49  
    50  	data, err := ioutil.ReadAll(f)
    51  	if err != nil {
    52  		b.Fatal(err)
    53  	}
    54  
    55  	b.ResetTimer()
    56  	for i := 0; i < b.N; i++ {
    57  		Parse(data, binary.BigEndian, 0, ptrSizeByRuntimeArch(), 0)
    58  	}
    59  }