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

Last change on this file since ea3eadf was ea3eadf, checked in by Sebastian Huber <sebastian.huber@…>, on 03/15/23 at 07:39:35

interface: Improve register bit field macros

Update #4828.

  • Property mode set to 100644
File size: 15.0 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 ) & IRQAMP_ITCNT_TCNT_MASK ) >> IRQAMP_ITCNT_TCNT_SHIFT )
269#define IRQAMP_ITCNT_TCNT( _val ) \\
270  ( ( _val ) << IRQAMP_ITCNT_TCNT_SHIFT )
271
272/** @} */
273
274/**
275 * @defgroup IrqampTimestampITSTMPC \\
276 *   Interrupt timestamp n control register (ITSTMPC)
277 *
278 * @brief This group contains register bit definitions.
279 *
280 * @{
281 */
282
283#define IRQAMP_ITSTMPC_TSTAMP_SHIFT 27
284#define IRQAMP_ITSTMPC_TSTAMP_MASK 0xf8000000U
285#define IRQAMP_ITSTMPC_TSTAMP_GET( _reg ) \\
286  ( ( ( _reg ) & IRQAMP_ITSTMPC_TSTAMP_MASK ) >> IRQAMP_ITSTMPC_TSTAMP_SHIFT )
287#define IRQAMP_ITSTMPC_TSTAMP( _val ) \\
288  ( ( _val ) << IRQAMP_ITSTMPC_TSTAMP_SHIFT )
289
290#define IRQAMP_ITSTMPC_S1 0x4000000U
291
292#define IRQAMP_ITSTMPC_S2 0x2000000U
293
294#define IRQAMP_ITSTMPC_KS 0x20U
295
296#define IRQAMP_ITSTMPC_TSISEL_SHIFT 0
297#define IRQAMP_ITSTMPC_TSISEL_MASK 0x1fU
298#define IRQAMP_ITSTMPC_TSISEL_GET( _reg ) \\
299  ( ( ( _reg ) & IRQAMP_ITSTMPC_TSISEL_MASK ) >> IRQAMP_ITSTMPC_TSISEL_SHIFT )
300#define IRQAMP_ITSTMPC_TSISEL( _val ) \\
301  ( ( _val ) << IRQAMP_ITSTMPC_TSISEL_SHIFT )
302
303/** @} */
304
305/**
306 * @defgroup IrqampTimestampITSTMPAS \\
307 *   Interrupt Assertion Timestamp n register (ITSTMPAS)
308 *
309 * @brief This group contains register bit definitions.
310 *
311 * @{
312 */
313
314#define IRQAMP_ITSTMPAS_TASSERTION_SHIFT 0
315#define IRQAMP_ITSTMPAS_TASSERTION_MASK 0xffffffffU
316#define IRQAMP_ITSTMPAS_TASSERTION_GET( _reg ) \\
317  ( ( ( _reg ) & IRQAMP_ITSTMPAS_TASSERTION_MASK ) >> IRQAMP_ITSTMPAS_TASSERTION_SHIFT )
318#define IRQAMP_ITSTMPAS_TASSERTION( _val ) \\
319  ( ( _val ) << IRQAMP_ITSTMPAS_TASSERTION_SHIFT )
320
321/** @} */
322
323/**
324 * @defgroup IrqampTimestampITSTMPAC \\
325 *   Interrupt Acknowledge Timestamp n register (ITSTMPAC)
326 *
327 * @brief This group contains register bit definitions.
328 *
329 * @{
330 */
331
332#define IRQAMP_ITSTMPAC_TACKNOWLEDGE_SHIFT 0
333#define IRQAMP_ITSTMPAC_TACKNOWLEDGE_MASK 0xffffffffU
334#define IRQAMP_ITSTMPAC_TACKNOWLEDGE_GET( _reg ) \\
335  ( ( ( _reg ) & IRQAMP_ITSTMPAC_TACKNOWLEDGE_MASK ) >> IRQAMP_ITSTMPAC_TACKNOWLEDGE_SHIFT )
336#define IRQAMP_ITSTMPAC_TACKNOWLEDGE( _val ) \\
337  ( ( _val ) << IRQAMP_ITSTMPAC_TACKNOWLEDGE_SHIFT )
338
339/** @} */
340
341/**
342 * @brief This structure defines the IRQ(A)MP Timestamp register block memory
343 *   map.
344 */
345typedef struct irqamp_timestamp {
346  /**
347   * @brief See @ref IrqampTimestampITCNT.
348   */
349  uint32_t itcnt;
350
351  /**
352   * @brief See @ref IrqampTimestampITSTMPC.
353   */
354  uint32_t itstmpc;
355
356  /**
357   * @brief See @ref IrqampTimestampITSTMPAS.
358   */
359  uint32_t itstmpas;
360
361  /**
362   * @brief See @ref IrqampTimestampITSTMPAC.
363   */
364  uint32_t itstmpac;
365} irqamp_timestamp;
366
367/** @} */
368
369/* Generated from spec:/irqamp */
370
371/**
372 * @defgroup Irqamp IRQ(A)MP
373 *
374 * @brief This group contains the IRQ(A)MP interfaces.
375 *
376 * @{
377 */
378
379/**
380 * @defgroup IrqampILEVEL Interrupt level register (ILEVEL)
381 *
382 * @brief This group contains register bit definitions.
383 *
384 * @{
385 */
386
387#define IRQAMP_ILEVEL_IL_15_1_SHIFT 1
388#define IRQAMP_ILEVEL_IL_15_1_MASK 0xfffeU
389#define IRQAMP_ILEVEL_IL_15_1_GET( _reg ) \\
390  ( ( ( _reg ) & IRQAMP_ILEVEL_IL_15_1_MASK ) >> IRQAMP_ILEVEL_IL_15_1_SHIFT )
391#define IRQAMP_ILEVEL_IL_15_1( _val ) \\
392  ( ( _val ) << IRQAMP_ILEVEL_IL_15_1_SHIFT )
393
394/** @} */
395
396/**
397 * @defgroup IrqampIPEND8 Interrupt pending register (IPEND8)
398 *
399 * @brief This group contains register bit definitions.
400 *
401 * @{
402 */
403
404/** @} */
405
406/**
407 * @brief This structure defines the IRQ(A)MP register block memory map.
408 */
409typedef struct irqamp {
410  /**
411   * @brief See @ref IrqampILEVEL.
412   */
413  uint32_t foobar_0;
414
415  #if defined(RTEMS_SMP)
416    /**
417     * @brief See @ref IrqampIPEND8.
418     */
419    uint8_t ipend8_0[ 4 ];
420  #else
421    /**
422     * @brief See @ref IrqampILEVEL.
423     */
424    uint32_t foobar_1;
425  #endif
426
427  uint8_t reserved_8_9;
428
429  /**
430   * @brief See @ref IrqampIPEND8.
431   */
432  uint8_t ipend8_1[ 4 ];
433
434  uint8_t reserved_d_100[ 243 ];
435
436  /**
437   * @brief See @ref IrqampTimestamp.
438   */
439  irqamp_timestamp itstmp[ 16 ];
440
441  uint32_t reserved_200_400[ 128 ];
442} irqamp;
443
444/** @} */
445
446/* Generated from spec:/macro */
447
448/**
449 * @ingroup GroupB
450 *
451 * @brief Very long macro brief description.
452 *
453 * @param VeryLongParam0 is very long parameter 0 with some super important and
454 *   extra very long description which makes a lot of sense.
455 *
456 * @param[in] VeryLongParam1 is very long parameter 1.
457 *
458 * @param[out] VeryLongParam2 is very long parameter 2.
459 *
460 * @param[in,out] VeryLongParam3 is very long parameter 3.
461 *
462 * @retval 1 is returned, in case A.
463 *
464 * @retval 2 is returned, in case B.
465 *
466 * @return Sometimes some value.
467 */
468#define VERY_LONG_MACRO( \\
469  VeryLongParam0, \\
470  VeryLongParam1, \\
471  VeryLongParam2, \\
472  VeryLongParam3 \\
473) \\
474  do { \\
475    (void) VeryLongParam1; \\
476    (void) VeryLongParam2; \\
477    (void) VeryLongParam3; \\
478  } while ( 0 ); \\
479  VeryLongParam0 + 1;
480
481/* Generated from spec:/macro2 */
482
483/**
484 * @ingroup GroupB
485 *
486 * @brief Short macro brief description.
487 *
488 * @param Param0 is parameter 0.
489 *
490 * @return Sometimes some value.
491 */
492#if 0
493  #define MACRO( Param0 )
494#else
495  #define MACRO( Param0 ) ( ( Param0 ) + 1 )
496#endif
497
498/* Generated from spec:/register-block-no-size */
499
500/**
501 * @defgroup RBNS RBNS
502 *
503 * @brief This group contains the RBNS interfaces.
504 *
505 * @{
506 */
507
508/**
509 * @defgroup RBNSR Brief. (R)
510 *
511 * @brief This group contains register bit definitions.
512 *
513 * @{
514 */
515
516/** @} */
517
518/**
519 * @name Registers
520 *
521 * @brief Brief.
522 *
523 * @{
524 */
525
526/**
527 * @brief See @ref RBNSR.
528 */
529#define RBNS_R 0x0
530
531/** @} */
532
533/** @} */
534
535/* Generated from spec:/s */
536
537/**
538 * @ingroup GroupC
539 */
540struct Struct {
541  /**
542   * @brief Brief union description.
543   *
544   * Union description.
545   */
546  union {
547    /**
548     * @brief Brief member description.
549     *
550     * Member description.
551     */
552    uint32_t some_member;
553
554    /**
555     * @brief Brief struct description.
556     *
557     * struct description.
558     */
559    struct {
560      /**
561       * @brief Brief member 2 description.
562       *
563       * Member 2 description.
564       */
565      uint32_t some_member_2;
566
567      /**
568       * @brief Brief member 3 description.
569       *
570       * Member 3 description.
571       */
572      Enum some_member_3;
573    } some_struct;
574  } some_union;
575
576  /**
577   * @brief Brief member 4 description.
578   *
579   * Member 4 description.
580   */
581  Enum some_member_4;
582};
583
584/* Generated from spec:/td */
585
586/**
587 * @ingroup GroupB
588 *
589 * @brief Typedef Integer brief description.
590 *
591 * Typedef Integer description.
592 */
593typedef uint32_t Integer /* Some comment. */;
594
595/* Generated from spec:/td3 */
596
597/**
598 * @ingroup GroupB
599 */
600#if defined(RTEMS_SMP)
601  typedef uint32_t Integer3;
602#endif
603
604/* Generated from spec:/u */
605
606/**
607 * @ingroup GroupC
608 */
609typedef union Union {
610  /**
611   * @brief Brief member 0 description.
612   */
613  int m_0;
614
615  /**
616   * @brief Brief member 1 description.
617   */
618  long m_1;
619} Union;
620
621#if !defined(ASM)
622  /* Generated from spec:/var */
623
624  /**
625   * @ingroup GroupC
626   *
627   * @brief Variable brief description.
628   *
629   * Variable description.
630   */
631  extern struct Struct *Variable;
632#endif
633
634/* Generated from spec:/func2 */
635
636/**
637 * @ingroup GroupB
638 *
639 * @brief Very long function brief description.
640 *
641 * @param VeryLongParam0 is very long parameter 0 with some super important and
642 *   extra very long description which makes a lot of sense.
643 *
644 * @param[in] VeryLongParam1 is very long parameter 1.
645 *
646 * @param[out] VeryLongParam2 is very long parameter 2.
647 *
648 * @param[in,out] VeryLongParam3 is very long parameter 3.
649 *
650 * VeryLongFunction description.
651 *
652 * @retval 1 is returned, in case A.
653 *
654 * @retval 2 is returned, in case B.
655 *
656 * @retval #Enum is returned, in case C.
657 *
658 * @return Sometimes some value.  See Function().
659 *
660 * @par Notes
661 * VeryLongFunction notes.
662 */
663__attribute__((__const__)) static inline int VeryLongFunction(
664  int                  VeryLongParam0,
665  const struct Struct *VeryLongParam1,
666  Union            *( *VeryLongParam2 )( void ),
667  struct Struct       *VeryLongParam3
668)
669{
670  (void) VeryLongParam1;
671  (void) VeryLongParam2;
672  (void) VeryLongParam3;
673  return VeryLongParam0 + 1;
674}
675
676#ifdef __cplusplus
677}
678#endif
679
680#endif /* _H_H */
681"""
682        assert content == src.read()
Note: See TracBrowser for help on using the repository browser.