...
1
2
3
4
5 package cpu_test
6
7 import (
8 "runtime"
9 "testing"
10
11 "golang.org/x/sys/cpu"
12 )
13
14 func TestAMD64minimalFeatures(t *testing.T) {
15 if runtime.GOARCH == "amd64" {
16 if !cpu.Initialized {
17 t.Fatal("Initialized expected true, got false")
18 }
19 if !cpu.X86.HasSSE2 {
20 t.Fatal("HasSSE2 expected true, got false")
21 }
22 }
23 }
24
25 func TestAVX2hasAVX(t *testing.T) {
26 if runtime.GOARCH == "amd64" {
27 if cpu.X86.HasAVX2 && !cpu.X86.HasAVX {
28 t.Fatal("HasAVX expected true, got false")
29 }
30 }
31 }
32
33 func TestAVX512HasAVX2AndAVX(t *testing.T) {
34 if runtime.GOARCH == "amd64" {
35 if cpu.X86.HasAVX512 && !cpu.X86.HasAVX {
36 t.Fatal("HasAVX expected true, got false")
37 }
38 if cpu.X86.HasAVX512 && !cpu.X86.HasAVX2 {
39 t.Fatal("HasAVX2 expected true, got false")
40 }
41 }
42 }
43
44 func TestARM64minimalFeatures(t *testing.T) {
45 if runtime.GOARCH != "arm64" || runtime.GOOS == "ios" {
46 return
47 }
48 if !cpu.ARM64.HasASIMD {
49 t.Fatal("HasASIMD expected true, got false")
50 }
51 if !cpu.ARM64.HasFP {
52 t.Fatal("HasFP expected true, got false")
53 }
54 }
55
56 func TestMIPS64Initialized(t *testing.T) {
57 if runtime.GOARCH == "mips64" || runtime.GOARCH == "mips64le" {
58 if !cpu.Initialized {
59 t.Fatal("Initialized expected true, got false")
60 }
61 }
62 }
63
64 func TestRISCV64Initialized(t *testing.T) {
65 if runtime.GOARCH == "riscv64" {
66 if !cpu.Initialized {
67 t.Fatal("Initialized expected true, got false")
68 }
69 }
70 }
71
72
73 func TestPPC64minimalFeatures(t *testing.T) {
74
75
76 if runtime.Compiler == "gccgo" && runtime.GOARCH == "ppc64" {
77 t.Skip("gccgo does not require POWER8 on ppc64; skipping")
78 }
79 if runtime.GOARCH == "ppc64" || runtime.GOARCH == "ppc64le" {
80 if !cpu.PPC64.IsPOWER8 {
81 t.Fatal("IsPOWER8 expected true, got false")
82 }
83 }
84 }
85
View as plain text