X-Git-Url: http://git.harvie.cz/?p=mirrors%2FPrograms.git;a=blobdiff_plain;f=lua%2Fprobe_memtest.lua;fp=lua%2Fprobe_memtest.lua;h=8df5bc93bf4621fbb96aadff42ccfacb11ec2e06;hp=0000000000000000000000000000000000000000;hb=2058ffa5e57c7857f002615bcba197d444da9946;hpb=0b8d006aa72c56eff1368c6c69b09547c455a5ed diff --git a/lua/probe_memtest.lua b/lua/probe_memtest.lua new file mode 100644 index 0000000..8df5bc9 --- /dev/null +++ b/lua/probe_memtest.lua @@ -0,0 +1,29 @@ +-- Returns array with parsed contents of /proc/meminfo +-- Returns nil on failure +function get_meminfo() + local r={} + local f=io.open("/proc/meminfo","r") + if not f then return nil; end + local s=f:read("*a") + for k,v in string.gmatch(s,"(%w+): *(%d+)") do + r[k]=tonumber(v) + end + f:close() + return r +end + +-- Returns 1 when RAM is bad, 0 when RAM is ok +-- Returns nil when memtest was not run +function memory_bad() + local m=get_meminfo() + if not m then return nil; end + if not m.HardwareCorrupted then return nil; end + if not m.EarlyMemtestBad then return nil; end + if m.HardwareCorrupted > 0 then return 1; end + if m.EarlyMemtestBad > 0 then return 1; end + return 0; +end + +m=get_meminfo() +print(m.MemTotal, m.MemFree, m.HardwareCorrupted, m.EarlyMemtestBad) +print(memory_bad());