github.com/SandwichDev/go-internals@v0.0.0-20210605002614-12311ac6b2c5/cpu/cpu_x86_test.go (about)

     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  
     5  // +build 386 amd64
     6  
     7  package cpu_test
     8  
     9  import (
    10  	"os"
    11  	"runtime"
    12  	"testing"
    13  
    14  	. "github.com/SandwichDev/go-internals/cpu"
    15  )
    16  
    17  func TestX86ifAVX2hasAVX(t *testing.T) {
    18  	if X86.HasAVX2 && !X86.HasAVX {
    19  		t.Fatalf("HasAVX expected true when HasAVX2 is true, got false")
    20  	}
    21  }
    22  
    23  func TestDisableSSE2(t *testing.T) {
    24  	runDebugOptionsTest(t, "TestSSE2DebugOption", "cpu.sse2=off")
    25  }
    26  
    27  func TestSSE2DebugOption(t *testing.T) {
    28  	MustHaveDebugOptionsSupport(t)
    29  
    30  	if os.Getenv("GODEBUG") != "cpu.sse2=off" {
    31  		t.Skipf("skipping test: GODEBUG=cpu.sse2=off not set")
    32  	}
    33  
    34  	want := runtime.GOARCH != "386" // SSE2 can only be disabled on 386.
    35  	if got := X86.HasSSE2; got != want {
    36  		t.Errorf("X86.HasSSE2 on %s expected %v, got %v", runtime.GOARCH, want, got)
    37  	}
    38  }
    39  
    40  func TestDisableSSE3(t *testing.T) {
    41  	runDebugOptionsTest(t, "TestSSE3DebugOption", "cpu.sse3=off")
    42  }
    43  
    44  func TestSSE3DebugOption(t *testing.T) {
    45  	MustHaveDebugOptionsSupport(t)
    46  
    47  	if os.Getenv("GODEBUG") != "cpu.sse3=off" {
    48  		t.Skipf("skipping test: GODEBUG=cpu.sse3=off not set")
    49  	}
    50  
    51  	want := false
    52  	if got := X86.HasSSE3; got != want {
    53  		t.Errorf("X86.HasSSE3 expected %v, got %v", want, got)
    54  	}
    55  }