From: Eric Wong <normalperson@yhbt.net>
To: sleepy.penguin@librelist.org
Subject: [sleepy.penguin] [PATCH 2/2] tests: remove version-dependent FD_CLOEXEC checks
Date: Sat, 19 Oct 2013 17:59:03 +0000 [thread overview]
Message-ID: <1382205543-29792-2-git-send-email-normalperson@yhbt.net> (raw)
In-Reply-To: 1382205543-29792-1-git-send-email-normalperson@yhbt.net
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.
---
test/helper.rb | 9 +++++++++
test/test_epoll.rb | 6 +-----
test/test_eventfd.rb | 6 +-----
test/test_inotify.rb | 6 +-----
test/test_timerfd.rb | 6 +-----
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
--
1.8.4.483.g7fe67e6.dirty
prev parent reply other threads:[~2013-10-19 17:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-19 17:59 [sleepy.penguin] [PATCH 1/2] remove all signalfd-related files Eric Wong
2013-10-19 17:59 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/sleepy_penguin/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1382205543-29792-2-git-send-email-normalperson@yhbt.net \
--to=normalperson@yhbt.net \
--cc=sleepy.penguin@librelist.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/sleepy_penguin.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).