cpu_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2018 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package cpu_test
  5. import (
  6. "runtime"
  7. "testing"
  8. "golang.org/x/sys/cpu"
  9. )
  10. func TestAMD64minimalFeatures(t *testing.T) {
  11. if runtime.GOARCH == "amd64" {
  12. if !cpu.Initialized {
  13. t.Fatal("Initialized expected true, got false")
  14. }
  15. if !cpu.X86.HasSSE2 {
  16. t.Fatal("HasSSE2 expected true, got false")
  17. }
  18. }
  19. }
  20. func TestAVX2hasAVX(t *testing.T) {
  21. if runtime.GOARCH == "amd64" {
  22. if cpu.X86.HasAVX2 && !cpu.X86.HasAVX {
  23. t.Fatal("HasAVX expected true, got false")
  24. }
  25. }
  26. }
  27. func TestARM64minimalFeatures(t *testing.T) {
  28. if runtime.GOARCH != "arm64" || runtime.GOOS != "linux" {
  29. return
  30. }
  31. if !cpu.ARM64.HasASIMD {
  32. t.Fatal("HasASIMD expected true, got false")
  33. }
  34. if !cpu.ARM64.HasFP {
  35. t.Fatal("HasFP expected true, got false")
  36. }
  37. }
  38. // On ppc64x, the ISA bit for POWER8 should always be set on POWER8 and beyond.
  39. func TestPPC64minimalFeatures(t *testing.T) {
  40. // Do not run this with gccgo on ppc64, as it doesn't have POWER8 as a minimum
  41. // requirement.
  42. if runtime.Compiler == "gccgo" && runtime.GOARCH == "ppc64" {
  43. t.Skip("gccgo does not require POWER8 on ppc64; skipping")
  44. }
  45. if runtime.GOARCH == "ppc64" || runtime.GOARCH == "ppc64le" {
  46. if !cpu.PPC64.IsPOWER8 {
  47. t.Fatal("IsPOWER8 expected true, got false")
  48. }
  49. }
  50. }
  51. func TestS390X(t *testing.T) {
  52. if runtime.GOARCH != "s390x" {
  53. return
  54. }
  55. if testing.Verbose() {
  56. t.Logf("%+v\n", cpu.S390X)
  57. }
  58. // z/Architecture is mandatory
  59. if !cpu.S390X.HasZARCH {
  60. t.Error("HasZARCH expected true, got false")
  61. }
  62. // vector-enhancements require vector facility to be enabled
  63. if cpu.S390X.HasVXE && !cpu.S390X.HasVX {
  64. t.Error("HasVX expected true, got false (VXE is true)")
  65. }
  66. }