git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9076 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
8f30e605e6
commit
d6dd34c381
|
@ -1031,7 +1031,7 @@ int32 OS_BinSemCreate(uint32 *sem_id, const char *sem_name,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Semaphore is initialized.*/
|
/* Semaphore is initialized.*/
|
||||||
chBSemObjectInit(bsp, sem_initial_value == 0 ? false : true);
|
chBSemObjectInit(bsp, sem_initial_value == 0 ? true : false);
|
||||||
|
|
||||||
*sem_id = (uint32)bsp;
|
*sem_id = (uint32)bsp;
|
||||||
|
|
||||||
|
@ -1102,7 +1102,10 @@ int32 OS_BinSemFlush(uint32 sem_id) {
|
||||||
return OS_SEM_FAILURE;
|
return OS_SEM_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If the semaphore state is "not taken" then it is not touched.*/
|
||||||
|
if (bsp->sem.cnt < 0) {
|
||||||
chBSemResetI(bsp, true);
|
chBSemResetI(bsp, true);
|
||||||
|
}
|
||||||
|
|
||||||
/* Leaving the critical zone.*/
|
/* Leaving the critical zone.*/
|
||||||
chSysRestoreStatusX(sts);
|
chSysRestoreStatusX(sts);
|
||||||
|
|
|
@ -925,7 +925,7 @@ test_assert_sequence("", "queue write errors occurred");]]></value>
|
||||||
<value>OS_QueueGet() with timeout functionality</value>
|
<value>OS_QueueGet() with timeout functionality</value>
|
||||||
</brief>
|
</brief>
|
||||||
<description>
|
<description>
|
||||||
<value>OS_QueueGetIdByName is tested.</value>
|
<value>OS_QueueGet() timeout functionality is tested.</value>
|
||||||
</description>
|
</description>
|
||||||
<condition>
|
<condition>
|
||||||
<value />
|
<value />
|
||||||
|
@ -1433,6 +1433,431 @@ test_assert(err == OS_SUCCESS, "timer stop failed");]]></value>
|
||||||
</case>
|
</case>
|
||||||
</cases>
|
</cases>
|
||||||
</sequence>
|
</sequence>
|
||||||
|
<sequence>
|
||||||
|
<type index="0">
|
||||||
|
<value>Internal Tests</value>
|
||||||
|
</type>
|
||||||
|
<brief>
|
||||||
|
<value>Binary Semaphores Functionality</value>
|
||||||
|
</brief>
|
||||||
|
<description>
|
||||||
|
<value>This sequence tests the NASA OSAL over ChibiOS/RT functionalities related to binary semaphores.</value>
|
||||||
|
</description>
|
||||||
|
<shared_code>
|
||||||
|
<value><![CDATA[#include "osapi.h"
|
||||||
|
|
||||||
|
uint32 bsid;]]></value>
|
||||||
|
</shared_code>
|
||||||
|
<cases>
|
||||||
|
<case>
|
||||||
|
<brief>
|
||||||
|
<value>OS_TimerCreate() and OS_TimerDelete() errors</value>
|
||||||
|
</brief>
|
||||||
|
<description>
|
||||||
|
<value>Parameters checking in OS_BinSemCreate() and OS_BinSemDelete() is tested.</value>
|
||||||
|
</description>
|
||||||
|
<condition>
|
||||||
|
<value />
|
||||||
|
</condition>
|
||||||
|
<various_code>
|
||||||
|
<setup_code>
|
||||||
|
<value />
|
||||||
|
</setup_code>
|
||||||
|
<teardown_code>
|
||||||
|
<value />
|
||||||
|
</teardown_code>
|
||||||
|
<local_variables>
|
||||||
|
<value />
|
||||||
|
</local_variables>
|
||||||
|
</various_code>
|
||||||
|
<steps>
|
||||||
|
<step>
|
||||||
|
<description>
|
||||||
|
<value>OS_BinSemCreate() is invoked with sem_id set to NULL, an error is expected.</value>
|
||||||
|
</description>
|
||||||
|
<tags>
|
||||||
|
<value />
|
||||||
|
</tags>
|
||||||
|
<code>
|
||||||
|
<value><![CDATA[int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemCreate(NULL, /* Error.*/
|
||||||
|
"failing semaphore",
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value>
|
||||||
|
</code>
|
||||||
|
</step>
|
||||||
|
<step>
|
||||||
|
<description>
|
||||||
|
<value>OS_BinSemCreate() is invoked with sem_name set to NULL, an error is expected.</value>
|
||||||
|
</description>
|
||||||
|
<tags>
|
||||||
|
<value />
|
||||||
|
</tags>
|
||||||
|
<code>
|
||||||
|
<value><![CDATA[int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemCreate(&bsid,
|
||||||
|
NULL, /* Error.*/
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value>
|
||||||
|
</code>
|
||||||
|
</step>
|
||||||
|
<step>
|
||||||
|
<description>
|
||||||
|
<value>OS_BinSemCreate() is invoked with an invalid sem_initial_value, an error is expected.</value>
|
||||||
|
</description>
|
||||||
|
<tags>
|
||||||
|
<value />
|
||||||
|
</tags>
|
||||||
|
<code>
|
||||||
|
<value><![CDATA[int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemCreate(&bsid,
|
||||||
|
"failing semaphore",
|
||||||
|
2, /* Error.*/
|
||||||
|
0);
|
||||||
|
test_assert(err == OS_INVALID_INT_NUM, "counter error not detected");]]></value>
|
||||||
|
</code>
|
||||||
|
</step>
|
||||||
|
<step>
|
||||||
|
<description>
|
||||||
|
<value>OS_BinSemCreate() is invoked with a very long timer name, an error is expected.</value>
|
||||||
|
</description>
|
||||||
|
<tags>
|
||||||
|
<value />
|
||||||
|
</tags>
|
||||||
|
<code>
|
||||||
|
<value><![CDATA[#if 0 /* Semaphore name currently not implemented.*/
|
||||||
|
int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemCreate(&bsid,
|
||||||
|
"very very long semaphore name", /* Error.*/
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");
|
||||||
|
#endif]]></value>
|
||||||
|
</code>
|
||||||
|
</step>
|
||||||
|
<step>
|
||||||
|
<description>
|
||||||
|
<value>OS_BinSemDelete() is invoked with timer_id set to -1, an error is expected.</value>
|
||||||
|
</description>
|
||||||
|
<tags>
|
||||||
|
<value />
|
||||||
|
</tags>
|
||||||
|
<code>
|
||||||
|
<value><![CDATA[int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemDelete((uint32)-1);
|
||||||
|
test_assert(err == OS_ERR_INVALID_ID, "wrong semaphore id not detected");]]></value>
|
||||||
|
</code>
|
||||||
|
</step>
|
||||||
|
<step>
|
||||||
|
<description>
|
||||||
|
<value>OS_TimerCreate() is invoked twice with duplicated name, an error is expected, then the queue is deleted using OS_TimerDelete().</value>
|
||||||
|
</description>
|
||||||
|
<tags>
|
||||||
|
<value />
|
||||||
|
</tags>
|
||||||
|
<code>
|
||||||
|
<value><![CDATA[int32 err;
|
||||||
|
uint32 bsid1; /*, bsid2;*/
|
||||||
|
|
||||||
|
err = OS_BinSemCreate(&bsid1, "my semaphore", 0, 0);
|
||||||
|
test_assert(err == OS_SUCCESS, "semaphore creation failed");
|
||||||
|
|
||||||
|
#if 0 /* Semaphore name currently not implemented.*/
|
||||||
|
err = OS_BinSemCreate(&bsid2, "my semaphore", 0, 0);
|
||||||
|
test_assert(err == OS_ERR_NAME_TAKEN, "name conflict not detected");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
err = OS_BinSemDelete(bsid1);
|
||||||
|
test_assert(err == OS_SUCCESS, "semaphore deletion failed");]]></value>
|
||||||
|
</code>
|
||||||
|
</step>
|
||||||
|
</steps>
|
||||||
|
</case>
|
||||||
|
<case>
|
||||||
|
<brief>
|
||||||
|
<value>OS_BinSemFlush() errors</value>
|
||||||
|
</brief>
|
||||||
|
<description>
|
||||||
|
<value>Parameters checking in OS_BinSemFlush() is tested.</value>
|
||||||
|
</description>
|
||||||
|
<condition>
|
||||||
|
<value />
|
||||||
|
</condition>
|
||||||
|
<various_code>
|
||||||
|
<setup_code>
|
||||||
|
<value />
|
||||||
|
</setup_code>
|
||||||
|
<teardown_code>
|
||||||
|
<value />
|
||||||
|
</teardown_code>
|
||||||
|
<local_variables>
|
||||||
|
<value />
|
||||||
|
</local_variables>
|
||||||
|
</various_code>
|
||||||
|
<steps>
|
||||||
|
<step>
|
||||||
|
<description>
|
||||||
|
<value>OS_BinSemFlush() is invoked with sem_id set to -1, an error is expected.</value>
|
||||||
|
</description>
|
||||||
|
<tags>
|
||||||
|
<value />
|
||||||
|
</tags>
|
||||||
|
<code>
|
||||||
|
<value><![CDATA[int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemFlush((uint32)-1);
|
||||||
|
test_assert(err == OS_ERR_INVALID_ID, "invalid sem_id not detected");]]></value>
|
||||||
|
</code>
|
||||||
|
</step>
|
||||||
|
</steps>
|
||||||
|
</case>
|
||||||
|
<case>
|
||||||
|
<brief>
|
||||||
|
<value>OS_BinSemGive() errors</value>
|
||||||
|
</brief>
|
||||||
|
<description>
|
||||||
|
<value>Parameters checking in OS_BinSemGive() is tested.</value>
|
||||||
|
</description>
|
||||||
|
<condition>
|
||||||
|
<value />
|
||||||
|
</condition>
|
||||||
|
<various_code>
|
||||||
|
<setup_code>
|
||||||
|
<value />
|
||||||
|
</setup_code>
|
||||||
|
<teardown_code>
|
||||||
|
<value />
|
||||||
|
</teardown_code>
|
||||||
|
<local_variables>
|
||||||
|
<value />
|
||||||
|
</local_variables>
|
||||||
|
</various_code>
|
||||||
|
<steps>
|
||||||
|
<step>
|
||||||
|
<description>
|
||||||
|
<value>OS_BinSemGive() is invoked with sem_id set to -1, an error is expected.</value>
|
||||||
|
</description>
|
||||||
|
<tags>
|
||||||
|
<value />
|
||||||
|
</tags>
|
||||||
|
<code>
|
||||||
|
<value><![CDATA[int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemGive((uint32)-1);
|
||||||
|
test_assert(err == OS_ERR_INVALID_ID, "invalid sem_id not detected");]]></value>
|
||||||
|
</code>
|
||||||
|
</step>
|
||||||
|
</steps>
|
||||||
|
</case>
|
||||||
|
<case>
|
||||||
|
<brief>
|
||||||
|
<value>OS_BinSemTake() errors</value>
|
||||||
|
</brief>
|
||||||
|
<description>
|
||||||
|
<value>Parameters checking in OS_BinSemTake() is tested.</value>
|
||||||
|
</description>
|
||||||
|
<condition>
|
||||||
|
<value />
|
||||||
|
</condition>
|
||||||
|
<various_code>
|
||||||
|
<setup_code>
|
||||||
|
<value />
|
||||||
|
</setup_code>
|
||||||
|
<teardown_code>
|
||||||
|
<value />
|
||||||
|
</teardown_code>
|
||||||
|
<local_variables>
|
||||||
|
<value />
|
||||||
|
</local_variables>
|
||||||
|
</various_code>
|
||||||
|
<steps>
|
||||||
|
<step>
|
||||||
|
<description>
|
||||||
|
<value>OS_BinSemTake() is invoked with sem_id set to -1, an error is expected.</value>
|
||||||
|
</description>
|
||||||
|
<tags>
|
||||||
|
<value />
|
||||||
|
</tags>
|
||||||
|
<code>
|
||||||
|
<value><![CDATA[int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemTake((uint32)-1);
|
||||||
|
test_assert(err == OS_ERR_INVALID_ID, "invalid sem_id not detected");]]></value>
|
||||||
|
</code>
|
||||||
|
</step>
|
||||||
|
</steps>
|
||||||
|
</case>
|
||||||
|
<case>
|
||||||
|
<brief>
|
||||||
|
<value>OS_BinSemTimedWait() errors</value>
|
||||||
|
</brief>
|
||||||
|
<description>
|
||||||
|
<value>Parameters checking in OS_BinSemTimedWait() is tested.</value>
|
||||||
|
</description>
|
||||||
|
<condition>
|
||||||
|
<value />
|
||||||
|
</condition>
|
||||||
|
<various_code>
|
||||||
|
<setup_code>
|
||||||
|
<value><![CDATA[bsid = 0;
|
||||||
|
(void) OS_BinSemCreate(&bsid, "test semaphore", 0, 0);]]></value>
|
||||||
|
</setup_code>
|
||||||
|
<teardown_code>
|
||||||
|
<value><![CDATA[if (bsid > 0) {
|
||||||
|
(void) OS_BinSemDelete(bsid);
|
||||||
|
}]]></value>
|
||||||
|
</teardown_code>
|
||||||
|
<local_variables>
|
||||||
|
<value />
|
||||||
|
</local_variables>
|
||||||
|
</various_code>
|
||||||
|
<steps>
|
||||||
|
<step>
|
||||||
|
<description>
|
||||||
|
<value>OS_BinSemTimedWait() is invoked with sem_id set to -1, an error is expected.</value>
|
||||||
|
</description>
|
||||||
|
<tags>
|
||||||
|
<value />
|
||||||
|
</tags>
|
||||||
|
<code>
|
||||||
|
<value><![CDATA[int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemTimedWait((uint32)-1, 1000);
|
||||||
|
test_assert(err == OS_ERR_INVALID_ID, "invalid sem_id not detected");]]></value>
|
||||||
|
</code>
|
||||||
|
</step>
|
||||||
|
<step>
|
||||||
|
<description>
|
||||||
|
<value>OS_BinSemTimedWait() is invoked with msecs set to 0, an error is expected.</value>
|
||||||
|
</description>
|
||||||
|
<tags>
|
||||||
|
<value />
|
||||||
|
</tags>
|
||||||
|
<code>
|
||||||
|
<value><![CDATA[int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemTimedWait(bsid, 0);
|
||||||
|
test_assert(err == OS_INVALID_INT_NUM, "invalid msec not detected");]]></value>
|
||||||
|
</code>
|
||||||
|
</step>
|
||||||
|
</steps>
|
||||||
|
</case>
|
||||||
|
<case>
|
||||||
|
<brief>
|
||||||
|
<value>OS_BinSemGetIdByName() errors</value>
|
||||||
|
</brief>
|
||||||
|
<description>
|
||||||
|
<value>Parameters checking in OS_BinSemGetIdByName() is tested.</value>
|
||||||
|
</description>
|
||||||
|
<condition>
|
||||||
|
<value />
|
||||||
|
</condition>
|
||||||
|
<various_code>
|
||||||
|
<setup_code>
|
||||||
|
<value />
|
||||||
|
</setup_code>
|
||||||
|
<teardown_code>
|
||||||
|
<value />
|
||||||
|
</teardown_code>
|
||||||
|
<local_variables>
|
||||||
|
<value />
|
||||||
|
</local_variables>
|
||||||
|
</various_code>
|
||||||
|
<steps>
|
||||||
|
<step>
|
||||||
|
<description>
|
||||||
|
<value>OS_BinSemGetIdByName() is invoked with sem_id set to NULL, an error is expected.</value>
|
||||||
|
</description>
|
||||||
|
<tags>
|
||||||
|
<value />
|
||||||
|
</tags>
|
||||||
|
<code>
|
||||||
|
<value><![CDATA[int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemGetIdByName(NULL, "semaphore");
|
||||||
|
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value>
|
||||||
|
</code>
|
||||||
|
</step>
|
||||||
|
<step>
|
||||||
|
<description>
|
||||||
|
<value>OS_BinSemGetIdByName() is invoked with semaphore name set to NULL, an error is expected.</value>
|
||||||
|
</description>
|
||||||
|
<tags>
|
||||||
|
<value />
|
||||||
|
</tags>
|
||||||
|
<code>
|
||||||
|
<value><![CDATA[int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemGetIdByName(&bsid, NULL);
|
||||||
|
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value>
|
||||||
|
</code>
|
||||||
|
</step>
|
||||||
|
<step>
|
||||||
|
<description>
|
||||||
|
<value>OS_BinSemGetIdByName() is invoked with a very long task name, an error is expected.</value>
|
||||||
|
</description>
|
||||||
|
<tags>
|
||||||
|
<value />
|
||||||
|
</tags>
|
||||||
|
<code>
|
||||||
|
<value><![CDATA[int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemGetIdByName(&bsid, "very very long semaphore name");
|
||||||
|
test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");]]></value>
|
||||||
|
</code>
|
||||||
|
</step>
|
||||||
|
</steps>
|
||||||
|
</case>
|
||||||
|
<case>
|
||||||
|
<brief>
|
||||||
|
<value>OS_BinSemTimedWait() timeout functionality</value>
|
||||||
|
</brief>
|
||||||
|
<description>
|
||||||
|
<value>OS_BinSemCreate() timeout functionality is tested.</value>
|
||||||
|
</description>
|
||||||
|
<condition>
|
||||||
|
<value />
|
||||||
|
</condition>
|
||||||
|
<various_code>
|
||||||
|
<setup_code>
|
||||||
|
<value><![CDATA[bsid = 0;
|
||||||
|
(void) OS_BinSemCreate(&bsid, "test semaphore", 0, 0);]]></value>
|
||||||
|
</setup_code>
|
||||||
|
<teardown_code>
|
||||||
|
<value><![CDATA[if (bsid > 0) {
|
||||||
|
(void) OS_BinSemDelete(bsid);
|
||||||
|
}]]></value>
|
||||||
|
</teardown_code>
|
||||||
|
<local_variables>
|
||||||
|
<value />
|
||||||
|
</local_variables>
|
||||||
|
</various_code>
|
||||||
|
<steps>
|
||||||
|
<step>
|
||||||
|
<description>
|
||||||
|
<value>OS_BinSemTimedWait() is invoked with timeout set to one second, an error is expected.</value>
|
||||||
|
</description>
|
||||||
|
<tags>
|
||||||
|
<value />
|
||||||
|
</tags>
|
||||||
|
<code>
|
||||||
|
<value><![CDATA[int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemTimedWait(bsid, 1000);
|
||||||
|
test_assert(err == OS_SEM_TIMEOUT, "unexpected error code");]]></value>
|
||||||
|
</code>
|
||||||
|
</step>
|
||||||
|
</steps>
|
||||||
|
</case>
|
||||||
|
</cases>
|
||||||
|
</sequence>
|
||||||
</sequences>
|
</sequences>
|
||||||
</instance>
|
</instance>
|
||||||
</instances>
|
</instances>
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
* - @subpage test_sequence_001
|
* - @subpage test_sequence_001
|
||||||
* - @subpage test_sequence_002
|
* - @subpage test_sequence_002
|
||||||
* - @subpage test_sequence_003
|
* - @subpage test_sequence_003
|
||||||
|
* - @subpage test_sequence_004
|
||||||
* .
|
* .
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -50,6 +51,7 @@ const testcase_t * const *test_suite[] = {
|
||||||
test_sequence_001,
|
test_sequence_001,
|
||||||
test_sequence_002,
|
test_sequence_002,
|
||||||
test_sequence_003,
|
test_sequence_003,
|
||||||
|
test_sequence_004,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "test_sequence_001.h"
|
#include "test_sequence_001.h"
|
||||||
#include "test_sequence_002.h"
|
#include "test_sequence_002.h"
|
||||||
#include "test_sequence_003.h"
|
#include "test_sequence_003.h"
|
||||||
|
#include "test_sequence_004.h"
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* External declarations. */
|
/* External declarations. */
|
||||||
|
|
|
@ -315,7 +315,7 @@ static const testcase_t test_002_003 = {
|
||||||
* @page test_002_004 OS_QueueGet() with timeout functionality
|
* @page test_002_004 OS_QueueGet() with timeout functionality
|
||||||
*
|
*
|
||||||
* <h2>Description</h2>
|
* <h2>Description</h2>
|
||||||
* OS_QueueGetIdByName is tested.
|
* OS_QueueGet() timeout functionality is tested.
|
||||||
*
|
*
|
||||||
* <h2>Test Steps</h2>
|
* <h2>Test Steps</h2>
|
||||||
* - Retrieving the queue by name.
|
* - Retrieving the queue by name.
|
||||||
|
|
|
@ -0,0 +1,435 @@
|
||||||
|
/*
|
||||||
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "hal.h"
|
||||||
|
#include "ch_test.h"
|
||||||
|
#include "test_root.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @page test_sequence_004 Binary Semaphores Functionality
|
||||||
|
*
|
||||||
|
* File: @ref test_sequence_004.c
|
||||||
|
*
|
||||||
|
* <h2>Description</h2>
|
||||||
|
* This sequence tests the NASA OSAL over ChibiOS/RT functionalities
|
||||||
|
* related to binary semaphores.
|
||||||
|
*
|
||||||
|
* <h2>Test Cases</h2>
|
||||||
|
* - @subpage test_004_001
|
||||||
|
* - @subpage test_004_002
|
||||||
|
* - @subpage test_004_003
|
||||||
|
* - @subpage test_004_004
|
||||||
|
* - @subpage test_004_005
|
||||||
|
* - @subpage test_004_006
|
||||||
|
* - @subpage test_004_007
|
||||||
|
* .
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Shared code.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "osapi.h"
|
||||||
|
|
||||||
|
uint32 bsid;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Test cases.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @page test_004_001 OS_TimerCreate() and OS_TimerDelete() errors
|
||||||
|
*
|
||||||
|
* <h2>Description</h2>
|
||||||
|
* Parameters checking in OS_BinSemCreate() and OS_BinSemDelete() is
|
||||||
|
* tested.
|
||||||
|
*
|
||||||
|
* <h2>Test Steps</h2>
|
||||||
|
* - OS_BinSemCreate() is invoked with sem_id set to NULL, an error is
|
||||||
|
* expected.
|
||||||
|
* - OS_BinSemCreate() is invoked with sem_name set to NULL, an error
|
||||||
|
* is expected.
|
||||||
|
* - OS_BinSemCreate() is invoked with an invalid sem_initial_value, an
|
||||||
|
* error is expected.
|
||||||
|
* - OS_BinSemCreate() is invoked with a very long timer name, an error
|
||||||
|
* is expected.
|
||||||
|
* - OS_BinSemDelete() is invoked with timer_id set to -1, an error is
|
||||||
|
* expected.
|
||||||
|
* - OS_TimerCreate() is invoked twice with duplicated name, an error
|
||||||
|
* is expected, then the queue is deleted using OS_TimerDelete().
|
||||||
|
* .
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void test_004_001_execute(void) {
|
||||||
|
|
||||||
|
/* OS_BinSemCreate() is invoked with sem_id set to NULL, an error is
|
||||||
|
expected.*/
|
||||||
|
test_set_step(1);
|
||||||
|
{
|
||||||
|
int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemCreate(NULL, /* Error.*/
|
||||||
|
"failing semaphore",
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
test_assert(err == OS_INVALID_POINTER, "NULL not detected");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OS_BinSemCreate() is invoked with sem_name set to NULL, an error
|
||||||
|
is expected.*/
|
||||||
|
test_set_step(2);
|
||||||
|
{
|
||||||
|
int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemCreate(&bsid,
|
||||||
|
NULL, /* Error.*/
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
test_assert(err == OS_INVALID_POINTER, "NULL not detected");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OS_BinSemCreate() is invoked with an invalid sem_initial_value, an
|
||||||
|
error is expected.*/
|
||||||
|
test_set_step(3);
|
||||||
|
{
|
||||||
|
int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemCreate(&bsid,
|
||||||
|
"failing semaphore",
|
||||||
|
2, /* Error.*/
|
||||||
|
0);
|
||||||
|
test_assert(err == OS_INVALID_INT_NUM, "counter error not detected");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OS_BinSemCreate() is invoked with a very long timer name, an error
|
||||||
|
is expected.*/
|
||||||
|
test_set_step(4);
|
||||||
|
{
|
||||||
|
#if 0 /* Semaphore name currently not implemented.*/
|
||||||
|
int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemCreate(&bsid,
|
||||||
|
"very very long semaphore name", /* Error.*/
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OS_BinSemDelete() is invoked with timer_id set to -1, an error is
|
||||||
|
expected.*/
|
||||||
|
test_set_step(5);
|
||||||
|
{
|
||||||
|
int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemDelete((uint32)-1);
|
||||||
|
test_assert(err == OS_ERR_INVALID_ID, "wrong semaphore id not detected");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OS_TimerCreate() is invoked twice with duplicated name, an error
|
||||||
|
is expected, then the queue is deleted using OS_TimerDelete().*/
|
||||||
|
test_set_step(6);
|
||||||
|
{
|
||||||
|
int32 err;
|
||||||
|
uint32 bsid1; /*, bsid2;*/
|
||||||
|
|
||||||
|
err = OS_BinSemCreate(&bsid1, "my semaphore", 0, 0);
|
||||||
|
test_assert(err == OS_SUCCESS, "semaphore creation failed");
|
||||||
|
|
||||||
|
#if 0 /* Semaphore name currently not implemented.*/
|
||||||
|
err = OS_BinSemCreate(&bsid2, "my semaphore", 0, 0);
|
||||||
|
test_assert(err == OS_ERR_NAME_TAKEN, "name conflict not detected");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
err = OS_BinSemDelete(bsid1);
|
||||||
|
test_assert(err == OS_SUCCESS, "semaphore deletion failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const testcase_t test_004_001 = {
|
||||||
|
"OS_TimerCreate() and OS_TimerDelete() errors",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
test_004_001_execute
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @page test_004_002 OS_BinSemFlush() errors
|
||||||
|
*
|
||||||
|
* <h2>Description</h2>
|
||||||
|
* Parameters checking in OS_BinSemFlush() is tested.
|
||||||
|
*
|
||||||
|
* <h2>Test Steps</h2>
|
||||||
|
* - OS_BinSemFlush() is invoked with sem_id set to -1, an error is
|
||||||
|
* expected.
|
||||||
|
* .
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void test_004_002_execute(void) {
|
||||||
|
|
||||||
|
/* OS_BinSemFlush() is invoked with sem_id set to -1, an error is
|
||||||
|
expected.*/
|
||||||
|
test_set_step(1);
|
||||||
|
{
|
||||||
|
int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemFlush((uint32)-1);
|
||||||
|
test_assert(err == OS_ERR_INVALID_ID, "invalid sem_id not detected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const testcase_t test_004_002 = {
|
||||||
|
"OS_BinSemFlush() errors",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
test_004_002_execute
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @page test_004_003 OS_BinSemGive() errors
|
||||||
|
*
|
||||||
|
* <h2>Description</h2>
|
||||||
|
* Parameters checking in OS_BinSemGive() is tested.
|
||||||
|
*
|
||||||
|
* <h2>Test Steps</h2>
|
||||||
|
* - OS_BinSemGive() is invoked with sem_id set to -1, an error is
|
||||||
|
* expected.
|
||||||
|
* .
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void test_004_003_execute(void) {
|
||||||
|
|
||||||
|
/* OS_BinSemGive() is invoked with sem_id set to -1, an error is
|
||||||
|
expected.*/
|
||||||
|
test_set_step(1);
|
||||||
|
{
|
||||||
|
int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemGive((uint32)-1);
|
||||||
|
test_assert(err == OS_ERR_INVALID_ID, "invalid sem_id not detected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const testcase_t test_004_003 = {
|
||||||
|
"OS_BinSemGive() errors",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
test_004_003_execute
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @page test_004_004 OS_BinSemTake() errors
|
||||||
|
*
|
||||||
|
* <h2>Description</h2>
|
||||||
|
* Parameters checking in OS_BinSemTake() is tested.
|
||||||
|
*
|
||||||
|
* <h2>Test Steps</h2>
|
||||||
|
* - OS_BinSemTake() is invoked with sem_id set to -1, an error is
|
||||||
|
* expected.
|
||||||
|
* .
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void test_004_004_execute(void) {
|
||||||
|
|
||||||
|
/* OS_BinSemTake() is invoked with sem_id set to -1, an error is
|
||||||
|
expected.*/
|
||||||
|
test_set_step(1);
|
||||||
|
{
|
||||||
|
int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemTake((uint32)-1);
|
||||||
|
test_assert(err == OS_ERR_INVALID_ID, "invalid sem_id not detected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const testcase_t test_004_004 = {
|
||||||
|
"OS_BinSemTake() errors",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
test_004_004_execute
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @page test_004_005 OS_BinSemTimedWait() errors
|
||||||
|
*
|
||||||
|
* <h2>Description</h2>
|
||||||
|
* Parameters checking in OS_BinSemTimedWait() is tested.
|
||||||
|
*
|
||||||
|
* <h2>Test Steps</h2>
|
||||||
|
* - OS_BinSemTimedWait() is invoked with sem_id set to -1, an error is
|
||||||
|
* expected.
|
||||||
|
* - OS_BinSemTimedWait() is invoked with msecs set to 0, an error is
|
||||||
|
* expected.
|
||||||
|
* .
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void test_004_005_setup(void) {
|
||||||
|
bsid = 0;
|
||||||
|
(void) OS_BinSemCreate(&bsid, "test semaphore", 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_004_005_teardown(void) {
|
||||||
|
if (bsid > 0) {
|
||||||
|
(void) OS_BinSemDelete(bsid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_004_005_execute(void) {
|
||||||
|
|
||||||
|
/* OS_BinSemTimedWait() is invoked with sem_id set to -1, an error is
|
||||||
|
expected.*/
|
||||||
|
test_set_step(1);
|
||||||
|
{
|
||||||
|
int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemTimedWait((uint32)-1, 1000);
|
||||||
|
test_assert(err == OS_ERR_INVALID_ID, "invalid sem_id not detected");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OS_BinSemTimedWait() is invoked with msecs set to 0, an error is
|
||||||
|
expected.*/
|
||||||
|
test_set_step(2);
|
||||||
|
{
|
||||||
|
int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemTimedWait(bsid, 0);
|
||||||
|
test_assert(err == OS_INVALID_INT_NUM, "invalid msec not detected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const testcase_t test_004_005 = {
|
||||||
|
"OS_BinSemTimedWait() errors",
|
||||||
|
test_004_005_setup,
|
||||||
|
test_004_005_teardown,
|
||||||
|
test_004_005_execute
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @page test_004_006 OS_BinSemGetIdByName() errors
|
||||||
|
*
|
||||||
|
* <h2>Description</h2>
|
||||||
|
* Parameters checking in OS_BinSemGetIdByName() is tested.
|
||||||
|
*
|
||||||
|
* <h2>Test Steps</h2>
|
||||||
|
* - OS_BinSemGetIdByName() is invoked with sem_id set to NULL, an
|
||||||
|
* error is expected.
|
||||||
|
* - OS_BinSemGetIdByName() is invoked with semaphore name set to NULL,
|
||||||
|
* an error is expected.
|
||||||
|
* - OS_BinSemGetIdByName() is invoked with a very long task name, an
|
||||||
|
* error is expected.
|
||||||
|
* .
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void test_004_006_execute(void) {
|
||||||
|
|
||||||
|
/* OS_BinSemGetIdByName() is invoked with sem_id set to NULL, an
|
||||||
|
error is expected.*/
|
||||||
|
test_set_step(1);
|
||||||
|
{
|
||||||
|
int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemGetIdByName(NULL, "semaphore");
|
||||||
|
test_assert(err == OS_INVALID_POINTER, "NULL not detected");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OS_BinSemGetIdByName() is invoked with semaphore name set to NULL,
|
||||||
|
an error is expected.*/
|
||||||
|
test_set_step(2);
|
||||||
|
{
|
||||||
|
int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemGetIdByName(&bsid, NULL);
|
||||||
|
test_assert(err == OS_INVALID_POINTER, "NULL not detected");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OS_BinSemGetIdByName() is invoked with a very long task name, an
|
||||||
|
error is expected.*/
|
||||||
|
test_set_step(3);
|
||||||
|
{
|
||||||
|
int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemGetIdByName(&bsid, "very very long semaphore name");
|
||||||
|
test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const testcase_t test_004_006 = {
|
||||||
|
"OS_BinSemGetIdByName() errors",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
test_004_006_execute
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @page test_004_007 OS_BinSemTimedWait() timeout functionality
|
||||||
|
*
|
||||||
|
* <h2>Description</h2>
|
||||||
|
* OS_BinSemCreate() timeout functionality is tested.
|
||||||
|
*
|
||||||
|
* <h2>Test Steps</h2>
|
||||||
|
* - OS_BinSemTimedWait() is invoked with timeout set to one second, an
|
||||||
|
* error is expected.
|
||||||
|
* .
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void test_004_007_setup(void) {
|
||||||
|
bsid = 0;
|
||||||
|
(void) OS_BinSemCreate(&bsid, "test semaphore", 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_004_007_teardown(void) {
|
||||||
|
if (bsid > 0) {
|
||||||
|
(void) OS_BinSemDelete(bsid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_004_007_execute(void) {
|
||||||
|
|
||||||
|
/* OS_BinSemTimedWait() is invoked with timeout set to one second, an
|
||||||
|
error is expected.*/
|
||||||
|
test_set_step(1);
|
||||||
|
{
|
||||||
|
int32 err;
|
||||||
|
|
||||||
|
err = OS_BinSemTimedWait(bsid, 1000);
|
||||||
|
test_assert(err == OS_SEM_TIMEOUT, "unexpected error code");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const testcase_t test_004_007 = {
|
||||||
|
"OS_BinSemTimedWait() timeout functionality",
|
||||||
|
test_004_007_setup,
|
||||||
|
test_004_007_teardown,
|
||||||
|
test_004_007_execute
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Exported data.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Binary Semaphores Functionality.
|
||||||
|
*/
|
||||||
|
const testcase_t * const test_sequence_004[] = {
|
||||||
|
&test_004_001,
|
||||||
|
&test_004_002,
|
||||||
|
&test_004_003,
|
||||||
|
&test_004_004,
|
||||||
|
&test_004_005,
|
||||||
|
&test_004_006,
|
||||||
|
&test_004_007,
|
||||||
|
NULL
|
||||||
|
};
|
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern const testcase_t * const test_sequence_004[];
|
|
@ -3,7 +3,8 @@ TESTSRC = ${CHIBIOS}/test/lib/ch_test.c \
|
||||||
${CHIBIOS}/test/nasa_osal/source/test/test_root.c \
|
${CHIBIOS}/test/nasa_osal/source/test/test_root.c \
|
||||||
${CHIBIOS}/test/nasa_osal/source/test/test_sequence_001.c \
|
${CHIBIOS}/test/nasa_osal/source/test/test_sequence_001.c \
|
||||||
${CHIBIOS}/test/nasa_osal/source/test/test_sequence_002.c \
|
${CHIBIOS}/test/nasa_osal/source/test/test_sequence_002.c \
|
||||||
${CHIBIOS}/test/nasa_osal/source/test/test_sequence_003.c
|
${CHIBIOS}/test/nasa_osal/source/test/test_sequence_003.c \
|
||||||
|
${CHIBIOS}/test/nasa_osal/source/test/test_sequence_004.c
|
||||||
|
|
||||||
# Required include directories
|
# Required include directories
|
||||||
TESTINC = ${CHIBIOS}/test/lib \
|
TESTINC = ${CHIBIOS}/test/lib \
|
||||||
|
|
Loading…
Reference in New Issue