about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-10-19 11:56:57 +0000
committerEric Wong <normalperson@yhbt.net>2013-10-19 11:56:57 +0000
commit099f4464e034e76d46493dae8fc211fdd93c9127 (patch)
treec591bd44bdb38a0ff6842b8c1bbb639d8857bd8a
parent620b6c13a00225d8f154bba875b710df15a64311 (diff)
downloadsleepy_penguin-099f4464e034e76d46493dae8fc211fdd93c9127.tar.gz
Not all versions/implementations of Ruby set FD_CLOEXEC by default.
And it is conceivable MRI will disable the current FD_CLOEXEC
default out of portability concerns, so we only test that our
code matches.
-rw-r--r--test/helper.rb9
-rw-r--r--test/test_epoll.rb6
-rw-r--r--test/test_eventfd.rb6
-rw-r--r--test/test_inotify.rb6
-rw-r--r--test/test_timerfd.rb6
5 files changed, 13 insertions, 20 deletions
diff --git a/test/helper.rb b/test/helper.rb
index 13f79b7..8261168 100644
--- a/test/helper.rb
+++ b/test/helper.rb
@@ -6,3 +6,12 @@ Testcase = begin
 rescue NameError
   Minitest::Unit::TestCase # minitest 4
 end
+
+def check_cloexec(io)
+  pipe = IO.pipe
+  rbimp = Fcntl::FD_CLOEXEC & pipe[0].fcntl(Fcntl::F_GETFD)
+  ours = Fcntl::FD_CLOEXEC & io.fcntl(Fcntl::F_GETFD)
+  assert_equal rbimp, ours, "CLOEXEC default does not match Ruby implementation"
+ensure
+  pipe.each { |io| io.close }
+end
diff --git a/test/test_epoll.rb b/test/test_epoll.rb
index 88d0b6c..61b6e8c 100644
--- a/test/test_epoll.rb
+++ b/test/test_epoll.rb
@@ -348,11 +348,7 @@ class TestEpoll < Testcase
   def test_new
     @ep.close
     io = Epoll.new.to_io
-    if RUBY_VERSION.to_f >= 2.0
-      assert_equal 1, io.fcntl(Fcntl::F_GETFD)
-    else
-      assert_equal 0, io.fcntl(Fcntl::F_GETFD)
-    end
+    check_cloexec(io)
   end
 
   def test_delete
diff --git a/test/test_eventfd.rb b/test/test_eventfd.rb
index 731a6cb..a6b3016 100644
--- a/test/test_eventfd.rb
+++ b/test/test_eventfd.rb
@@ -20,11 +20,7 @@ class TestEventFD < Testcase
   def test_new
     efd = EventFD.new 0
     assert_kind_of(IO, efd)
-    if RUBY_VERSION.to_f >= 2.0
-      assert_equal 1, efd.fcntl(Fcntl::F_GETFD)
-    else
-      assert_equal 0, efd.fcntl(Fcntl::F_GETFD)
-    end
+    check_cloexec(efd)
   end
 
   def test_new_nonblock
diff --git a/test/test_inotify.rb b/test/test_inotify.rb
index c91d6e4..5cf5839 100644
--- a/test/test_inotify.rb
+++ b/test/test_inotify.rb
@@ -17,11 +17,7 @@ class TestInotify < Testcase
   def test_new
     @ino = Inotify.new
     assert_kind_of(IO, ino)
-    if RUBY_VERSION.to_f >= 2.0
-      assert_equal 1, ino.fcntl(Fcntl::F_GETFD)
-    else
-      assert_equal 0, ino.fcntl(Fcntl::F_GETFD)
-    end
+    check_cloexec(ino)
   end
 
   def test_constants
diff --git a/test/test_timerfd.rb b/test/test_timerfd.rb
index 23940a1..6189168 100644
--- a/test/test_timerfd.rb
+++ b/test/test_timerfd.rb
@@ -15,11 +15,7 @@ class TestTimerFD < Testcase
   def test_create
     tfd = TimerFD.new
     assert_kind_of(IO, tfd)
-    if RUBY_VERSION.to_f >= 2.0
-      assert_equal 1, tfd.fcntl(Fcntl::F_GETFD)
-    else
-      assert_equal 0, tfd.fcntl(Fcntl::F_GETFD)
-    end
+    check_cloexec(tfd)
   end
 
   def test_create_nonblock