summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2015-10-29 12:28:38 -0700
committerTim Smith <tsmith84@gmail.com>2015-10-29 12:28:38 -0700
commit9362a69b8ea2ba2bbb433b9d99a4af7c24ead533 (patch)
treede3e46f44ab5b4f71abc3b0eaa4beb900dd71dca
parentf954a2cfddbe040038e1270b4a8180144953ec7d (diff)
downloadohai-9362a69b8ea2ba2bbb433b9d99a4af7c24ead533.tar.gz
Fix detection on FreeBSD <=10.1
-rw-r--r--lib/ohai/plugins/freebsd/cpu.rb2
-rw-r--r--spec/unit/plugins/freebsd/cpu_spec.rb36
2 files changed, 36 insertions, 2 deletions
diff --git a/lib/ohai/plugins/freebsd/cpu.rb b/lib/ohai/plugins/freebsd/cpu.rb
index 3b9f791a..347bff34 100644
--- a/lib/ohai/plugins/freebsd/cpu.rb
+++ b/lib/ohai/plugins/freebsd/cpu.rb
@@ -41,7 +41,7 @@ Ohai.plugin(:CPU) do
when /CPU:\s+(.+) \(([\d.]+).+\)/
cpuinfo["model_name"] = $1
cpuinfo["mhz"] = $2
- when /\s+Origin="(.*)"\s.*Family=(?:0x)?(\S+)\s.*Model=(?:0x)?(\S+)\s+Stepping=(?:0x)?(\S+)/
+ when /\s+Origin.*"(.*)".*Family.*0x(\S+).*Model.*0x(\S+).*Stepping.*(\S+)/
cpuinfo["vendor_id"] = $1
cpuinfo["family"] = $2
cpuinfo["model"] = $3
diff --git a/spec/unit/plugins/freebsd/cpu_spec.rb b/spec/unit/plugins/freebsd/cpu_spec.rb
index 9e19e50b..93b173d2 100644
--- a/spec/unit/plugins/freebsd/cpu_spec.rb
+++ b/spec/unit/plugins/freebsd/cpu_spec.rb
@@ -18,7 +18,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
-describe Ohai::System, "FreeBSD cpu plugin" do
+describe Ohai::System, "FreeBSD cpu plugin on FreeBSD >=10.2" do
before(:each) do
@plugin = get_plugin("freebsd/cpu")
allow(@plugin).to receive(:collect_os).and_return(:freebsd)
@@ -77,3 +77,37 @@ describe Ohai::System, "FreeBSD cpu plugin" do
end
end
+
+describe Ohai::System, "FreeBSD cpu plugin on FreeBSD <=10.1" do
+ before(:each) do
+ @plugin = get_plugin("freebsd/cpu")
+ allow(@plugin).to receive(:collect_os).and_return(:freebsd)
+ allow(@plugin).to receive(:shell_out).with("sysctl -n hw.ncpu").and_return(mock_shell_out(0, "2", ""))
+ @double_file = double("/var/run/dmesg.boot")
+ allow(@double_file).to receive(:each).
+ and_yield('CPU: Intel(R) Atom(TM) CPU N270 @ 1.60GHz (1596.03-MHz 686-class CPU)').
+ and_yield(' Origin = "GenuineIntel" Id = 0x106c2 Family = 0x6 Model = 0x1c Stepping = 2')
+ allow(File).to receive(:open).with("/var/run/dmesg.boot").and_return(@double_file)
+ end
+
+ it "detects CPU vendor_id" do
+ @plugin.run
+ expect(@plugin[:cpu][:vendor_id]).to eq("GenuineIntel")
+ end
+
+ it "detects CPU family" do
+ @plugin.run
+ expect(@plugin[:cpu][:family]).to eq("6")
+ end
+
+ it "detects CPU model" do
+ @plugin.run
+ expect(@plugin[:cpu][:model]).to eq("1c")
+ end
+
+ it "detects CPU stepping" do
+ @plugin.run
+ expect(@plugin[:cpu][:stepping]).to eq("2")
+ end
+
+end