4 #define pipe(X) _pipe((X), 1024, _O_BINARY) 32 : FileDescriptorActivity(0), step_count(0), count(0), other_count(0), do_read(false) {}
43 result = read(fd, &buffer, 1);
45 if (isUpdated(other_fd))
49 result = read(other_fd, &buffer, 1);
59 #if __cplusplus > 199711L 60 unique_ptr<TestFDActivity>
62 auto_ptr<TestFDActivity>
65 static const int USLEEP = 250000;
69 piperet = pipe(pipe_fds);
70 BOOST_REQUIRE(piperet == 0);
71 int reader = pipe_fds[0];
72 int writer = pipe_fds[1];
75 piperet = pipe(other_pipe);
76 BOOST_REQUIRE(piperet == 0);
77 int other_reader = other_pipe[0];
78 int other_writer = other_pipe[1];
80 activity->fd = reader;
81 activity->other_fd = other_reader;
83 BOOST_CHECK( activity->start() );
86 activity->watch(reader);
87 activity->watch(other_reader);
89 BOOST_CHECK( !activity->isRunning() && activity->isActive() );
90 BOOST_CHECK_EQUAL(0, activity->step_count);
93 activity->do_read =
false;
94 BOOST_CHECK( activity->trigger() );
96 BOOST_CHECK_EQUAL(1, activity->step_count);
97 BOOST_CHECK_EQUAL(0, activity->count);
98 BOOST_CHECK_EQUAL(0, activity->other_count);
99 BOOST_CHECK( !activity->isRunning() && activity->isActive() );
102 activity->do_read =
true;
104 result = write(writer, &buffer, 2);
105 BOOST_CHECK( result == 2 );
107 BOOST_CHECK_EQUAL(3, activity->step_count);
108 BOOST_CHECK_EQUAL(2, activity->count);
109 BOOST_CHECK_EQUAL(0, activity->other_count);
110 BOOST_CHECK( !activity->isRunning() && activity->isActive() );
112 result = write(other_writer, &buffer, 2);
113 BOOST_CHECK( result == 2 );
115 BOOST_CHECK_EQUAL(5, activity->step_count);
116 BOOST_CHECK_EQUAL(2, activity->count);
117 BOOST_CHECK_EQUAL(2, activity->other_count);
118 BOOST_CHECK( !activity->isRunning() && activity->isActive() );
121 BOOST_CHECK( activity->stop() );
123 BOOST_CHECK( !activity->isRunning() && !activity->isActive() );
126 activity->do_read =
false;
127 activity->setTimeout(100);
128 BOOST_CHECK_EQUAL(100, activity->getTimeout());
129 BOOST_CHECK( activity->start() );
131 BOOST_CHECK( activity->step_count >= 10 );
132 BOOST_CHECK_EQUAL(2, activity->count);
133 BOOST_CHECK_EQUAL(2, activity->other_count);
134 BOOST_CHECK( activity->stop() );
135 activity->setTimeout(0);
138 activity->step_count = 0;
139 activity->mutex.lock();
140 BOOST_CHECK( activity->start() );
145 for(std::size_t i = 0; i < 65537; ++i) activity->trigger();
146 activity->mutex.unlock();
148 BOOST_CHECK_EQUAL(2, activity->step_count);
149 BOOST_CHECK( activity->stop() );
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
BOOST_AUTO_TEST_CASE(testFileDescriptorActivity)
#define BOOST_AUTO_TEST_SUITE_END()
int usleep(unsigned int us)
unsigned int sleep(unsigned int s)
An object oriented wrapper around a non recursive mutex.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
MutexLock is a scope based Monitor, protecting critical sections with a Mutex object through locking ...