Skip to content

Commit

Permalink
Merge pull request #19 from avan989/OS_ERROR
Browse files Browse the repository at this point in the history
Fix #11, Update OS_TimerSet to return OS_ERROR
  • Loading branch information
skliper authored Oct 1, 2019
2 parents 5df61b6 + 7265719 commit 58cf977
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/os/shared/osapi-time.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ int32 OS_TimerSet(uint32 timer_id, uint32 start_time, uint32 interval_time)
{
return OS_TIMER_ERR_INVALID_ARGS;
}

if (start_time == 0 && interval_time == 0)
{
return OS_ERROR;
}

/*
* Check our context. Not allowed to use the timer API from a timer callback.
Expand Down
10 changes: 6 additions & 4 deletions src/unit-test-coverage/shared/src/coveragetest-time.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,28 @@ void Test_OS_TimerSet(void)
* Test Case For:
* int32 OS_TimerSet(uint32 timer_id, uint32 start_time, uint32 interval_time)
*/
int32 expected = OS_SUCCESS;
int32 expected = OS_ERROR;
int32 actual = OS_TimerSet(1, 0, 0);
UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_ERROR", (long)actual);

expected = OS_SUCCESS;
actual = OS_TimerSet(1, 0, 1);
UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_SUCCESS", (long)actual);

OS_timecb_table[2].timebase_ref = 0;
OS_timecb_table[2].flags = TIMECB_FLAG_DEDICATED_TIMEBASE;
OS_global_timebase_table[0].active_id = 2;
actual = OS_TimerSet(2, 0, 0);
actual = OS_TimerSet(2, 0, 1);
UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_SUCCESS", (long)actual);
memset(OS_timecb_table, 0, sizeof(OS_timecb_table));

expected = OS_TIMER_ERR_INVALID_ARGS;
actual = OS_TimerSet(2, 1 << 31, 1 << 31);
UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_TIMER_ERR_INVALID_ARGS", (long)actual);


UT_SetForceFail(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT));
expected = OS_ERR_INCORRECT_OBJ_STATE;
actual = OS_TimerSet(2, 0, 0);
actual = OS_TimerSet(2, 0, 1);
UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual);
UT_ClearForceFail(UT_KEY(OS_TaskGetId_Impl));
}
Expand Down

0 comments on commit 58cf977

Please sign in to comment.