source: rtems-central/rtemsspec/tests/test_interface.py @ 942e8b2

Last change on this file since 942e8b2 was 942e8b2, checked in by Sebastian Huber <sebastian.huber@…>, on 02/14/23 at 07:02:57

rtemsspec: Use @ref for appl config options

The application configuration options are documented in
"cpukit/doxygen/appl-config.h". Since the application configuration
option defines are also present in multiple test program sources, the
"#OPTION" references cannot be mapped to a unique definition. Add an
anchor for each option and reference it to avoid the issues with the
multiple definitions.

  • Property mode set to 100644
File size: 14.5 KB
Line 
1# SPDX-License-Identifier: BSD-2-Clause
2""" Unit tests for the rtemsspec.interface module. """
3
4# Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26
27import os
28import pytest
29
30from rtemsspec.interface import generate
31from rtemsspec.items import EmptyItemCache, ItemCache
32from rtemsspec.tests.util import create_item_cache_config_and_copy_spec
33
34
35def test_interface(tmpdir):
36    interface_config = {}
37    interface_config["item-level-interfaces"] = []
38    base_directory = os.path.join(tmpdir, "base")
39    interface_domains = {"/domain-abc": base_directory}
40    interface_config["domains"] = interface_domains
41    interface_config["enabled"] = []
42
43    generate(interface_config, EmptyItemCache())
44
45    interface_config["item-level-interfaces"] = ["/command-line"]
46
47    item_cache_config = create_item_cache_config_and_copy_spec(
48        tmpdir, "spec-interface", with_spec_types=True)
49    generate(interface_config, ItemCache(item_cache_config))
50
51    with open(os.path.join(base_directory, "include", "h.h"), "r") as src:
52        content = """/* SPDX-License-Identifier: BSD-2-Clause */
53
54/**
55 * @file
56 *
57 * @ingroup GroupA
58 * @ingroup GroupB
59 * @ingroup GroupC
60 *
61 * @brief This header file defines X.
62 */
63
64/*
65 * Copyright (C) 2020, 2022 embedded brains GmbH (http://www.embedded-brains.de)
66 *
67 * Redistribution and use in source and binary forms, with or without
68 * modification, are permitted provided that the following conditions
69 * are met:
70 * 1. Redistributions of source code must retain the above copyright
71 *    notice, this list of conditions and the following disclaimer.
72 * 2. Redistributions in binary form must reproduce the above copyright
73 *    notice, this list of conditions and the following disclaimer in the
74 *    documentation and/or other materials provided with the distribution.
75 *
76 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
77 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
78 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
79 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
80 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
81 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
82 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
83 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
84 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
85 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
86 * POSSIBILITY OF SUCH DAMAGE.
87 */
88
89/*
90 * This file is part of the RTEMS quality process and was automatically
91 * generated.  If you find something that needs to be fixed or
92 * worded better please post a report or patch to an RTEMS mailing list
93 * or raise a bug report:
94 *
95 * https://www.rtems.org/bugs.html
96 *
97 * For information on updating and regenerating please refer to the How-To
98 * section in the Software Requirements Engineering chapter of the
99 * RTEMS Software Engineering manual.  The manual is provided as a part of
100 * a release.  For development sources please refer to the online
101 * documentation at:
102 *
103 * https://docs.rtems.org
104 */
105
106/* Generated from spec:/h */
107
108#ifndef _H_H
109#define _H_H
110
111#include <h3.h>
112#include <math.h>
113#include <stdint.h>
114
115#if !defined(ASM) && defined(RTEMS_SMP)
116  #include <h2.h>
117#endif
118
119#if defined(ASM) && defined(RTEMS_SMP)
120  #include <h4.h>
121#endif
122
123#ifdef __cplusplus
124extern "C" {
125#endif
126
127/* Generated from spec:/ga */
128
129/**
130 * @defgroup GroupA Group A
131 *
132 * @brief Group A brief description.
133 *
134 * Group A description.
135 */
136
137/* Generated from spec:/gb */
138
139/**
140 * @defgroup GroupB Group B
141 *
142 * @ingroup GroupA
143 */
144
145/* Generated from spec:/define */
146
147/**
148 * @ingroup GroupA
149 */
150#if defined(A) || (B > C)
151  #define DEFINE ((float_t) 456)
152#elif defined(C) && defined(D)
153  #define DEFINE ((float_t) 789)
154#else
155  #define DEFINE \\
156    ((float_t) 123)
157#endif
158
159/* Generated from spec:/enum */
160
161/**
162 * @ingroup GroupB
163 *
164 * @brief Enum brief description.
165 *
166 * Enum description.
167 */
168typedef enum {
169  /**
170   * @brief Enumerator 0 brief description.
171   */
172  ENUMERATOR_0,
173
174  /**
175   * @brief Enumerator 1 brief description.
176   */
177  ENUMERATOR_1,
178
179  /**
180   * @brief Enumerator 2 brief description.
181   */
182  ENUMERATOR_2
183} Enum;
184
185/* Generated from spec:/enum3 */
186
187/**
188 * @ingroup GroupB
189 *
190 * @brief Enum B brief description.
191 */
192typedef enum EnumB {
193  /**
194   * @brief Enumerator B brief description.
195   */
196  ENUMERATOR_B = ENUMERATOR_A
197} EnumB;
198
199/* Generated from spec:/forward-decl */
200
201/* Forward declaration */
202struct Struct;
203
204/* Generated from spec:/func */
205
206/**
207 * @ingroup GroupA
208 *
209 * @brief Function brief description.
210 *
211 * @param Param0 is parameter 0.
212 *
213 * @param[in] Param1 is parameter 1.
214 *
215 * @param[out] Param2 is parameter 2.
216 *
217 * @param[in,out] Param3 is parameter 3.
218 *
219 * Function description.  References to xs, VeryLongFunction(), ::Integer,
220 * #Enum, #DEFINE, VERY_LONG_MACRO(), #Variable, ::ENUMERATOR_0, Struct, @ref
221 * a, interface, @ref GroupA, and @ref GroupF.  Second parameter is ``Param1``.
222 *
223 * @code
224 * these two lines
225 * are not wrapped
226 * @endcode
227 *
228 * @par Constraints
229 * @parblock
230 * The following constraints apply to this directive:
231 *
232 * * Constraint A for Function().
233 * @endparblock
234 */
235void Function(
236  int        Param0,
237  const int *Param1,
238  int       *Param2,
239  int       *Param3,
240  int       *Param4
241);
242
243/* Generated from spec:/func6 */
244void Function6( int Param0 );
245
246/* Generated from spec:/irqamp-timestamp */
247
248/**
249 * @defgroup IrqampTimestamp IRQ(A)MP Timestamp
250 *
251 * @brief This group contains the IRQ(A)MP Timestamp interfaces.
252 *
253 * @{
254 */
255
256/**
257 * @defgroup IrqampTimestampITCNT \\
258 *   Interrupt timestamp counter n register (ITCNT)
259 *
260 * @brief This group contains register bit definitions.
261 *
262 * @{
263 */
264
265#define IRQAMP_ITCNT_TCNT_SHIFT 0
266#define IRQAMP_ITCNT_TCNT_MASK 0xffffffffU
267#define IRQAMP_ITCNT_TCNT_GET( _reg ) \\
268  ( ( ( _reg ) >> 0 ) & 0xffffffffU )
269#define IRQAMP_ITCNT_TCNT( _val ) ( ( _val ) << 0 )
270
271/** @} */
272
273/**
274 * @defgroup IrqampTimestampITSTMPC \\
275 *   Interrupt timestamp n control register (ITSTMPC)
276 *
277 * @brief This group contains register bit definitions.
278 *
279 * @{
280 */
281
282#define IRQAMP_ITSTMPC_TSTAMP_SHIFT 27
283#define IRQAMP_ITSTMPC_TSTAMP_MASK 0xf8000000U
284#define IRQAMP_ITSTMPC_TSTAMP_GET( _reg ) \\
285  ( ( ( _reg ) >> 27 ) & 0x1fU )
286#define IRQAMP_ITSTMPC_TSTAMP( _val ) ( ( _val ) << 27 )
287
288#define IRQAMP_ITSTMPC_S1 0x4000000U
289
290#define IRQAMP_ITSTMPC_S2 0x2000000U
291
292#define IRQAMP_ITSTMPC_KS 0x20U
293
294#define IRQAMP_ITSTMPC_TSISEL_SHIFT 0
295#define IRQAMP_ITSTMPC_TSISEL_MASK 0x1fU
296#define IRQAMP_ITSTMPC_TSISEL_GET( _reg ) \\
297  ( ( ( _reg ) >> 0 ) & 0x1fU )
298#define IRQAMP_ITSTMPC_TSISEL( _val ) ( ( _val ) << 0 )
299
300/** @} */
301
302/**
303 * @defgroup IrqampTimestampITSTMPAS \\
304 *   Interrupt Assertion Timestamp n register (ITSTMPAS)
305 *
306 * @brief This group contains register bit definitions.
307 *
308 * @{
309 */
310
311#define IRQAMP_ITSTMPAS_TASSERTION_SHIFT 0
312#define IRQAMP_ITSTMPAS_TASSERTION_MASK 0xffffffffU
313#define IRQAMP_ITSTMPAS_TASSERTION_GET( _reg ) \\
314  ( ( ( _reg ) >> 0 ) & 0xffffffffU )
315#define IRQAMP_ITSTMPAS_TASSERTION( _val ) ( ( _val ) << 0 )
316
317/** @} */
318
319/**
320 * @defgroup IrqampTimestampITSTMPAC \\
321 *   Interrupt Acknowledge Timestamp n register (ITSTMPAC)
322 *
323 * @brief This group contains register bit definitions.
324 *
325 * @{
326 */
327
328#define IRQAMP_ITSTMPAC_TACKNOWLEDGE_SHIFT 0
329#define IRQAMP_ITSTMPAC_TACKNOWLEDGE_MASK 0xffffffffU
330#define IRQAMP_ITSTMPAC_TACKNOWLEDGE_GET( _reg ) \\
331  ( ( ( _reg ) >> 0 ) & 0xffffffffU )
332#define IRQAMP_ITSTMPAC_TACKNOWLEDGE( _val ) ( ( _val ) << 0 )
333
334/** @} */
335
336/**
337 * @brief This structure defines the IRQ(A)MP Timestamp register block memory
338 *   map.
339 */
340typedef struct irqamp_timestamp {
341  /**
342   * @brief See @ref IrqampTimestampITCNT.
343   */
344  uint32_t itcnt;
345
346  /**
347   * @brief See @ref IrqampTimestampITSTMPC.
348   */
349  uint32_t itstmpc;
350
351  /**
352   * @brief See @ref IrqampTimestampITSTMPAS.
353   */
354  uint32_t itstmpas;
355
356  /**
357   * @brief See @ref IrqampTimestampITSTMPAC.
358   */
359  uint32_t itstmpac;
360} irqamp_timestamp;
361
362/** @} */
363
364/* Generated from spec:/irqamp */
365
366/**
367 * @defgroup Irqamp IRQ(A)MP
368 *
369 * @brief This group contains the IRQ(A)MP interfaces.
370 *
371 * @{
372 */
373
374/**
375 * @defgroup IrqampILEVEL Interrupt level register (ILEVEL)
376 *
377 * @brief This group contains register bit definitions.
378 *
379 * @{
380 */
381
382#define IRQAMP_ILEVEL_IL_15_1_SHIFT 1
383#define IRQAMP_ILEVEL_IL_15_1_MASK 0xfffeU
384#define IRQAMP_ILEVEL_IL_15_1_GET( _reg ) \\
385  ( ( ( _reg ) >> 1 ) & 0x7fffU )
386#define IRQAMP_ILEVEL_IL_15_1( _val ) ( ( _val ) << 1 )
387
388/** @} */
389
390/**
391 * @defgroup IrqampIPEND8 Interrupt pending register (IPEND8)
392 *
393 * @brief This group contains register bit definitions.
394 *
395 * @{
396 */
397
398/** @} */
399
400/**
401 * @brief This structure defines the IRQ(A)MP register block memory map.
402 */
403typedef struct irqamp {
404  /**
405   * @brief See @ref IrqampILEVEL.
406   */
407  uint32_t foobar_0;
408
409  #if defined(RTEMS_SMP)
410    /**
411     * @brief See @ref IrqampIPEND8.
412     */
413    uint8_t ipend8_0[ 4 ];
414  #else
415    /**
416     * @brief See @ref IrqampILEVEL.
417     */
418    uint32_t foobar_1;
419  #endif
420
421  uint8_t reserved_8_9;
422
423  /**
424   * @brief See @ref IrqampIPEND8.
425   */
426  uint8_t ipend8_1[ 4 ];
427
428  uint8_t reserved_d_100[ 243 ];
429
430  /**
431   * @brief See @ref IrqampTimestamp.
432   */
433  irqamp_timestamp itstmp[ 16 ];
434
435  uint32_t reserved_200_400[ 128 ];
436} irqamp;
437
438/** @} */
439
440/* Generated from spec:/macro */
441
442/**
443 * @ingroup GroupB
444 *
445 * @brief Very long macro brief description.
446 *
447 * @param VeryLongParam0 is very long parameter 0 with some super important and
448 *   extra very long description which makes a lot of sense.
449 *
450 * @param[in] VeryLongParam1 is very long parameter 1.
451 *
452 * @param[out] VeryLongParam2 is very long parameter 2.
453 *
454 * @param[in,out] VeryLongParam3 is very long parameter 3.
455 *
456 * @retval 1 is returned, in case A.
457 *
458 * @retval 2 is returned, in case B.
459 *
460 * @return Sometimes some value.
461 */
462#define VERY_LONG_MACRO( \\
463  VeryLongParam0, \\
464  VeryLongParam1, \\
465  VeryLongParam2, \\
466  VeryLongParam3 \\
467) \\
468  do { \\
469    (void) VeryLongParam1; \\
470    (void) VeryLongParam2; \\
471    (void) VeryLongParam3; \\
472  } while ( 0 ); \\
473  VeryLongParam0 + 1;
474
475/* Generated from spec:/macro2 */
476
477/**
478 * @ingroup GroupB
479 *
480 * @brief Short macro brief description.
481 *
482 * @param Param0 is parameter 0.
483 *
484 * @return Sometimes some value.
485 */
486#if 0
487  #define MACRO( Param0 )
488#else
489  #define MACRO( Param0 ) ( ( Param0 ) + 1 )
490#endif
491
492/* Generated from spec:/register-block-no-size */
493
494/**
495 * @defgroup RBNS RBNS
496 *
497 * @brief This group contains the RBNS interfaces.
498 *
499 * @{
500 */
501
502/**
503 * @defgroup RBNSR Brief. (R)
504 *
505 * @brief This group contains register bit definitions.
506 *
507 * @{
508 */
509
510/** @} */
511
512/**
513 * @name Registers
514 *
515 * @brief Brief.
516 *
517 * @{
518 */
519
520/**
521 * @brief See @ref RBNSR.
522 */
523#define RBNS_R 0x0
524
525/** @} */
526
527/** @} */
528
529/* Generated from spec:/s */
530
531/**
532 * @ingroup GroupC
533 */
534struct Struct {
535  /**
536   * @brief Brief union description.
537   *
538   * Union description.
539   */
540  union {
541    /**
542     * @brief Brief member description.
543     *
544     * Member description.
545     */
546    uint32_t some_member;
547
548    /**
549     * @brief Brief struct description.
550     *
551     * struct description.
552     */
553    struct {
554      /**
555       * @brief Brief member 2 description.
556       *
557       * Member 2 description.
558       */
559      uint32_t some_member_2;
560
561      /**
562       * @brief Brief member 3 description.
563       *
564       * Member 3 description.
565       */
566      Enum some_member_3;
567    } some_struct;
568  } some_union;
569
570  /**
571   * @brief Brief member 4 description.
572   *
573   * Member 4 description.
574   */
575  Enum some_member_4;
576};
577
578/* Generated from spec:/td */
579
580/**
581 * @ingroup GroupB
582 *
583 * @brief Typedef Integer brief description.
584 *
585 * Typedef Integer description.
586 */
587typedef uint32_t Integer /* Some comment. */;
588
589/* Generated from spec:/td3 */
590
591/**
592 * @ingroup GroupB
593 */
594#if defined(RTEMS_SMP)
595  typedef uint32_t Integer3;
596#endif
597
598/* Generated from spec:/u */
599
600/**
601 * @ingroup GroupC
602 */
603typedef union Union {
604  /**
605   * @brief Brief member 0 description.
606   */
607  int m_0;
608
609  /**
610   * @brief Brief member 1 description.
611   */
612  long m_1;
613} Union;
614
615#if !defined(ASM)
616  /* Generated from spec:/var */
617
618  /**
619   * @ingroup GroupC
620   *
621   * @brief Variable brief description.
622   *
623   * Variable description.
624   */
625  extern struct Struct *Variable;
626#endif
627
628/* Generated from spec:/func2 */
629
630/**
631 * @ingroup GroupB
632 *
633 * @brief Very long function brief description.
634 *
635 * @param VeryLongParam0 is very long parameter 0 with some super important and
636 *   extra very long description which makes a lot of sense.
637 *
638 * @param[in] VeryLongParam1 is very long parameter 1.
639 *
640 * @param[out] VeryLongParam2 is very long parameter 2.
641 *
642 * @param[in,out] VeryLongParam3 is very long parameter 3.
643 *
644 * VeryLongFunction description.
645 *
646 * @retval 1 is returned, in case A.
647 *
648 * @retval 2 is returned, in case B.
649 *
650 * @retval #Enum is returned, in case C.
651 *
652 * @return Sometimes some value.  See Function().
653 *
654 * @par Notes
655 * VeryLongFunction notes.
656 */
657__attribute__((__const__)) static inline int VeryLongFunction(
658  int                  VeryLongParam0,
659  const struct Struct *VeryLongParam1,
660  Union            *( *VeryLongParam2 )( void ),
661  struct Struct       *VeryLongParam3
662)
663{
664  (void) VeryLongParam1;
665  (void) VeryLongParam2;
666  (void) VeryLongParam3;
667  return VeryLongParam0 + 1;
668}
669
670#ifdef __cplusplus
671}
672#endif
673
674#endif /* _H_H */
675"""
676        assert content == src.read()
Note: See TracBrowser for help on using the repository browser.