cpu_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.X86.HasSSE2 {
  13. t.Fatal("HasSSE2 expected true, got false")
  14. }
  15. }
  16. }
  17. func TestAVX2hasAVX(t *testing.T) {
  18. if runtime.GOARCH == "amd64" {
  19. if cpu.X86.HasAVX2 && !cpu.X86.HasAVX {
  20. t.Fatal("HasAVX expected true, got false")
  21. }
  22. }
  23. }
  24. func TestARM64minimalFeatures(t *testing.T) {
  25. if runtime.GOARCH != "arm64" || runtime.GOOS != "linux" {
  26. return
  27. }
  28. if !cpu.ARM64.HasASIMD {
  29. t.Fatal("HasASIMD expected true, got false")
  30. }
  31. if !cpu.ARM64.HasFP {
  32. t.Fatal("HasFP expected true, got false")
  33. }
  34. }
  35. // On ppc64x, the ISA bit for POWER8 should always be set on POWER8 and beyond.
  36. func TestPPC64minimalFeatures(t *testing.T) {
  37. // Do not run this with gccgo on ppc64, as it doesn't have POWER8 as a minimum
  38. // requirement.
  39. if runtime.Compiler == "gccgo" && runtime.GOARCH == "ppc64" {
  40. t.Skip("gccgo does not require POWER8 on ppc64; skipping")
  41. }
  42. if runtime.GOARCH == "ppc64" || runtime.GOARCH == "ppc64le" {
  43. if !cpu.PPC64.IsPOWER8 {
  44. t.Fatal("IsPOWER8 expected true, got false")
  45. }
  46. }
  47. }