diff --git a/pdata/internal/cmd/pdatagen/internal/base_slices.go b/pdata/internal/cmd/pdatagen/internal/base_slices.go index f3f27ad23e3f..8cc7c9cad507 100644 --- a/pdata/internal/cmd/pdatagen/internal/base_slices.go +++ b/pdata/internal/cmd/pdatagen/internal/base_slices.go @@ -240,6 +240,23 @@ func (es ${structName}) Sort(less func(a, b ${elementName}) bool) { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) }` +// TODO: Use assert.Less once https://github.com/stretchr/testify/pull/1339 is merged. +const slicePtrTestTemplate = `func Test${structName}_Sort(t *testing.T) { + es := generateTest${structName}() + es.Sort(func(a, b ${elementName}) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b ${elementName}) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +}` + const sliceValueTemplate = `// CopyTo copies all elements from the current slice overriding the destination. func (es ${structName}) CopyTo(dest ${structName}) { srcLen := es.Len() @@ -295,7 +312,8 @@ func (ss *sliceOfPtrs) generateStruct(sb *bytes.Buffer) { } func (ss *sliceOfPtrs) generateTests(sb *bytes.Buffer) { - sb.WriteString(os.Expand(commonSliceTestTemplate, ss.templateFields())) + sb.WriteString(os.Expand(commonSliceTestTemplate, ss.templateFields()) + newLine + newLine) + sb.WriteString(os.Expand(slicePtrTestTemplate, ss.templateFields())) } func (ss *sliceOfPtrs) generateTestValueHelpers(sb *bytes.Buffer) { diff --git a/pdata/internal/cmd/pdatagen/internal/plog_package.go b/pdata/internal/cmd/pdatagen/internal/plog_package.go index f9bfeca8dea6..ea94e4fec924 100644 --- a/pdata/internal/cmd/pdatagen/internal/plog_package.go +++ b/pdata/internal/cmd/pdatagen/internal/plog_package.go @@ -27,6 +27,7 @@ var plog = &Package{ }, testImports: []string{ `"testing"`, + `"unsafe"`, ``, `"github.com/stretchr/testify/assert"`, ``, diff --git a/pdata/internal/cmd/pdatagen/internal/pmetric_package.go b/pdata/internal/cmd/pdatagen/internal/pmetric_package.go index 05e5db7c5af9..8e08dfa53462 100644 --- a/pdata/internal/cmd/pdatagen/internal/pmetric_package.go +++ b/pdata/internal/cmd/pdatagen/internal/pmetric_package.go @@ -27,6 +27,7 @@ var pmetric = &Package{ }, testImports: []string{ `"testing"`, + `"unsafe"`, ``, `"github.com/stretchr/testify/assert"`, ``, diff --git a/pdata/internal/cmd/pdatagen/internal/ptrace_package.go b/pdata/internal/cmd/pdatagen/internal/ptrace_package.go index 2f330039a1ac..ad44a8c283e0 100644 --- a/pdata/internal/cmd/pdatagen/internal/ptrace_package.go +++ b/pdata/internal/cmd/pdatagen/internal/ptrace_package.go @@ -27,6 +27,7 @@ var ptrace = &Package{ }, testImports: []string{ `"testing"`, + `"unsafe"`, ``, `"github.com/stretchr/testify/assert"`, ``, diff --git a/pdata/plog/generated_logrecordslice_test.go b/pdata/plog/generated_logrecordslice_test.go index c02079f163bd..b2fa2345eec0 100644 --- a/pdata/plog/generated_logrecordslice_test.go +++ b/pdata/plog/generated_logrecordslice_test.go @@ -19,6 +19,7 @@ package plog import ( "testing" + "unsafe" "github.com/stretchr/testify/assert" @@ -118,6 +119,22 @@ func TestLogRecordSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func TestLogRecordSlice_Sort(t *testing.T) { + es := generateTestLogRecordSlice() + es.Sort(func(a, b LogRecord) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b LogRecord) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + func generateTestLogRecordSlice() LogRecordSlice { es := NewLogRecordSlice() fillTestLogRecordSlice(es) diff --git a/pdata/plog/generated_resourcelogsslice_test.go b/pdata/plog/generated_resourcelogsslice_test.go index ff61705f40d7..4db84600d053 100644 --- a/pdata/plog/generated_resourcelogsslice_test.go +++ b/pdata/plog/generated_resourcelogsslice_test.go @@ -19,6 +19,7 @@ package plog import ( "testing" + "unsafe" "github.com/stretchr/testify/assert" @@ -118,6 +119,22 @@ func TestResourceLogsSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func TestResourceLogsSlice_Sort(t *testing.T) { + es := generateTestResourceLogsSlice() + es.Sort(func(a, b ResourceLogs) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b ResourceLogs) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + func generateTestResourceLogsSlice() ResourceLogsSlice { es := NewResourceLogsSlice() fillTestResourceLogsSlice(es) diff --git a/pdata/plog/generated_scopelogsslice_test.go b/pdata/plog/generated_scopelogsslice_test.go index 6e4832a60263..45fbe3077c78 100644 --- a/pdata/plog/generated_scopelogsslice_test.go +++ b/pdata/plog/generated_scopelogsslice_test.go @@ -19,6 +19,7 @@ package plog import ( "testing" + "unsafe" "github.com/stretchr/testify/assert" @@ -118,6 +119,22 @@ func TestScopeLogsSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func TestScopeLogsSlice_Sort(t *testing.T) { + es := generateTestScopeLogsSlice() + es.Sort(func(a, b ScopeLogs) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b ScopeLogs) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + func generateTestScopeLogsSlice() ScopeLogsSlice { es := NewScopeLogsSlice() fillTestScopeLogsSlice(es) diff --git a/pdata/pmetric/generated_exponentialhistogramdatapointslice_test.go b/pdata/pmetric/generated_exponentialhistogramdatapointslice_test.go index 80a9a2ffd3e0..1eeecc97be80 100644 --- a/pdata/pmetric/generated_exponentialhistogramdatapointslice_test.go +++ b/pdata/pmetric/generated_exponentialhistogramdatapointslice_test.go @@ -19,6 +19,7 @@ package pmetric import ( "testing" + "unsafe" "github.com/stretchr/testify/assert" @@ -118,6 +119,22 @@ func TestExponentialHistogramDataPointSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func TestExponentialHistogramDataPointSlice_Sort(t *testing.T) { + es := generateTestExponentialHistogramDataPointSlice() + es.Sort(func(a, b ExponentialHistogramDataPoint) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b ExponentialHistogramDataPoint) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + func generateTestExponentialHistogramDataPointSlice() ExponentialHistogramDataPointSlice { es := NewExponentialHistogramDataPointSlice() fillTestExponentialHistogramDataPointSlice(es) diff --git a/pdata/pmetric/generated_histogramdatapointslice_test.go b/pdata/pmetric/generated_histogramdatapointslice_test.go index ee00017d9b1b..8999f0401086 100644 --- a/pdata/pmetric/generated_histogramdatapointslice_test.go +++ b/pdata/pmetric/generated_histogramdatapointslice_test.go @@ -19,6 +19,7 @@ package pmetric import ( "testing" + "unsafe" "github.com/stretchr/testify/assert" @@ -118,6 +119,22 @@ func TestHistogramDataPointSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func TestHistogramDataPointSlice_Sort(t *testing.T) { + es := generateTestHistogramDataPointSlice() + es.Sort(func(a, b HistogramDataPoint) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b HistogramDataPoint) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + func generateTestHistogramDataPointSlice() HistogramDataPointSlice { es := NewHistogramDataPointSlice() fillTestHistogramDataPointSlice(es) diff --git a/pdata/pmetric/generated_metricslice_test.go b/pdata/pmetric/generated_metricslice_test.go index 4a6c05ad96ef..a7d0daedcd3e 100644 --- a/pdata/pmetric/generated_metricslice_test.go +++ b/pdata/pmetric/generated_metricslice_test.go @@ -19,6 +19,7 @@ package pmetric import ( "testing" + "unsafe" "github.com/stretchr/testify/assert" @@ -118,6 +119,22 @@ func TestMetricSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func TestMetricSlice_Sort(t *testing.T) { + es := generateTestMetricSlice() + es.Sort(func(a, b Metric) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b Metric) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + func generateTestMetricSlice() MetricSlice { es := NewMetricSlice() fillTestMetricSlice(es) diff --git a/pdata/pmetric/generated_numberdatapointslice_test.go b/pdata/pmetric/generated_numberdatapointslice_test.go index 02ac86f82324..d14d644f007d 100644 --- a/pdata/pmetric/generated_numberdatapointslice_test.go +++ b/pdata/pmetric/generated_numberdatapointslice_test.go @@ -19,6 +19,7 @@ package pmetric import ( "testing" + "unsafe" "github.com/stretchr/testify/assert" @@ -118,6 +119,22 @@ func TestNumberDataPointSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func TestNumberDataPointSlice_Sort(t *testing.T) { + es := generateTestNumberDataPointSlice() + es.Sort(func(a, b NumberDataPoint) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b NumberDataPoint) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + func generateTestNumberDataPointSlice() NumberDataPointSlice { es := NewNumberDataPointSlice() fillTestNumberDataPointSlice(es) diff --git a/pdata/pmetric/generated_resourcemetricsslice_test.go b/pdata/pmetric/generated_resourcemetricsslice_test.go index 76bf47d49f75..27e31e3fc881 100644 --- a/pdata/pmetric/generated_resourcemetricsslice_test.go +++ b/pdata/pmetric/generated_resourcemetricsslice_test.go @@ -19,6 +19,7 @@ package pmetric import ( "testing" + "unsafe" "github.com/stretchr/testify/assert" @@ -118,6 +119,22 @@ func TestResourceMetricsSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func TestResourceMetricsSlice_Sort(t *testing.T) { + es := generateTestResourceMetricsSlice() + es.Sort(func(a, b ResourceMetrics) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b ResourceMetrics) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + func generateTestResourceMetricsSlice() ResourceMetricsSlice { es := NewResourceMetricsSlice() fillTestResourceMetricsSlice(es) diff --git a/pdata/pmetric/generated_scopemetricsslice_test.go b/pdata/pmetric/generated_scopemetricsslice_test.go index b2cdfa085cbc..8fd2f48ecbe6 100644 --- a/pdata/pmetric/generated_scopemetricsslice_test.go +++ b/pdata/pmetric/generated_scopemetricsslice_test.go @@ -19,6 +19,7 @@ package pmetric import ( "testing" + "unsafe" "github.com/stretchr/testify/assert" @@ -118,6 +119,22 @@ func TestScopeMetricsSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func TestScopeMetricsSlice_Sort(t *testing.T) { + es := generateTestScopeMetricsSlice() + es.Sort(func(a, b ScopeMetrics) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b ScopeMetrics) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + func generateTestScopeMetricsSlice() ScopeMetricsSlice { es := NewScopeMetricsSlice() fillTestScopeMetricsSlice(es) diff --git a/pdata/pmetric/generated_summarydatapointslice_test.go b/pdata/pmetric/generated_summarydatapointslice_test.go index bc40214a3022..713f185191e7 100644 --- a/pdata/pmetric/generated_summarydatapointslice_test.go +++ b/pdata/pmetric/generated_summarydatapointslice_test.go @@ -19,6 +19,7 @@ package pmetric import ( "testing" + "unsafe" "github.com/stretchr/testify/assert" @@ -118,6 +119,22 @@ func TestSummaryDataPointSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func TestSummaryDataPointSlice_Sort(t *testing.T) { + es := generateTestSummaryDataPointSlice() + es.Sort(func(a, b SummaryDataPoint) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b SummaryDataPoint) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + func generateTestSummaryDataPointSlice() SummaryDataPointSlice { es := NewSummaryDataPointSlice() fillTestSummaryDataPointSlice(es) diff --git a/pdata/pmetric/generated_summarydatapointvalueatquantileslice_test.go b/pdata/pmetric/generated_summarydatapointvalueatquantileslice_test.go index 44aef4ca490c..c2c898178a83 100644 --- a/pdata/pmetric/generated_summarydatapointvalueatquantileslice_test.go +++ b/pdata/pmetric/generated_summarydatapointvalueatquantileslice_test.go @@ -19,6 +19,7 @@ package pmetric import ( "testing" + "unsafe" "github.com/stretchr/testify/assert" @@ -118,6 +119,22 @@ func TestSummaryDataPointValueAtQuantileSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func TestSummaryDataPointValueAtQuantileSlice_Sort(t *testing.T) { + es := generateTestSummaryDataPointValueAtQuantileSlice() + es.Sort(func(a, b SummaryDataPointValueAtQuantile) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b SummaryDataPointValueAtQuantile) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + func generateTestSummaryDataPointValueAtQuantileSlice() SummaryDataPointValueAtQuantileSlice { es := NewSummaryDataPointValueAtQuantileSlice() fillTestSummaryDataPointValueAtQuantileSlice(es) diff --git a/pdata/ptrace/generated_resourcespansslice_test.go b/pdata/ptrace/generated_resourcespansslice_test.go index b22f1b892cf5..59b525d3c9a6 100644 --- a/pdata/ptrace/generated_resourcespansslice_test.go +++ b/pdata/ptrace/generated_resourcespansslice_test.go @@ -19,6 +19,7 @@ package ptrace import ( "testing" + "unsafe" "github.com/stretchr/testify/assert" @@ -118,6 +119,22 @@ func TestResourceSpansSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func TestResourceSpansSlice_Sort(t *testing.T) { + es := generateTestResourceSpansSlice() + es.Sort(func(a, b ResourceSpans) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b ResourceSpans) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + func generateTestResourceSpansSlice() ResourceSpansSlice { es := NewResourceSpansSlice() fillTestResourceSpansSlice(es) diff --git a/pdata/ptrace/generated_scopespansslice_test.go b/pdata/ptrace/generated_scopespansslice_test.go index 7e9c389cabbd..c5eb91d0bc30 100644 --- a/pdata/ptrace/generated_scopespansslice_test.go +++ b/pdata/ptrace/generated_scopespansslice_test.go @@ -19,6 +19,7 @@ package ptrace import ( "testing" + "unsafe" "github.com/stretchr/testify/assert" @@ -118,6 +119,22 @@ func TestScopeSpansSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func TestScopeSpansSlice_Sort(t *testing.T) { + es := generateTestScopeSpansSlice() + es.Sort(func(a, b ScopeSpans) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b ScopeSpans) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + func generateTestScopeSpansSlice() ScopeSpansSlice { es := NewScopeSpansSlice() fillTestScopeSpansSlice(es) diff --git a/pdata/ptrace/generated_spaneventslice_test.go b/pdata/ptrace/generated_spaneventslice_test.go index f6982b263817..3f27cac4e376 100644 --- a/pdata/ptrace/generated_spaneventslice_test.go +++ b/pdata/ptrace/generated_spaneventslice_test.go @@ -19,6 +19,7 @@ package ptrace import ( "testing" + "unsafe" "github.com/stretchr/testify/assert" @@ -118,6 +119,22 @@ func TestSpanEventSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func TestSpanEventSlice_Sort(t *testing.T) { + es := generateTestSpanEventSlice() + es.Sort(func(a, b SpanEvent) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b SpanEvent) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + func generateTestSpanEventSlice() SpanEventSlice { es := NewSpanEventSlice() fillTestSpanEventSlice(es) diff --git a/pdata/ptrace/generated_spanlinkslice_test.go b/pdata/ptrace/generated_spanlinkslice_test.go index 5a71dc3e93df..ea409c48cbd2 100644 --- a/pdata/ptrace/generated_spanlinkslice_test.go +++ b/pdata/ptrace/generated_spanlinkslice_test.go @@ -19,6 +19,7 @@ package ptrace import ( "testing" + "unsafe" "github.com/stretchr/testify/assert" @@ -118,6 +119,22 @@ func TestSpanLinkSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func TestSpanLinkSlice_Sort(t *testing.T) { + es := generateTestSpanLinkSlice() + es.Sort(func(a, b SpanLink) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b SpanLink) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + func generateTestSpanLinkSlice() SpanLinkSlice { es := NewSpanLinkSlice() fillTestSpanLinkSlice(es) diff --git a/pdata/ptrace/generated_spanslice_test.go b/pdata/ptrace/generated_spanslice_test.go index f600d9b7f34a..b4bbc2398751 100644 --- a/pdata/ptrace/generated_spanslice_test.go +++ b/pdata/ptrace/generated_spanslice_test.go @@ -19,6 +19,7 @@ package ptrace import ( "testing" + "unsafe" "github.com/stretchr/testify/assert" @@ -118,6 +119,22 @@ func TestSpanSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func TestSpanSlice_Sort(t *testing.T) { + es := generateTestSpanSlice() + es.Sort(func(a, b Span) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b Span) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + func generateTestSpanSlice() SpanSlice { es := NewSpanSlice() fillTestSpanSlice(es)