summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2015-12-09 12:03:59 -0800
committerTim Smith <tsmith@chef.io>2015-12-09 12:03:59 -0800
commit84f5550692706d59d1f83cf07e9548713af77001 (patch)
treee5657764845677a7ecac46954a92e9c23cd4edad
parent5c274f75cf87aa3084d98ce7d242e2a6ee74232d (diff)
parent2603a335d5e176a225acb393aa758229a3113384 (diff)
downloadohai-84f5550692706d59d1f83cf07e9548713af77001.tar.gz
Merge pull request #672 from tas50/osx_cpu
Correctly count real vs. total vs. cores on darwin
-rw-r--r--lib/ohai/plugins/darwin/cpu.rb8
-rw-r--r--spec/unit/plugins/darwin/cpu_spec.rb11
2 files changed, 13 insertions, 6 deletions
diff --git a/lib/ohai/plugins/darwin/cpu.rb b/lib/ohai/plugins/darwin/cpu.rb
index ec8f095b..9ff64ba5 100644
--- a/lib/ohai/plugins/darwin/cpu.rb
+++ b/lib/ohai/plugins/darwin/cpu.rb
@@ -1,7 +1,7 @@
#
# Author:: Nathan L Smith (<nlloyds@gmail.com>)
-# Author:: Tim Smith (<tsmith@limelight.com>)
-# Copyright:: Copyright (c) 2013 Opscode, Inc.
+# Author:: Tim Smith (<tsmith@chef.io>)
+# Copyright:: Copyright (c) 2013-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,8 +22,10 @@ Ohai.plugin(:CPU) do
collect_data(:darwin) do
cpu Mash.new
- so = shell_out("sysctl -n hw.physicalcpu")
+ so = shell_out("sysctl -n hw.packages")
cpu[:real] = so.stdout.to_i
+ so = shell_out("sysctl -n hw.physicalcpu")
+ cpu[:cores] = so.stdout.to_i
so = shell_out("sysctl -n hw.logicalcpu")
cpu[:total] = so.stdout.to_i
so = shell_out("sysctl -n hw.cpufrequency")
diff --git a/spec/unit/plugins/darwin/cpu_spec.rb b/spec/unit/plugins/darwin/cpu_spec.rb
index 5ddc6e3a..fab98b27 100644
--- a/spec/unit/plugins/darwin/cpu_spec.rb
+++ b/spec/unit/plugins/darwin/cpu_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Nathan L Smith (<nlloyds@gmail.com>)
-# Copyright:: Copyright (c) 2013 Opscode, Inc.
+# Copyright:: Copyright (c) 2013-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,6 +23,7 @@ describe Ohai::System, "Darwin cpu plugin" do
before(:each) do
@plugin = get_plugin("darwin/cpu")
allow(@plugin).to receive(:collect_os).and_return(:darwin)
+ allow(@plugin).to receive(:shell_out).with("sysctl -n hw.packages").and_return(mock_shell_out(0, "1", ""))
allow(@plugin).to receive(:shell_out).with("sysctl -n hw.physicalcpu").and_return(mock_shell_out(0, "4", ""))
allow(@plugin).to receive(:shell_out).with("sysctl -n hw.logicalcpu").and_return(mock_shell_out(0, "8", ""))
allow(@plugin).to receive(:shell_out).with("sysctl -n hw.cpufrequency").and_return(mock_shell_out(0, "2300000000", ""))
@@ -35,12 +36,16 @@ describe Ohai::System, "Darwin cpu plugin" do
@plugin.run
end
+ it "should set cpu[:cores] to 4" do
+ expect(@plugin[:cpu][:cores]).to eq(4)
+ end
+
it "should set cpu[:total] to 8" do
expect(@plugin[:cpu][:total]).to eq(8)
end
- it "should set cpu[:real] to 4" do
- expect(@plugin[:cpu][:real]).to eq(4)
+ it "should set cpu[:real] to 1" do
+ expect(@plugin[:cpu][:real]).to eq(1)
end
it "should set cpu[:mhz] to 2300" do