summaryrefslogtreecommitdiffstats
path: root/testsuites/validation/tc-dev-grlib-apbuart-inbyte-nonblocking.c
blob: b33b6f1a25b05552028c4108815a0c4e870b7b29 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/* SPDX-License-Identifier: BSD-2-Clause */

/**
 * @file
 *
 * @ingroup DevGrlibReqApbuartInbyteNonblocking
 */

/*
 * Copyright (C) 2021 embedded brains GmbH & Co. KG
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * This file is part of the RTEMS quality process and was automatically
 * generated.  If you find something that needs to be fixed or
 * worded better please post a report or patch to an RTEMS mailing list
 * or raise a bug report:
 *
 * https://www.rtems.org/bugs.html
 *
 * For information on updating and regenerating please refer to the How-To
 * section in the Software Requirements Engineering chapter of the
 * RTEMS Software Engineering manual.  The manual is provided as a part of
 * a release.  For development sources please refer to the online
 * documentation at:
 *
 * https://docs.rtems.org
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <string.h>
#include <grlib/apbuart.h>

#include <rtems/test.h>

/**
 * @defgroup DevGrlibReqApbuartInbyteNonblocking \
 *   spec:/dev/grlib/req/apbuart-inbyte-nonblocking
 *
 * @ingroup TestsuitesBspsValidationBsp0
 *
 * @{
 */

typedef enum {
  DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_Yes,
  DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_No,
  DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_NA
} DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady;

typedef enum {
  DevGrlibReqApbuartInbyteNonblocking_Post_Result_Data,
  DevGrlibReqApbuartInbyteNonblocking_Post_Result_MinusOne,
  DevGrlibReqApbuartInbyteNonblocking_Post_Result_NA
} DevGrlibReqApbuartInbyteNonblocking_Post_Result;

typedef enum {
  DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags_Cleared,
  DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags_NA
} DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags;

typedef struct {
  uint8_t Skip : 1;
  uint8_t Pre_DataReady_NA : 1;
  uint8_t Post_Result : 2;
  uint8_t Post_ErrorFlags : 1;
} DevGrlibReqApbuartInbyteNonblocking_Entry;

/**
 * @brief Test context for spec:/dev/grlib/req/apbuart-inbyte-nonblocking test
 *   case.
 */
typedef struct {
  /**
   * @brief This member provides the APBUART register block.
   */
  apbuart regs;

  /**
   * @brief This member contains the return value of the
   *   apbuart_inbyte_nonblocking() call.
   */
  int result;

  struct {
    /**
     * @brief This member defines the pre-condition states for the next action.
     */
    size_t pcs[ 1 ];

    /**
     * @brief If this member is true, then the test action loop is executed.
     */
    bool in_action_loop;

    /**
     * @brief This member contains the next transition map index.
     */
    size_t index;

    /**
     * @brief This member contains the current transition map entry.
     */
    DevGrlibReqApbuartInbyteNonblocking_Entry entry;

    /**
     * @brief If this member is true, then the current transition variant
     *   should be skipped.
     */
    bool skip;
  } Map;
} DevGrlibReqApbuartInbyteNonblocking_Context;

static DevGrlibReqApbuartInbyteNonblocking_Context
  DevGrlibReqApbuartInbyteNonblocking_Instance;

static const char * const DevGrlibReqApbuartInbyteNonblocking_PreDesc_DataReady[] = {
  "Yes",
  "No",
  "NA"
};

static const char * const * const DevGrlibReqApbuartInbyteNonblocking_PreDesc[] = {
  DevGrlibReqApbuartInbyteNonblocking_PreDesc_DataReady,
  NULL
};

static void DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_Prepare(
  DevGrlibReqApbuartInbyteNonblocking_Context      *ctx,
  DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady state
)
{
  switch ( state ) {
    case DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_Yes: {
      /*
       * While the data ready flag is set in the status register of the
       * register block specified by ``regs`` parameter.
       */
      ctx->regs.status |= APBUART_STATUS_DR;
      break;
    }

    case DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_No: {
      /*
       * While the data ready flag is cleared in the status register of the
       * register block specified by ``regs`` parameter.
       */
      ctx->regs.status &= ~APBUART_STATUS_DR;
      break;
    }

    case DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_NA:
      break;
  }
}

static void DevGrlibReqApbuartInbyteNonblocking_Post_Result_Check(
  DevGrlibReqApbuartInbyteNonblocking_Context    *ctx,
  DevGrlibReqApbuartInbyteNonblocking_Post_Result state
)
{
  switch ( state ) {
    case DevGrlibReqApbuartInbyteNonblocking_Post_Result_Data: {
      /*
       * The return value of apbuart_inbyte_nonblocking() shall be the data
       * read from the data register of the register block specified by
       * ``regs``.
       */
      T_eq_int( ctx->result, 0xff );
      break;
    }

    case DevGrlibReqApbuartInbyteNonblocking_Post_Result_MinusOne: {
      /*
       * The return value of apbuart_inbyte_nonblocking() shall be minus one.
       */
      T_eq_int( ctx->result, -1 );
      break;
    }

    case DevGrlibReqApbuartInbyteNonblocking_Post_Result_NA:
      break;
  }
}

