posix_mq RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* [PATCH 0/5] some FreeBSD9 fixes pushed to master
@ 2012-07-12 19:45 Eric Wong
  2012-07-12 19:45 ` [PATCH 1/5] notify: set lower bound for notify stack size Eric Wong
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Eric Wong @ 2012-07-12 19:45 UTC (permalink / raw)
  To: ruby.posix.mq

The following are now in "master" of git://bogomips.org/ruby_posix_mq

  [1/5] notify: set lower bound for notify stack size
  [2/5] ext: fix type inconsistencies for int vs mqd_t retvals
  [3/5] test: disable IO.select test if #to_io is missing
  [4/5] extconf: fix __mq_oshandle() detection on FreeBSD
  [5/5] test: relax test timings for timed* tests

I still get the following failures under FreeBSD 9.  I suspect
some functionality fails across forks, even though mq_send/mq_receive
continue to work across forks:

ruby -I lib:tmp/ext/ruby-1.8.7/ext/posix_mq test/test_posix_mq.rb 
POSIX_MQ#notify not supported on this platform: i386-freebsd9
Loaded suite test/test_posix_mq
Started
...................#<Errno::EBADF: Bad file descriptor - mq_notify>
F..........test/test_posix_mq.rb:297:in `nonblock=': Bad file descriptor - mq_setattr (Errno::EBADF)
	from test/test_posix_mq.rb:297:in `test_setattr_fork'
	from test/test_posix_mq.rb:297:in `fork'
	from test/test_posix_mq.rb:297:in `test_setattr_fork'
	from /usr/local/lib/ruby/1.8/test/unit/testcase.rb:78:in `__send__'
	from /usr/local/lib/ruby/1.8/test/unit/testcase.rb:78:in `run'
	from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'
	from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each'
	from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run'
	from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'
	from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each'
	from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run'
	from /usr/local/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in `run_suite'
	from /usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:67:in `start_mediator'
	from /usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:41:in `start'
	from /usr/local/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb:29:in `run'
	from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:216:in `run'
	from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:12:in `run'
	from /usr/local/lib/ruby/1.8/test/unit.rb:279
	from test/test_posix_mq.rb:421
F.........
Finished in 2.431081 seconds.

  1) Failure:
test_notify_none(Test_POSIX_MQ) [test/test_posix_mq.rb:276]:
#<Process::Status: pid=39972,exited(1)>.
<false> is not true.

  2) Failure:
test_setattr_fork(Test_POSIX_MQ) [test/test_posix_mq.rb:298]:
<false> is not true.

40 tests, 238 assertions, 2 failures, 0 errors
gmake: *** [test/test_posix_mq.rb] Error 1

-- 
EW


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] notify: set lower bound for notify stack size
  2012-07-12 19:45 [PATCH 0/5] some FreeBSD9 fixes pushed to master Eric Wong
@ 2012-07-12 19:45 ` Eric Wong
  2012-07-12 19:45 ` [PATCH 2/5] ext: fix type inconsistencies for int vs mqd_t retvals Eric Wong
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2012-07-12 19:45 UTC (permalink / raw)
  To: ruby.posix.mq

Some OSes have ridiculously low boundaries and we don't
want mysterious failures on them
---
 ext/posix_mq/posix_mq.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/ext/posix_mq/posix_mq.c b/ext/posix_mq/posix_mq.c
index df667e3..66f3f99 100644
--- a/ext/posix_mq/posix_mq.c
+++ b/ext/posix_mq/posix_mq.c
@@ -850,6 +850,19 @@ static void my_mq_notify(mqd_t des, struct sigevent *not)
 	}
 }
 
+static void lower_stack_size(pthread_attr_t *attr)
+{
+/* some OSes have ridiculously small stack sizes */
+#ifdef PTHREAD_STACK_MIN
+	size_t stack_size = PTHREAD_STACK_MIN;
+	size_t min_size = 4096;
+
+	if (stack_size < min_size)
+		stack_size = min_size;
+	pthread_attr_setstacksize(attr, stack_size);
+#endif
+}
+
 /* :nodoc: */
 static VALUE setnotify_exec(VALUE self, VALUE io, VALUE thr)
 {
@@ -864,10 +877,7 @@ static VALUE setnotify_exec(VALUE self, VALUE io, VALUE thr)
 	errno = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 	if (errno) rb_sys_fail("pthread_attr_setdetachstate");
 
-#ifdef PTHREAD_STACK_MIN
-	(void)pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
-#endif
-
+	lower_stack_size(&attr);
 	not.sigev_notify = SIGEV_THREAD;
 	not.sigev_notify_function = thread_notify_fd;
 	not.sigev_notify_attributes = &attr;
-- 
1.7.11.rc0.55.gb2478aa



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/5] ext: fix type inconsistencies for int vs mqd_t retvals
  2012-07-12 19:45 [PATCH 0/5] some FreeBSD9 fixes pushed to master Eric Wong
  2012-07-12 19:45 ` [PATCH 1/5] notify: set lower bound for notify stack size Eric Wong
