-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
BogdanIrimie
committed
Aug 28, 2020
1 parent
21efd8f
commit dab67e9
Showing
8 changed files
with
204 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
module Processors | ||
class Speed | ||
FACT_NAME = 'processors.speed' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Linux::Processors.resolve(:speed) | ||
speed = Facter::FactsUtils::UnitConverter.hertz_to_human_readable(fact_value) | ||
Facter::ResolvedFact.new(FACT_NAME, speed) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facts::Linux::Processors::Speed do | ||
describe '#call_the_resolver' do | ||
subject(:fact) { Facts::Linux::Processors::Speed.new } | ||
|
||
let(:speed) { 1_800_000_000 } | ||
let(:converted_speed) { '1.80 GHz' } | ||
|
||
before do | ||
allow(Facter::Resolvers::Linux::Processors).to \ | ||
receive(:resolve).with(:speed).and_return(speed) | ||
end | ||
|
||
it 'calls Facter::Resolvers::Linux::Processors' do | ||
fact.call_the_resolver | ||
expect(Facter::Resolvers::Linux::Processors).to have_received(:resolve).with(:speed) | ||
end | ||
|
||
it 'returns a resolved fact' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ | ||
have_attributes(name: 'processors.speed', value: converted_speed) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,145 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facter::Resolvers::Linux::Processors do | ||
let(:processors) { 4 } | ||
let(:models) do | ||
['Intel(R) Xeon(R) CPU E5-2697 v4 @ 2.30GHz', 'Intel(R) Xeon(R) CPU E5-2697 v4 @ 2.30GHz', | ||
'Intel(R) Xeon(R) CPU E5-2697 v4 @ 2.30GHz', 'Intel(R) Xeon(R) CPU E5-2697 v4 @ 2.30GHz'] | ||
end | ||
let(:physical_processors) { 1 } | ||
|
||
context 'when cpuinfo file is readable' do | ||
before do | ||
allow(Facter::Util::FileHelper).to receive(:safe_readlines) | ||
.with('/proc/cpuinfo') | ||
.and_return(load_fixture('cpuinfo').readlines) | ||
context 'when on x86 architecture' do | ||
let(:processors) { 4 } | ||
let(:models) do | ||
['Intel(R) Xeon(R) CPU E5-2697 v4 @ 2.30GHz', 'Intel(R) Xeon(R) CPU E5-2697 v4 @ 2.30GHz', | ||
'Intel(R) Xeon(R) CPU E5-2697 v4 @ 2.30GHz', 'Intel(R) Xeon(R) CPU E5-2697 v4 @ 2.30GHz'] | ||
end | ||
let(:physical_processors) { 1 } | ||
|
||
after do | ||
Facter::Resolvers::Linux::Processors.invalidate_cache | ||
end | ||
context 'when cpuinfo file is readable' do | ||
before do | ||
allow(Facter::Util::FileHelper).to receive(:safe_readlines) | ||
.with('/proc/cpuinfo') | ||
.and_return(load_fixture('cpuinfo').readlines) | ||
end | ||
|
||
let(:speed) { 2_294_000_000 } | ||
|
||
after do | ||
Facter::Resolvers::Linux::Processors.invalidate_cache | ||
end | ||
|
||
it 'returns number of processors' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:processors) | ||
|
||
expect(result).to eq(processors) | ||
end | ||
|
||
it 'returns list of models' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:models) | ||
|
||
expect(result).to eq(models) | ||
end | ||
|
||
it 'returns number of processors' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:processors) | ||
it 'returns number of physical processors' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:physical_count) | ||
|
||
expect(result).to eq(processors) | ||
expect(result).to eq(physical_processors) | ||
end | ||
|
||
it 'returns cpu speed' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:speed) | ||
|
||
expect(result).to eq(speed) | ||
end | ||
end | ||
|
||
it 'returns list of models' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:models) | ||
context 'when cpuinfo file is readable but no physical id' do | ||
before do | ||
allow(Facter::Util::FileHelper).to receive(:safe_readlines) | ||
.with('/proc/cpuinfo') | ||
.and_return(load_fixture('cpuinfo_wo_physical_id').readlines) | ||
allow(Dir).to receive(:entries).with('/sys/devices/system/cpu').and_return(%w[cpu0 cpu1 cpuindex]) | ||
|
||
expect(result).to eq(models) | ||
allow(File).to receive(:exist?) | ||
.with('/sys/devices/system/cpu/cpu0/topology/physical_package_id') | ||
.and_return(true) | ||
|
||
allow(File).to receive(:exist?) | ||
.with('/sys/devices/system/cpu/cpu1/topology/physical_package_id') | ||
.and_return(true) | ||
end | ||
|
||
after do | ||
Facter::Resolvers::Linux::Processors.invalidate_cache | ||
end | ||
|
||
let(:physical_processors) { 2 } | ||
|
||
it 'returns number of processors' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:processors) | ||
|
||
expect(result).to eq(processors) | ||
end | ||
|
||
it 'returns list of models' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:models) | ||
|
||
expect(result).to eq(models) | ||
end | ||
|
||
it 'returns number of physical processors' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:physical_count) | ||
|
||
expect(result).to eq(physical_processors) | ||
end | ||
end | ||
|
||
it 'returns number of physical processors' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:physical_count) | ||
context 'when cpuinfo is not readable' do | ||
before do | ||
allow(Facter::Util::FileHelper).to receive(:safe_readlines) | ||
.with('/proc/cpuinfo') | ||
.and_return([]) | ||
end | ||
|
||
expect(result).to eq(physical_processors) | ||
it 'returns nil' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:physical_count) | ||
|
||
expect(result).to be(nil) | ||
end | ||
end | ||
end | ||
|
||
context 'when cpuinfo file is readable but no physical id' do | ||
context 'when on powerpc architecture' do | ||
before do | ||
allow(Facter::Util::FileHelper).to receive(:safe_readlines) | ||
.with('/proc/cpuinfo') | ||
.and_return(load_fixture('cpuinfo_wo_physical_id').readlines) | ||
allow(Dir).to receive(:entries).with('/sys/devices/system/cpu').and_return(%w[cpu0 cpu1 cpuindex]) | ||
end | ||
.and_return(load_fixture('cpuinfo_powerpc').readlines) | ||
|
||
after do | ||
Facter::Resolvers::Linux::Processors.invalidate_cache | ||
allow(Dir).to receive(:entries).with('/sys/devices/system/cpu').and_return(%w[cpu0 cpu1 cpuindex]) | ||
allow(File).to receive(:exist?).with('/sys/devices/system/cpu/cpu0/topology/physical_package_id').and_return(true) | ||
allow(File).to receive(:exist?).with('/sys/devices/system/cpu/cpu1/topology/physical_package_id').and_return(true) | ||
end | ||
|
||
let(:speed) { 2_926_000_000 } | ||
let(:physical_processors) { 2 } | ||
|
||
it 'returns number of processors' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:processors) | ||
|
||
expect(result).to eq(processors) | ||
end | ||
|
||
it 'returns list of models' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:models) | ||
|
||
expect(result).to eq(models) | ||
let(:models) do | ||
['POWER8 (raw), altivec supported', | ||
'POWER8 (raw), altivec supported', | ||
'POWER8 (raw), altivec supported', | ||
'POWER8 (raw), altivec supported'] | ||
end | ||
|
||
it 'returns number of physical processors' do | ||
it 'returns physical_devices_count' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:physical_count) | ||
|
||
expect(result).to eq(physical_processors) | ||
end | ||
end | ||
|
||
context 'when cpuinfo is not readable' do | ||
before do | ||
allow(Facter::Util::FileHelper).to receive(:safe_readlines) | ||
.with('/proc/cpuinfo') | ||
.and_return([]) | ||
it 'returns list of models' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:models) | ||
|
||
expect(result).to eq(models) | ||
end | ||
|
||
it 'returns nil' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:physical_count) | ||
it 'returns cpu speed' do | ||
result = Facter::Resolvers::Linux::Processors.resolve(:speed) | ||
|
||
expect(result).to be(nil) | ||
expect(result).to eq(speed) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
processor : 0 | ||
cpu : POWER8 (raw), altivec supported | ||
clock : 2926.000000MHz | ||
revision : 2.0 (pvr 004d 0200) | ||
|
||
processor : 1 | ||
cpu : POWER8 (raw), altivec supported | ||
clock : 2926.000000MHz | ||
revision : 2.0 (pvr 004d 0200) | ||
|
||
processor : 2 | ||
cpu : POWER8 (raw), altivec supported | ||
clock : 2926.000000MHz | ||
revision : 2.0 (pvr 004d 0200) | ||
|
||
processor : 3 | ||
cpu : POWER8 (raw), altivec supported | ||
clock : 2926.000000MHz | ||
revision : 2.0 (pvr 004d 0200) | ||
|
||
timebase : 512000000 | ||
platform : pSeries | ||
model : IBM pSeries (emulated by qemu) | ||
machine : CHRP IBM pSeries (emulated by qemu) |