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

Fix #11, Update OS_TimerSet to return OS_ERROR #19

Merged
merged 1 commit into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
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
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