| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-14 03:01:33 +02:00
										 |  |  | require "hardware" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe Hardware::CPU do | 
					
						
							| 
									
										
										
										
											2018-04-14 03:01:33 +02:00
										 |  |  |   describe "::type" do | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |     let(:cpu_types) do | 
					
						
							| 
									
										
										
										
											2018-04-14 03:01:33 +02:00
										 |  |  |       [ | 
					
						
							| 
									
										
										
										
											2019-03-08 14:32:40 +11:00
										 |  |  |         :arm, | 
					
						
							| 
									
										
										
										
											2018-04-14 03:01:33 +02:00
										 |  |  |         :intel, | 
					
						
							| 
									
										
										
										
											2019-03-08 14:32:40 +11:00
										 |  |  |         :ppc, | 
					
						
							| 
									
										
										
										
											2018-04-14 03:01:33 +02:00
										 |  |  |         :dunno, | 
					
						
							|  |  |  |       ] | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-04-14 03:01:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "returns the current CPU's type as a symbol, or :dunno if it cannot be detected" do | 
					
						
							|  |  |  |       expect(cpu_types).to include(described_class.type) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "::family" do | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |     let(:cpu_families) do | 
					
						
							| 
									
										
										
										
											2018-04-14 03:01:33 +02:00
										 |  |  |       [ | 
					
						
							| 
									
										
										
										
											2021-03-04 23:50:35 +00:00
										 |  |  |         :amd_k7, | 
					
						
							|  |  |  |         :amd_k8, | 
					
						
							|  |  |  |         :amd_k8_k10_hybrid, | 
					
						
							|  |  |  |         :amd_k10, | 
					
						
							|  |  |  |         :amd_k12, | 
					
						
							|  |  |  |         :arm, | 
					
						
							| 
									
										
										
										
											2021-12-19 09:27:08 +01:00
										 |  |  |         :arm_blizzard_avalanche, | 
					
						
							| 
									
										
										
										
											2020-11-17 09:34:00 +01:00
										 |  |  |         :arm_firestorm_icestorm, | 
					
						
							| 
									
										
										
										
											2020-11-17 16:26:53 +01:00
										 |  |  |         :arm_hurricane_zephyr, | 
					
						
							| 
									
										
										
										
											2024-01-05 15:37:33 -08:00
										 |  |  |         :arm_ibiza, | 
					
						
							| 
									
										
										
										
											2020-11-17 16:26:53 +01:00
										 |  |  |         :arm_lightning_thunder, | 
					
						
							| 
									
										
										
										
											2024-01-05 15:37:33 -08:00
										 |  |  |         :arm_lobos, | 
					
						
							| 
									
										
										
										
											2020-11-17 16:26:53 +01:00
										 |  |  |         :arm_monsoon_mistral, | 
					
						
							| 
									
										
										
										
											2024-01-05 15:37:33 -08:00
										 |  |  |         :arm_palma, | 
					
						
							| 
									
										
										
										
											2020-11-17 16:26:53 +01:00
										 |  |  |         :arm_twister, | 
					
						
							|  |  |  |         :arm_typhoon, | 
					
						
							| 
									
										
										
										
											2020-11-06 15:33:29 +01:00
										 |  |  |         :arm_vortex_tempest, | 
					
						
							| 
									
										
										
										
											2019-03-08 14:32:40 +11:00
										 |  |  |         :atom, | 
					
						
							| 
									
										
										
										
											2021-03-04 23:50:35 +00:00
										 |  |  |         :bobcat, | 
					
						
							| 
									
										
										
										
											2019-03-08 14:32:40 +11:00
										 |  |  |         :broadwell, | 
					
						
							| 
									
										
										
										
											2021-03-04 23:50:35 +00:00
										 |  |  |         :bulldozer, | 
					
						
							|  |  |  |         :cannonlake, | 
					
						
							| 
									
										
										
										
											2021-12-19 09:27:08 +01:00
										 |  |  |         :cometlake, | 
					
						
							| 
									
										
										
										
											2018-04-14 03:01:33 +02:00
										 |  |  |         :core, | 
					
						
							|  |  |  |         :core2, | 
					
						
							| 
									
										
										
										
											2019-03-08 14:32:40 +11:00
										 |  |  |         :dothan, | 
					
						
							|  |  |  |         :haswell, | 
					
						
							| 
									
										
										
										
											2020-06-20 14:14:56 +08:00
										 |  |  |         :icelake, | 
					
						
							| 
									
										
										
										
											2019-03-08 14:32:40 +11:00
										 |  |  |         :ivybridge, | 
					
						
							| 
									
										
										
										
											2021-03-04 23:50:35 +00:00
										 |  |  |         :jaguar, | 
					
						
							| 
									
										
										
										
											2019-03-08 14:32:40 +11:00
										 |  |  |         :kabylake, | 
					
						
							|  |  |  |         :merom, | 
					
						
							| 
									
										
										
										
											2018-04-14 03:01:33 +02:00
										 |  |  |         :nehalem, | 
					
						
							| 
									
										
										
										
											2019-03-08 14:32:40 +11:00
										 |  |  |         :penryn, | 
					
						
							| 
									
										
										
										
											2021-03-04 23:50:35 +00:00
										 |  |  |         :ppc, | 
					
						
							| 
									
										
										
										
											2019-03-08 14:32:40 +11:00
										 |  |  |         :prescott, | 
					
						
							|  |  |  |         :presler, | 
					
						
							| 
									
										
										
										
											2018-04-14 03:01:33 +02:00
										 |  |  |         :sandybridge, | 
					
						
							|  |  |  |         :skylake, | 
					
						
							| 
									
										
										
										
											2019-03-08 14:32:40 +11:00
										 |  |  |         :westmere, | 
					
						
							| 
									
										
										
										
											2021-03-04 23:50:35 +00:00
										 |  |  |         :zen, | 
					
						
							|  |  |  |         :zen3, | 
					
						
							| 
									
										
										
										
											2018-04-14 03:01:33 +02:00
										 |  |  |         :dunno, | 
					
						
							|  |  |  |       ] | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-04-14 03:01:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "returns the current CPU's family name as a symbol, or :dunno if it cannot be detected" do | 
					
						
							|  |  |  |       expect(cpu_families).to include described_class.family | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-11-17 09:34:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     context "when hw.cpufamily is 0x573b5eec on a Mac", :needs_macos do | 
					
						
							|  |  |  |       before do | 
					
						
							|  |  |  |         allow(described_class) | 
					
						
							|  |  |  |           .to receive(:sysctl_int) | 
					
						
							|  |  |  |           .with("hw.cpufamily") | 
					
						
							|  |  |  |           .and_return(0x573b5eec) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "returns :arm_firestorm_icestorm on ARM" do | 
					
						
							| 
									
										
										
										
											2023-12-14 02:52:30 +00:00
										 |  |  |         allow(described_class).to receive_messages(arm?: true, intel?: false) | 
					
						
							| 
									
										
										
										
											2020-11-17 09:34:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(described_class.family).to eq(:arm_firestorm_icestorm) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "returns :westmere on Intel" do | 
					
						
							| 
									
										
										
										
											2023-12-14 02:52:30 +00:00
										 |  |  |         allow(described_class).to receive_messages(arm?: false, intel?: true) | 
					
						
							| 
									
										
										
										
											2020-11-17 09:34:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(described_class.family).to eq(:westmere) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-04-14 03:01:33 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | end |