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

Last change on this file since 3f3e088 was 3f3e088, checked in by Sebastian Huber <sebastian.huber@…>, on 10/10/20 at 19:18:29

interface: Improve ordering

Close #4134.

  • 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 * Do not manually edit this file.  It is part of the RTEMS quality process
90 * and was automatically generated.
91 *
92 * If you find something that needs to be fixed or worded better please
93 * post a report to an RTEMS mailing list or raise a bug report:
94 *
95 * https://docs.rtems.org/branches/master/user/support/bugs.html
96 *
97 * For information on updating and regenerating please refer to:
98 *
99 * https://docs.rtems.org/branches/master/eng/req/howto.html
100 */
101
102/* Generated from spec:/h */
103
104#ifndef _H_H
105#define _H_H
106
107#include <h3.h>
108#include <math.h>
109#include <stdint.h>
110
111#if !defined(ASM) && defined(RTEMS_SMP)
112  #include <h2.h>
113#endif
114
115#if defined(ASM) && defined(RTEMS_SMP)
116  #include <h4.h>
117#endif
118
119#ifdef __cplusplus
120extern "C" {
121#endif
122
123/* Generated from spec:/ga */
124
125/**
126 * @defgroup GroupA Group A
127 *
128 * @brief Group A brief description.
129 *
130 * Group A description.
131 */
132
133/* Generated from spec:/gb */
134
135/**
136 * @defgroup GroupB Group B
137 *
138 * @ingroup GroupA
139 */
140
141/* Generated from spec:/define */
142
143/**
144 * @ingroup GroupA
145 */
146#if defined(A) || (B > C)
147  #define DEFINE ((float_t) 456)
148#elif defined(C) && defined(D)
149  #define DEFINE ((float_t) 789)
150#else
151  #define DEFINE \\
152    ((float_t) 123)
153#endif
154
155/* Generated from spec:/forward-decl */
156
157/* Forward declaration */
158struct Struct;
159
160/* Generated from spec:/enum */
161
162/**
163 * @ingroup GroupB
164 *
165 * @brief Enum brief description.
166 *
167 * Enum description.
168 */
169typedef enum {
170  /**
171   * @brief Enumerator 0 brief description.
172   */
173  ENUMERATOR_0,
174
175  /**
176   * @brief Enumerator 1 brief description.
177   */
178  ENUMERATOR_1,
179
180  /**
181   * @brief Enumerator 2 brief description.
182   */
183  ENUMERATOR_2
184} Enum;
185
186/* Generated from spec:/enum3 */
187
188/**
189 * @ingroup GroupB
190 *
191 * @brief Enum B brief description.
192 */
193typedef enum EnumB {
194  /**
195   * @brief Enumerator B brief description.
196   */
197  ENUMERATOR_B = ENUMERATOR_A
198} EnumB;
199
200/* Generated from spec:/func */
201
202/**
203 * @ingroup GroupA
204 *
205 * @brief Function brief description.
206 *
207 * Function description.  References to VeryLongFunction(), ::Integer, #Enum,
208 * #DEFINE, VERY_LONG_MACRO(), #Variable, ::ENUMERATOR_0, Struct, #a, and
209 * interface.
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 */
219void Function( int Param0, const int *Param1, int *Param2, int *Param3 );
220
221/* Generated from spec:/macro */
222
223/**
224 * @ingroup GroupB
225 *
226 * @brief Very long macro brief description.
227 *
228 * @param VeryLongParam0 is very long parameter 0 with some super important and
229 *   extra very long description which makes a lot of sense.
230 *
231 * @param[in] VeryLongParam1 is very long parameter 1.
232 *
233 * @param[out] VeryLongParam2 is very long parameter 2.
234 *
235 * @param[in,out] VeryLongParam3 is very long parameter 3.
236 *
237 * @retval 1 is returned, in case A.
238 *
239 * @retval 2 is returned, in case B.
240 *
241 * @return Sometimes some value.
242 */
243#define VERY_LONG_MACRO( \\
244  VeryLongParam0, \\
245  VeryLongParam1, \\
246  VeryLongParam2, \\
247  VeryLongParam3 \\
248) \\
249  do { \\
250    (void) VeryLongParam1; \\
251    (void) VeryLongParam2; \\
252    (void) VeryLongParam3; \\
253  } while ( 0 ); \\
254  VeryLongParam0 + 1;
255
256/* Generated from spec:/macro2 */
257
258/**
259 * @ingroup GroupB
260 *
261 * @brief Short macro brief description.
262 *
263 * @param Param0 is parameter 0.
264 *
265 * @return Sometimes some value.
266 */
267#if 0
268  #define MACRO( Param0 )
269#else
270  #define MACRO( Param0 ) ( ( Param0 ) + 1 )
271#endif
272
273/* Generated from spec:/s */
274
275/**
276 * @ingroup GroupC
277 */
278struct Struct {
279  /**
280   * @brief Brief union description.
281   *
282   * Union description.
283   */
284  union {
285    /**
286     * @brief Brief member description.
287     *
288     * Member description.
289     */
290    uint32_t some_member;
291
292    /**
293     * @brief Brief struct description.
294     *
295     * struct description.
296     */
297    struct {
298      /**
299       * @brief Brief member 2 description.
300       *
301       * Member 2 description.
302       */
303      uint32_t some_member_2;
304
305      /**
306       * @brief Brief member 3 description.
307       *
308       * Member 3 description.
309       */
310      Enum some_member_3;
311    } some_struct;
312  } some_union;
313
314  /**
315   * @brief Brief member 4 description.
316   *
317   * Member 4 description.
318   */
319  Enum some_member_4;
320};
321
322/* Generated from spec:/td */
323
324/**
325 * @ingroup GroupB
326 *
327 * @brief Typedef Integer brief description.
328 *
329 * Typedef Integer description.
330 */
331typedef uint32_t Integer /* Some comment. */;
332
333/* Generated from spec:/td3 */
334
335/**
336 * @ingroup GroupB
337 */
338#if defined(RTEMS_SMP)
339  typedef uint32_t Integer3;
340#endif
341
342#if !defined(ASM)
343  /* Generated from spec:/var */
344
345  /**
346   * @ingroup GroupC
347   *
348   * @brief Variable brief description.
349   *
350   * Variable description.
351   */
352  extern struct Struct *Variable;
353#endif
354
355/* Generated from spec:/func2 */
356
357/**
358 * @ingroup GroupB
359 *
360 * @brief Very long function brief description.
361 *
362 * VeryLongFunction description.
363 *
364 * VeryLongFunction notes.
365 *
366 * @param VeryLongParam0 is very long parameter 0 with some super important and
367 *   extra very long description which makes a lot of sense.
368 *
369 * @param[in] VeryLongParam1 is very long parameter 1.
370 *
371 * @param[out] VeryLongParam2 is very long parameter 2.
372 *
373 * @param[in,out] VeryLongParam3 is very long parameter 3.
374 *
375 * @retval 1 is returned, in case A.
376 *
377 * @retval 2 is returned, in case B.
378 *
379 * @retval #Enum is returned, in case C.
380 *
381 * @return Sometimes some value.  See Function().
382 */
383static inline int VeryLongFunction(
384  int                  VeryLongParam0,
385  const struct Struct *VeryLongParam1,
386  struct Struct    *( *VeryLongParam2 )( void ),
387  struct Struct       *VeryLongParam3
388)
389{
390  (void) VeryLongParam1;
391  (void) VeryLongParam2;
392  (void) VeryLongParam3;
393  return VeryLongParam0 + 1;
394}
395
396#ifdef __cplusplus
397}
398#endif
399
400#endif /* _H_H */
401"""
402        assert content == src.read()
Note: See TracBrowser for help on using the repository browser.