|
From: <tho...@us...> - 2014-05-01 13:02:39
|
Revision: 548
http://sourceforge.net/p/cgreen/code/548
Author: thomasnilsson
Date: 2014-05-01 13:02:30 +0000 (Thu, 01 May 2014)
Log Message:
-----------
Modified handling of the pipe becoming full. Now an exception is also generated.
Fixed a presumable error in that cgreen_pipe_write() wrote the message twice.
Modified Paths:
--------------
trunk/cgreen/src/posix_cgreen_pipe.c
trunk/cgreen/tests/messaging_tests.c
Modified: trunk/cgreen/src/posix_cgreen_pipe.c
===================================================================
--- trunk/cgreen/src/posix_cgreen_pipe.c 2014-04-12 08:45:59 UTC (rev 547)
+++ trunk/cgreen/src/posix_cgreen_pipe.c 2014-05-01 13:02:30 UTC (rev 548)
@@ -56,16 +56,18 @@
{
int pipe_write_result = write(p, buf, count);
if (pipe_write_result < 0) {
- if (errno == EWOULDBLOCK) {
- fprintf(stderr, "\tToo many assertions (> 8192) within a single test.\n");
+ if (errno == EWOULDBLOCK) {
+ fprintf(stderr, "\tCGREEN EXCEPTION: Too many assertions within a single test.\n");
} else if (errno != EPIPE) {
- fprintf(stderr, "\tError reporting from test case process to reporter\n");
+ fprintf(stderr, "\tCGREEN EXCEPTION: Error when reporting from test case process to reporter\n");
}
-
kill(getpid(), SIGPIPE);
+ raise(SIGPIPE);
}
- return write(p,buf,count);
+ return write(p, buf, count);
+
+ // return pipe_write_result;
}
Modified: trunk/cgreen/tests/messaging_tests.c
===================================================================
--- trunk/cgreen/tests/messaging_tests.c 2014-04-12 08:45:59 UTC (rev 547)
+++ trunk/cgreen/tests/messaging_tests.c 2014-05-01 13:02:30 UTC (rev 548)
@@ -29,14 +29,28 @@
assert_equal(receive_cgreen_message(messaging), 99);
}
-Ensure(failure_reported_when_messaging_would_block) {
+static int signal_received = 0;
+static void catch_signal(int s) {
+ fprintf(stderr, "CAUGHT"); fflush(NULL);
+ signal_received = 1;
+ signal(SIGPIPE, SIG_DFL);
+}
+
+Ensure(failure_reported_and_exception_thrown_when_messaging_would_block) {
+ const int LOOPS = 65536;
int messaging = start_cgreen_messaging(33);
int loop;
- for (loop = 0; loop < 65536; loop++) {
+
+ signal_received = 0;
+ signal(SIGPIPE, catch_signal);
+ for (loop = 0; loop < LOOPS; loop++) {
send_cgreen_message(messaging, 99);
+ if (signal_received == 1)
+ break;
}
- fail_test("This test should be killed due to too many messages before it gets here");
+ assert_that(signal_received, is_equal_to(1));
+ assert_that(loop, is_less_than(LOOPS));
}
TestSuite *messaging_tests() {
@@ -44,7 +58,7 @@
add_suite(suite, highly_nested_test_suite());
add_test(suite, can_send_message);
#ifndef WIN32 // TODO: win32 needs non-blocking pipes like posix for this to pass
- add_test(suite, failure_reported_when_messaging_would_block);
+ add_test(suite, failure_reported_and_exception_thrown_when_messaging_would_block);
#endif
return suite;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|