Source file src/internal/cpu/cpu_riscv64_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 riscv64
     6  
     7  package cpu_test
     8  
     9  import (
    10  	. "internal/cpu"
    11  	"internal/godebug"
    12  	"testing"
    13  )
    14  
    15  func TestRISCV64VectorLength(t *testing.T) {
    16  	if RISCV64.HasV && RISCV64.VLENB == 0 {
    17  		t.Fatal("VLENB should be non-zero when HasV is true")
    18  	}
    19  }
    20  
    21  func TestDisableZbb(t *testing.T) {
    22  	if GetGORISCV64level() > 20 {
    23  		t.Skip("skipping test: can't run on GORISCV64>rva20u64")
    24  	}
    25  	runDebugOptionsTest(t, "TestZbbDebugOption", "cpu.zbb=off")
    26  }
    27  
    28  func TestZbbDebugOption(t *testing.T) {
    29  	MustHaveDebugOptionsSupport(t)
    30  
    31  	if godebug.New("#cpu.zbb").Value() != "off" {
    32  		t.Skipf("skipping test: GODEBUG=cpu.zbb=off not set")
    33  	}
    34  
    35  	if RISCV64.HasZbb {
    36  		t.Errorf("RISCV64.HasZbb is true, want false")
    37  	}
    38  }
    39  
    40  func TestDisableV(t *testing.T) {
    41  	if GetGORISCV64level() > 22 {
    42  		t.Skip("skipping test: can't run on GORISCV64>rva22u64")
    43  	}
    44  
    45  	runDebugOptionsTest(t, "TestVDebugOption", "cpu.v=off")
    46  }
    47  
    48  func TestVDebugOption(t *testing.T) {
    49  	MustHaveDebugOptionsSupport(t)
    50  
    51  	if godebug.New("#cpu.v").Value() != "off" {
    52  		t.Skipf("skipping test: GODEBUG=cpu.v=off not set")
    53  	}
    54  
    55  	if RISCV64.HasV {
    56  		t.Errorf("RISCV64.HasV is true, want false")
    57  	}
    58  }
    59  
    60  func TestDisableZvbb(t *testing.T) {
    61  	if GetGORISCV64level() > 22 {
    62  		t.Skip("skipping test: can't run on GORISCV64>rva22u64")
    63  	}
    64  
    65  	runDebugOptionsTest(t, "TestZvbbDebugOption", "cpu.zvbb=off")
    66  }
    67  
    68  func TestZvbbDebugOption(t *testing.T) {
    69  	MustHaveDebugOptionsSupport(t)
    70  
    71  	if godebug.New("#cpu.zvbb").Value() != "off" {
    72  		t.Skipf("skipping test: GODEBUG=cpu.zvbb=off not set")
    73  	}
    74  
    75  	if RISCV64.HasZvbb {
    76  		t.Errorf("RISCV64.HasZvbb is true, want false")
    77  	}
    78  }
    79  
    80  func TestRISCV64ZvbbHasV(t *testing.T) {
    81  	if RISCV64.HasZvbb && !RISCV64.HasV {
    82  		t.Fatalf("HasV is false when HasZvbb is true, want true")
    83  	}
    84  }
    85  
    86  func TestRISCV64ZvbcHasV(t *testing.T) {
    87  	if RISCV64.HasZvbc && !RISCV64.HasV {
    88  		t.Fatalf("HasV is false when HasZvbc is true, want true")
    89  	}
    90  }
    91  
    92  func TestRISCV64ZvkgHasV(t *testing.T) {
    93  	if RISCV64.HasZvkg && !RISCV64.HasV {
    94  		t.Fatalf("HasV is false when HasZvkg is true, want true")
    95  	}
    96  }
    97  
    98  func TestRISCV64ZvknedHasV(t *testing.T) {
    99  	if RISCV64.HasZvkned && !RISCV64.HasV {
   100  		t.Fatalf("HasV is false when HasZvkned is true, want true")
   101  	}
   102  }
   103  
   104  func TestRISCV64ZvknhaHasV(t *testing.T) {
   105  	if RISCV64.HasZvknha && !RISCV64.HasV {
   106  		t.Fatalf("HasV is false when HasZvknha is true, want true")
   107  	}
   108  }
   109  
   110  func TestRISCV64ZvknhbHasV(t *testing.T) {
   111  	if RISCV64.HasZvknhb && !RISCV64.HasV {
   112  		t.Fatalf("HasV is false when HasZvknhb is true, want true")
   113  	}
   114  }
   115  
   116  func TestRISCV64ZvksedHasV(t *testing.T) {
   117  	if RISCV64.HasZvksed && !RISCV64.HasV {
   118  		t.Fatalf("HasV is false when HasZvksed is true, want true")
   119  	}
   120  }
   121  
   122  func TestRISCV64ZvkshHasV(t *testing.T) {
   123  	if RISCV64.HasZvksh && !RISCV64.HasV {
   124  		t.Fatalf("HasV is false when HasZvksh is true, want true")
   125  	}
   126  }
   127  
   128  func TestRISCV64ZvktHasV(t *testing.T) {
   129  	if RISCV64.HasZvkt && !RISCV64.HasV {
   130  		t.Fatalf("HasV is false when HasZvkt is true, want true")
   131  	}
   132  }
   133  

View as plain text