source: rtems/testsuites/validation/tc-score-thread.c @ 9bfe5f5

Last change on this file since 9bfe5f5 was 9bfe5f5, checked in by Sebastian Huber <sebastian.huber@…>, on 02/14/23 at 14:59:22

validation: Derive names from item UIDs

Use the item UID converted to CamelCase for Doxygen group names and
testsuite names.

Update #3716.

  • Property mode set to 100644
File size: 7.8 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup ScoreThreadValThread
7 */
8
9/*
10 * Copyright (C) 2021 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#include <rtems/score/statesimpl.h>
57#include <rtems/score/threadimpl.h>
58
59#include "ts-config.h"
60#include "tx-support.h"
61
62#include <rtems/test.h>
63
64/**
65 * @defgroup ScoreThreadValThread spec:/score/thread/val/thread
66 *
67 * @ingroup TestsuitesValidationNoClock0
68 *
69 * @brief Tests general thread behaviour.
70 *
71 * This test case performs the following actions:
72 *
73 * - Create an extension set with a thread terminate extension which deletes
74 *   the killer task if it is invoked for the worker task.  Create and start
75 *   the worker task.  Create and start the killer task.  The killer task
76 *   deletes the worker task.
77 *
78 *   - Check that the killer task was deleted.
79 *
80 *   - Check that the worker task still exists.
81 *
82 *   - Check that the life of the worker task is protected and terminating.
83 *
84 *   - Check that the worker task is waiting for a joining thread.
85 *
86 *   - Delete the worker task using brute force.
87 *
88 *   - Clean up all used resources.
89 *
90 * - Delete a thread which least recently used the floating point coprocessor.
91 *
92 *   - Start the worker thread.  Let it use the floating point coprocessor.
93 *
94 *   - Delete the worker thread and free the thread resources.
95 *
96 *   - Clean up all used resources.
97 *
98 * @{
99 */
100
101/**
102 * @brief Test context for spec:/score/thread/val/thread test case.
103 */
104typedef struct {
105  /**
106   * @brief This member contains the worker task identifier.
107   */
108  rtems_id worker_id;
109
110  /**
111   * @brief This member contains the killer task identifier.
112   */
113  rtems_id killer_id;
114
115  /**
116   * @brief This member contains a floating-point object.
117   */
118  volatile double fp_obj;
119} ScoreThreadValThread_Context;
120
121static ScoreThreadValThread_Context
122  ScoreThreadValThread_Instance;
123
124typedef ScoreThreadValThread_Context Context;
125
126static void TaskTerminate( rtems_tcb *executing )
127{
128  Context *ctx;
129
130  ctx = T_fixture_context();
131
132  if ( ctx->worker_id == executing->Object.id ) {
133    DeleteTask( ctx->killer_id );
134  }
135}
136
137static void WorkerTask( rtems_task_argument arg )
138{
139  (void) arg;
140  SuspendSelf();
141}
142
143static void GoBackToRunner( void *arg )
144{
145  Context *ctx;
146
147  ctx = arg;
148  SetPriority( ctx->worker_id, PRIO_LOW );
149}
150
151static void FloatingPointTask( rtems_task_argument arg )
152{
153  Context *ctx;
154
155  ctx = (Context *) arg;
156  ctx->fp_obj *= 1.23;
157
158  /*
159   * We use an interrupt to go back to the runner since on some
160   * architectures, the floating-point context is only saved during interrupt
161   * processing and not for synchronous thread switches.
162   */
163  CallWithinISR( GoBackToRunner, ctx );
164}
165
166static void KillerTask( rtems_task_argument arg )
167{
168  Context *ctx;
169
170  ctx = (Context *) arg;
171  DeleteTask( ctx->worker_id );
172}
173
174static T_fixture ScoreThreadValThread_Fixture = {
175  .setup = NULL,
176  .stop = NULL,
177  .teardown = NULL,
178  .scope = NULL,
179  .initial_context = &ScoreThreadValThread_Instance
180};
181
182/**
183 * @brief Create an extension set with a thread terminate extension which
184 *   deletes the killer task if it is invoked for the worker task.  Create and
185 *   start the worker task.  Create and start the killer task.  The killer task
186 *   deletes the worker task.
187 */
188static void ScoreThreadValThread_Action_0( ScoreThreadValThread_Context *ctx )
189{
190  rtems_extensions_table table = {
191    .thread_terminate = TaskTerminate
192  };
193  rtems_status_code sc;
194  rtems_id          id;
195  rtems_tcb        *worker_tcb;
196
197  sc = rtems_extension_create(
198    rtems_build_name( 'T', 'E', 'S', 'T' ),
199    &table,
200    &id
201  );
202  T_rsc_success( sc );
203
204  SetSelfPriority( PRIO_NORMAL );
205  ctx->worker_id = CreateTask( "WORK", PRIO_HIGH );
206  worker_tcb = GetThread( ctx->worker_id );
207  StartTask( ctx->worker_id, WorkerTask, NULL );
208  ctx->killer_id = CreateTask( "KILL", PRIO_HIGH );
209  StartTask( ctx->killer_id, KillerTask, ctx );
210
211  /*
212   * Check that the killer task was deleted.
213   */
214  sc = rtems_event_send( ctx->killer_id, RTEMS_EVENT_0 );
215  T_rsc( sc, RTEMS_INVALID_ID );
216
217  /*
218   * Check that the worker task still exists.
219   */
220  sc = rtems_event_send( ctx->worker_id, RTEMS_EVENT_0 );
221  T_rsc_success( sc );
222
223  /*
224   * Check that the life of the worker task is protected and terminating.
225   */
226  T_eq_int(
227    worker_tcb->Life.state,
228    THREAD_LIFE_PROTECTED | THREAD_LIFE_TERMINATING
229  );
230
231  /*
232   * Check that the worker task is waiting for a joining thread.
233   */
234  T_eq_u32(
235    worker_tcb->current_state,
236    STATES_WAITING_FOR_JOIN_AT_EXIT
237  );
238
239  /*
240   * Delete the worker task using brute force.
241   */
242  worker_tcb->Life.state = THREAD_LIFE_DETACHED |
243    THREAD_LIFE_PROTECTED | THREAD_LIFE_TERMINATING;
244  _Thread_Clear_state( worker_tcb, STATES_WAITING_FOR_JOIN_AT_EXIT );
245
246  /*
247   * Clean up all used resources.
248   */
249  KillZombies();
250  RestoreRunnerPriority();
251
252  sc = rtems_extension_delete( id );
253  T_rsc_success( sc );
254}
255
256/**
257 * @brief Delete a thread which least recently used the floating point
258 *   coprocessor.
259 */
260static void ScoreThreadValThread_Action_1( ScoreThreadValThread_Context *ctx )
261{
262  rtems_status_code sc;
263
264  SetSelfPriority( PRIO_NORMAL );
265  sc = rtems_task_create(
266    rtems_build_name( 'W', 'O', 'R', 'K'),
267    PRIO_HIGH,
268    TEST_MINIMUM_STACK_SIZE,
269    RTEMS_DEFAULT_MODES,
270    RTEMS_FLOATING_POINT,
271    &ctx->worker_id
272  );
273  T_rsc_success( sc );
274
275  /*
276   * Start the worker thread.  Let it use the floating point coprocessor.
277   */
278  StartTask( ctx->worker_id, FloatingPointTask, ctx );
279
280  /*
281   * Delete the worker thread and free the thread resources.
282   */
283  DeleteTask( ctx->worker_id );
284  KillZombies();
285
286  /*
287   * Clean up all used resources.
288   */
289  RestoreRunnerPriority();
290}
291
292/**
293 * @fn void T_case_body_ScoreThreadValThread( void )
294 */
295T_TEST_CASE_FIXTURE( ScoreThreadValThread, &ScoreThreadValThread_Fixture )
296{
297  ScoreThreadValThread_Context *ctx;
298
299  ctx = T_fixture_context();
300
301  ScoreThreadValThread_Action_0( ctx );
302  ScoreThreadValThread_Action_1( ctx );
303}
304
305/** @} */
Note: See TracBrowser for help on using the repository browser.