@ 2012-07-12 19:45 ` Eric Wong
  2012-07-12 19:45 ` [PATCH 3/5] test: disable IO.select test if #to_io is missing Eric Wong
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2012-07-12 19:45 UTC (permalink / raw)
  To: ruby.posix.mq

From: "ew@fbsd90-32.(none)" <ew@fbsd90-32.(none)>

Somehow I mixed up return values for mq_* functions that
return "int".  This was noticed on FreeBSD where mqd_t
is NOT an integer.
---
 ext/posix_mq/posix_mq.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/ext/posix_mq/posix_mq.c b/ext/posix_mq/posix_mq.c
index 66f3f99..7a3dc14 100644
--- a/ext/posix_mq/posix_mq.c
+++ b/ext/posix_mq/posix_mq.c
@@ -468,9 +468,9 @@ static VALUE init(int argc, VALUE *argv, VALUE self)
  */
 static VALUE s_unlink(VALUE self, VALUE name)
 {
-	mqd_t rv = mq_unlink(StringValueCStr(name));
+	int rv = mq_unlink(StringValueCStr(name));
 
-	if (rv == MQD_INVALID)
+	if (rv == -1)
 		rb_sys_fail("mq_unlink");
 
 	return INT2NUM(1);
@@ -489,12 +489,12 @@ static VALUE s_unlink(VALUE self, VALUE name)
 static VALUE _unlink(VALUE self)
 {
 	struct posix_mq *mq = get(self, 0);
-	mqd_t rv;
+	int rv;
 
 	assert(TYPE(mq->name) == T_STRING && "mq->name is not a string");
 
 	rv = mq_unlink(RSTRING_PTR(mq->name));
-	if (rv == MQD_INVALID)
+	if (rv == -1)
 		rb_sys_fail("mq_unlink");
 
 	return self;
@@ -532,7 +532,7 @@ static VALUE _send(int sflags, int argc, VALUE *argv, VALUE self)
 	struct posix_mq *mq = get(self, 1);
 	struct rw_args x;
 	VALUE buffer, prio, timeout;
-	mqd_t rv;
+	int rv;
 	struct timespec expire;
 
 	rb_scan_args(argc, argv, "12", &buffer, &prio, &timeout);
@@ -543,8 +543,8 @@ static VALUE _send(int sflags, int argc, VALUE *argv, VALUE self)
 	x.msg_prio = NIL_P(prio) ? 0 : NUM2UINT(prio);
 
 retry:
-	rv = (mqd_t)rb_thread_blocking_region(xsend, &x, RUBY_UBF_IO, 0);
-	if (rv == MQD_INVALID) {
+	rv = (int)rb_thread_blocking_region(xsend, &x, RUBY_UBF_IO, 0);
+	if (rv == -1) {
 		if (errno == EINTR)
 			goto retry;
 		if (errno == EAGAIN && (sflags & PMQ_TRY))
@@ -570,7 +570,7 @@ static VALUE send0(VALUE self, VALUE buffer)
 {
 	struct posix_mq *mq = get(self, 1);
 	struct rw_args x;
-	mqd_t rv;
+	int rv;
 
 	setup_send_buffer(&x, buffer);
 	x.des = mq->des;
@@ -578,8 +578,8 @@ static VALUE send0(VALUE self, VALUE buffer)
 	x.msg_prio = 0;
 
 retry:
-	rv = (mqd_t)rb_thread_blocking_region(xsend, &x, RUBY_UBF_IO, 0);
-	if (rv == MQD_INVALID) {
+	rv = (int)rb_thread_blocking_region(xsend, &x, RUBY_UBF_IO, 0);
+	if (rv == -1) {
 		if (errno == EINTR)
 			goto retry;
 		rb_sys_fail("mq_send");
@@ -838,14 +838,14 @@ static void thread_notify_fd(union sigval sv)
 
 static void my_mq_notify(mqd_t des, struct sigevent *not)
 {
-	mqd_t rv = mq_notify(des, not);
+	int rv = mq_notify(des, not);
 
-	if (rv == MQD_INVALID) {
+	if (rv == -1) {
 		if (errno == ENOMEM) {
 			rb_gc();
 			rv = mq_notify(des, not);
 		}
-		if (rv == MQD_INVALID)
+		if (rv == -1)
 			rb_sys_fail("mq_notify");
 	}
 }
-- 
1.7.11.rc0.55.gb2478aa



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/5] test: disable IO.select test if #to_io is missing
  2012-07-12 19:45 [PATCH 0/5] some FreeBSD9 fixes pushed to master Eric Wong
  2012-07-12 19:45 ` [PATCH 1/5] notify: set lower bound for notify stack size Eric Wong
  2012-07-12 19:45 ` [PATCH 2/5] ext: fix type inconsistencies for int vs mqd_t retvals Eric Wong
@ 2012-07-12 19:45 ` Eric Wong
  2012-07-12 19:45 ` [PATCH 4/5] extconf: fix __mq_oshandle() detection on FreeBSD Eric Wong
  2012-07-12 19:45 ` [PATCH 5/5] test: relax test timings for timed* tests Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2012-07-12 19:45 UTC (permalink / raw)
  To: ruby.posix.mq

From: "ew@fbsd90-32.(none)" <ew@fbsd90-32.(none)>

---
 test/test_posix_mq.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/test_posix_mq.rb b/test/test_posix_mq.rb
index 8d6b014..82ab868 100644
--- a/test/test_posix_mq.rb
+++ b/test/test_posix_mq.rb
@@ -257,7 +257,7 @@ def test_notify
     assert_nil IO.select([rd], nil, nil, 0.1)
     ensure
       trap(:USR1, orig)
-  end
+  end if POSIX_MQ.method_defined?(:to_io)
 
   def test_notify_none
     @mq = POSIX_MQ.new @path, IO::CREAT|IO::RDWR, 0666
-- 
1.7.11.rc0.55.gb2478aa



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/5] extconf: fix __mq_oshandle() detection on FreeBSD
  2012-07-12 19:45 [PATCH 0/5] some FreeBSD9 fixes pushed to master Eric Wong
                   ` (2 preceding siblings ...)
  2012-07-12 19:45 ` [PATCH 3/5] test: disable IO.select test if #to_io is missing Eric Wong
@ 2012-07-12 19:45 ` Eric Wong
  2012-07-12 19:45 ` [PATCH 5/5] test: relax test timings for timed* tests Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2012-07-12 19:45 UTC (permalink / raw)
  To: ruby.posix.mq

From: "ew@fbsd90-32.(none)" <ew@fbsd90-32.(none)>

We need to have -lrt in LDFLAGS before we can detect it.
---
 ext/posix_mq/extconf.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ext/posix_mq/extconf.rb b/ext/posix_mq/extconf.rb
index 310de3d..db50ee3 100644
--- a/ext/posix_mq/extconf.rb
+++ b/ext/posix_mq/extconf.rb
@@ -3,7 +3,6 @@
 have_header("sys/select.h")
 have_header("signal.h")
 have_header("mqueue.h") or abort "mqueue.h header missing"
-have_func("__mq_oshandle")
 have_header("pthread.h")
 have_func("rb_str_set_len")
 have_func('rb_thread_blocking_region')
@@ -11,6 +10,7 @@
 have_library("rt")
 have_library("pthread")
 
+have_func("__mq_oshandle")
 have_func("mq_timedsend")
 have_func("mq_timedreceive")
 create_makefile("posix_mq_ext")
-- 
1.7.11.rc0.55.gb2478aa



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/5] test: relax test timings for timed* tests
  2012-07-12 19:45 [PATCH 0/5] some FreeBSD9 fixes pushed to master Eric Wong
                   ` (3 preceding siblings ...)
  2012-07-12 19:45 ` [PATCH 4/5] extconf: fix __mq_oshandle() detection on FreeBSD Eric Wong
@ 2012-07-12 19:45 ` Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2012-07-12 19:45 UTC (permalink / raw)
  To: ruby.posix.mq

From: "ew@fbsd90-32.(none)" <ew@fbsd90-32.(none)>

On my i386-freebsd9 VM, this takes just longer than the
maximum allowable time.
---
 test/test_posix_mq.rb | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/test/test_posix_mq.rb b/test/test_posix_mq.rb
index 82ab868..1cc24aa 100644
--- a/test/test_posix_mq.rb
+++ b/test/test_posix_mq.rb
@@ -73,8 +73,8 @@ def test_timed_receive_float
     t0 = Time.now
     maybe_timeout { @mq.receive "", interval } or return
     elapsed = Time.now - t0
-    assert elapsed > interval, elapsed.inspect
-    assert elapsed < 0.02, elapsed.inspect
+    assert_operator elapsed, :>, interval, elapsed.inspect
+    assert_operator elapsed, :<, 0.04, elapsed.inspect
   end
 
   def test_timed_receive_divmod
@@ -87,8 +87,8 @@ def interval.divmod(num)
     t0 = Time.now
     maybe_timeout { @mq.receive "", interval } or return
     elapsed = Time.now - t0
-    assert elapsed >= 0.01, elapsed.inspect
-    assert elapsed <= 0.02, elapsed.inspect
+    assert_operator elapsed, :>=, 0.01, elapsed.inspect
+    assert_operator elapsed, :<=, 0.04, elapsed.inspect
   end
 
   def test_timed_receive_fixnum
-- 
1.7.11.rc0.55.gb2478aa



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-07-12 19:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-12 19:45 [PATCH 0/5] some FreeBSD9 fixes pushed to master Eric Wong
2012-07-12 19:45 ` [PATCH 1/5] notify: set lower bound for notify stack size Eric Wong
2012-07-12 19:45 ` [PATCH 2/5] ext: fix type inconsistencies for int vs mqd_t retvals Eric Wong
2012-07-12 19:45 ` [PATCH 3/5] test: disable IO.select test if #to_io is missing Eric Wong
2012-07-12 19:45 ` [PATCH 4/5] extconf: fix __mq_oshandle() detection on FreeBSD Eric Wong
2012-07-12 19:45 ` [PATCH 5/5] test: relax test timings for timed* tests Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/ruby_posix_mq.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).