Skip to content

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

@jphickey

Description

@jphickey

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugunit-testTickets related to the OSAL unit testing (functional and/or coverage)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions