summaryrefslogtreecommitdiffstats
path: root/rtemsspec/tests/test_interface.py
blob: bee4f00a1a2970a99a5eef2c762323dfbd782cab (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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
# SPDX-License-Identifier: BSD-2-Clause
""" Unit tests for the rtemsspec.interface module. """

# Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

import os
import pytest

from rtemsspec.interface import generate
from rtemsspec.items import EmptyItemCache, ItemCache, item_is_enabled
from rtemsspec.tests.util import create_item_cache_config_and_copy_spec


def test_interface(tmpdir):
    interface_config = {}
    interface_config["item-level-interfaces"] = []
    base_directory = os.path.join(tmpdir, "base")
    interface_domains = {"/domain-abc": base_directory}
    interface_config["domains"] = interface_domains
    interface_config["enabled"] = []

    generate(interface_config, EmptyItemCache())

    interface_config["item-level-interfaces"] = ["/command-line"]

    item_cache_config = create_item_cache_config_and_copy_spec(
        tmpdir, "spec-interface", with_spec_types=True)
    generate(interface_config,
             ItemCache(item_cache_config, is_item_enabled=item_is_enabled))

    with open(os.path.join(base_directory, "include", "h.h"), "r") as src:
        content = """/* SPDX-License-Identifier: BSD-2-Clause */

/**
 * @file
 *
 * @ingroup GroupA
 * @ingroup GroupB
 * @ingroup GroupC
 *
 * @brief This header file defines X.
 */

/*
 * Copyright (C) 2020, 2023 embedded brains GmbH & Co. KG
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * This file is part of the RTEMS quality process and was automatically
 * generated.  If you find something that needs to be fixed or
 * worded better please post a report or patch to an RTEMS mailing list
 * or raise a bug report:
 *
 * https://www.rtems.org/bugs.html
 *
 * For information on updating and regenerating please refer to the How-To
 * section in the Software Requirements Engineering chapter of the
 * RTEMS Software Engineering manual.  The manual is provided as a part of
 * a release.  For development sources please refer to the online
 * documentation at:
 *
 * https://docs.rtems.org
 */

/* Generated from spec:/h */

#ifndef _H_H
#define _H_H

#include <h2.h>
#include <h3.h>
#include <math.h>
#include <stdint.h>

#if !defined(ASM) || defined(RTEMS_SMP)
  #include <h9.h>
#endif

#if 0
  #include <h5.h>
  #include <h6.h>
  #include <h7.h>
#endif

#if defined(ASM)
  #include <h4.h>
#endif

#if defined(ASM) && defined(RTEMS_MULTIPROCESSING)
  #include <h8.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

/* Generated from spec:/ga */

/**
 * @defgroup GroupA Group A
 *
 * @brief Group A brief description.
 *
 * Group A description.
 */

/* Generated from spec:/gb */

/**
 * @defgroup GroupB Group B
 *
 * @ingroup GroupA
 */

/* Generated from spec:/define */

/**
 * @ingroup GroupA
 */
#if defined(A) || (B > C)
  #define DEFINE ((float_t) 456)
#elif defined(C) && defined(D)
  #define DEFINE ((float_t) 789)
#else
  #define DEFINE \\
    ((float_t) 123)
#endif

/* Generated from spec:/enum */

/**
 * @ingroup GroupB
 *
 * @brief Enum brief description.
 *
 * Enum description.
 */
typedef enum {
  /**
   * @brief Enumerator 0 brief description.
   */
  ENUMERATOR_0,

  /**
   * @brief Enumerator 1 brief description.
   */
  ENUMERATOR_1,

  /**
   * @brief Enumerator 2 brief description.
   */
  ENUMERATOR_2
} Enum;

/* Generated from spec:/enum3 */

/**
 * @ingroup GroupB
 *
 * @brief Enum B brief description.
 */
typedef enum EnumB {
  /**
   * @brief Enumerator B brief description.
   */
  ENUMERATOR_B = ENUMERATOR_A
} EnumB;

/* Generated from spec:/forward-decl */

/* Forward declaration */
struct Struct;

/* Generated from spec:/func */

/**
 * @ingroup GroupA
 *
 * @brief Function brief description.
 *
 * @param Param0 is parameter 0.
 *
 * @param[in] Param1 is parameter 1.
 *
 * @param[out] Param2 is parameter 2.
 *
 * @param[in,out] Param3 is parameter 3.
 *
 * Function description.  References to xs, VeryLongFunction(), ::Integer,
 * #Enum, #DEFINE, VERY_LONG_MACRO(), #Variable, ::ENUMERATOR_0, Struct, @ref
 * a, interface, @ref GroupA, and @ref GroupF.  Second parameter is ``Param1``.
 * Mention struct US.
 *
 * @code
 * these two lines
 * are not wrapped
 * @endcode
 *
 * @par Constraints
 * @parblock
 * The following constraints apply to this directive:
 *
 * * Constraint A for Function().
 * @endparblock
 */
void Function(
  int        Param0,
  const int *Param1,
  int       *Param2,
  int       *Param3,
  int       *Param4
);

/* Generated from spec:/func6 */
void Function6( int Param0 );

/* Generated from spec:/irqamp-timestamp */

/**
 * @defgroup IrqampTimestamp IRQ(A)MP Timestamp
 *
 * @brief This group contains the IRQ(A)MP Timestamp interfaces.
 *
 * @{
 */

/**
 * @defgroup IrqampTimestampITCNT \\
 *   Interrupt timestamp counter n register (ITCNT)
 *
 * @brief This group contains register bit definitions.
 *
 * @{
 */

#define IRQAMP_ITCNT_TCNT_SHIFT 0
#define IRQAMP_ITCNT_TCNT_MASK 0xffffffffU
#define IRQAMP_ITCNT_TCNT_GET( _reg ) \\
  ( ( ( _reg ) & IRQAMP_ITCNT_TCNT_MASK ) >> IRQAMP_ITCNT_TCNT_SHIFT )
#define IRQAMP_ITCNT_TCNT( _val ) \\
  ( ( _val ) << IRQAMP_ITCNT_TCNT_SHIFT )

/** @} */

/**
 * @defgroup IrqampTimestampITSTMPC \\
 *   Interrupt timestamp n control register (ITSTMPC)
 *
 * @brief This group contains register bit definitions.
 *
 * @{
 */

#define IRQAMP_ITSTMPC_TSTAMP_SHIFT 27
#define IRQAMP_ITSTMPC_TSTAMP_MASK 0xf8000000U
#define IRQAMP_ITSTMPC_TSTAMP_GET( _reg ) \\
  ( ( ( _reg ) & IRQAMP_ITSTMPC_TSTAMP_MASK ) >> IRQAMP_ITSTMPC_TSTAMP_SHIFT )
#define IRQAMP_ITSTMPC_TSTAMP( _val ) \\
  ( ( _val ) << IRQAMP_ITSTMPC_TSTAMP_SHIFT )

#define IRQAMP_ITSTMPC_S1 0x4000000U

#define IRQAMP_ITSTMPC_S2 0x2000000U

#define IRQAMP_ITSTMPC_KS 0x20U

#define IRQAMP_ITSTMPC_TSISEL_SHIFT 0
#define IRQAMP_ITSTMPC_TSISEL_MASK 0x1fU
#define IRQAMP_ITSTMPC_TSISEL_GET( _reg ) \\
  ( ( ( _reg ) & IRQAMP_ITSTMPC_TSISEL_MASK ) >> IRQAMP_ITSTMPC_TSISEL_SHIFT )
#define IRQAMP_ITSTMPC_TSISEL( _val ) \\
  ( ( _val ) << IRQAMP_ITSTMPC_TSISEL_SHIFT )

/** @} */

/**
 * @defgroup IrqampTimestampITSTMPAS \\
 *   Interrupt Assertion Timestamp n register (ITSTMPAS)
 *
 * @brief This group contains register bit definitions.
 *
 * @{
 */

#define IRQAMP_ITSTMPAS_TASSERTION_SHIFT 0
#define IRQAMP_ITSTMPAS_TASSERTION_MASK 0xffffffffU
#define IRQAMP_ITSTMPAS_TASSERTION_GET( _reg ) \\
  ( ( ( _reg ) & IRQAMP_ITSTMPAS_TASSERTION_MASK ) >> IRQAMP_ITSTMPAS_TASSERTION_SHIFT )
#define IRQAMP_ITSTMPAS_TASSERTION( _val ) \\
  ( ( _val ) << IRQAMP_ITSTMPAS_TASSERTION_SHIFT )

/** @} */

/**
 * @defgroup IrqampTimestampITSTMPAC \\
 *   Interrupt Acknowledge Timestamp n register (ITSTMPAC)
 *
 * @brief This group contains register bit definitions.
 *
 * @{
 */

#define IRQAMP_ITSTMPAC_TACKNOWLEDGE_SHIFT 0
#define IRQAMP_ITSTMPAC_TACKNOWLEDGE_MASK 0xffffffffU
#define IRQAMP_ITSTMPAC_TACKNOWLEDGE_GET( _reg ) \\
  ( ( ( _reg ) & IRQAMP_ITSTMPAC_TACKNOWLEDGE_MASK ) >> IRQAMP_ITSTMPAC_TACKNOWLEDGE_SHIFT )
#define IRQAMP_ITSTMPAC_TACKNOWLEDGE( _val ) \\
  ( ( _val ) << IRQAMP_ITSTMPAC_TACKNOWLEDGE_SHIFT )

/** @} */

/**
 * @brief This structure defines the IRQ(A)MP Timestamp register block memory
 *   map.
 */
typedef struct irqamp_timestamp {
  /**
   * @brief See @ref IrqampTimestampITCNT.
   */
  uint32_t itcnt;

  /**
   * @brief See @ref IrqampTimestampITSTMPC.
   */
  uint32_t itstmpc;

  /**
   * @brief See @ref IrqampTimestampITSTMPAS.
   */
  uint32_t itstmpas;

  /**
   * @brief See @ref IrqampTimestampITSTMPAC.
   */
  uint32_t itstmpac;
} irqamp_timestamp;

/** @} */

/* Generated from spec:/irqamp */

/**
 * @defgroup Irqamp IRQ(A)MP
 *
 * @brief This group contains the IRQ(A)MP interfaces.
 *
 * @{
 */

/**
 * @defgroup IrqampILEVEL Interrupt level register (ILEVEL)
 *
 * @brief This group contains register bit definitions.
 *
 * @{
 */

#define IRQAMP_ILEVEL_IL_15_1_SHIFT 1
#define IRQAMP_ILEVEL_IL_15_1_MASK 0xfffeU
#define IRQAMP_ILEVEL_IL_15_1_GET( _reg ) \\
  ( ( ( _reg ) & IRQAMP_ILEVEL_IL_15_1_MASK ) >> IRQAMP_ILEVEL_IL_15_1_SHIFT )
#define IRQAMP_ILEVEL_IL_15_1( _val ) \\
  ( ( _val ) << IRQAMP_ILEVEL_IL_15_1_SHIFT )

/** @} */

/**
 * @defgroup IrqampIPEND8 Interrupt pending register (IPEND8)
 *
 * @brief This group contains register bit definitions.
 *
 * @{
 */

/** @} */

/**
 * @brief This structure defines the IRQ(A)MP register block memory map.
 */
typedef struct irqamp {
  /**
   * @brief See @ref IrqampILEVEL.
   */
  uint32_t foobar_0;

  #if defined(RTEMS_SMP)
    /**
     * @brief See @ref IrqampIPEND8.
     */
    uint8_t ipend8_0[ 4 ];
  #else
    /**
     * @brief See @ref IrqampILEVEL.
     */
    uint32_t foobar_1;
  #endif

  uint8_t reserved_8_9;

  /**
   * @brief See @ref IrqampIPEND8.
   */
  uint8_t ipend8_1[ 4 ];

  uint8_t reserved_d_100[ 243 ];

  /**
   * @brief See @ref IrqampTimestamp.
   */
  irqamp_timestamp itstmp[ 16 ];

  uint32_t reserved_200_400[ 128 ];
} irqamp;

/** @} */

/* Generated from spec:/macro */

/**
 * @ingroup GroupB
 *
 * @brief Very long macro brief description.
 *
 * @param VeryLongParam0 is very long parameter 0 with some super important and
 *   extra very long description which makes a lot of sense.
 *
 * @param[in] VeryLongParam1 is very long parameter 1.
 *
 * @param[out] VeryLongParam2 is very long parameter 2.
 *
 * @param[in,out] VeryLongParam3 is very long parameter 3.
 *
 * @retval 1 is returned, in case A.
 *
 * @retval 2 is returned, in case B.
 *
 * @return Sometimes some value.
 */
#define VERY_LONG_MACRO( \\
  VeryLongParam0, \\
  VeryLongParam1, \\
  VeryLongParam2, \\
  VeryLongParam3 \\
) \\
  do { \\
    (void) VeryLongParam1; \\
    (void) VeryLongParam2; \\
    (void) VeryLongParam3; \\
  } while ( 0 ); \\
  VeryLongParam0 + 1;

/* Generated from spec:/macro2 */

/**
 * @ingroup GroupB
 *
 * @brief Short macro brief description.
 *
 * @param Param0 is parameter 0.
 *
 * @return Sometimes some value.
 */
#if 0
  #define MACRO( Param0 )
#else
  #define MACRO( Param0 ) ( ( Param0 ) + 1 )
#endif

/* Generated from spec:/register-block-no-size */

/**
 * @defgroup RBNS RBNS
 *
 * @brief This group contains the RBNS interfaces.
 *
 * @{
 */

/**
 * @defgroup RBNSR Brief. (R)
 *
 * @brief This group contains register bit definitions.
 *
 * @{
 */

/** @} */

/**
 * @name Registers
 *
 * @brief Brief.
 *
 * @{
 */

/**
 * @brief See @ref RBNSR.
 */
#define RBNS_R 0x0

/** @} */

/** @} */

/* Generated from spec:/s */

/**
 * @ingroup GroupC
 */
struct Struct {
  /**
   * @brief Brief union description.
   *
   * Union description.
   */
  union {
    /**
     * @brief Brief member description.
     *
     * Member description.
     */
    uint32_t some_member;

    /**
     * @brief Brief struct description.
     *
     * struct description.
     */
    struct {
      /**
       * @brief Brief member 2 description.
       *
       * Member 2 description.
       */
      uint32_t some_member_2;

      /**
       * @brief Brief member 3 description.
       *
       * Member 3 description.
       */
      Enum some_member_3;
    } some_struct;
  } some_union;

  /**
   * @brief Brief member 4 description.
   *
   * Member 4 description.
   */
  Enum some_member_4;
};

/* Generated from spec:/s2 */

/**
 * @ingroup GroupA
 *
 * References: Struct2
 *
 * @par Notes
 * Notes.
 *
 * @par Constraints
 * @parblock
 * The following constraints apply to this structure:
 *
 * * Some constraint.
 *
 * * Members of the type shall not be accessed directly by the application.
 * @endparblock
 */
typedef struct {
  /**
   * @brief Brief member description.
   *
   * Member description.
   */
  uint32_t member;
} Struct2;

/* Generated from spec:/td */

/**
 * @ingroup GroupB
 *
 * @brief Typedef Integer brief description.
 *
 * Typedef Integer description.
 */
typedef uint32_t Integer /* Some comment. */;

/* Generated from spec:/td3 */

/**
 * @ingroup GroupB
 */
#if defined(RTEMS_SMP)
  typedef uint32_t Integer3;
#endif

/* Generated from spec:/u */

/**
 * @ingroup GroupC
 */
typedef union Union {
  /**
   * @brief Brief member 0 description.
   */
  int m_0;

  /**
   * @brief Brief member 1 description.
   */
  long m_1;
} Union;

#if !defined(ASM)
  /* Generated from spec:/var */

  /**
   * @ingroup GroupC
   *
   * @brief Variable brief description.
   *
   * Variable description.
   */
  extern struct Struct *Variable;
#endif

/* Generated from spec:/func2 */

/**
 * @ingroup GroupB
 *
 * @brief Very long function brief description.
 *
 * @param VeryLongParam0 is very long parameter 0 with some super important and
 *   extra very long description which makes a lot of sense.
 *
 * @param[in] VeryLongParam1 is very long parameter 1.
 *
 * @param[out] VeryLongParam2 is very long parameter 2.
 *
 * @param[in,out] VeryLongParam3 is very long parameter 3.
 *
 * VeryLongFunction description.
 *
 * @retval 1 is returned, in case A.
 *
 * @retval 2 is returned, in case B.
 *
 * @retval #Enum is returned, in case C.
 *
 * @return Sometimes some value.  See Function().
 *
 * @par Notes
 * VeryLongFunction notes.
 */
__attribute__((__const__)) static inline int VeryLongFunction(
  int                  VeryLongParam0,
  const struct Struct *VeryLongParam1,
  Union            *( *VeryLongParam2 )( void ),
  struct Struct       *VeryLongParam3
)
{
  (void) VeryLongParam1;
  (void) VeryLongParam2;
  (void) VeryLongParam3;
  return VeryLongParam0 + 1;
}

#ifdef __cplusplus
}
#endif

#endif /* _H_H */
"""
        assert content == src.read()