static void DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags_Check(
  DevGrlibReqApbuartInbyteNonblocking_Context        *ctx,
  DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags state
)
{
  switch ( state ) {
    case DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags_Cleared: {
      /*
       * The framing error, parity error, overrun, and break received flags in
       * the status register of the register block specified by ``regs`` shall
       * be cleared.
       */
      T_eq_u32( ctx->regs.status & 0x78, 0 );
      break;
    }

    case DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags_NA:
      break;
  }
}

static void DevGrlibReqApbuartInbyteNonblocking_Prepare(
  DevGrlibReqApbuartInbyteNonblocking_Context *ctx
)
{
  memset( &ctx->regs, 0, sizeof( ctx->regs ) );
  ctx->regs.status = 0x78;
  ctx->regs.data = 0xff;
}

static void DevGrlibReqApbuartInbyteNonblocking_Action(
  DevGrlibReqApbuartInbyteNonblocking_Context *ctx
)
{
  ctx->result = apbuart_inbyte_nonblocking( &ctx->regs );
}

static const DevGrlibReqApbuartInbyteNonblocking_Entry
DevGrlibReqApbuartInbyteNonblocking_Entries[] = {
  { 0, 0, DevGrlibReqApbuartInbyteNonblocking_Post_Result_Data,
    DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags_Cleared },
  { 0, 0, DevGrlibReqApbuartInbyteNonblocking_Post_Result_MinusOne,
    DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags_Cleared }
};

static const uint8_t
DevGrlibReqApbuartInbyteNonblocking_Map[] = {
  0, 1
};

static size_t DevGrlibReqApbuartInbyteNonblocking_Scope(
  void  *arg,
  char  *buf,
  size_t n
)
{
  DevGrlibReqApbuartInbyteNonblocking_Context *ctx;

  ctx = arg;

  if ( ctx->Map.in_action_loop ) {
    return T_get_scope(
      DevGrlibReqApbuartInbyteNonblocking_PreDesc,
      buf,
      n,
      ctx->Map.pcs
    );
  }

  return 0;
}

static T_fixture DevGrlibReqApbuartInbyteNonblocking_Fixture = {
  .setup = NULL,
  .stop = NULL,
  .teardown = NULL,
  .scope = DevGrlibReqApbuartInbyteNonblocking_Scope,
  .initial_context = &DevGrlibReqApbuartInbyteNonblocking_Instance
};

static inline DevGrlibReqApbuartInbyteNonblocking_Entry
DevGrlibReqApbuartInbyteNonblocking_PopEntry(
  DevGrlibReqApbuartInbyteNonblocking_Context *ctx
)
{
  size_t index;

  index = ctx->Map.index;
  ctx->Map.index = index + 1;
  return DevGrlibReqApbuartInbyteNonblocking_Entries[
    DevGrlibReqApbuartInbyteNonblocking_Map[ index ]
  ];
}

static void DevGrlibReqApbuartInbyteNonblocking_TestVariant(
  DevGrlibReqApbuartInbyteNonblocking_Context *ctx
)
{
  DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_Prepare(
    ctx,
    ctx->Map.pcs[ 0 ]
  );
  DevGrlibReqApbuartInbyteNonblocking_Action( ctx );
  DevGrlibReqApbuartInbyteNonblocking_Post_Result_Check(
    ctx,
    ctx->Map.entry.Post_Result
  );
  DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags_Check(
    ctx,
    ctx->Map.entry.Post_ErrorFlags
  );
}

/**
 * @fn void T_case_body_DevGrlibReqApbuartInbyteNonblocking( void )
 */
T_TEST_CASE_FIXTURE(
  DevGrlibReqApbuartInbyteNonblocking,
  &DevGrlibReqApbuartInbyteNonblocking_Fixture
)
{
  DevGrlibReqApbuartInbyteNonblocking_Context *ctx;

  ctx = T_fixture_context();
  ctx->Map.in_action_loop = true;
  ctx->Map.index = 0;

  for (
    ctx->Map.pcs[ 0 ] = DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_Yes;
    ctx->Map.pcs[ 0 ] < DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_NA;
    ++ctx->Map.pcs[ 0 ]
  ) {
    ctx->Map.entry = DevGrlibReqApbuartInbyteNonblocking_PopEntry( ctx );
    DevGrlibReqApbuartInbyteNonblocking_Prepare( ctx );
    DevGrlibReqApbuartInbyteNonblocking_TestVariant( ctx );
  }
}

/** @} */