From f18af3b6c329b4f951c2a3655b41175cab3c405f Mon Sep 17 00:00:00 2001 From: ian <141902143+yumosx@users.noreply.github.com> Date: Fri, 28 Mar 2025 16:23:26 +0800 Subject: [PATCH] internaltest: remove alignment.go from internaltest (#6550) Fix #6519 --------- Co-authored-by: Sam Xie Co-authored-by: Damien Mathieu <42@dmathieu.com> --- exporters/zipkin/internal/gen.go | 1 - .../zipkin/internal/internaltest/alignment.go | 63 ------------------- internal/gen.go | 1 - internal/internaltest/alignment.go | 63 ------------------- .../shared/internaltest/alignment.go.tmpl | 63 ------------------- sdk/internal/gen.go | 1 - sdk/internal/internaltest/alignment.go | 63 ------------------- 7 files changed, 255 deletions(-) delete mode 100644 exporters/zipkin/internal/internaltest/alignment.go delete mode 100644 internal/internaltest/alignment.go delete mode 100644 internal/shared/internaltest/alignment.go.tmpl delete mode 100644 sdk/internal/internaltest/alignment.go diff --git a/exporters/zipkin/internal/gen.go b/exporters/zipkin/internal/gen.go index f6e2532ab..031782ff6 100644 --- a/exporters/zipkin/internal/gen.go +++ b/exporters/zipkin/internal/gen.go @@ -8,7 +8,6 @@ package internal // import "go.opentelemetry.io/otel/exporters/zipkin/internal" //go:generate gotmpl --body=../../../internal/shared/matchers/expecter.go.tmpl "--data={}" --out=matchers/expecter.go //go:generate gotmpl --body=../../../internal/shared/matchers/temporal_matcher.go.tmpl "--data={}" --out=matchers/temporal_matcher.go -//go:generate gotmpl --body=../../../internal/shared/internaltest/alignment.go.tmpl "--data={}" --out=internaltest/alignment.go //go:generate gotmpl --body=../../../internal/shared/internaltest/env.go.tmpl "--data={}" --out=internaltest/env.go //go:generate gotmpl --body=../../../internal/shared/internaltest/env_test.go.tmpl "--data={}" --out=internaltest/env_test.go //go:generate gotmpl --body=../../../internal/shared/internaltest/errors.go.tmpl "--data={}" --out=internaltest/errors.go diff --git a/exporters/zipkin/internal/internaltest/alignment.go b/exporters/zipkin/internal/internaltest/alignment.go deleted file mode 100644 index b307e7e45..000000000 --- a/exporters/zipkin/internal/internaltest/alignment.go +++ /dev/null @@ -1,63 +0,0 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/internaltest/alignment.go.tmpl - -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package internaltest // import "go.opentelemetry.io/otel/exporters/zipkin/internal/internaltest" - -/* -This file contains common utilities and objects to validate memory alignment -of Go types. The primary use of this functionality is intended to ensure -`struct` fields that need to be 64-bit aligned so they can be passed as -arguments to 64-bit atomic operations. - -The common workflow is to define a slice of `FieldOffset` and pass them to the -`Aligned8Byte` function from within a `TestMain` function from a package's -tests. It is important to make this call from the `TestMain` function prior -to running the rest of the test suit as it can provide useful diagnostics -about field alignment instead of ambiguous nil pointer dereference and runtime -panic. - -For more information: -https://github.com/open-telemetry/opentelemetry-go/issues/341 -*/ - -import ( - "fmt" - "io" -) - -// FieldOffset is a preprocessor representation of a struct field alignment. -type FieldOffset struct { - // Name of the field. - Name string - - // Offset of the field in bytes. - // - // To compute this at compile time use unsafe.Offsetof. - Offset uintptr -} - -// Aligned8Byte returns if all fields are aligned modulo 8-bytes. -// -// Error messaging is printed to out for any field determined misaligned. -func Aligned8Byte(fields []FieldOffset, out io.Writer) bool { - misaligned := make([]FieldOffset, 0) - for _, f := range fields { - if f.Offset%8 != 0 { - misaligned = append(misaligned, f) - } - } - - if len(misaligned) == 0 { - return true - } - - fmt.Fprintln(out, "struct fields not aligned for 64-bit atomic operations:") - for _, f := range misaligned { - fmt.Fprintf(out, " %s: %d-byte offset\n", f.Name, f.Offset) - } - - return false -} diff --git a/internal/gen.go b/internal/gen.go index 4259f0320..67a1b4e1d 100644 --- a/internal/gen.go +++ b/internal/gen.go @@ -7,7 +7,6 @@ package internal // import "go.opentelemetry.io/otel/internal" //go:generate gotmpl --body=./shared/matchers/expecter.go.tmpl "--data={}" --out=matchers/expecter.go //go:generate gotmpl --body=./shared/matchers/temporal_matcher.go.tmpl "--data={}" --out=matchers/temporal_matcher.go -//go:generate gotmpl --body=./shared/internaltest/alignment.go.tmpl "--data={}" --out=internaltest/alignment.go //go:generate gotmpl --body=./shared/internaltest/env.go.tmpl "--data={}" --out=internaltest/env.go //go:generate gotmpl --body=./shared/internaltest/env_test.go.tmpl "--data={}" --out=internaltest/env_test.go //go:generate gotmpl --body=./shared/internaltest/errors.go.tmpl "--data={}" --out=internaltest/errors.go diff --git a/internal/internaltest/alignment.go b/internal/internaltest/alignment.go deleted file mode 100644 index cf0bfbbdc..000000000 --- a/internal/internaltest/alignment.go +++ /dev/null @@ -1,63 +0,0 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/internaltest/alignment.go.tmpl - -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package internaltest // import "go.opentelemetry.io/otel/internal/internaltest" - -/* -This file contains common utilities and objects to validate memory alignment -of Go types. The primary use of this functionality is intended to ensure -`struct` fields that need to be 64-bit aligned so they can be passed as -arguments to 64-bit atomic operations. - -The common workflow is to define a slice of `FieldOffset` and pass them to the -`Aligned8Byte` function from within a `TestMain` function from a package's -tests. It is important to make this call from the `TestMain` function prior -to running the rest of the test suit as it can provide useful diagnostics -about field alignment instead of ambiguous nil pointer dereference and runtime -panic. - -For more information: -https://github.com/open-telemetry/opentelemetry-go/issues/341 -*/ - -import ( - "fmt" - "io" -) - -// FieldOffset is a preprocessor representation of a struct field alignment. -type FieldOffset struct { - // Name of the field. - Name string - - // Offset of the field in bytes. - // - // To compute this at compile time use unsafe.Offsetof. - Offset uintptr -} - -// Aligned8Byte returns if all fields are aligned modulo 8-bytes. -// -// Error messaging is printed to out for any field determined misaligned. -func Aligned8Byte(fields []FieldOffset, out io.Writer) bool { - misaligned := make([]FieldOffset, 0) - for _, f := range fields { - if f.Offset%8 != 0 { - misaligned = append(misaligned, f) - } - } - - if len(misaligned) == 0 { - return true - } - - fmt.Fprintln(out, "struct fields not aligned for 64-bit atomic operations:") - for _, f := range misaligned { - fmt.Fprintf(out, " %s: %d-byte offset\n", f.Name, f.Offset) - } - - return false -} diff --git a/internal/shared/internaltest/alignment.go.tmpl b/internal/shared/internaltest/alignment.go.tmpl deleted file mode 100644 index 1dd096072..000000000 --- a/internal/shared/internaltest/alignment.go.tmpl +++ /dev/null @@ -1,63 +0,0 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/internaltest/alignment.go.tmpl - -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package internaltest - -/* -This file contains common utilities and objects to validate memory alignment -of Go types. The primary use of this functionality is intended to ensure -`struct` fields that need to be 64-bit aligned so they can be passed as -arguments to 64-bit atomic operations. - -The common workflow is to define a slice of `FieldOffset` and pass them to the -`Aligned8Byte` function from within a `TestMain` function from a package's -tests. It is important to make this call from the `TestMain` function prior -to running the rest of the test suit as it can provide useful diagnostics -about field alignment instead of ambiguous nil pointer dereference and runtime -panic. - -For more information: -https://github.com/open-telemetry/opentelemetry-go/issues/341 -*/ - -import ( - "fmt" - "io" -) - -// FieldOffset is a preprocessor representation of a struct field alignment. -type FieldOffset struct { - // Name of the field. - Name string - - // Offset of the field in bytes. - // - // To compute this at compile time use unsafe.Offsetof. - Offset uintptr -} - -// Aligned8Byte returns if all fields are aligned modulo 8-bytes. -// -// Error messaging is printed to out for any field determined misaligned. -func Aligned8Byte(fields []FieldOffset, out io.Writer) bool { - misaligned := make([]FieldOffset, 0) - for _, f := range fields { - if f.Offset%8 != 0 { - misaligned = append(misaligned, f) - } - } - - if len(misaligned) == 0 { - return true - } - - fmt.Fprintln(out, "struct fields not aligned for 64-bit atomic operations:") - for _, f := range misaligned { - fmt.Fprintf(out, " %s: %d-byte offset\n", f.Name, f.Offset) - } - - return false -} diff --git a/sdk/internal/gen.go b/sdk/internal/gen.go index b1107e1c9..4c5e3b5bc 100644 --- a/sdk/internal/gen.go +++ b/sdk/internal/gen.go @@ -8,7 +8,6 @@ package internal // import "go.opentelemetry.io/otel/sdk/internal" //go:generate gotmpl --body=../../internal/shared/matchers/expecter.go.tmpl "--data={}" --out=matchers/expecter.go //go:generate gotmpl --body=../../internal/shared/matchers/temporal_matcher.go.tmpl "--data={}" --out=matchers/temporal_matcher.go -//go:generate gotmpl --body=../../internal/shared/internaltest/alignment.go.tmpl "--data={}" --out=internaltest/alignment.go //go:generate gotmpl --body=../../internal/shared/internaltest/env.go.tmpl "--data={}" --out=internaltest/env.go //go:generate gotmpl --body=../../internal/shared/internaltest/env_test.go.tmpl "--data={}" --out=internaltest/env_test.go //go:generate gotmpl --body=../../internal/shared/internaltest/errors.go.tmpl "--data={}" --out=internaltest/errors.go diff --git a/sdk/internal/internaltest/alignment.go b/sdk/internal/internaltest/alignment.go deleted file mode 100644 index 0e48fa41e..000000000 --- a/sdk/internal/internaltest/alignment.go +++ /dev/null @@ -1,63 +0,0 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/internaltest/alignment.go.tmpl - -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package internaltest // import "go.opentelemetry.io/otel/sdk/internal/internaltest" - -/* -This file contains common utilities and objects to validate memory alignment -of Go types. The primary use of this functionality is intended to ensure -`struct` fields that need to be 64-bit aligned so they can be passed as -arguments to 64-bit atomic operations. - -The common workflow is to define a slice of `FieldOffset` and pass them to the -`Aligned8Byte` function from within a `TestMain` function from a package's -tests. It is important to make this call from the `TestMain` function prior -to running the rest of the test suit as it can provide useful diagnostics -about field alignment instead of ambiguous nil pointer dereference and runtime -panic. - -For more information: -https://github.com/open-telemetry/opentelemetry-go/issues/341 -*/ - -import ( - "fmt" - "io" -) - -// FieldOffset is a preprocessor representation of a struct field alignment. -type FieldOffset struct { - // Name of the field. - Name string - - // Offset of the field in bytes. - // - // To compute this at compile time use unsafe.Offsetof. - Offset uintptr -} - -// Aligned8Byte returns if all fields are aligned modulo 8-bytes. -// -// Error messaging is printed to out for any field determined misaligned. -func Aligned8Byte(fields []FieldOffset, out io.Writer) bool { - misaligned := make([]FieldOffset, 0) - for _, f := range fields { - if f.Offset%8 != 0 { - misaligned = append(misaligned, f) - } - } - - if len(misaligned) == 0 { - return true - } - - fmt.Fprintln(out, "struct fields not aligned for 64-bit atomic operations:") - for _, f := range misaligned { - fmt.Fprintf(out, " %s: %d-byte offset\n", f.Name, f.Offset) - } - - return false -}