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

Last change on this file since dd5659a was dd5659a, checked in by Sebastian Huber <sebastian.huber@…>, on 11/11/20 at 07:11:02

content: Improve automatically generated warning

  • Property mode set to 100644
File size: 9.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
42    generate(interface_config, EmptyItemCache())
43
44    interface_config["item-level-interfaces"] = ["/command-line"]
45
46    item_cache_config = create_item_cache_config_and_copy_spec(
47        tmpdir, "spec-interface", with_spec_types=True)
48    generate(interface_config, ItemCache(item_cache_config))
49
50    with open(os.path.join(base_directory, "include", "h.h"), "r") as src:
51        content = """/* SPDX-License-Identifier: BSD-2-Clause */
52
53/**
54 * @file
55 *
56 * @ingroup GroupA
57 * @ingroup GroupB
58 * @ingroup GroupC
59 *
60 * @brief This header file defines X.
61 */
62
63/*
64 * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
65 *
66 * Redistribution and use in source and binary forms, with or without
67 * modification, are permitted provided that the following conditions
68 * are met:
69 * 1. Redistributions of source code must retain the above copyright
70 *    notice, this list of conditions and the following disclaimer.
71 * 2. Redistributions in binary form must reproduce the above copyright
72 *    notice, this list of conditions and the following disclaimer in the
73 *    documentation and/or other materials provided with the distribution.
74 *
75 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
76 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
77 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
78 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
79 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
80 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
81 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
82 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
83 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
84 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
85 * POSSIBILITY OF SUCH DAMAGE.
86 */
87
88/*
89 * This file is part of the RTEMS quality process and was automatically
90 * generated.  If you find something that needs to be fixed or
91 * worded better please post a report or patch to an RTEMS mailing list
92 * or raise a bug report:
93 *
94 * https://docs.rtems.org/branches/master/user/support/bugs.html
95 *
96 * For information on updating and regenerating please refer to:
97 *
98 * https://docs.rtems.org/branches/master/eng/req/howto.html
99 */
100
101/* Generated from spec:/h */
102
103#ifndef _H_H
104#define _H_H
105
106#include <h3.h>
107#include <math.h>
108#include <stdint.h>
109
110#if !defined(ASM) && defined(RTEMS_SMP)
111  #include <h2.h>
112#endif
113
114#if defined(ASM) && defined(RTEMS_SMP)
115  #include <h4.h>
116#endif
117
118#ifdef __cplusplus
119extern "C" {
120#endif
121
122/* Generated from spec:/ga */
123
124/**
125 * @defgroup GroupA Group A
126 *
127 * @brief Group A brief description.
128 *
129 * Group A description.
130 */
131
132/* Generated from spec:/gb */
133
134/**
135 * @defgroup GroupB Group B
136 *
137 * @ingroup GroupA
138 */
139
140/* Generated from spec:/define */
141
142/**
143 * @ingroup GroupA
144 */
145#if defined(A) || (B > C)
146  #define DEFINE ((float_t) 456)
147#elif defined(C) && defined(D)
148  #define DEFINE ((float_t) 789)
149#else
150  #define DEFINE \\
151    ((float_t) 123)
152#endif
153
154/* Generated from spec:/forward-decl */
155
156/* Forward declaration */
157struct Struct;
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:/func */
200
201/**
202 * @ingroup GroupA
203 *
204 * @brief Function brief description.
205 *
206 * Function description.  References to VeryLongFunction(), ::Integer, #Enum,
207 * #DEFINE, VERY_LONG_MACRO(), #Variable, ::ENUMERATOR_0, Struct, #a, and
208 * interface.
209 *
210 * @param Param0 is parameter 0.
211 *
212 * @param[in] Param1 is parameter 1.
213 *
214 * @param[out] Param2 is parameter 2.
215 *
216 * @param[in,out] Param3 is parameter 3.
217 */
218void Function( int Param0, const int *Param1, int *Param2, int *Param3 );
219
220/* Generated from spec:/macro */
221
222/**
223 * @ingroup GroupB
224 *
225 * @brief Very long macro brief description.
226 *
227 * @param VeryLongParam0 is very long parameter 0 with some super important and
228 *   extra very long description which makes a lot of sense.
229 *
230 * @param[in] VeryLongParam1 is very long parameter 1.
231 *
232 * @param[out] VeryLongParam2 is very long parameter 2.
233 *
234 * @param[in,out] VeryLongParam3 is very long parameter 3.
235 *
236 * @retval 1 is returned, in case A.
237 *
238 * @retval 2 is returned, in case B.
239 *
240 * @return Sometimes some value.
241 */
242#define VERY_LONG_MACRO( \\
243  VeryLongParam0, \\
244  VeryLongParam1, \\
245  VeryLongParam2, \\
246  VeryLongParam3 \\
247) \\
248  do { \\
249    (void) VeryLongParam1; \\
250    (void) VeryLongParam2; \\
251    (void) VeryLongParam3; \\
252  } while ( 0 ); \\
253  VeryLongParam0 + 1;
254
255/* Generated from spec:/macro2 */
256
257/**
258 * @ingroup GroupB
259 *
260 * @brief Short macro brief description.
261 *
262 * @param Param0 is parameter 0.
263 *
264 * @return Sometimes some value.
265 */
266#if 0
267  #define MACRO( Param0 )
268#else
269  #define MACRO( Param0 ) ( ( Param0 ) + 1 )
270#endif
271
272/* Generated from spec:/s */
273
274/**
275 * @ingroup GroupC
276 */
277struct Struct {
278  /**
279   * @brief Brief union description.
280   *
281   * Union description.
282   */
283  union {
284    /**
285     * @brief Brief member description.
286     *
287     * Member description.
288     */
289    uint32_t some_member;
290
291    /**
292     * @brief Brief struct description.
293     *
294     * struct description.
295     */
296    struct {
297      /**
298       * @brief Brief member 2 description.
299       *
300       * Member 2 description.
301       */
302      uint32_t some_member_2;
303
304      /**
305       * @brief Brief member 3 description.
306       *
307       * Member 3 description.
308       */
309      Enum some_member_3;
310    } some_struct;
311  } some_union;
312
313  /**
314   * @brief Brief member 4 description.
315   *
316   * Member 4 description.
317   */
318  Enum some_member_4;
319};
320
321/* Generated from spec:/td */
322
323/**
324 * @ingroup GroupB
325 *
326 * @brief Typedef Integer brief description.
327 *
328 * Typedef Integer description.
329 */
330typedef uint32_t Integer /* Some comment. */;
331
332/* Generated from spec:/td3 */
333
334/**
335 * @ingroup GroupB
336 */
337#if defined(RTEMS_SMP)
338  typedef uint32_t Integer3;
339#endif
340
341#if !defined(ASM)
342  /* Generated from spec:/var */
343
344  /**
345   * @ingroup GroupC
346   *
347   * @brief Variable brief description.
348   *
349   * Variable description.
350   */
351  extern struct Struct *Variable;
352#endif
353
354/* Generated from spec:/func2 */
355
356/**
357 * @ingroup GroupB
358 *
359 * @brief Very long function brief description.
360 *
361 * VeryLongFunction description.
362 *
363 * VeryLongFunction notes.
364 *
365 * @param VeryLongParam0 is very long parameter 0 with some super important and
366 *   extra very long description which makes a lot of sense.
367 *
368 * @param[in] VeryLongParam1 is very long parameter 1.
369 *
370 * @param[out] VeryLongParam2 is very long parameter 2.
371 *
372 * @param[in,out] VeryLongParam3 is very long parameter 3.
373 *
374 * @retval 1 is returned, in case A.
375 *
376 * @retval 2 is returned, in case B.
377 *
378 * @retval #Enum is returned, in case C.
379 *
380 * @return Sometimes some value.  See Function().
381 */
382__attribute__((__const__)) static inline int VeryLongFunction(
383  int                  VeryLongParam0,
384  const struct Struct *VeryLongParam1,
385  struct Struct    *( *VeryLongParam2 )( void ),
386  struct Struct       *VeryLongParam3
387)
388{
389  (void) VeryLongParam1;
390  (void) VeryLongParam2;
391  (void) VeryLongParam3;
392  return VeryLongParam0 + 1;
393}
394
395#ifdef __cplusplus
396}
397#endif
398
399#endif /* _H_H */
400"""
401        assert content == src.read()
Note: See TracBrowser for help on using the repository browser.