summaryrefslogtreecommitdiffstats
path: root/spec/rtems/cpuuse/val/cpuuse.yml
blob: dc549b7e9ac7843921e18f42a1751f680cf0498b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
copyrights:
- Copyright (C) 2021 embedded brains GmbH & Co. KG
enabled-by: true
links: []
test-actions:
- action-brief: |
    Create a worker thread.  Generate some CPU usage.
  action-code: |
    rtems_id          id;
    Thread_Control   *self;
    Thread_Control   *other;
    Timestamp_Control cpu_usage_self;
    Timestamp_Control cpu_usage_other;
    uint32_t          idle_tasks;
    uint32_t          cpu_index;

    idle_tasks = 0;

    for ( cpu_index = 0; cpu_index < rtems_scheduler_get_processor_maximum(); ++cpu_index ) {
      rtems_status_code sc;
      rtems_id          unused;

      sc = rtems_scheduler_ident_by_processor( cpu_index, &unused );

      if ( sc == RTEMS_SUCCESSFUL ) {
        ++idle_tasks;
      }
    }

    id = CreateTask( "WORK", GetSelfPriority() );
    StartTask( id, Worker, NULL );

    self = GetThread( RTEMS_SELF );
    other = GetThread( id );

    Yield();
    Yield();
  checks:
  - brief: |
      Check that we have a non-zero CPU usage.  Reset the CPU usage.  Check
      that it was cleared to zero.
    code: |
      TimecounterTick();

      cpu_usage_self = _Thread_Get_CPU_time_used( self );
      cpu_usage_other = _Thread_Get_CPU_time_used( other );

      T_gt_i64( _Thread_Get_CPU_time_used_after_last_reset( self ), 0 );
      T_gt_i64( _Thread_Get_CPU_time_used_after_last_reset( other ), 0 );

      rtems_cpu_usage_reset();

      /*
       * Our CPU usage after the last reset is now exactly one tick of the
       * software timecounter.
       */
      T_eq_i64( _Thread_Get_CPU_time_used_after_last_reset( self ), 4295 );
      T_eq_i64(
        _Thread_Get_CPU_time_used( self ),
        cpu_usage_self + 12885 + 4295 * idle_tasks
      );

      T_eq_i64( _Thread_Get_CPU_time_used_after_last_reset( other ), 0 );
      T_eq_i64( _Thread_Get_CPU_time_used( other ), cpu_usage_other );
    links:
    - role: validation
      uid: ../req/reset
  - brief: |
      Clean up all used resources.
    code: |
      DeleteTask( id );
    links: []
  links: []
test-brief: |
  Tests the CPU usage reporting and reset.
test-context: []
test-context-support: null
test-description: null
test-header: null
test-includes:
- rtems/cpuuse.h
- rtems/score/threadimpl.h
test-local-includes:
- tx-support.h
test-setup: null
test-stop: null
test-support: |
  static void Worker( rtems_task_argument arg )
  {
    (void) arg;

    while ( true ) {
      Yield();
    }
  }
test-target: testsuites/validation/tc-cpuuse.c
test-teardown: null
type: test-case