cpu_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. }