summaryrefslogtreecommitdiffstats
path: root/eng/req/howto.rst
blob: 308bb382ad2464eb775990f533dae46e15ac8591 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
.. SPDX-License-Identifier: CC-BY-SA-4.0

.. Copyright (C) 2020, 2021 embedded brains GmbH (http://www.embedded-brains.de)

How-To
======

Getting Started
---------------

The RTEMS specification items and qualification tools are work in progress.  The
first step to work with the RTEMS specification and the corresponding tools is a
clone of the following repository:

.. code-block:: none

    git clone git://git.rtems.org/rtems-central.git
    git submodule init
    git submodule update

The tools need a virtual Python 3 environment. To set it up use:

.. code-block:: none

    cd rtems-central
    make env

Each time you want to use one of the tools, you have to activate the
environment in your shell:

.. code-block:: none

    cd rtems-central
    . env/bin/activate

Application Configuration Options
---------------------------------

The application configuration options and groups are maintained by
specification items in the directory :file:`spec/if/acfg`.  Application
configuration options are grouped by
:ref:`SpecTypeApplicationConfigurationGroupItemType` items which should be
stored in files using the :file:`spec/if/acfg/group-*.yml` pattern.  Each
application configuration option shall link to exactly one group item with the
:ref:`SpecTypeApplicationConfigurationGroupMemberLinkRole`.  There are four
application option item types available which cover all existing options:

* The *feature enable options* let the application enable a feature option.  If
  the option is not defined, then the feature is simply not available or
  active.  There should be no feature-specific code linked to the application
  if the option is not defined.  Examples are options which enable a device
  driver like ``CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER``.  These options are
  specified by
  :ref:`SpecTypeApplicationConfigurationFeatureEnableOptionItemType` items.

* The *feature options* let the application enable a specific feature option.
  If the option is not defined, then a default feature option is used.
  Regardless whether the option is defined or not defined, feature-specific
  code may be linked to the application.  Examples are options which disable a
  feature if the option is defined such as
  ``CONFIGURE_APPLICATION_DISABLE_FILESYSTEM`` and options which provide a stub
  implementation of a feature by default and a full implementation if the
  option is defined such as ``CONFIGURE_IMFS_ENABLE_MKFIFO``.  These options
  are specified by :ref:`SpecTypeApplicationConfigurationFeatureOptionItemType`
  items.

* The *integer value options* let the application define a specific value for a
  system parameter.  If the option is not defined, then a default value is used
  for the system parameter.  Examples are options which define the maximum
  count of objects available for application use such as
  ``CONFIGURE_MAXIMUM_TASKS``.  These options are specified by
  :ref:`SpecTypeApplicationConfigurationValueOptionItemType` items.

* The *initializer options* let the application define a specific initializer
  for a system parameter.  If the option is not defined, then a default setting
  is used for the system parameter.  An example option of this type is
  ``CONFIGURE_INITIAL_EXTENSIONS``.  These options are specified by
  :ref:`SpecTypeApplicationConfigurationValueOptionItemType` items.

Sphinx documentation sources and header files with Doxygen markup are generated
from the specification items.  The descriptions in the items shall use a
restricted Sphinx formatting.  Emphasis via one asterisk ("*"), strong emphasis
via two asterisk ("**"), code samples via blockquotes ("``"), code blocks ("..
code-block:: c") and lists are allowed.  References to interface items are also
allowed, for example "${appl-needs-clock-driver:/name}" and
"${../rtems/tasks/create:/name}".  References to other parts of the
documentation are possible, however, they are currently provided by hard-coded
tables in :file:`rtemsspec/applconfig.py`.

Modify an Existing Group
^^^^^^^^^^^^^^^^^^^^^^^^

Search for the group by its section header and edit the specification item
file.  For example:

.. code-block:: none

    $ grep -rl "name: General System Configuration" spec/if/acfg
    spec/if/acfg/group-general.yml
    $ vi spec/if/acfg/group-general.yml

Modify an Existing Option
^^^^^^^^^^^^^^^^^^^^^^^^^

Search for the option by its C preprocessor define name and edit the
specification item file.  For example:

.. code-block:: none

    $ grep -rl CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER spec/if/acfg
    spec/if/acfg/appl-needs-clock-driver.yml
    $ vi spec/if/acfg/appl-needs-clock-driver.yml

Add a New Group
^^^^^^^^^^^^^^^

Let ``new`` be the UID name part of the new group.  Create the file
:file:`spec/if/acfg/group-new.yml` and provide all attributes for an
:ref:`SpecTypeApplicationConfigurationGroupItemType` item.  For example:

.. code-block:: none

    $ vi spec/if/acfg/group-new.yml

Add a New Option
^^^^^^^^^^^^^^^^

Let ``my-new-option`` be the UID name of the option.  Create the file
:file:`if/acfg/my-new-option.yml` and provide all attributes for an appropriate
refinement of :ref:`SpecTypeApplicationConfigurationOptionItemType`.  For
example:

.. code-block:: none

    $ vi spec/if/acfg/my-new-option.yml

Generate Content after Changes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Once you are done with the modifications of an existing item or the creation of
a new item, the changes need to be propagated to generated source files.  This
is done by the :file:`spec2modules.py` script.  Before you call this script,
make sure the Git submodules are up-to-date.

.. code-block:: none

    $ ./spec2dmodules.py

The script modifies or creates source files in :file:`modules/rtems` and
:file:`modules/rtems-docs`.  Create patch sets for these changes just as if
these were work done by a human and follow the normal patch review process
described in the *RTEMS User Manual*.  When the changes are integrated, update
the Git submodules and check in the changed items.

Glossary Specification
----------------------

The glossary of terms for the RTEMS Project is defined by
:ref:`SpecTypeGlossaryTermItemType` items in the :file:`spec/glossary`
directory.  For a new glossary term add a glossary item to this directory.  As
the file name use the term in lower case with all white space and special
characters removed or replaced by alphanumeric characters, for example
:file:`spec/glossary/magicpower.yml` for the term `magic power`.

Use ``${uid:/attribute}`` substitutions to reference other parts of the
specification.

.. code-block:: yaml

    SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
    copyrights:
    - Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
    enabled-by: true
    glossary-type: term
    links:
    - role: glossary-member
      uid: ../glossary-general
    term: magic power
    text: |
      Magic power enables a caller to create magic objects using a
      ${magicwand:/term}.
    type: glossary

Define acronyms with the phrase `This term is an acronym for *.` in the
``text`` attribute:

.. code-block:: yaml

    ...
    term: MP
    ...
    text: |
      This term is an acronym for Magic Power.
    ...

Once you are done with the glossary items, run the script
:file:`spec2modules.py` to generate the derived documentation content.  Send
patches for the generated documentation and the specification to the
:r:list:`devel` and follow the normal patch review process.

Interface Specification
-----------------------

.. _ReqEngAddAPIHeaderFile:

Specify an API Header File
^^^^^^^^^^^^^^^^^^^^^^^^^^

The RTEMS :term:`API` header files are specified under ``spec:/if/rtems/*``.
Create a subdirectory with a corresponding name for the API, for example in
:file:`spec/if/rtems/foo` for the `foo` API.  In this new subdirectory place an
:ref:`SpecTypeInterfaceHeaderFileItemType` item named :file:`header.yml`
(:file:`spec/if/rtems/foo/header.yml`) and populate it with the required
attributes.

.. code-block:: yaml

    SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
    copyrights:
    - Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
    enabled-by: true
    interface-type: header-file
    links:
    - role: interface-placement
      uid: /if/domains/api
    path: rtems/rtems/foo.h
    prefix: cpukit/include
    type: interface

Specify an API Element
^^^^^^^^^^^^^^^^^^^^^^

Figure out the corresponding header file item.  If it does not exist, see
:ref:`ReqEngAddAPIHeaderFile`.  Place a specialization of an
:ref:`SpecTypeInterfaceItemType` item into the directory of the header file
item, for example :file:`spec/if/rtems/foo/bar.yml` for the :c:func:`bar`
function.  Add the required attributes for the new interface item.  Do not hard
code interface names which are used to define the new interface.  Use
``${uid-of-interface-item:/name}`` instead.  If the referenced interface is
specified in the same directory, then use a relative UID.  Using interface
references creates implicit dependencies and helps the header file generator to
resolve the interface dependencies and header file includes for you.  Use
:ref:`SpecTypeInterfaceUnspecifiedItemType` items for interface dependencies to
other domains such as the C language, the compiler, the implementation, or
user-provided defines.  To avoid cyclic dependencies between types you may use
an :ref:`SpecTypeInterfaceForwardDeclarationItemType` item.

.. code-block:: yaml

    SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
    brief: Tries to create a magic object and returns it.
    copyrights:
    - Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
    definition:
      default:
        body: null
        params:
        - ${magic-wand:/name} ${.:/params[0]/name}
        return: ${magic-type:/name} *
      variants: []
    description: |
      The magic object is created out of nothing with the help of a magic wand.
    enabled-by: true
    interface-type: function
    links:
    - role: interface-placement
      uid: header
    - role: interface-ingroup
      uid: /groups/api/classic/foo
    name: bar
    notes: null
    params:
    - description: is the magic wand.
      dir: null
      name: magic_wand
    return:
      return: Otherwise, the magic object is returned.
      return-values:
      - description: The caller did not have enough magic power.
        value: ${/if/c/null}
    type: interface

Requirements Depending on Build Configuration Options
-----------------------------------------------------

Use the ``enabled-by`` attribute of items or parts of an item to make it
dependent on build configuration options such as :c:data:`RTEMS_SMP` or
architecture-specific options such as
:c:data:`CPU_ENABLE_ROBUST_THREAD_DISPATCH`, see
:ref:`SpecTypeEnabledByExpression`.  With this attribute the specification can
be customized at the level of an item or parts of an item.  If the
``enabled-by`` attribute evaluates to false for a particular configuration,
then the item or the associated part is disabled in the specification.  The
``enabled-by`` attribute acts as a formalized *where* clause, see
:ref:`recommended requirements syntax <ReqEngSyntax>`.

Please have a look at the following example which specifies the transition map
of :c:func:`rtems_signal_catch`:

.. code-block:: yaml

    transition-map:
    - enabled-by: true
      post-conditions:
        Status: Ok
        ASRInfo:
        - if:
            pre-conditions:
              Handler: Valid
          then: New
        - else: Inactive
      pre-conditions:
        Pending: all
        Handler: all
        Preempt: all
        Timeslice: all
        ASR: all
        IntLvl: all
    - enabled-by: CPU_ENABLE_ROBUST_THREAD_DISPATCH
      post-conditions:
        Status: NotImplIntLvl
        ASRInfo: NopIntLvl
      pre-conditions:
        Pending: all
        Handler:
        - Valid
        Preempt: all
        Timeslice: all
        ASR: all
        IntLvl:
        - Positive
    - enabled-by: RTEMS_SMP
      post-conditions:
        Status: NotImplNoPreempt
        ASRInfo: NopNoPreempt
      pre-conditions:
        Pending: all
        Handler:
        - Valid
        Preempt:
        - 'No'
        Timeslice: all
        ASR: all
        IntLvl: all

Requirements Depending on Application Configuration Options
-----------------------------------------------------------

Requirements which depend on application configuration options such as
:c:data:`CONFIGURE_MAXIMUM_PROCESSORS` should be written in the following
:ref:`syntax <ReqEngSyntax>`:

    **Where** <feature is included>, the <system name> shall <system response>.

Use these clauses with care.  Make sure all feature combinations are covered.
Using a truth table may help.  If a requirement depends on multiple features,
use:

    **Where** <feature 0>, **where** <feature 1>, **where** <feature ...>, the
    <system name> shall <system response>.

For application configuration options, use the clauses like this:

:c:data:`CONFIGURE_MAXIMUM_PROCESSORS` equal to one

   **Where** the system was configured with a processor maximum of exactly
   one, ...

:c:data:`CONFIGURE_MAXIMUM_PROCESSORS` greater than one

   **Where** the system was configured with a processor maximum greater than
   one, ...

Please have a look at the following example used to specify
:c:func:`rtems_signal_catch`.  The example is a post-condition state
specification of an action requirement, so there is an implicit set of
pre-conditions and the trigger:

   **While** <pre-condition(s)>, **when** rtems_signal_catch() is called, ...

The *where* clauses should be mentally placed before the *while* clauses.

.. code-block:: yaml

    post-conditions:
    - name: ASRInfo
      states:
      - name: NopNoPreempt
        test-code: |
          if ( rtems_configuration_get_maximum_processors() > 1 ) {
            CheckNoASRChange( ctx );
          } else {
            CheckNewASRSettings( ctx );
          }
        text: |
          Where the scheduler does not support the no-preempt mode, the ASR
          information of the caller of ${../if/catch:/name} shall not be
          changed by the ${../if/catch:/name} call.

          Where the scheduler does support the no-preempt mode, the ASR
          processing for the caller of ${../if/catch:/name} shall be done using
          the handler specified by ${../if/catch:/params[0]/name} in the mode
          specified by ${../if/catch:/params[1]/name}.

Action Requirements
-------------------

:ref:`SpecTypeActionRequirementItemType` items may be used to specify and
validate directive calls.  They are a generator for event-driven requirements.
Event-driven requirements should be written in the following :ref:`syntax
<ReqEngSyntax>`:

    **While** <pre-condition 0>, **while** <pre-condition 1>, ..., **while**
    <pre-condition *n*>, **when** <trigger>, the <system name> shall <system
    response>.

The list of *while* <pre-condition *i*> clauses for *i* from 1 to *n* in the
EARS notation is generated by *n* pre-condition states in the action
requirement item, see the ``pre-condition`` attribute in the
:ref:`SpecTypeActionRequirementItemType`.

The <trigger> in the EARS notation is defined for an action requirement item by
the link to an :ref:`SpecTypeInterfaceFunctionItemType` or an
:ref:`SpecTypeInterfaceMacroItemType` item using the
:ref:`SpecTypeInterfaceFunctionLinkRole`.  The code provided by the
``test-action`` attribute defines the action code which should invoke the
trigger directive in a particular set of pre-condition states.

Each post-condition state of the action requirement item generates a <system
name> shall <system response> clause in the EARS notation, see the
``post-condition`` attribute in the :ref:`SpecTypeActionRequirementItemType`.

Each entry in the transition map is an event-driven requirement composed of the
pre-condition states, the trigger defined by the link to a directive, and the
post-condition states.  The transition map is defined by a list of
:ref:`SpecTypeActionRequirementTransition` descriptors.

Use ``CamelCase`` for the pre-condition names, post-condition names, and state
names in action requirement items.  The more conditions a directive has, the
shorter should be the names.  The transition map may be documented as a table
and more conditions need more table columns.  Use item attribute references in
the ``text`` attributes.  This allows context-sensitive substitutions.

Pre-Conditions
^^^^^^^^^^^^^^

Specify all directive parameters as separate pre-conditions.  Use the following
syntax for directive object identifier parameters:

.. code-block:: yaml

    - name: Id
      states:
      - name: NoObj
        test-code: |
          ctx->id = 0xffffffff;
        text: |
          While the ${../if/directive:/params[0]/name} parameter is not
          associated with a thing.
      - name: ClassA
        test-code: |
          ctx->id = ctx->class_a_id;
        text: |
          While the ${../if/directive:/params[0]/name} parameter is associated
          with a class A thing.
      - name: ClassB
        test-code: |
          ctx->id = ctx->class_b_id;
        text: |
          While the ${../if/directive:/params[0]/name} parameter is associated
          with a class B thing.
      test-epilogue: null
      test-prologue: null

Do not add specifications for invalid pointers.  In general, there are a lot of
invalid pointers and the use of an invalid pointer is in almost all cases
undefined behaviour in RTEMS.  There may be specifications for special cases
which deal with some very specific invalid pointers such as the :c:data:`NULL`
pointer or pointers which do not satisfy a range or boundary condition.  Use
the following syntax for directive pointer parameters:

.. code-block:: yaml

    - name: Id
      states:
      - name: Valid
        test-code: |
          ctx->id = &ctx->id_value;
        text: |
          While the ${../if/directive:/params[3]/name} parameter references an
          object of type ${../../type/if/id:/name}.
      - name: 'Null'
        test-code: |
          ctx->id = NULL;
        text: |
          While the ${../if/directive:/params[3]/name} parameter is
          ${/c/if/null:/name}.
      test-epilogue: null
      test-prologue: null

Use the following syntax for other directive parameters:

.. code-block:: yaml

    - name: Name
      states:
      - name: Valid
        test-code: |
          ctx->name = NAME;
        text: |
          While the ${../if/directive:/params[0]/name} parameter is valid.
      - name: Invalid
        test-code: |
          ctx->name = 0;
        text: |
          While the ${../if/directive:/params[0]/name} parameter is invalid.
      test-epilogue: null
      test-prologue: null

Post-Conditions
^^^^^^^^^^^^^^^

Do not mix different things into one post-condition.  If you write multiple
sentences to describe what happened, then think about splitting up the
post-condition.  Keep the post-condition simple and focus on one testable
aspect which may be changed by a directive call.

For directives returning an :c:type:`rtems_status_code` use the following
post-condition states.  Specify only status codes which may be returned by the
directive.  Use it as the first post-condition.  The first state shall be
``Ok``.  The other states shall be listed in the order in which they can occur.

.. code-block:: yaml

    - name: Status
      states:
      - name: Ok
        test-code: |
          T_rsc_success( ctx->status );
        text: |
          The return status of ${../if/directive:/name} shall be
          ${../../status/if/successful:/name}.
      - name: IncStat
        test-code: |
          T_rsc( ctx->status, RTEMS_INCORRECT_STATE );
        text: |
          The return status of ${../if/directive:/name} shall be
          ${../../status/if/incorrect-state:/name}.
      - name: InvAddr
        test-code: |
          T_rsc( ctx->status, RTEMS_INVALID_ADDRESS );
        text: |
          The return status of ${../if/directive:/name} shall be
          ${../../status/if/invalid-address:/name}.
      - name: InvName
        test-code: |
          T_rsc( ctx->status, RTEMS_INVALID_NAME );
        text: |
          The return status of ${../if/directive:/name} shall be
          ${../../status/if/invalid-name:/name}.
      - name: InvNum
        test-code: |
          T_rsc( ctx->status, RTEMS_INVALID_NUMBER );
        text: |
          The return status of ${../if/directive:/name} shall be
          ${../../status/if/invalid-number:/name}.
      - name: InvSize
        test-code: |
          T_rsc( ctx->status, RTEMS_INVALID_SIZE );
        text: |
          The return status of ${../if/directive:/name} shall be
          ${../../status/if/invalid-size:/name}.
      - name: InvPrio
        test-code: |
          T_rsc( ctx->status, RTEMS_INVALID_PRIORITY );
        text: |
          The return status of ${../if/directive:/name} shall be
          ${../../status/if/invalid-priority:/name}.
      - name: NotConf
        test-code: |
          T_rsc( ctx->status, RTEMS_NOT_CONFIGURED );
        text: |
          The return status of ${../if/directive:/name} shall be
          ${../../status/if/not-configured:/name}.
      - name: NotDef
        test-code: |
          T_rsc( ctx->status, RTEMS_NOT_DEFINED );
        text: |
          The return status of ${../if/directive:/name} shall be
          ${../../status/if/not-defined:/name}.
      - name: NotImpl
        test-code: |
          T_rsc( ctx->status, RTEMS_NOT_IMPLEMENTED );
        text: |
          The return status of ${../if/directive:/name} shall be
          ${../../status/if/not-implemented:/name}.
      - name: TooMany
        test-code: |
          T_rsc( ctx->status, RTEMS_TOO_MANY );
        text: |
          The return status of ${../if/directive:/name} shall be
          ${../../status/if/too-many:/name}.
      - name: Unsat
        test-code: |
          T_rsc( ctx->status, RTEMS_UNSATISFIED  );
        text: |
          The return status of ${../if/directive:/name} shall be
          ${../../status/if/unsatisfied:/name}.
      test-epilogue: null
      test-prologue: null

For values which are returned by reference through directive parameters, use
the following post-condition states.

.. code-block:: yaml

    - name: SomeParamVar
      states:
      - name: Set
        test-code: |
          /* Add code to check that the object value was set to X */
        text: |
          The value of the object referenced by the
          ${../if/directive:/params[0]/name} parameter shall be set to X after
          the return of the ${../if/directive:/name} call.
      - name: Nop
        test-code: |
          /* Add code to check that the object was not modified */
        text: |
          Objects referenced by the ${../if/directive:/params[0]/name}
          parameter in past calls to ${../if/directive:/name} shall not be
          accessed by the ${../if/directive:/name} call.