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

osal core test is not a good example of how to write tasks #670

Closed
jphickey opened this issue Dec 7, 2020 · 0 comments · Fixed by #671 or #690
Closed

osal core test is not a good example of how to write tasks #670

jphickey opened this issue Dec 7, 2020 · 0 comments · Fixed by #671 or #690
Labels
bug unit-test Tickets related to the OSAL unit testing (functional and/or coverage)
Milestone

Comments

@jphickey
Copy link
Contributor

jphickey commented Dec 7, 2020

Describe the bug
The osal-core-test.c refers to task functions that are actually defined (not just declared) in osal-core-test.h

Furthermore, these tasks just implement a tight loop:

void task_0(void)
{
OS_TaskRegister();
while (1)
;
return;
} /* end task_0 */

Multiple Problems:

  1. Against coding standards to implement code in a header.
  2. Same function is defined 20 times.
  3. The task has no blocking statement at all, so it spins using 100% cpu after it is started.
  4. On some operating systems (e.g. POSIX), unless async task cancellation is enabled this also means the task also cannot be deleted, because it will never execute a cancellation point.

Although the osal-core-test program passes and attempts to delete these tasks, in reality they keep running on POSIX and do not actually exit.

To Reproduce
View in a debugger after creating + deleting these tasks - the threads are still there. CPU usage is also very high (e.g. 300%) for the remainder of the test because these tasks are spinning and do not exit.

Expected behavior
There is no need to redefine the same function. Recommend to use the task_generic_no_exit() function (which already exists) for all of these tasks. This function also uses OS_TaskDelay() so it does not consume max CPU and also this serves as a cancellation point thus allowing the task to be deleted normally.

System observed on:
Ubuntu 20.04

Additional context
This becomes a bigger issue when #642 is done, as the tasks effectively are un-deletable.

Reporter Info
Joseph Hickey, Vantage Systems, Inc.

jphickey added a commit to jphickey/osal that referenced this issue Dec 7, 2020
Move all definitions and instantiations out of the header file.
Reuse the single task definition that was already defined.

Also only define 3 instances of each type, as this is all that
the test actually uses (no need for 20).
@astrogeco astrogeco added bug unit-test Tickets related to the OSAL unit testing (functional and/or coverage) labels Dec 17, 2020
@astrogeco astrogeco added this to the 6.0.0 milestone Dec 17, 2020
astrogeco added a commit that referenced this issue Dec 17, 2020
Fix #670, clean up task definitions in core test
jphickey pushed a commit to jphickey/osal that referenced this issue Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unit-test Tickets related to the OSAL unit testing (functional and/or coverage)
Projects
None yet
2 participants