From 352d8339e8b9a29c57d977f5c64810689466b25b Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 15 May 2023 14:32:57 +0200 Subject: [PATCH] cpu: add test for IsBigEndian For golang/go#57237 Change-Id: I11d1c954f942ebd836c4deb9c710c40778dc5599 Reviewed-on: https://go-review.googlesource.com/c/sys/+/494858 Auto-Submit: Tobias Klauser Run-TryBot: Tobias Klauser Reviewed-by: Ian Lance Taylor Reviewed-by: Heschi Kreinick TryBot-Result: Gopher Robot --- cpu/endian_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 cpu/endian_test.go diff --git a/cpu/endian_test.go b/cpu/endian_test.go new file mode 100644 index 00000000..b066bfb3 --- /dev/null +++ b/cpu/endian_test.go @@ -0,0 +1,21 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package cpu_test + +import ( + "testing" + "unsafe" + + "golang.org/x/sys/cpu" +) + +func TestIsBigEndian(t *testing.T) { + b := uint16(0xff00) + want := *(*byte)(unsafe.Pointer(&b)) == 0xff + if cpu.IsBigEndian != want { + t.Errorf("IsBigEndian = %t, want %t", + cpu.IsBigEndian, want) + } +}