Signed-off-by: Michael Kincaid <[email protected]>
---
Local-branch: ticket/next/6515
 lib/facter/processor.rb              |  135 ++++++++++++--------------
 lib/facter/util/processor.rb         |   88 +++++++++++++++++
 spec/fixtures/cpuinfo/amd64dual      |   57 +++++++++++
 spec/fixtures/cpuinfo/amd64quad      |   79 +++++++++++++++
 spec/fixtures/cpuinfo/amd64solo      |   23 +++++
 spec/fixtures/cpuinfo/amd64tri       |   86 +++++++++++++++++
 spec/fixtures/cpuinfo/bbg3-armel     |   12 +++
 spec/fixtures/cpuinfo/beaglexm-armel |   12 +++
 spec/fixtures/cpuinfo/panda-armel    |   17 ++++
 spec/fixtures/cpuinfo/ppc64          |   19 ++++
 spec/fixtures/cpuinfo/sparc          |   10 ++
 spec/unit/processor_spec.rb          |  174 ++++++++++++++++++++++++++++++++++
 spec/unit/util/processor_spec.rb     |   62 ++++++++++++
 13 files changed, 702 insertions(+), 72 deletions(-)
 create mode 100644 lib/facter/util/processor.rb
 create mode 100644 spec/fixtures/cpuinfo/amd64dual
 create mode 100644 spec/fixtures/cpuinfo/amd64quad
 create mode 100644 spec/fixtures/cpuinfo/amd64solo
 create mode 100644 spec/fixtures/cpuinfo/amd64tri
 create mode 100644 spec/fixtures/cpuinfo/bbg3-armel
 create mode 100644 spec/fixtures/cpuinfo/beaglexm-armel
 create mode 100644 spec/fixtures/cpuinfo/panda-armel
 create mode 100644 spec/fixtures/cpuinfo/ppc64
 create mode 100644 spec/fixtures/cpuinfo/sparc
 create mode 100755 spec/unit/processor_spec.rb
 create mode 100755 spec/unit/util/processor_spec.rb

diff --git a/lib/facter/processor.rb b/lib/facter/processor.rb
index ec196b2..df4e9af 100644
--- a/lib/facter/processor.rb
+++ b/lib/facter/processor.rb
@@ -19,88 +19,79 @@
 #
 
 require 'thread'
+require 'facter/util/processor'
 
-if ["Linux", "GNU/kFreeBSD"].include? Facter.value(:kernel)
-    processor_num = -1
-    processor_list = []
-    Thread::exclusive do
-        File.readlines("/proc/cpuinfo").each do |l|
-            if l =~ /processor\s+:\s+(\d+)/
-                processor_num = $1.to_i
-            elsif l =~ /model name\s+:\s+(.*)\s*$/
-                processor_list[processor_num] = $1 unless processor_num == -1
-                processor_num = -1
-            elsif l =~ /processor\s+(\d+):\s+(.*)/
-                processor_num = $1.to_i
-                processor_list[processor_num] = $2 unless processor_num == -1
-            end
-        end
+Facter.add("ProcessorCount") do
+  confine :kernel => [ :linux, :"gnu/kfreebsd" ]
+  setcode do
+    processor_list = Facter::Util::Processor.enum_cpuinfo
+    
+    ## If this returned nothing, then don't resolve the fact
+    if processor_list.length != 0
+      processor_list.length.to_s
     end
+  end
+end
 
-    Facter.add("ProcessorCount") do
-        confine :kernel => [ :linux, :"gnu/kfreebsd" ]
-        setcode do
-            processor_list.length.to_s
-        end
-    end
+Facter.add("ProcessorCount") do
+       confine :kernel => [ :linux, :"gnu/kfreebsd" ]
+       setcode do
+## The method above is preferable since it provides the description of the CPU 
as well
+## but if that returned 0, then we enumerate sysfs
+                       sysfs_cpu_directory = '/sys/devices/system/cpu'
+                       if File.exists?(sysfs_cpu_directory)
+                               lookup_pattern = "#{sysfs_cpu_directory}" + 
"/cpu[0-9]*"
+                               cpuCount = Dir.glob(lookup_pattern).length
+                               cpuCount.to_s
+                       end
+       end
+end
 
-    processor_list.each_with_index do |desc, i|
-        Facter.add("Processor#{i}") do
-            confine :kernel => [ :linux, :"gnu/kfreebsd" ]
-            setcode do
-                desc
-            end
-        end
-    end
+Facter.add("ProcessorCount") do
+  confine :kernel => :aix
+  setcode do
+    processor_list = Facter::Util::Processor.enum_lsdev
+        
+    processor_list.length.to_s
+  end
 end
 
