aboutsummaryrefslogtreecommitdiffstats
path: root/test/fiddle
diff options
context:
space:
mode:
Diffstat (limited to 'test/fiddle')
-rw-r--r--test/fiddle/test_function.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/fiddle/test_function.rb b/test/fiddle/test_function.rb
index 2e3a432ec3..9351f961df 100644
--- a/test/fiddle/test_function.rb
+++ b/test/fiddle/test_function.rb
@@ -73,6 +73,25 @@ module Fiddle
assert_equal("123", str.to_s)
end
+ def test_nogvl_poll
+ begin
+ poll = @libc['poll']
+ rescue Fiddle::DLError
+ skip 'poll(2) not available'
+ end
+ f = Function.new(poll, [TYPE_VOIDP, TYPE_INT, TYPE_INT], TYPE_INT)
+
+ msec = 200
+ t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
+ th = Thread.new { f.call(nil, 0, msec) }
+ n1 = f.call(nil, 0, msec)
+ n2 = th.value
+ t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
+ assert_in_delta(msec, t1 - t0, 100, 'slept correct amount of time')
+ assert_equal(0, n1, 'poll(2) called correctly main-thread')
+ assert_equal(0, n2, 'poll(2) called correctly in sub-thread')
+ end
+
def test_no_memory_leak
prep = 'r = Fiddle::Function.new(Fiddle.dlopen(nil)["rb_obj_tainted"], [Fiddle::TYPE_UINTPTR_T], Fiddle::TYPE_UINTPTR_T); a = "a"'
code = 'begin r.call(a); rescue TypeError; end'