source: rtems/testsuites/validation/tc-preinit-array.c @ c821b92

Last change on this file since c821b92 was c821b92, checked in by Sebastian Huber <sebastian.huber@…>, on 11/22/22 at 18:09:12

validation: Test the global construction

Update #3716.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup ScoreThreadValPreinitArray
7 */
8
9/*
10 * Copyright (C) 2022 embedded brains GmbH (http://www.embedded-brains.de)
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/*
35 * This file is part of the RTEMS quality process and was automatically
36 * generated.  If you find something that needs to be fixed or
37 * worded better please post a report or patch to an RTEMS mailing list
38 * or raise a bug report:
39 *
40 * https://www.rtems.org/bugs.html
41 *
42 * For information on updating and regenerating please refer to the How-To
43 * section in the Software Requirements Engineering chapter of the
44 * RTEMS Software Engineering manual.  The manual is provided as a part of
45 * a release.  For development sources please refer to the online
46 * documentation at:
47 *
48 * https://docs.rtems.org
49 */
50
51#ifdef HAVE_CONFIG_H
52#include "config.h"
53#endif
54
55#include <rtems.h>
56
57#include <rtems/test.h>
58
59/**
60 * @defgroup ScoreThreadValPreinitArray spec:/score/thread/val/preinit-array
61 *
62 * @ingroup TestsuitesValidationNoClock0
63 *
64 * @brief Tests the ``.preinit_array`` constructor handling of the C runtime
65 *   support.
66 *
67 * This test case performs the following actions:
68 *
69 * - Validate the ``.preinit_array`` constructor invocation.  Mark that the
70 *   test case executed.
71 *
72 *   - Check that the ``.preinit_array`` constructor was called exactly once.
73 *
74 *   - Check that the ``.preeinit_array`` construction was done by the Classic
75 *     API user initialization task.
76 *
77 *   - Check that the ``.preinit_array`` constructor was called before the
78 *     global constructor invocations.
79 *
80 * @{
81 */
82
83static bool test_case_executed;
84
85static bool constructor_test_case_executed;
86
87static uint32_t counter;
88
89static uint32_t normal_constructor_counter;
90
91static uint32_t constructor_counter;
92
93static uint32_t constructor_calls;
94
95static rtems_id constructor_id;
96
97static __attribute__(( __constructor__ )) void NormalConstructor( void )
98{
99  ++counter;
100  normal_constructor_counter = counter;
101}
102
103static void Constructor( void )
104{
105  constructor_test_case_executed = test_case_executed;
106  ++counter;
107  constructor_counter = counter;
108  ++constructor_calls;
109  constructor_id = rtems_task_self();
110}
111
112static RTEMS_USED RTEMS_SECTION( ".preinit_array" ) void
113  ( * const constructor_registration )( void ) = Constructor;
114
115/**
116 * @brief Validate the ``.preinit_array`` constructor invocation.  Mark that
117 *   the test case executed.
118 */
119static void ScoreThreadValPreinitArray_Action_0( void )
120{
121  test_case_executed = true;
122
123  /*
124   * Check that the ``.preinit_array`` constructor was called exactly once.
125   */
126  T_eq_u32( constructor_calls, 1 );
127
128  /*
129   * Check that the ``.preeinit_array`` construction was done by the Classic
130   * API user initialization task.
131   */
132  T_eq_u32( constructor_id, rtems_task_self() );
133
134  /*
135   * Check that the ``.preinit_array`` constructor was called before the global
136   * constructor invocations.
137   */
138  T_eq_u32( constructor_counter, 1 );
139  T_eq_u32( normal_constructor_counter, 2 );
140}
141
142/**
143 * @fn void T_case_body_ScoreThreadValPreinitArray( void )
144 */
145T_TEST_CASE( ScoreThreadValPreinitArray )
146{
147  ScoreThreadValPreinitArray_Action_0();
148}
149
150/** @} */
Note: See TracBrowser for help on using the repository browser.