Skip to content

Commit

Permalink
added memory detection code
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Feb 10, 2014
1 parent 8cae936 commit d900a1a
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 3 deletions.
9 changes: 7 additions & 2 deletions library/system/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ scrconf_DATA = \
desktop_DATA = \
desktop/messages.desktop

EXTRA_DIST = $(module_DATA) $(client_DATA) $(ynclude_DATA) $(scrconf_DATA) $(desktop_DATA)
ylibdir = @ylibdir@/yast2
ylib_DATA = \
lib/yast2/hw_detection.rb

include $(top_srcdir)/Makefile.am.common

EXTRA_DIST = $(module_DATA) $(client_DATA) $(ynclude_DATA) $(scrconf_DATA) $(desktop_DATA) $(ylib_DATA)

include $(top_srcdir)/Makefile.am.common
70 changes: 70 additions & 0 deletions library/system/src/lib/yast2/hw_detection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# encoding: utf-8

# ***************************************************************************
#
# Copyright (c) 2014 SUSE LLC
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com
#
# ***************************************************************************
# File:
# HWDetection.rb
#
# Authors:
# Ladislav Slezak <lslezak@suse.cz>
#
# Summary:
# Module for detecting hardware
#

require "yast"

module Yast
class HwDetection
include Yast::Logger

# this is from <hd.h> include (in hwinfo-devel)
MEMORY_CLASS = 257 # "bc_internal" value
MEMORY_SUBCLASS = 2 # "sc_int_main_mem" value

# Return size of the system memory (in bytes)
# @return Fixnum,Bignum detected memory size
def self.memory
memory_size = 0

memory = SCR.Read(path(".probe.memory"))
log.debug("hwinfo memory: #{memory}")

if memory
memory.each do |info|
# internal class, main memory
if info["class_id"] == MEMORY_CLASS && info["sub_class_id"] == MEMORY_SUBCLASS
info.fetch("resource", {}).fetch("phys_mem", []).each do |phys_mem|
memory_size += phys_mem.fetch("range", 0)
end
end
end
else
raise "Memory detection failed"
end

log.info("Detected memory size: #{memory_size} (#{memory_size/1024/1024}MiB)")

return memory_size
end
end
end
37 changes: 37 additions & 0 deletions library/system/test/hw_detection_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#! /usr/bin/rspec

#ENV["Y2DIR"] = File.expand_path("../../src", __FILE__)

require "yast"
include Yast

#$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)

require_relative "../src/lib/yast2/hw_detection"
#Yast.import "HWDetection"

describe "HwDetection" do
describe "#memory" do
it "returns detected memory size in bytes" do
SCR.should_receive(:Read).with(path(".probe.memory")).and_return([{
"bus" => "None",
"bus_hwcfg" => "none",
"class_id" => 257,
"model" => "Main Memory",
"old_unique_key" => "4srm.CxwsZFjVASF",
"resource" => {
"mem" => [{"active" => true, "length" => 16815341568, "start" => 0}],
"phys_mem" => [{"range" => 17179869184}]
},
"sub_class_id" => 2,
"unique_key" => "rdCR.CxwsZFjVASF"
}])
expect(HwDetection.memory).to eq(17179869184)
end

it "raises exception when detection fails" do
SCR.should_receive(:Read).with(path(".probe.memory")).and_return(nil)
expect{HwDetection.memory}.to raise_error
end
end
end
6 changes: 6 additions & 0 deletions package/yast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Mon Feb 10 13:18:52 UTC 2014 - lslezak@suse.cz

- added memory detection code (gh#yast/yast-packager#33)
- 3.1.19

-------------------------------------------------------------------
Wed Feb 5 11:26:09 CET 2014 - jsuchome@suse.cz

Expand Down
3 changes: 2 additions & 1 deletion package/yast2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2
Version: 3.1.18
Version: 3.1.19
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down Expand Up @@ -208,6 +208,7 @@ mkdir -p "$RPM_BUILD_ROOT"/etc/YaST2
%{yast_ydatadir}/*.ycp
%{yast_clientdir}/*
%{yast_moduledir}/*
%{yast_libdir}/*
%{yast_scrconfdir}/*
%{yast_ybindir}/*
%{yast_agentdir}/ag_*
Expand Down

0 comments on commit d900a1a

Please sign in to comment.