/* SPDX-License-Identifier: BSD-2-Clause */ /** * @file * * @ingroup RTEMSTestCaseRtemsModelEventsMgr */ /* * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) * Trinity College Dublin (http://www.tcd.ie) * * 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 was automatically generated. Do not edit it manually. * Please have a look at * * https://docs.rtems.org/branches/master/eng/req/howto.html * * for information how to maintain and re-generate this file. */ #ifndef HAVE_CONFIG_H #include "config.h" #endif #include #include "tr-model-events-mgr.h" // =============================================== // @@@ 0 NAME Event_Manager_TestGen // @@@ 0 DEF NO_OF_EVENTS 4 #define NO_OF_EVENTS 4 // @@@ 0 DEF EVTS_NONE 0 #define EVTS_NONE 0 // @@@ 0 DEF EVTS_PENDING 0 #define EVTS_PENDING 0 // @@@ 0 DEF EVT_0 1 #define EVT_0 1 // @@@ 0 DEF EVT_1 2 #define EVT_1 2 // @@@ 0 DEF EVT_2 4 #define EVT_2 4 // @@@ 0 DEF EVT_3 8 #define EVT_3 8 // @@@ 0 DEF NO_TIMEOUT 0 #define NO_TIMEOUT 0 // @@@ 0 DEF TASK_MAX 2 #define TASK_MAX 2 // @@@ 0 DEF BAD_ID 2 #define BAD_ID 2 // @@@ 0 DEF SEMA_MAX 2 #define SEMA_MAX 2 // @@@ 0 DEF RC_OK RTEMS_SUCCESSFUL #define RC_OK RTEMS_SUCCESSFUL // @@@ 0 DEF RC_InvId RTEMS_INVALID_ID #define RC_InvId RTEMS_INVALID_ID // @@@ 0 DEF RC_InvAddr RTEMS_INVALID_ADDRESS #define RC_InvAddr RTEMS_INVALID_ADDRESS // @@@ 0 DEF RC_Unsat RTEMS_UNSATISFIED #define RC_Unsat RTEMS_UNSATISFIED // @@@ 0 DEF RC_Timeout RTEMS_TIMEOUT #define RC_Timeout RTEMS_TIMEOUT // @@@ 0 DCLARRAY EvtSet pending TASK_MAX static rtems_event_set pending[TASK_MAX]; // @@@ 0 DECL byte sendrc 0 static rtems_status_code sendrc = 0; // @@@ 0 DECL byte recrc 0 static rtems_status_code recrc = 0; // @@@ 0 DECL byte recout 0 static rtems_event_set recout = 0; // @@@ 0 DCLARRAY Semaphore semaphore SEMA_MAX static rtems_id semaphore[SEMA_MAX]; // ===== TEST CODE SEGMENT 0 ===== static void TestSegment0( Context* ctx ) { /* Test Name is defined in the Test Case code (tc-model-events-mgr.c) */ T_log(T_NORMAL,"@@@ 0 INIT"); initialise_pending( pending, TASK_MAX ); initialise_semaphore( ctx, semaphore ); } // ===== TEST CODE SEGMENT 3 ===== static void TestSegment3( Context* ctx ) { T_log(T_NORMAL,"@@@ 3 TASK Worker"); checkTaskIs( ctx->worker_id ); T_log(T_NORMAL,"@@@ 3 WAIT 0"); Wait( semaphore[0] ); T_log(T_NORMAL,"@@@ 3 SIGNAL 1"); Wakeup( semaphore[1] ); T_log(T_NORMAL,"@@@ 3 STATE 0 Zombie"); /* Code to check that Task 0 has terminated */ } // ===== TEST CODE SEGMENT 4 ===== static void TestSegment4( Context* ctx ) { T_log(T_NORMAL,"@@@ 4 TASK Runner"); checkTaskIs( ctx->runner_id ); T_log(T_NORMAL,"@@@ 4 SIGNAL 0"); Wakeup( semaphore[0] ); T_log(T_NORMAL,"@@@ 4 WAIT 1"); Wait( semaphore[1] ); T_log(T_NORMAL,"@@@ 4 SCALAR pending 1 0"); pending[1] = GetPending( ctx ); T_eq_int( pending[1], 0 ); T_log(T_NORMAL,"@@@ 4 CALL event_receive 10 0 1 0 recout recrc"); T_log( T_NORMAL, "Calling Receive(%d,%d,%d,%d)", 10, mergeopts( 0, 1 ) ,0 ,&recout ); recrc = ( *ctx->receive )( 10, mergeopts( 0, 1 ), 0, &recout ); T_log( T_NORMAL, "Returned 0x%x from Receive", recrc ); T_log(T_NORMAL,"@@@ 4 SCALAR recrc 13"); T_rsc( recrc, 13 ); T_log(T_NORMAL,"@@@ 4 SCALAR recout 0"); T_eq_int( recout, 0 ); T_log(T_NORMAL,"@@@ 4 SCALAR pending 1 0"); pending[1] = GetPending( ctx ); T_eq_int( pending[1], 0 ); T_log(T_NORMAL,"@@@ 4 SIGNAL 0"); Wakeup( semaphore[0] ); T_log(T_NORMAL,"@@@ 4 STATE 1 Zombie"); /* Code to check that Task 1 has terminated */ } // =============================================== static void Runner( RtemsModelEventsMgr_Context *ctx ) { T_log( T_NORMAL, "Runner running" ); TestSegment4( ctx ); T_log( T_NORMAL, "Runner finished" ); } static void Worker1( rtems_task_argument arg ) { Context *ctx; ctx = (Context *) arg; T_log( T_NORMAL, "Worker Running" ); TestSegment3( ctx ); T_log( T_NORMAL, "Worker finished" ); (void) rtems_task_suspend( RTEMS_SELF ); } RTEMS_ALIGNED( RTEMS_TASK_STORAGE_ALIGNMENT ) static char WorkerStorage1[ RTEMS_TASK_STORAGE_SIZE( MAX_TLS_SIZE + RTEMS_MINIMUM_STACK_SIZE, WORKER_ATTRIBUTES ) ]; static const rtems_task_config WorkerConfig1 = { .name = rtems_build_name( 'W', 'O', 'R', 'K' ), .initial_priority = PRIO_LOW, .storage_area = WorkerStorage1, .storage_size = sizeof( WorkerStorage1 ), .maximum_thread_local_storage_size = MAX_TLS_SIZE, .initial_modes = RTEMS_DEFAULT_MODES, .attributes = WORKER_ATTRIBUTES }; static void RtemsModelEventsMgr_Setup1( RtemsModelEventsMgr_Context *ctx ) { rtems_status_code sc; rtems_task_priority prio; T_log( T_NORMAL, "Runner Setup" ); memset( ctx, 0, sizeof( *ctx ) ); ctx->runner_thread = _Thread_Get_executing(); ctx->runner_id = ctx->runner_thread->Object.id; ctx->worker_wakeup = CreateWakeupSema(); ctx->runner_wakeup = CreateWakeupSema(); sc = rtems_task_get_scheduler( RTEMS_SELF, &ctx->runner_sched ); T_rsc_success( sc ); #if defined(RTEMS_SMP) sc = rtems_scheduler_ident_by_processor( 1, &ctx->other_sched ); T_rsc_success( sc ); T_ne_u32( ctx->runner_sched, ctx->other_sched ); #endif prio = 0; sc = rtems_task_set_priority( RTEMS_SELF, PRIO_NORMAL, &prio ); T_rsc_success( sc ); T_eq_u32( prio, PRIO_HIGH ); sc = rtems_task_construct( &WorkerConfig1, &ctx->worker_id ); T_log( T_NORMAL, "Construct Worker, sc = %x", sc ); T_assert_rsc_success( sc ); T_log( T_NORMAL, "Starting Worker..." ); sc = rtems_task_start( ctx->worker_id, Worker1, (rtems_task_argument) ctx ); T_log( T_NORMAL, "Started Worker, sc = %x", sc ); T_assert_rsc_success( sc ); } static void RtemsModelEventsMgr_Setup_Wrap1( void *arg ) { RtemsModelEventsMgr_Context *ctx; ctx = arg; RtemsModelEventsMgr_Setup1( ctx ); } static RtemsModelEventsMgr_Context RtemsModelEventsMgr_Instance1; static T_fixture RtemsModelEventsMgr_Fixture1 = { .setup = RtemsModelEventsMgr_Setup_Wrap1, .stop = NULL, .teardown = RtemsModelEventsMgr_Teardown_Wrap, .scope = RtemsModelEventsMgr_Scope, .initial_context = &RtemsModelEventsMgr_Instance1 }; static T_fixture_node RtemsModelEventsMgr_Node1; void RtemsModelEventsMgr_Run1( rtems_status_code ( *send )( rtems_id, rtems_event_set ), rtems_status_code ( *receive )( rtems_event_set, rtems_option, rtems_interval, rtems_event_set * ), rtems_event_set ( *get_pending_events )( Thread_Control * ), unsigned int wait_class, int waiting_for_event ) { RtemsModelEventsMgr_Context *ctx; T_set_verbosity( T_NORMAL ); T_log( T_NORMAL, "Runner Invoked" ); T_log( T_NORMAL, "Runner Wait Class: %d", wait_class ); T_log( T_NORMAL, "Runner WaitForEvent: %d", waiting_for_event ); T_log( T_NORMAL, "Pushing Test Fixture..." ); ctx = T_push_fixture( &RtemsModelEventsMgr_Node1, &RtemsModelEventsMgr_Fixture1 ); T_log( T_NORMAL, "Test Fixture Pushed" ); ctx->send = send; ctx->receive = receive; ctx->get_pending_events = get_pending_events; ctx->wait_class = wait_class; ctx->waiting_for_event = waiting_for_event; ctx->this_test_number = 1; // RtemsModelEventsMgr_Prepare( ctx ); ctx->events_to_send = 0; ctx->send_status = RTEMS_INCORRECT_STATE; ctx->received_events = 0xffffffff; ctx->receive_option_set = 0; ctx->receive_timeout = RTEMS_NO_TIMEOUT; ctx->unsatisfied_pending = 0xffffffff; memset( &ctx->thread_switch_log, 0, sizeof( ctx->thread_switch_log ) ); T_eq_u32( GetPending( ctx ), 0 ); _Thread_Wait_flags_set( ctx->runner_thread, THREAD_WAIT_FLAGS_INITIAL ); TestSegment0( ctx ); Runner( ctx ); RtemsModelEventsMgr_Cleanup( ctx ); T_log( T_NORMAL, "Run Pop Fixture" ); T_pop_fixture(); } /** @} */