SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
copyrights:
- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
enabled-by: true
links: []
test-actions:
- action-brief: |
    Call ${../if/self:/name} check the returned value.
  action-code: |
    rtems_id id;

    id = rtems_task_self();
  checks:
  - brief: |
      Check that the returned value is equal to the object identifier of the
      calling task.
    code: |
      T_step_eq_u32( ${step}, id, 0x0a010001 );
    links: []
  links:
  - role: validation
    uid: ../req/self
- action-brief: |
    Call ${../if/iterate:/name} with a visitor which always returns
    ${/c/if/false:/name}.
  action-code: |
    TaskIterateContext ctx;
    uint32_t           task_count;

    task_count = rtems_scheduler_get_processor_maximum();

    if ( task_count > 4 ) {
      task_count = 4;
    }

    ++task_count;

    memset( &ctx, 0, sizeof( ctx ) );
    ctx.owner_before = _RTEMS_Allocator_is_owner();
    rtems_task_iterate( TaskVisitor, &ctx );
    ctx.owner_after = _RTEMS_Allocator_is_owner();
  checks:
  - brief: |
      Check that the all counter is equal to the count of tasks.  Check that
      the calling task was visited exacly once.  Firstly, this shows that
      ${../if/iterate:/name} used the parameters specified by
      ${../if/iterate:/params[0]/name} and ${../if/iterate:/params[1]/name}.
      Secondly, this shows that the iteration was done over all tasks.
    code: |
      T_step_eq_u32( ${step}, ctx.counter_all, task_count );
      T_step_eq_u32( ${step}, ctx.counter_self, 1 );
    links:
    - role: validation
      uid: ../req/iterate-visit
    - role: validation
      uid: ../req/iterate-done
  - brief: |
      Check that the object alloctor mutex was not owned before and after the
      call.  Check that the object alloctor mutex was owned during the
      iteration.
    code: |
      T_step_false( ${step}, ctx.owner_before );
      T_step_true( ${step}, ctx.owner_in_visitor );
      T_step_false( ${step}, ctx.owner_after );
    links:
    - role: validation
      uid: ../req/iterate-start
    - role: validation
      uid: ../req/iterate-done
  links:
  - role: validation
    uid: ../req/iterate-start
- action-brief: |
    Call ${../if/iterate:/name} with a visitor which returns
    ${/c/if/true:/name}.
  action-code: |
    TaskIterateContext ctx;

    memset( &ctx, 0, sizeof( ctx ) );
    ctx.done = true;
    rtems_task_iterate( TaskVisitor, &ctx );
  checks:
  - brief: |
      Check that the all counter is equal to one.  This shows that the
      iteration stops when the visitor returns ${/c/if/true:/name}.
    code: |
      T_step_eq_u32( ${step}, ctx.counter_all, 1 );
    links:
    - role: validation
      uid: ../req/iterate-stop
  links: []
- action-brief: |
    Assert that ${../if/storage-alignment:/name} is a constant expression which
    evaluates to the expected value.
  action-code: |
    RTEMS_STATIC_ASSERT(
      RTEMS_TASK_STORAGE_ALIGNMENT == CPU_STACK_ALIGNMENT,
      STORAGE_ALIGNMENT
    );
  checks: []
  links:
  - role: validation
    uid: ../req/storage-alignment
- action-brief: |
    Assert that ${../if/no-priority:/name} is a constant expression which
    evaluates to the expected value.
  action-code: |
    RTEMS_STATIC_ASSERT(
      RTEMS_NO_PRIORITY == RTEMS_CURRENT_PRIORITY,
      NO_PRIORITY
    );
  checks: []
  links:
  - role: validation
    uid: ../req/no-priority
- action-brief: |
    Assert that ${../if/minimum-stack-size:/name} is a constant expression which
    evaluates to the expected value.
  action-code: |
    RTEMS_STATIC_ASSERT(
      RTEMS_MINIMUM_STACK_SIZE == STACK_MINIMUM_SIZE,
      MINIMUM_STACK_SIZE
    );
  checks: []
  links:
  - role: validation
    uid: ../req/minimum-stack-size
- action-brief: |
    Assert that ${../if/minimum-priority:/name} is a constant expression which
    evaluates to the expected value.
  action-code: |
    RTEMS_STATIC_ASSERT( RTEMS_MINIMUM_PRIORITY == 1, MINIMUM_PRIORITY );
  checks: []
  links:
  - role: validation
    uid: ../req/minimum-priority
- action-brief: |
    Validate ${../if/self-define:/name} using a sample directive call.
  action-code: |
    rtems_status_code sc;
  checks:
  - brief: |
      Check that ${../if/is-suspended:/name} returns the expected status if
      called with a task identifier parameter of ${../if/self-define:/name}.
    code: |
      sc = rtems_task_is_suspended( RTEMS_SELF );
      T_step_rsc_success( ${step}, sc );
    links:
    - role: validation
      uid: ../req/self-define
  links: []
test-brief: |
  This test case collection provides validation test cases for requirements of
  the ${../if/group:/name}.
test-context: []
test-context-support: null
test-description: null
test-header: null
test-includes:
- rtems.h
- string.h
- rtems/score/apimutex.h
test-local-includes: []
test-setup: null
test-stop: null
test-support: |
  typedef struct {
    bool     owner_before;
    bool     owner_in_visitor;
    bool     owner_after;
    uint32_t counter_all;
    uint32_t counter_self;
    bool     done;
  } TaskIterateContext;

  static bool TaskVisitor( rtems_tcb *tcb, void *arg )
  {
    TaskIterateContext *ctx;

    ctx = arg;
    ++ctx->counter_all;

    if ( rtems_task_self() == tcb->Object.id ) {
      ++ctx->counter_self;
    }

    ctx->owner_in_visitor = _RTEMS_Allocator_is_owner();

    return ctx->done;
  }
test-target: testsuites/validation/tc-task.c
test-teardown: null
type: test-case
