github.com/cnboonhan/delve@v0.0.0-20230908061759-363f2388c2fb/pkg/proc/internal/ebpf/helpers_test.go (about)

     1  //go:build linux && amd64 && cgo && go1.16
     2  // +build linux,amd64,cgo,go1.16
     3  
     4  package ebpf
     5  
     6  import (
     7  	"reflect"
     8  	"testing"
     9  
    10  	"github.com/go-delve/delve/pkg/proc/internal/ebpf/testhelper"
    11  )
    12  
    13  func compareStructTypes(t *testing.T, gostructVal, cstructVal interface{}) {
    14  	gostruct := reflect.ValueOf(gostructVal).Type()
    15  	cstruct := reflect.ValueOf(cstructVal).Type()
    16  	if gostruct.NumField() != cstruct.NumField() {
    17  		t.Errorf("mismatched field number %d %d", gostruct.NumField(), cstruct.NumField())
    18  		return
    19  	}
    20  	for i := 0; i < cstruct.NumField(); i++ {
    21  		gofield := gostruct.Field(i)
    22  		cfield := cstruct.Field(i)
    23  		t.Logf("%d %s %s\n", i, gofield.Name, cfield.Name)
    24  		if gofield.Name != cfield.Name {
    25  			t.Errorf("mismatched name for field %s %s", gofield.Name, cfield.Name)
    26  		}
    27  		if gofield.Offset != cfield.Offset {
    28  			t.Errorf("mismatched offset for field %s %s (%d %d)", gofield.Name, cfield.Name, gofield.Offset, cfield.Offset)
    29  		}
    30  		if gofield.Type.Size() != cfield.Type.Size() {
    31  			t.Errorf("mismatched size for field %s %s (%d %d)", gofield.Name, cfield.Name, gofield.Type.Size(), cfield.Type.Size())
    32  		}
    33  	}
    34  }
    35  
    36  func TestStructConsistency(t *testing.T) {
    37  	t.Run("function_parameter_t", func(t *testing.T) {
    38  		compareStructTypes(t, function_parameter_t{}, testhelper.Function_parameter_t{})
    39  	})
    40  	t.Run("function_parameter_list_t", func(t *testing.T) {
    41  		compareStructTypes(t, function_parameter_list_t{}, testhelper.Function_parameter_list_t{})
    42  	})
    43  }