Source file src/simd/variant_test.go

     1  // Copyright 2026 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  //go:build goexperiment.simd
     6  
     7  package simd_test
     8  
     9  import (
    10  	"os"
    11  	"os/exec"
    12  	"runtime"
    13  	"simd"
    14  	"testing"
    15  )
    16  
    17  func TestVariant(t *testing.T) {
    18  	if runtime.GOARCH != "arm64" {
    19  		t.Skip("Variant test requires arm64")
    20  		return
    21  	}
    22  	if simd.VectorBitSize() != 128 {
    23  		t.Skip("Variant test requires 128-bit vectors")
    24  		return
    25  	}
    26  	if !simd.HasHardwareCarrylessMultiply() {
    27  		t.Skip("Variant test does not test itself")
    28  		return
    29  	}
    30  
    31  	var args = []string{} // "-test.run=TestClMul"
    32  
    33  	if testing.Verbose() {
    34  		args = append(args, "-test.v")
    35  	}
    36  
    37  	cmd := exec.Command(os.Args[0], args...)
    38  
    39  	cmd.Env = append(os.Environ(),
    40  		// @variant undocumented testing option.
    41  		"GODEBUG=simd=@nclm",
    42  	)
    43  
    44  	output, err := cmd.CombinedOutput()
    45  	if err != nil {
    46  		t.Fatalf("variant test failed: %v, output: %s", err, output)
    47  	}
    48  
    49  	t.Logf("Parent got output from child:\n%s", output)
    50  }
    51  

View as plain text