Add CPU level test (#96)
Example: `cpuid -check-level=4`
diff --git a/cmd/cpuid/main.go b/cmd/cpuid/main.go
index abd5c5e..5869a4b 100644
--- a/cmd/cpuid/main.go
+++ b/cmd/cpuid/main.go
@@ -14,6 +14,7 @@
"encoding/json"
"flag"
"fmt"
+ "log"
"os"
"strings"
@@ -21,9 +22,22 @@
)
var js = flag.Bool("json", false, "Output as JSON")
+var level = flag.Int("check-level", 0, "Check microarchitecture level. Exit code will be 0 if supported")
func main() {
flag.Parse()
+ if level != nil && *level > 0 {
+ if *level < 1 || *level > 4 {
+ log.Fatalln("Supply CPU level 1-4 to test as argument")
+ }
+ log.Println(cpuid.CPU.BrandName)
+ if cpuid.CPU.X64Level() < *level {
+ // Does os.Exit(1)
+ log.Fatalf("Microarchitecture level %d not supported. Max level is %d.", *level, cpuid.CPU.X64Level())
+ }
+ log.Printf("Microarchitecture level %d is supported. Max level is %d.", *level, cpuid.CPU.X64Level())
+ os.Exit(0)
+ }
if *js {
info := struct {
cpuid.CPUInfo