-if Facter.value(:kernel) == "AIX"
-    processor_num = -1
-    processor_list = {}
-    Thread::exclusive do
-        procs = Facter::Util::Resolution.exec('lsdev -Cc processor')
-        procs.each do |proc|
-            if proc =~ /^proc(\d+)/
-                processor_num = $1.to_i
-                # Not retrieving the frequency since AIX 4.3.3 doesn't support 
the
-                # attribute and some people still use the OS.
-                proctype = Facter::Util::Resolution.exec('lsattr -El proc0 -a 
type')
-                if proctype =~ /^type\s+(\S+)\s+/
-                    processor_list["processor#{processor_num}"] = $1
-                end
-            end
-        end
-    end
 
-    Facter.add("ProcessorCount") do
-        confine :kernel => :aix
-        setcode do
-            processor_list.length.to_s
-        end
-    end
+Facter.add("ProcessorCount") do
+       confine :kernel => :openbsd
+       setcode do
+               Facter::Util::Resolution.exec("sysctl hw.ncpu | cut -d'=' -f2")
+       end
+end
 
-    processor_list.each do |proc, desc|
-        Facter.add(proc) do
-            confine :kernel => :aix
-            setcode do
-                desc
-            end
-        end
-    end
+Facter.add("ProcessorCount") do
+       confine :kernel => :Darwin
+       setcode do
+               Facter::Util::Resolution.exec("sysctl hw.ncpu | cut -d' ' -f2")
+       end
 end
 
-if Facter.value(:kernel) == "OpenBSD"
-    Facter.add("Processor") do
-        confine :kernel => :openbsd
-        setcode do
-            Facter::Util::Resolution.exec("uname -p")
-        end
-    end
+## We have to enumerate these outside a Facter.add block to get the processorN 
descriptions iteratively
+## (but we need them inside the Facter.add block above for tests on 
processorcount to work)
+processor_list = Facter::Util::Processor.enum_cpuinfo
+processor_list_aix = Facter::Util::Processor.enum_lsdev
 
-    Facter.add("ProcessorCount") do
-        confine :kernel => :openbsd
-        setcode do
-            Facter::Util::Resolution.exec("sysctl hw.ncpu | cut -d'=' -f2")
-        end
+if processor_list.length != 0
+  processor_list.each_with_index do |desc, i|
+    Facter.add("Processor#{i}") do
+      confine :kernel => [ :linux, :"gnu/kfreebsd" ]
+      setcode do
+        desc
+      end
+    end
+  end
+elsif processor_list_aix.length != 0
+  processor_list_aix.each_with_index do |desc, i|
+    Facter.add("Processor#{i}") do
+      confine :kernel => [ :aix ]
+      setcode do
+        desc
+      end
     end
+  end
 end
