source: rtems-central/rtemsqual/tests/test_interface.py @ 3276ce2

Last change on this file since 3276ce2 was 3276ce2, checked in by Sebastian Huber <sebastian.huber@…>, on 05/10/20 at 18:20:57

interface: Add support for interface includes

  • Property mode set to 100644
File size: 8.1 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    interface_config["item-level-interfaces"] = []
41    base_directory = os.path.join(tmpdir, "base")
42    interface_domains = {"abc": base_directory}
43    interface_config["interface-domains"] = interface_domains
44
45    item_cache_config["paths"] = [os.path.normpath(tmpdir)]
46    generate(interface_config, ItemCache(item_cache_config))
47
48    interface_config["item-level-interfaces"] = ["/command-line"]
49
50    spec_src = os.path.join(os.path.dirname(__file__), "spec-interface")
51    spec_dst = os.path.join(tmpdir, "spec")
52    shutil.copytree(spec_src, spec_dst)
53    item_cache_config["paths"] = [os.path.normpath(spec_dst)]
54    generate(interface_config, ItemCache(item_cache_config))
55
56    with open(os.path.join(base_directory, "include", "h.h"), "r") as src:
57        content = """/* SPDX-License-Identifier: BSD-2-Clause */
58
59/**
60 * @file
61 *
62 * @ingroup GroupA
63 * @ingroup GroupB
64 * @ingroup GroupC
65 */
66
67/*
68 * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
69 *
70 * Redistribution and use in source and binary forms, with or without
71 * modification, are permitted provided that the following conditions
72 * are met:
73 * 1. Redistributions of source code must retain the above copyright
74 *    notice, this list of conditions and the following disclaimer.
75 * 2. Redistributions in binary form must reproduce the above copyright
76 *    notice, this list of conditions and the following disclaimer in the
77 *    documentation and/or other materials provided with the distribution.
78 *
79 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
80 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
81 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
82 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
83 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
84 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
85 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
86 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
87 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
88 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
89 * POSSIBILITY OF SUCH DAMAGE.
90 */
91
92#ifndef _H_H
93#define _H_H
94
95#include <h2.h>
96#include <h3.h>
97#include <h4.h>
98#include <math.h>
99#include <stdint.h>
100
101#ifdef __cplusplus
102extern "C" {
103#endif
104
105/**
106 * @defgroup GroupA Group A
107 *
108 * @brief Group A brief description.
109 *
110 * Group A description.
111 */
112
113/**
114 * @defgroup GroupB Group B
115 *
116 * @ingroup GroupA
117 */
118
119/* Forward declaration */
120struct Struct;
121
122/**
123 * @ingroup GroupB
124 *
125 * @brief Enum brief description.
126 *
127 * Enum description.
128 */
129typedef enum {
130  /**
131   * @brief Enumerator 0 brief description.
132   */
133  ENUMERATOR_0,
134
135  /**
136   * @brief Enumerator 1 brief description.
137   */
138  ENUMERATOR_1,
139
140  /**
141   * @brief Enumerator 2 brief description.
142   */
143  ENUMERATOR_2
144} Enum;
145
146/**
147 * @ingroup GroupA
148 */
149#if defined(A) || (B > C)
150  #define DEFINE ((float_t) 456)
151#elif defined(C) && defined(D)
152  #define DEFINE ((float_t) 789)
153#else
154  #define DEFINE \\
155    ((float_t) 123)
156#endif
157
158/**
159 * @ingroup GroupB
160 *
161 * @brief Enum B brief description.
162 */
163typedef enum EnumB {
164  /**
165   * @brief Enumerator B brief description.
166   */
167  ENUMERATOR_B = ENUMERATOR_A
168} EnumB;
169
170/**
171 * @ingroup GroupA
172 *
173 * @brief Function brief description.
174 *
175 * Function description.
176 *
177 * @param Param0 is parameter 0.
178 *
179 * @param[in] Param1 is parameter 1.
180 *
181 * @param[out] Param2 is parameter 2.
182 *
183 * @param[in,out] Param3 is parameter 3.
184 */
185void Function(int Param0, const int *Param1, int *Param2, int *Param3);
186
187/**
188 * @ingroup GroupB
189 *
190 * @brief Very long function brief description.
191 *
192 * @param VeryLongParam0 is very long parameter 0 with some super important and
193 *        extra very long description which makes a lot of sense.
194 *
195 * @param[in] VeryLongParam1 is very long parameter 1.
196 *
197 * @param[out] VeryLongParam2 is very long parameter 2.
198 *
199 * @param[in,out] VeryLongParam3 is very long parameter 3.
200 *
201 * @retval 1 is returned, in case A.
202 *
203 * @retval 2 is returned, in case B.
204 *
205 * @return Sometimes some value.
206 */
207static inline int VeryLongFunction(
208  int VeryLongParam0,
209  const struct Struct *VeryLongParam1,
210  struct Struct *VeryLongParam2,
211  struct Struct *VeryLongParam3
212)
213{
214  (void) VeryLongParam1;
215  (void) VeryLongParam2;
216  (void) VeryLongParam3;
217  return VeryLongParam0 + 1;
218}
219
220/**
221 * @ingroup GroupB
222 *
223 * @brief Very long macro brief description.
224 *
225 * @param VeryLongParam0 is very long parameter 0 with some super important and
226 *        extra very long description which makes a lot of sense.
227 *
228 * @param[in] VeryLongParam1 is very long parameter 1.
229 *
230 * @param[out] VeryLongParam2 is very long parameter 2.
231 *
232 * @param[in,out] VeryLongParam3 is very long parameter 3.
233 *
234 * @retval 1 is returned, in case A.
235 *
236 * @retval 2 is returned, in case B.
237 *
238 * @return Sometimes some value.
239 */
240#define VERY_LONG_MACRO( \\
241  VeryLongParam0, \\
242  VeryLongParam1, \\
243  VeryLongParam2, \\
244  VeryLongParam3 \\
245) do { \\
246    (void) VeryLongParam1; \\
247    (void) VeryLongParam2; \\
248    (void) VeryLongParam3; \\
249  } while ( 0 ); \\
250  VeryLongParam0 + 1;
251
252/**
253 * @ingroup GroupB
254 *
255 * @brief Short macro brief description.
256 *
257 * @param Param0 is parameter 0.
258 *
259 * @return Sometimes some value.
260 */
261#define MACRO(Param0) ( ( Param0 ) + 1 )
262
263/**
264 * @ingroup GroupC
265 */
266struct Struct {
267  /**
268   * @brief Brief union description.
269   *
270   * Union description.
271   */
272  union {
273    /**
274     * @brief Brief member description.
275     *
276     * Member description.
277     */
278    uint32_t some_member;
279
280    /**
281     * @brief Brief struct description.
282     *
283     * struct description.
284     */
285    struct {
286      /**
287       * @brief Brief member 2 description.
288       *
289       * Member 2 description.
290       */
291      uint32_t some_member_2;
292
293      /**
294       * @brief Brief member 3 description.
295       *
296       * Member 3 description.
297       */
298      Enum some_member_3;
299    } some_struct;
300  } some_union;
301};
302
303/**
304 * @ingroup GroupB
305 *
306 * @brief Typedef Integer brief description.
307 *
308 * Typedef Integer description.
309 */
310typedef uint32_t Integer /* Some comment. */;
311
312/**
313 * @ingroup GroupB
314 */
315#if defined(RTEMS_SMP)
316  typedef uint32_t Integer3;
317#endif
318
319#if !defined(ASM)
320  /**
321   * @ingroup GroupC
322   *
323   * @brief Variable brief description.
324   *
325   * Variable description.
326   */
327  extern struct Struct *Variable;
328#endif
329
330#ifdef __cplusplus
331}
332#endif
333
334#endif /* _H_H */
335"""
336        assert content == src.read()
Note: See TracBrowser for help on using the repository browser.