--- /dev/null
+! Copyright (C) 2013 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel tools.test unix.linux.proc ;
+IN: unix.linux.proc.tests
+
+{ } [ parse-proc-cmdline drop ] unit-test
+{ } [ parse-proc-cpuinfo drop ] unit-test
+{ } [ parse-proc-loadavg drop ] unit-test
+{ } [ parse-proc-meminfo drop ] unit-test
+{ } [ parse-proc-partitions drop ] unit-test
+{ } [ parse-proc-stat drop ] unit-test
+{ } [ parse-proc-swaps drop ] unit-test
+{ } [ parse-proc-uptime drop ] unit-test
{ microcode integer }
{ cpu-mhz number }
{ cache-size integer }
+ { fdiv-bug? boolean }
+ { hlt-bug? boolean }
+ { f00f-bug? boolean }
+ { coma-bug? boolean }
{ physical-id integer }
{ siblings integer }
{ core-id integer }
{ cpu-cores integer }
{ apicid integer }
{ initial-apicid integer }
- { fpu string }
- { fpu-expception string }
+ { fpu? boolean }
+ { fpu-exception? boolean }
{ cpuid-level integer }
- { wp string }
+ { wp? boolean }
{ flags array }
{ bogomips number }
{ clflush-size integer }
- { cache-alignent integer }
+ { cache-alignment integer }
{ address-sizes array }
{ power-management string } ;
+
+ERROR: unknown-cpuinfo-line string ;
+
+: line>processor-info ( processor-info string -- processor-info )
+ ":" split first2 swap
+ [ CHAR: \t = ] trim-tail [ [ CHAR: \s = ] trim ] bi@
+ {
+ { "address sizes" [
+ "," split [ [ CHAR: \s = ] trim " " split first string>number ] map
+ >>address-sizes
+ ] }
+ { "apicid" [ string>number >>apicid ] }
+ { "bogomips" [ string>number >>bogomips ] }
+ { "cache size" [
+ " " split first [ CHAR: \s = ] trim
+ string>number 1024 * >>cache-size
+ ] }
+ { "cache_alignment" [ string>number >>cache-alignment ] }
+ { "clflush size" [ string>number >>clflush-size ] }
+ { "coma_bug" [ "yes" = >>coma-bug? ] }
+ { "core id" [ string>number >>core-id ] }
+ { "cpu MHz" [ string>number >>cpu-mhz ] }
+ { "cpu cores" [ string>number >>cpu-cores ] }
+ { "cpu family" [ string>number >>cpu-family ] }
+ { "cpuid level" [ string>number >>cpuid-level ] }
+ { "f00f_bug" [ "yes" = >>f00f-bug? ] }
+ { "fdiv_bug" [ "yes" = >>fdiv-bug? ] }
+ { "flags" [ " " split harvest >>flags ] }
+ { "fpu" [ "yes" = >>fpu? ] }
+ { "fpu_exception" [ "yes" = >>fpu-exception? ] }
+ { "hlt_bug" [ "yes" = >>hlt-bug? ] }
+ { "initial apicid" [ string>number >>initial-apicid ] }
+ { "microcode" [ string>number >>microcode ] }
+ { "model" [ string>number >>model ] }
+ { "model name" [ >>model-name ] }
+ { "physical id" [ string>number >>physical-id ] }
+ { "power management" [ >>power-management ] }
+ { "processor" [ string>number >>processor ] }
+ { "siblings" [ string>number >>siblings ] }
+ { "stepping" [ string>number >>stepping ] }
+ { "vendor_id" [ >>vendor-id ] }
+ { "wp" [ "yes" = >>wp? ] }
+ [ unknown-cpuinfo-line ]
+ } case ;
+
+
! Linux 2.6 has fewer values than new kernels
: lines>processor-info ( strings -- processor-info )
- [ ":" split second [ CHAR: \s = ] trim ] map
- 25 f pad-tail
- [
- {
- [ string>number ]
- [ ]
- [ string>number ]
- [ string>number ]
- [ ]
- [ string>number ]
- [ string>number ]
- [ string>number ]
- [ " " split first [ CHAR: \s = ] trim string>number 1024 * ]
- [ string>number ]
- [ string>number ]
- [ string>number ]
- [ string>number ]
- [ string>number ]
- [ string>number ]
- [ ]
- [ ]
- [ string>number ]
- [ ]
- [ " " split harvest ]
- [ string>number ]
- [ string>number ]
- [ string>number ]
- [ "," split [ [ CHAR: \s = ] trim " " split first string>number ] map ]
- [ ]
- } spread
- ] input<sequence processor-info boa ;
+ [ processor-info new ] dip
+ [ line>processor-info ] each ;
: parse-proc-cpuinfo ( -- seq )
"/proc/cpuinfo" utf8 file-lines