Browse files

Add test, fix two bugs in new rusage stuff.

  • Loading branch information...
1 parent 6e14c21 commit 58bec694866a20d81cd8cfcc77cfb60dc4c8f1cc Al Tobey committed Apr 12, 2012
Showing with 9 additions and 3 deletions.
  1. +2 −2 lib/ffi/libc/libc.rb
  2. +1 −1 lib/ffi/libc/rusage.rb
  3. +6 −0 spec/libc_spec.rb
View
4 lib/ffi/libc/libc.rb
@@ -162,11 +162,11 @@ def self.each_ifaddrs
RUSAGE_CHILDREN = -1
RUSAGE_THREAD = 1 # Linux/glibc only
- attach_function :getrusage, [:int, :pointer], :int
+ attach_function :sys_getrusage, :getrusage, [:int, :pointer], :int
def self.getrusage(who=RUSAGE_SELF)
ru = RUsage.new
- ret = getrusage(who, ru)
+ ret = sys_getrusage(who, ru)
raise_error(ret) unless ret == 0
ru
end
View
2 lib/ffi/libc/rusage.rb
@@ -19,7 +19,7 @@ class RUsage < FFI::Struct
:ru_msgrcv, :long,
:ru_nsignals, :long,
:ru_nvcsw, :long,
- :ru_nivcsw, :long,
+ :ru_nivcsw, :long
end
end
end
View
6 spec/libc_spec.rb
@@ -6,4 +6,10 @@
require 'ffi/libc/libc'
}.should_not raise_error(FFI::NotFoundError)
end
+
+ it "should be able to fetch its own memory usage" do
+ require 'ffi/libc'
+ ru = FFI::LibC.getrusage
+ ru[:ru_maxrss].should be > 4000
+ end
end

0 comments on commit 58bec69

Please sign in to comment.