Skip to content

Commit bf2dea1

Browse files
committed
colflow: adjust TestHashRouterComputesDestination for big endian
Also add a helper to `util/system` package to expose whether we're running on a big endian system. (Go doesn't seem to expose this information explicitly.) Release note: None
1 parent 7898c83 commit bf2dea1

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

pkg/sql/colflow/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ go_test(
134134
"//pkg/util/randutil",
135135
"//pkg/util/stop",
136136
"//pkg/util/syncutil",
137+
"//pkg/util/system",
137138
"//pkg/util/timeutil",
138139
"@com_github_cockroachdb_errors//:errors",
139140
"@com_github_stretchr_testify//require",

pkg/sql/colflow/routers_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/cockroachdb/cockroach/pkg/util/mon"
3939
"github.com/cockroachdb/cockroach/pkg/util/randutil"
4040
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
41+
"github.com/cockroachdb/cockroach/pkg/util/system"
4142
"github.com/cockroachdb/errors"
4243
"github.com/stretchr/testify/require"
4344
)
@@ -724,6 +725,11 @@ func TestHashRouterComputesDestination(t *testing.T) {
724725
valsPushed = make([]int, numOutputs)
725726
)
726727

728+
if system.BigEndian {
729+
// On big endian architectures we expect a different distribution.
730+
expectedNumVals = []int{238, 260, 259, 267}
731+
}
732+
727733
outputs := make([]routerOutput, numOutputs)
728734
for i := range outputs {
729735
// Capture the index.

pkg/util/system/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go_library(
44
name = "system",
55
srcs = [
66
"cache_line.go",
7+
"endian.go",
78
"num_cpu.go",
89
],
910
importpath = "github.com/cockroachdb/cockroach/pkg/util/system",

pkg/util/system/endian.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2025 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the CockroachDB Software License
4+
// included in the /LICENSE file.
5+
6+
package system
7+
8+
import "encoding/binary"
9+
10+
// BigEndian is true if we're running on a system with big endian architecture
11+
// like s390x (most architectures we're running on are little endian).
12+
var BigEndian = binary.NativeEndian.Uint16([]byte{0x12, 0x34}) == uint16(0x1234)

0 commit comments

Comments
 (0)