github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/cpuid/cpuid_arm64_test.go (about)

     1  // Copyright 2020 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // +build arm64
    16  
    17  package cpuid
    18  
    19  import (
    20  	"testing"
    21  )
    22  
    23  var justFP = &FeatureSet{
    24  	Set: map[Feature]bool{
    25  		ARM64FeatureFP: true,
    26  	}}
    27  
    28  func TestHostFeatureSet(t *testing.T) {
    29  	hostFeatures := HostFeatureSet()
    30  	if len(hostFeatures.Set) == 0 {
    31  		t.Errorf("Got invalid feature set %v from HostFeatureSet()", hostFeatures)
    32  	}
    33  }
    34  
    35  func TestHasFeature(t *testing.T) {
    36  	if !justFP.HasFeature(ARM64FeatureFP) {
    37  		t.Errorf("HasFeature failed, %v should contain %v", justFP, ARM64FeatureFP)
    38  	}
    39  
    40  	if justFP.HasFeature(ARM64FeatureSM3) {
    41  		t.Errorf("HasFeature failed, %v should not contain %v", justFP, ARM64FeatureSM3)
    42  	}
    43  }
    44  
    45  func TestFeatureFromString(t *testing.T) {
    46  	f, ok := FeatureFromString("asimd")
    47  	if f != ARM64FeatureASIMD || !ok {
    48  		t.Errorf("got %v want asimd", f)
    49  	}
    50  
    51  	f, ok = FeatureFromString("bad")
    52  	if ok {
    53  		t.Errorf("got %v want nothing", f)
    54  	}
    55  }