diff --git a/lib/facter/util/processor.rb b/lib/facter/util/processor.rb
new file mode 100644
index 0000000..d74c1c8
--- /dev/null
+++ b/lib/facter/util/processor.rb
@@ -0,0 +1,88 @@
+module Facter::Util::Processor
+  def self.enum_cpuinfo
+    processor_num = -1
+    processor_list = []
+    cpuinfo = "/proc/cpuinfo"
+
+    if File.exists?(cpuinfo)
+      model = Facter.value(:architecture)
+      case model
+      when "x86_64", "amd64", "i386", /parisc/, "hppa", "ia64"
+        Thread::exclusive do
+          File.readlines(cpuinfo).each do |l|
+            if l =~ /processor\s+:\s+(\d+)/
+              processor_num = $1.to_i
+            elsif l =~ /model name\s+:\s+(.*)\s*$/
+              processor_list[processor_num] = $1 unless processor_num == -1
+              processor_num = -1
+            elsif l =~ /processor\s+(\d+):\s+(.*)/
+              processor_num = $1.to_i
+              processor_list[processor_num] = $2 unless processor_num == -1
+            end
+          end
+        end
+       
+      when "ppc64"
+        Thread::exclusive do
+          File.readlines(cpuinfo).each do |l|
+            if l =~ /processor\s+:\s+(\d+)/
+              processor_num = $1.to_i  
+            elsif l =~ /cpu\s+:\s+(.*)\s*$/
+              processor_list[processor_num] = $1 unless processor_num == -1
+              processor_num = -1
+            end
+          end
+        end
+          
+      when /arm/
+        Thread::exclusive do
+          File.readlines(cpuinfo).each do |l|
+            if l =~ /Processor\s+:\s+(.+)/
+              processor_num += 1
+              processor_list[processor_num] = $1.chomp
+            elsif l =~ /processor\s+:\s+(\d+)\s*$/
+              proc_num = $1.to_i
+              if proc_num != 0
+                processor_num += 1
+                processor_list[processor_num] = processor_list[processor_num-1]
+              end
+            end
+          end
+        end
+
+      when /sparc/
+        Thread::exclusive do
+          File.readlines(cpuinfo).each do |l|
+            if l =~ /cpu\s+:\s+(.*)\s*$/
+              processor_num += 1
+              processor_list[processor_num] = $1
+            end
+          end
+        end
+      end
+    end
+    processor_list
+  end
+  
+  def self.enum_lsdev
+    processor_num = -1
+    processor_list = {}
+    Thread::exclusive do
+      procs = Facter::Util::Resolution.exec('lsdev -Cc processor')
+      if procs
+        procs.each do |proc|
+          if proc =~ /^proc(\d+)/
+            processor_num = $1.to_i
+            # Not retrieving the frequency since AIX 4.3.3 doesn't support the
+            # attribute and some people still use the OS.
+            proctype = Facter::Util::Resolution.exec('lsattr -El proc0 -a 
type')
+            if proctype =~ /^type\s+(\S+)\s+/
+              processor_list[processor_num] = $1
+            end
+          end
+        end
+      end
+    end
+    processor_list
+  end
+end
\ No newline at end of file
diff --git a/spec/fixtures/cpuinfo/amd64dual b/spec/fixtures/cpuinfo/amd64dual
new file mode 100644
index 0000000..101e5b5
--- /dev/null
+++ b/spec/fixtures/cpuinfo/amd64dual
@@ -0,0 +1,57 @@
+processor      : 0
+vendor_id      : GenuineIntel
+cpu family     : 6
+model          : 23
+model name     : Intel(R) Core(TM)2 Duo CPU     P8700  @ 2.53GHz
+stepping       : 10
+cpu MHz                : 689.302
+cache size     : 6144 KB
+physical id    : 0
+siblings       : 2
+core id                : 0
+cpu cores      : 2
+apicid         : 0
+initial apicid : 0
+fdiv_bug       : no
+hlt_bug                : no
+f00f_bug       : no
+coma_bug       : no
+fpu            : yes
+fpu_exception  : yes
+cpuid level    : 5
+wp             : yes
+flags          : fpu vme de pse tsc msr mce cx8 apic mtrr pge mca cmov pat 
pse36 clflush mmx fxsr sse sse2 ht constant_tsc pni ssse3
+bogomips       : 1378.60
+clflush size   : 64
+cache_alignment        : 64
+address sizes  : 36 bits physical, 48 bits virtual
+power management:
+
+processor      : 1
+vendor_id      : GenuineIntel
+cpu family     : 6
+model          : 23
+model name     : Intel(R) Core(TM)2 Duo CPU     P8700  @ 2.53GHz
+stepping       : 10
+cpu MHz                : 689.302
+cache size     : 6144 KB
+physical id    : 0
+siblings       : 2
+core id                : 1
+cpu cores      : 2
+apicid         : 1
+initial apicid : 1
+fdiv_bug       : no
+hlt_bug                : no
+f00f_bug       : no
+coma_bug       : no
+fpu            : yes
+fpu_exception  : yes
+cpuid level    : 5
+wp             : yes
+flags          : fpu vme de pse tsc msr mce cx8 apic mtrr pge mca cmov pat 
pse36 clflush mmx fxsr sse sse2 ht constant_tsc pni ssse3
+bogomips       : 1687.45
+clflush size   : 64
+cache_alignment        : 64
+address sizes  : 36 bits physical, 48 bits virtual
+power management:
diff --git a/spec/fixtures/cpuinfo/amd64quad b/spec/fixtures/cpuinfo/amd64quad
new file mode 100644
index 0000000..3675476
--- /dev/null
+++ b/spec/fixtures/cpuinfo/amd64quad
@@ -0,0 +1,79 @@
+processor      : 0
+vendor_id      : AuthenticAMD
+cpu family     : 16
+model          : 4
+model name     : Quad-Core AMD Opteron(tm) Processor 2374 HE
+stepping       : 2
+cpu MHz                : 1386667.908
+cache size     : 512 KB
+fpu            : yes
+fpu_exception  : yes
+cpuid level    : 5
+wp             : yes
+flags          : fpu de tsc msr pae cx8 cmov pat clflush mmx fxsr sse sse2 ht 
syscall nx mmxext fxsr_opt lm 3dnowext 3dnow constant_tsc rep_good nonstop_tsc 
pni cx16 popcnt lahf_lm cmp_legacy extapic cr8_legacy abm sse4a misalignsse 
3dnowprefetch
+bogomips       : 4400.17
+TLB size       : 1024 4K pages
+clflush size   : 64
+cache_alignment        : 64
+address sizes  : 48 bits physical, 48 bits virtual
+power management: ts ttp tm stc 100mhzsteps hwpstate
+
+processor      : 1
+vendor_id      : AuthenticAMD
+cpu family     : 16
+model          : 4
+model name     : Quad-Core AMD Opteron(tm) Processor 2374 HE
+stepping       : 2
+cpu MHz                : 1386667.908
+cache size     : 512 KB
+fpu            : yes
+fpu_exception  : yes
+cpuid level    : 5
+wp             : yes
+flags          : fpu de tsc msr pae cx8 cmov pat clflush mmx fxsr sse sse2 ht 
syscall nx mmxext fxsr_opt lm 3dnowext 3dnow constant_tsc rep_good nonstop_tsc 
pni cx16 popcnt lahf_lm cmp_legacy extapic cr8_legacy abm sse4a misalignsse 
3dnowprefetch
+bogomips       : 4400.17
+TLB size       : 1024 4K pages
+clflush size   : 64
+cache_alignment        : 64
+address sizes  : 48 bits physical, 48 bits virtual
+power management: ts ttp tm stc 100mhzsteps hwpstate
+
+processor      : 2
+vendor_id      : AuthenticAMD
+cpu family     : 16
+model          : 4
+model name     : Quad-Core AMD Opteron(tm) Processor 2374 HE
+stepping       : 2
+cpu MHz                : 1386667.908
+cache size     : 512 KB
+fpu            : yes
+fpu_exception  : yes
+cpuid level    : 5
+wp             : yes
+flags          : fpu de tsc msr pae cx8 cmov pat clflush mmx fxsr sse sse2 ht 
syscall nx mmxext fxsr_opt lm 3dnowext 3dnow constant_tsc rep_good nonstop_tsc 
pni cx16 popcnt lahf_lm cmp_legacy extapic cr8_legacy abm sse4a misalignsse 
3dnowprefetch
+bogomips       : 4400.17
+TLB size       : 1024 4K pages
+clflush size   : 64
+cache_alignment        : 64
+address sizes  : 48 bits physical, 48 bits virtual
+power management: ts ttp tm stc 100mhzsteps hwpstate
+
+processor      : 3
+vendor_id      : AuthenticAMD
+cpu family     : 16
+model          : 4
+model name     : Quad-Core AMD Opteron(tm) Processor 2374 HE
+stepping       : 2
+cpu MHz                : 1386667.908
+cache size     : 512 KB
+fpu            : yes
+fpu_exception  : yes
+cpuid level    : 5
+wp             : yes
+flags          : fpu de tsc msr pae cx8 cmov pat clflush mmx fxsr sse sse2 ht 
syscall nx mmxext fxsr_opt lm 3dnowext 3dnow constant_tsc rep_good nonstop_tsc 
pni cx16 popcnt lahf_lm cmp_legacy extapic cr8_legacy abm sse4a misalignsse 
3dnowprefetch
+bogomips       : 4400.17
+TLB size       : 1024 4K pages
+clflush size   : 64
+cache_alignment        : 64
+address sizes  : 48 bits physical, 48 bits virtual
+power management: ts ttp tm stc 100mhzsteps hwpstate
diff --git a/spec/fixtures/cpuinfo/amd64solo b/spec/fixtures/cpuinfo/amd64solo
new file mode 100644
index 0000000..09c3bb4
--- /dev/null
+++ b/spec/fixtures/cpuinfo/amd64solo
@@ -0,0 +1,23 @@
+processor      : 0
+vendor_id      : GenuineIntel
+cpu family     : 6
+model          : 23
+model name     : Intel(R) Core(TM)2 Duo CPU     P8700  @ 2.53GHz
+stepping       : 10
+cpu MHz                : 600.825
+cache size     : 6144 KB
+fdiv_bug       : no
+hlt_bug                : no
+f00f_bug       : no
+coma_bug       : no
+fpu            : yes
+fpu_exception  : yes
+cpuid level    : 5
+wp             : yes
+flags          : fpu vme de pse tsc msr mce cx8 apic mtrr pge mca cmov pat 
pse36 clflush mmx fxsr sse sse2 constant_tsc up pni monitor ssse3
+bogomips       : 1201.65
+clflush size   : 64
+cache_alignment        : 64
+address sizes  : 36 bits physical, 48 bits virtual
+power management:
+
diff --git a/spec/fixtures/cpuinfo/amd64tri b/spec/fixtures/cpuinfo/amd64tri
new file mode 100644
index 0000000..993c49c
--- /dev/null
+++ b/spec/fixtures/cpuinfo/amd64tri
@@ -0,0 +1,86 @@
+processor      : 0
+vendor_id      : GenuineIntel
+cpu family     : 6
+model          : 23
+model name     : Intel(R) Core(TM)2 Duo CPU     P8700  @ 2.53GHz
+stepping       : 10
+cpu MHz                : 910.177
+cache size     : 6144 KB
+physical id    : 0
+siblings       : 3
+core id                : 0
+cpu cores      : 3
+apicid         : 0
+initial apicid : 0
+fdiv_bug       : no
+hlt_bug                : no
+f00f_bug       : no
+coma_bug       : no
+fpu            : yes
+fpu_exception  : yes
+cpuid level    : 5
+wp             : yes
+flags          : fpu vme de pse tsc msr mce cx8 apic mtrr pge mca cmov pat 
pse36 clflush mmx fxsr sse sse2 ht constant_tsc pni ssse3
+bogomips       : 1820.35
+clflush size   : 64
+cache_alignment        : 64
+address sizes  : 36 bits physical, 48 bits virtual
+power management:
+
+processor      : 1
+vendor_id      : GenuineIntel
+cpu family     : 6
+model          : 23
+model name     : Intel(R) Core(TM)2 Duo CPU     P8700  @ 2.53GHz
+stepping       : 10
+cpu MHz                : 910.177
+cache size     : 6144 KB
+physical id    : 0
+siblings       : 3
+core id                : 1
+cpu cores      : 3
+apicid         : 1
+initial apicid : 1
+fdiv_bug       : no
+hlt_bug                : no
+f00f_bug       : no
+coma_bug       : no
+fpu            : yes
+fpu_exception  : yes
+cpuid level    : 5
+wp             : yes
+flags          : fpu vme de pse tsc msr mce cx8 apic mtrr pge mca cmov pat 
pse36 clflush mmx fxsr sse sse2 ht constant_tsc pni ssse3
+bogomips       : 1875.49
+clflush size   : 64
+cache_alignment        : 64
+address sizes  : 36 bits physical, 48 bits virtual
+power management:
+
+processor      : 2
+vendor_id      : GenuineIntel
+cpu family     : 6
+model          : 23
+model name     : Intel(R) Core(TM)2 Duo CPU     P8700  @ 2.53GHz
+stepping       : 10
+cpu MHz                : 910.177
+cache size     : 6144 KB
+physical id    : 0
+siblings       : 3
+core id                : 2
+cpu cores      : 3
+apicid         : 2
+initial apicid : 2
+fdiv_bug       : no
+hlt_bug                : no
+f00f_bug       : no
+coma_bug       : no
+fpu            : yes
+fpu_exception  : yes
+cpuid level    : 5
+wp             : yes
+flags          : fpu vme de pse tsc msr mce cx8 apic mtrr pge mca cmov pat 
pse36 clflush mmx fxsr sse sse2 ht constant_tsc pni ssse3
+bogomips       : 1523.26
+clflush size   : 64
+cache_alignment        : 64
+address sizes  : 36 bits physical, 48 bits virtual
+power management:
diff --git a/spec/fixtures/cpuinfo/bbg3-armel b/spec/fixtures/cpuinfo/bbg3-armel
new file mode 100644
index 0000000..6dd9d49
--- /dev/null
+++ b/spec/fixtures/cpuinfo/bbg3-armel
@@ -0,0 +1,12 @@
+Processor      : ARMv7 Processor rev 5 (v7l)
+BogoMIPS       : 799.53
+Features       : swp half thumb fastmult vfp edsp thumbee neon vfpv3 
+CPU implementer        : 0x41
+CPU architecture: 7
+CPU variant    : 0x2
+CPU part       : 0xc08
+CPU revision   : 5
+
+Hardware       : Freescale MX51 Babbage Board
+Revision       : 51130
+Serial         : 0000000000000000
diff --git a/spec/fixtures/cpuinfo/beaglexm-armel 
b/spec/fixtures/cpuinfo/beaglexm-armel
new file mode 100644
index 0000000..1de8986
--- /dev/null
+++ b/spec/fixtures/cpuinfo/beaglexm-armel
@@ -0,0 +1,12 @@
+Processor      : ARMv7 Processor rev 2 (v7l)
+BogoMIPS       : 506.27
+Features       : swp half thumb fastmult vfp edsp neon vfpv3 
+CPU implementer        : 0x41
+CPU architecture: 7
+CPU variant    : 0x3
+CPU part       : 0xc08
+CPU revision   : 2
+
+Hardware       : OMAP3 Beagle Board
+Revision       : 0020
+Serial         : 0000000000000000
diff --git a/spec/fixtures/cpuinfo/panda-armel 
b/spec/fixtures/cpuinfo/panda-armel
new file mode 100644
index 0000000..18b21a7
--- /dev/null
+++ b/spec/fixtures/cpuinfo/panda-armel
@@ -0,0 +1,17 @@
+Processor      : ARMv7 Processor rev 2 (v7l)
+processor      : 0
+BogoMIPS       : 2013.45
+
+processor      : 1
+BogoMIPS       : 1963.05
+
+Features       : swp half thumb fastmult vfp edsp thumbee neon vfpv3 
+CPU implementer        : 0x41
+CPU architecture: 7
+CPU variant    : 0x1
+CPU part       : 0xc09
+CPU revision   : 2
+
+Hardware       : OMAP4430 Panda Board
+Revision       : 0020
+Serial         : 0000000000000000
diff --git a/spec/fixtures/cpuinfo/ppc64 b/spec/fixtures/cpuinfo/ppc64
new file mode 100644
index 0000000..4375a97
--- /dev/null
+++ b/spec/fixtures/cpuinfo/ppc64
@@ -0,0 +1,19 @@
+processor      : 0
+cpu            : PPC970FX, altivec supported
+clock          : 2000.000000MHz
+revision       : 3.0 (pvr 003c 0300)
+
+processor      : 1
+cpu            : PPC970FX, altivec supported
+clock          : 2000.000000MHz
+revision       : 3.0 (pvr 003c 0300)
+
+timebase       : 33333333
+platform       : PowerMac
+model          : RackMac3,1
+machine                : RackMac3,1
+motherboard    : RackMac3,1 MacRISC4 Power Macintosh 
+detected as    : 339 (XServe G5)
+pmac flags     : 00000000
+L2 cache       : 512K unified
+pmac-generation        : NewWorld
diff --git a/spec/fixtures/cpuinfo/sparc b/spec/fixtures/cpuinfo/sparc
new file mode 100644
index 0000000..c186ac8
--- /dev/null
+++ b/spec/fixtures/cpuinfo/sparc
@@ -0,0 +1,10 @@
+cpu            : TI UltraSparc IIIi (Jalapeno)
+fpu            : UltraSparc IIIi integrated FPU
+prom           : OBP 4.16.2 2004/10/04 18:22
+type           : sun4u
+ncpus probed   : 1
+ncpus active   : 1
+D$ parity tl1  : 0
+I$ parity tl1  : 0
+Cpu0ClkTck     : 000000004fa1be00
+MMU Type       : Cheetah+
diff --git a/spec/unit/processor_spec.rb b/spec/unit/processor_spec.rb
new file mode 100755
index 0000000..571d01f
--- /dev/null
+++ b/spec/unit/processor_spec.rb
@@ -0,0 +1,174 @@
+#!/usr/bin/env ruby
+
+## This only tests the processorcount fact
+## The processor0, processor1, ... facts can't be tested using the current 
architecture
+## because the fact iterates over them outside of Facter.add,
+## and the testing stubs are only present inside the Facter.add block.
+
+$basedir = File.expand_path(File.dirname(__FILE__) + '/..')
+require File.join($basedir, 'spec_helper')
+
+require 'facter'
+
+def cpuinfo_fixture(filename)
+    cpuinfo = File.open(File.join($basedir, 'fixtures', 'cpuinfo', 
filename)).readlines
+end
+
+describe "Processor count fact" do
+
+       ## Will not autoload because processor.rb does not match fact name
+
+    before do
+               Facter.loadfacts
+       end
+       
+    after do
+        Facter.clear
+    end
+
+  it "should be 1 in SPARC fixture on Linux" do
+       Facter.fact(:kernel).stubs(:value).returns("Linux")
+       Facter.fact(:architecture).stubs(:value).returns("sparc")
+    File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
+    
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("sparc"))
+
+    Facter.fact(:processorcount).value.should == "1"
+  end
+
+  it "should be 2 in ppc64 fixture on Linux" do
+       Facter.fact(:kernel).stubs(:value).returns("Linux")
+       Facter.fact(:architecture).stubs(:value).returns("ppc64")
+    File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
+    
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("ppc64"))
+
+    Facter.fact(:processorcount).value.should == "2"
+  end
+
+  it "should be 2 in panda-armel fixture on Linux" do
+       Facter.fact(:kernel).stubs(:value).returns("Linux")
+       Facter.fact(:architecture).stubs(:value).returns("arm")
+    File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
+    
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("panda-armel"))
+
+    Facter.fact(:processorcount).value.should == "2"
+  end
+
+  it "should be 1 in bbg3-armel fixture on Linux" do
+       Facter.fact(:kernel).stubs(:value).returns("Linux")
+       Facter.fact(:architecture).stubs(:value).returns("arm")
+    File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
+    
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("bbg3-armel"))
+
+    Facter.fact(:processorcount).value.should == "1"
+  end
+
+  it "should be 1 in beaglexm-armel fixture on Linux" do
+       Facter.fact(:kernel).stubs(:value).returns("Linux")
+       Facter.fact(:architecture).stubs(:value).returns("arm")
+    File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
+    
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("beaglexm-armel"))
+
+    Facter.fact(:processorcount).value.should == "1"
+  end
+  
+  it "should be 1 in amd64solo fixture on Linux" do
+       Facter.fact(:kernel).stubs(:value).returns("Linux")
+       Facter.fact(:architecture).stubs(:value).returns("amd64")
+    File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
+    
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64solo"))
+
+    Facter.fact(:processorcount).value.should == "1"
+  end
+  
+  it "should be 2 in amd64dual fixture on Linux" do
+       Facter.fact(:kernel).stubs(:value).returns("Linux")
+       Facter.fact(:architecture).stubs(:value).returns("amd64")
+    File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
+    
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64dual"))
+
+    Facter.fact(:processorcount).value.should == "2"
+  end
+  
+  it "should be 3 in amd64tri fixture on Linux" do
+       Facter.fact(:kernel).stubs(:value).returns("Linux")
+       Facter.fact(:architecture).stubs(:value).returns("amd64")
+    File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
+    
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64tri"))
+
+    Facter.fact(:processorcount).value.should == "3"
+  end
+  
+  it "should be 4 in amd64quad fixture on Linux" do
+       Facter.fact(:kernel).stubs(:value).returns("Linux")
+       Facter.fact(:architecture).stubs(:value).returns("amd64")
+    File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
+    
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64quad"))
+
+    Facter.fact(:processorcount).value.should == "4"
+  end
+
+  it "should be 2 on dual-processor Darwin box" do
+       Facter.fact(:kernel).stubs(:value).returns("Darwin")
+    Facter::Util::Resolution.stubs(:exec).with("sysctl hw.ncpu | cut -d' ' 
-f2").returns('2')
+
+    Facter.fact(:processorcount).value.should == "2"
+  end
+  
+  it "should be 2 on dual-processor OpenBSD box" do
+       Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
+    Facter::Util::Resolution.stubs(:exec).with("sysctl hw.ncpu | cut -d'=' 
-f2").returns('2')
+
+    Facter.fact(:processorcount).value.should == "2"
+  end
+
+  it "should be 6 on six-processor AIX box" do
+       Facter.fact(:kernel).stubs(:value).returns("AIX")
+    Facter::Util::Resolution.stubs(:exec).with("lsdev -Cc 
processor").returns("proc0 Available 00-00 Processor\nproc2 Available 00-02 
Processor\nproc4 Available 00-04 Processor\nproc6 Available 00-06 
Processor\nproc8 Available 00-08 Processor\nproc10 Available 00-10 Processor")
+    Facter::Util::Resolution.stubs(:exec).with("lsattr -El proc0 -a 
type").returns("type PowerPC_POWER3 Processor type False")
+
+    Facter.fact(:processorcount).value.should == "6"
+  end
+  
+  it "should be 2 via sysfs when cpu0 and cpu1 are present" do
+       Facter.fact(:kernel).stubs(:value).returns("Linux")
+       File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
+       ## sysfs method is only used if cpuinfo method returned no processors
+    File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
+    File.stubs(:readlines).with("/proc/cpuinfo").returns("")
+       Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu[0-9]*").returns(%w{
+          /sys/devices/system/cpu/cpu0
+          /sys/devices/system/cpu/cpu1
+       })
+
+    Facter.fact(:processorcount).value.should == "2"
+  end
+
+  it "should be 16 via sysfs when cpu0 through cpu15 are present" do
+       Facter.fact(:kernel).stubs(:value).returns("Linux")
+       File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
+       ## sysfs method is only used if cpuinfo method returned no processors
+    File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
+    File.stubs(:readlines).with("/proc/cpuinfo").returns("")
+       Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu[0-9]*").returns(%w{
+          /sys/devices/system/cpu/cpu0
+          /sys/devices/system/cpu/cpu1
+          /sys/devices/system/cpu/cpu2
+          /sys/devices/system/cpu/cpu3
+          /sys/devices/system/cpu/cpu4
+          /sys/devices/system/cpu/cpu5
+          /sys/devices/system/cpu/cpu6
+          /sys/devices/system/cpu/cpu7
+          /sys/devices/system/cpu/cpu8
+          /sys/devices/system/cpu/cpu9
+          /sys/devices/system/cpu/cpu10
+          /sys/devices/system/cpu/cpu11
+          /sys/devices/system/cpu/cpu12
+          /sys/devices/system/cpu/cpu13
+          /sys/devices/system/cpu/cpu14
+          /sys/devices/system/cpu/cpu15
+       })
+       
+    Facter.fact(:processorcount).value.should == "16"
+  end
+
+end
diff --git a/spec/unit/util/processor_spec.rb b/spec/unit/util/processor_spec.rb
new file mode 100755
index 0000000..1c8800d
--- /dev/null
+++ b/spec/unit/util/processor_spec.rb
@@ -0,0 +1,62 @@
+#!/usr/bin/env ruby
+
+$basedir = File.expand_path(File.dirname(__FILE__) + '/../..')
+require File.join($basedir, 'spec_helper')
+
+require 'facter/util/processor'
+
+def cpuinfo_fixture(filename)
+    cpuinfo = File.open(File.join($basedir, 'fixtures', 'cpuinfo', 
filename)).readlines
+end
+
+describe Facter::Util::Processor do
+  it "should get the processor description from the amd64solo fixture" do
+       Facter.fact(:kernel).stubs(:value).returns("Linux")
+       Facter.fact(:architecture).stubs(:value).returns("amd64")
+    File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
+    
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64solo"))
+    
+    Facter::Util::Processor.enum_cpuinfo[0].should == "Intel(R) Core(TM)2 Duo 
CPU     P8700  @ 2.53GHz"
+  end
+
+  it "should get the processor descriptions from the amd64dual fixture" do
+       Facter.fact(:kernel).stubs(:value).returns("Linux")
+       Facter.fact(:architecture).stubs(:value).returns("amd64")
+    File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
+    
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64dual"))
+    
+    Facter::Util::Processor.enum_cpuinfo[0].should == "Intel(R) Core(TM)2 Duo 
CPU     P8700  @ 2.53GHz"
+    Facter::Util::Processor.enum_cpuinfo[1].should == "Intel(R) Core(TM)2 Duo 
CPU     P8700  @ 2.53GHz"
+  end
+  
+  it "should get the processor descriptions from the amd64tri fixture" do
+       Facter.fact(:kernel).stubs(:value).returns("Linux")
+       Facter.fact(:architecture).stubs(:value).returns("amd64")
+    File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
+    
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64tri"))
+    
+    Facter::Util::Processor.enum_cpuinfo[0].should == "Intel(R) Core(TM)2 Duo 
CPU     P8700  @ 2.53GHz"
+    Facter::Util::Processor.enum_cpuinfo[1].should == "Intel(R) Core(TM)2 Duo 
CPU     P8700  @ 2.53GHz"
+    Facter::Util::Processor.enum_cpuinfo[2].should == "Intel(R) Core(TM)2 Duo 
CPU     P8700  @ 2.53GHz"
+  end
+  
+  it "should get the processor descriptions from the amd64quad fixture" do
+       Facter.fact(:kernel).stubs(:value).returns("Linux")
+       Facter.fact(:architecture).stubs(:value).returns("amd64")
+    File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
+    
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64quad"))
+    
+    Facter::Util::Processor.enum_cpuinfo[0].should == "Quad-Core AMD 
Opteron(tm) Processor 2374 HE"
+    Facter::Util::Processor.enum_cpuinfo[1].should == "Quad-Core AMD 
Opteron(tm) Processor 2374 HE"
+    Facter::Util::Processor.enum_cpuinfo[2].should == "Quad-Core AMD 
Opteron(tm) Processor 2374 HE"
+    Facter::Util::Processor.enum_cpuinfo[3].should == "Quad-Core AMD 
Opteron(tm) Processor 2374 HE"
+  end
+
+  it "should get the processor type on AIX box" do
+       Facter.fact(:kernel).stubs(:value).returns("AIX")
+    Facter::Util::Resolution.stubs(:exec).with("lsdev -Cc 
processor").returns("proc0 Available 00-00 Processor\nproc2 Available 00-02 
Processor\nproc4 Available 00-04 Processor\nproc6 Available 00-06 
Processor\nproc8 Available 00-08 Processor\nproc10 Available 00-10 Processor")
+    Facter::Util::Resolution.stubs(:exec).with("lsattr -El proc0 -a 
type").returns("type PowerPC_POWER3 Processor type False")
+
+    Facter::Util::Processor.enum_lsdev[0].should == "PowerPC_POWER3"
+  end
+end
-- 
1.7.4.1

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to