Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid infinite sem-speed-test #324

Merged
merged 1 commit into from
Dec 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/tests/sem-speed-test/sem-speed-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@
#include "uttest.h"
#include "utbsp.h"

/*
* Note the worker priority must be lower than that of
* the executive (init) task. Otherwise, the SemRun()
* function may may never get CPU time to stop the test.
*/
#define SEMTEST_TASK_PRIORITY 150

/*
* A limit for the maximum amount
* of iterations that this test will
* perform. This prevents the test
* from running infinitely in case the
* time-based stop routine does not
* work correctly. See note above
* about priority requirements.
*/
#define SEMTEST_WORK_LIMIT 10000000


/* Define setup and test functions for UT assert */
void SemSetup(void);
void SemRun(void);
Expand All @@ -54,8 +73,6 @@ void SemRun(void);
*/
#define SEMOP(op) SEMCALL(Count,op)

#define TASK_PRIORITY 50

uint32 task_1_id;
uint32 task_1_work;

Expand All @@ -72,7 +89,7 @@ void task_1(void)
OS_printf("Starting task 1\n");
OS_TaskRegister();

while(1)
while(task_1_work < SEMTEST_WORK_LIMIT)
{
status = SEMOP(Take)(sem_id_1);
if ( status != OS_SUCCESS )
Expand All @@ -99,7 +116,7 @@ void task_2(void)
OS_printf("Starting task 2\n");
OS_TaskRegister();

while(1)
while(task_2_work < SEMTEST_WORK_LIMIT)
{
status = SEMOP(Take)(sem_id_2);
if ( status != OS_SUCCESS )
Expand Down Expand Up @@ -150,10 +167,10 @@ void SemSetup(void)
/*
** Create the tasks
*/
status = OS_TaskCreate( &task_1_id, "Task 1", task_1, NULL, 4096, TASK_PRIORITY, 0);
status = OS_TaskCreate( &task_1_id, "Task 1", task_1, NULL, 4096, SEMTEST_TASK_PRIORITY, 0);
UtAssert_True(status == OS_SUCCESS, "Task 1 create Id=%u Rc=%d", (unsigned int)task_1_id, (int)status);

status = OS_TaskCreate( &task_2_id, "Task 2", task_2, NULL, 4096, TASK_PRIORITY, 0);
status = OS_TaskCreate( &task_2_id, "Task 2", task_2, NULL, 4096, SEMTEST_TASK_PRIORITY, 0);
UtAssert_True(status == OS_SUCCESS, "Task 2 create Id=%u Rc=%d", (unsigned int)task_2_id, (int)status);

/* A small delay just to allow the tasks
Expand All @@ -173,6 +190,9 @@ void SemRun(void)

/*
** Delete resources
**
** NOTE: if the work limit was reached, the
** OS_TaskDelete calls may return non-success.
*/
status = OS_TaskDelete( task_1_id );
UtAssert_True(status == OS_SUCCESS, "Task 1 delete Rc=%d", (int)status);
Expand Down