gitlab.com/Raven-IO/raven-delve@v1.22.4/pkg/proc/internal/ebpf/helpers_test.go (about)

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