@@ -67,3 +67,116 @@ func TestBuiltinExpansion(t *testing.T) {
6767 }
6868 }
6969}
70+
71+ func TestLscpuCheckARM (t * testing.T ) {
72+ lscpuARM := `Architecture: aarch64
73+ CPU op-mode(s): 32-bit, 64-bit
74+ Byte Order: Little Endian
75+ CPU(s): 80
76+ On-line CPU(s) list: 0-79
77+ Vendor ID: ARM
78+ BIOS Vendor ID: Ampere(R)
79+ Model name: Neoverse-N1
80+ BIOS Model name: Ampere(R) Altra(R) Processor Q80-30 CPU @ 3.0GHz
81+ BIOS CPU family: 257
82+ Model: 1
83+ Thread(s) per core: 1
84+ Core(s) per socket: 80
85+ Socket(s): 1
86+ Stepping: r3p1
87+ Frequency boost: disabled
88+ CPU(s) scaling MHz: 100%
89+ CPU max MHz: 3000.0000
90+ CPU min MHz: 1000.0000
91+ BogoMIPS: 50.00
92+ Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
93+ L1d cache: 5 MiB (80 instances)
94+ L1i cache: 5 MiB (80 instances)
95+ L2 cache: 80 MiB (80 instances)
96+ NUMA node(s): 1
97+ NUMA node0 CPU(s): 0-79
98+ Vulnerability Gather data sampling: Not affected
99+ Vulnerability Itlb multihit: Not affected
100+ Vulnerability L1tf: Not affected
101+ Vulnerability Mds: Not affected
102+ Vulnerability Meltdown: Not affected
103+ Vulnerability Mmio stale data: Not affected
104+ Vulnerability Reg file data sampling: Not affected
105+ Vulnerability Retbleed: Not affected
106+ Vulnerability Spec rstack overflow: Not affected
107+ Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
108+ Vulnerability Spectre v1: Mitigation; __user pointer sanitization
109+ Vulnerability Spectre v2: Mitigation; CSV2, BHB
110+ Vulnerability Srbds: Not affected
111+ Vulnerability Tsx async abort: Not affected
112+ `
113+
114+ tests := []struct {
115+ name string
116+ args []string
117+ want string
118+ wantErr bool
119+ }{
120+ {
121+ name : "Match ARM Vendor ID" ,
122+ args : []string {"Vendor ID\\ :\\ s*GenuineIntel" , "intel" , "Vendor ID\\ :\\ s*AuthenticAMD" , "amd" , "Architecture\\ :\\ s*aarch64" , "arm" , "unknown" },
123+ want : "arm" ,
124+ wantErr : false ,
125+ },
126+ {
127+ name : "Match aarch64 architecture" ,
128+ args : []string {"Architecture\\ :\\ s*x86_64" , "x86" , "Architecture\\ :\\ s*aarch64" , "aarch64" },
129+ want : "aarch64" ,
130+ wantErr : false ,
131+ },
132+ {
133+ name : "No match returns fallback" ,
134+ args : []string {"NonExistentPattern" , "result" , "fallback" },
135+ want : "fallback" ,
136+ wantErr : false ,
137+ },
138+ {
139+ name : "No match no fallback returns empty string" ,
140+ args : []string {"AuthenticAMD" , "amd" },
141+ want : "" ,
142+ wantErr : false ,
143+ },
144+ {
145+ name : "First match wins" ,
146+ args : []string {"^Architecture" , "aarch64" , "ARM" , "arm" , "unknown" },
147+ want : "aarch64" ,
148+ wantErr : false ,
149+ },
150+ {
151+ name : "One argument returns error" ,
152+ args : []string {"fallback" },
153+ want : "" ,
154+ wantErr : true ,
155+ },
156+ {
157+ name : "Zero arguments returns error" ,
158+ args : []string {},
159+ want : "" ,
160+ wantErr : true ,
161+ },
162+ {
163+ name : "Invalid regex returns error" ,
164+ args : []string {"[invalid(regex" , "result" },
165+ want : "" ,
166+ wantErr : true ,
167+ },
168+ }
169+
170+ for _ , tc := range tests {
171+ t .Run (tc .name , func (t * testing.T ) {
172+ got , err := lscpu_check (lscpuARM , tc .args )
173+ if (err != nil ) != tc .wantErr {
174+ t .Errorf ("lscpu_check() error = %v, wantErr %v" , err , tc .wantErr )
175+ return
176+ }
177+ if got != tc .want {
178+ t .Errorf ("lscpu_check() = %v, want %v" , got , tc .want )
179+ }
180+ })
181+ }
182+ }
0 commit comments