mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #5158 from YarivCol/master
RTOS : added empty and full functions to Mail and Queuepull/5353/merge
commit
3a05b63f1e
|
@ -454,6 +454,43 @@ void test_calloc()
|
|||
TEST_ASSERT_EQUAL(0, *mail);
|
||||
}
|
||||
|
||||
/** Test mail empty
|
||||
|
||||
Given a mail of uint32_t data
|
||||
before data is inserted the mail should be empty
|
||||
after data is inserted the mail shouldn't be empty
|
||||
*/
|
||||
void test_mail_empty()
|
||||
{
|
||||
Mail<mail_t, 1> m;
|
||||
|
||||
mail_t *mail = m.alloc();
|
||||
|
||||
TEST_ASSERT_EQUAL(true, m.empty());
|
||||
|
||||
m.put(mail);
|
||||
|
||||
TEST_ASSERT_EQUAL(false, m.empty());
|
||||
}
|
||||
|
||||
/** Test mail empty
|
||||
|
||||
Given a mail of uint32_t data with size of 1
|
||||
before data is inserted the mail shouldn't be full
|
||||
after data is inserted the mail should be full
|
||||
*/
|
||||
void test_mail_full()
|
||||
{
|
||||
Mail<mail_t, 1> m;
|
||||
|
||||
mail_t *mail = m.alloc();
|
||||
|
||||
TEST_ASSERT_EQUAL(false, m.full());
|
||||
|
||||
m.put(mail);
|
||||
|
||||
TEST_ASSERT_EQUAL(true, m.full());
|
||||
}
|
||||
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases)
|
||||
{
|
||||
|
@ -475,7 +512,9 @@ Case cases[] = {
|
|||
Case("Test invalid message free", test_free_wrong),
|
||||
Case("Test message send/receive single thread and order", test_single_thread_order),
|
||||
Case("Test message send/receive multi-thread and per thread order", test_multi_thread_order),
|
||||
Case("Test message send/receive multi-thread, multi-Mail and per thread order", test_multi_thread_multi_mail_order)
|
||||
Case("Test message send/receive multi-thread, multi-Mail and per thread order", test_multi_thread_multi_mail_order),
|
||||
Case("Test mail empty", test_mail_empty),
|
||||
Case("Test mail full", test_mail_full)
|
||||
};
|
||||
|
||||
Specification specification(test_setup, cases);
|
||||
|
|
|
@ -282,6 +282,40 @@ void test_msg_prio()
|
|||
TEST_ASSERT_EQUAL(TEST_UINT_MSG, evt.value.v);
|
||||
}
|
||||
|
||||
/** Test queue empty
|
||||
|
||||
Given a queue of uint32_t data
|
||||
before data is inserted the queue should be empty
|
||||
after data is inserted the queue shouldn't be empty
|
||||
*/
|
||||
void test_queue_empty()
|
||||
{
|
||||
Queue<uint32_t, 1> q;
|
||||
|
||||
TEST_ASSERT_EQUAL(true, q.empty());
|
||||
|
||||
q.put((uint32_t*) TEST_UINT_MSG, TEST_TIMEOUT, 1);
|
||||
|
||||
TEST_ASSERT_EQUAL(false, q.empty());
|
||||
}
|
||||
|
||||
/** Test queue empty
|
||||
|
||||
Given a queue of uint32_t data with size of 1
|
||||
before data is inserted the queue shouldn't be full
|
||||
after data is inserted the queue should be full
|
||||
*/
|
||||
void test_queue_full()
|
||||
{
|
||||
Queue<uint32_t, 1> q;
|
||||
|
||||
TEST_ASSERT_EQUAL(false, q.full());
|
||||
|
||||
q.put((uint32_t*) TEST_UINT_MSG, TEST_TIMEOUT, 1);
|
||||
|
||||
TEST_ASSERT_EQUAL(true, q.full());
|
||||
}
|
||||
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(5, "default_auto");
|
||||
|
@ -299,7 +333,9 @@ Case cases[] = {
|
|||
Case("Test put full timeout", test_put_full_timeout),
|
||||
Case("Test put full wait forever", test_put_full_waitforever),
|
||||
Case("Test message ordering", test_msg_order),
|
||||
Case("Test message priority", test_msg_prio)
|
||||
Case("Test message priority", test_msg_prio),
|
||||
Case("Test queue empty", test_queue_empty),
|
||||
Case("Test queue full", test_queue_full)
|
||||
};
|
||||
|
||||
Specification specification(test_setup, cases);
|
||||
|
|
16
rtos/Mail.h
16
rtos/Mail.h
|
@ -54,6 +54,22 @@ public:
|
|||
/** Create and Initialise Mail queue. */
|
||||
Mail() { };
|
||||
|
||||
/** Check if the mail queue is empty
|
||||
*
|
||||
* @return True if the mail queue is empty, false if not
|
||||
*/
|
||||
bool empty() const {
|
||||
return _queue.empty();
|
||||
}
|
||||
|
||||
/** Check if the mail queue is full
|
||||
*
|
||||
* @return True if the mail queue is full, false if not
|
||||
*/
|
||||
bool full() const {
|
||||
return _queue.full();
|
||||
}
|
||||
|
||||
/** Allocate a memory block of type T
|
||||
@param millisec timeout value or 0 in case of no time-out. (default: 0).
|
||||
@return pointer to memory block that can be filled with mail or NULL in case error.
|
||||
|
|
16
rtos/Queue.h
16
rtos/Queue.h
|
@ -64,6 +64,22 @@ public:
|
|||
osMessageQueueDelete(_id);
|
||||
}
|
||||
|
||||
/** Check if the queue is empty
|
||||
*
|
||||
* @return True if the queue is empty, false if not
|
||||
*/
|
||||
bool empty() const {
|
||||
return osMessageQueueGetCount(_id) == 0;
|
||||
}
|
||||
|
||||
/** Check if the queue is full
|
||||
*
|
||||
* @return True if the queue is full, false if not
|
||||
*/
|
||||
bool full() const {
|
||||
return osMessageQueueGetSpace(_id) == 0;
|
||||
}
|
||||
|
||||
/** Put a message in a Queue.
|
||||
@param data message pointer.
|
||||
@param millisec timeout value or 0 in case of no time-out. (default: 0)
|
||||
|
|
Loading…
Reference in New Issue