From 2058ffa5e57c7857f002615bcba197d444da9946 Mon Sep 17 00:00:00 2001 From: Tomas Mudrunka Date: Mon, 27 Mar 2023 15:14:45 +0200 Subject: [PATCH] proc memtest lua --- lua/probe_memtest.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lua/probe_memtest.lua 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()); -- 2.30.2