source: rtems-central/rtemsqual/tests/test_interface.py @ 4fc185c

Last change on this file since 4fc185c was 4fc185c, checked in by Sebastian Huber <sebastian.huber@…>, on 05/04/20 at 12:47:15

interface: Fix specification of compounds

Use definition attribute for compound members.

  • Property mode set to 100644
File size: 7.9 KB
Line 
1# SPDX-License-Identifier: BSD-2-Clause
2""" Unit tests for the rtemsqual.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
29import shutil
30
31from rtemsqual.interface import generate
32from rtemsqual.items import ItemCache
33
34
35def test_interface(tmpdir):
36    item_cache_config = {}
37    item_cache_config["cache-directory"] = "cache"
38
39    interface_config = {}
40    base_directory = os.path.join(tmpdir, "base")
41    path_domains = {"abc": base_directory}
42    interface_config["path-domains"] = path_domains
43
44    item_cache_config["paths"] = [os.path.normpath(tmpdir)]
45    generate(interface_config, ItemCache(item_cache_config))
46
47    spec_src = os.path.join(os.path.dirname(__file__), "spec-interface")
48    spec_dst = os.path.join(tmpdir, "spec")
49    shutil.copytree(spec_src, spec_dst)
50    item_cache_config["paths"] = [os.path.normpath(spec_dst)]
51    generate(interface_config, ItemCache(item_cache_config))
52
53    with open(os.path.join(base_directory, "include", "h.h"), "r") as src:
54        content = """/* SPDX-License-Identifier: BSD-2-Clause */
55
56/**
57 * @file
58 *
59 * @ingroup GroupA
60 * @ingroup GroupB
61 * @ingroup GroupC
62 */
63
64/*
65 * Copyright (C) 2020 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#ifndef _H_H
90#define _H_H
91
92#include <h3.h>
93#include <math.h>
94#include <stdint.h>
95
96#ifdef __cplusplus
97extern "C" {
98#endif
99
100/**
101 * @defgroup GroupA Group A
102 *
103 * @brief Group A brief description.
104 *
105 * Group A description.
106 */
107
108/**
109 * @defgroup GroupB Group B
110 *
111 * @ingroup GroupA
112 */
113
114/* Forward declaration */
115struct Struct;
116
117/**
118 * @ingroup GroupB
119 *
120 * @brief Enum brief description.
121 *
122 * Enum description.
123 */
124typedef enum {
125  /**
126   * @brief Enumerator 0 brief description.
127   */
128  ENUMERATOR_0,
129
130  /**
131   * @brief Enumerator 1 brief description.
132   */
133  ENUMERATOR_1,
134
135  /**
136   * @brief Enumerator 2 brief description.
137   */
138  ENUMERATOR_2
139} Enum;
140
141/**
142 * @ingroup GroupA
143 */
144#if defined(A) || defined(B)
145  #define DEFINE ((float_t) 456)
146#elif defined(C) && \\
147  defined(D)
148  #define DEFINE ((float_t) 789)
149#else
150  #define DEFINE \\
151    ((float_t) 123)
152#endif
153
154/**
155 * @ingroup GroupB
156 *
157 * @brief Enum B brief description.
158 */
159typedef enum EnumB {
160  /**
161   * @brief Enumerator B brief description.
162   */
163  ENUMERATOR_B = ENUMERATOR_A
164} EnumB;
165
166/**
167 * @ingroup GroupA
168 *
169 * @brief Function brief description.
170 *
171 * Function description.
172 *
173 * @param Param0 is parameter 0.
174 *
175 * @param[in] Param1 is parameter 1.
176 *
177 * @param[out] Param2 is parameter 2.
178 *
179 * @param[in,out] Param3 is parameter 3.
180 */
181void Function(int Param0, const int *Param1, int *Param2, int *Param3);
182
183/**
184 * @ingroup GroupB
185 *
186 * @brief Very long function brief description.
187 *
188 * @param VeryLongParam0 is very long parameter 0 with some super important and
189 *        extra very long description which makes a lot of sense.
190 *
191 * @param[in] VeryLongParam1 is very long parameter 1.
192 *
193 * @param[out] VeryLongParam2 is very long parameter 2.
194 *
195 * @param[in,out] VeryLongParam3 is very long parameter 3.
196 *
197 * @retval 1 is returned, in case A.
198 *
199 * @retval 2 is returned, in case B.
200 *
201 * @return Sometimes some value.
202 */
203static inline int VeryLongFunction(
204  int VeryLongParam0,
205  const struct Struct *VeryLongParam1,
206  struct Struct *VeryLongParam2,
207  struct Struct *VeryLongParam3
208)
209{
210  (void) VeryLongParam1;
211  (void) VeryLongParam2;
212  (void) VeryLongParam3;
213  return VeryLongParam0 + 1;
214}
215
216/**
217 * @ingroup GroupB
218 *
219 * @brief Very long macro brief description.
220 *
221 * @param VeryLongParam0 is very long parameter 0 with some super important and
222 *        extra very long description which makes a lot of sense.
223 *
224 * @param[in] VeryLongParam1 is very long parameter 1.
225 *
226 * @param[out] VeryLongParam2 is very long parameter 2.
227 *
228 * @param[in,out] VeryLongParam3 is very long parameter 3.
229 *
230 * @retval 1 is returned, in case A.
231 *
232 * @retval 2 is returned, in case B.
233 *
234 * @return Sometimes some value.
235 */
236#define VERY_LONG_MACRO( \\
237  VeryLongParam0, \\
238  VeryLongParam1, \\
239  VeryLongParam2, \\
240  VeryLongParam3 \\
241) do { \\
242    (void) VeryLongParam1; \\
243    (void) VeryLongParam2; \\
244    (void) VeryLongParam3; \\
245  } while ( 0 ); \\
246  VeryLongParam0 + 1;
247
248/**
249 * @ingroup GroupB
250 *
251 * @brief Short macro brief description.
252 *
253 * @param Param0 is parameter 0.
254 *
255 * @return Sometimes some value.
256 */
257#define MACRO(Param0) ( ( Param0 ) + 1 )
258
259/**
260 * @ingroup GroupC
261 */
262struct Struct {
263  /**
264   * @brief Brief union description.
265   *
266   * Union description.
267   */
268  union {
269    /**
270     * @brief Brief member description.
271     *
272     * Member description.
273     */
274    uint32_t some_member;
275
276    /**
277     * @brief Brief struct description.
278     *
279     * struct description.
280     */
281    struct {
282      /**
283       * @brief Brief member 2 description.
284       *
285       * Member 2 description.
286       */
287      uint32_t some_member_2;
288
289      /**
290       * @brief Brief member 3 description.
291       *
292       * Member 3 description.
293       */
294      Enum some_member_3;
295    } some_struct;
296  } some_union;
297};
298
299/**
300 * @ingroup GroupB
301 *
302 * @brief Typedef Integer brief description.
303 *
304 * Typedef Integer description.
305 */
306typedef uint32_t Integer /* Some comment. */;
307
308/**
309 * @ingroup GroupB
310 */
311#if defined(RTEMS_SMP)
312  typedef uint32_t Integer3;
313#endif
314
315/**
316 * @ingroup GroupC
317 *
318 * @brief Variable brief description.
319 *
320 * Variable description.
321 */
322extern struct Struct *Variable;
323
324#ifdef __cplusplus
325}
326#endif
327
328#endif /* _H_H */
329"""
330        assert content == src.read()
Note: See TracBrowser for help on using the repository browser.