Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:36

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  *  @file
0005  *
0006  *  Based upon user code supplied in conjunction with PR1759
0007  */
0008 
0009 /*
0010  *  COPYRIGHT (c) 1989-2012.
0011  *  On-Line Applications Research Corporation (OAR).
0012  *
0013  * Redistribution and use in source and binary forms, with or without
0014  * modification, are permitted provided that the following conditions
0015  * are met:
0016  * 1. Redistributions of source code must retain the above copyright
0017  *    notice, this list of conditions and the following disclaimer.
0018  * 2. Redistributions in binary form must reproduce the above copyright
0019  *    notice, this list of conditions and the following disclaimer in the
0020  *    documentation and/or other materials provided with the distribution.
0021  *
0022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0023  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0025  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0026  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0027  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0028  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0029  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0030  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0031  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0032  * POSSIBILITY OF SUCH DAMAGE.
0033  */
0034 
0035 #define _GNU_SOURCE
0036 
0037 #ifdef HAVE_CONFIG_H
0038 #include "config.h"
0039 #endif
0040 
0041 #include <stdio.h>
0042 #include <rtems.h>
0043 #include <pthread.h>
0044 #include <unistd.h>
0045 #include <errno.h>
0046 #include <string.h>
0047 #include <sched.h>
0048 #include <tmacros.h>
0049 
0050 const char rtems_test_name[] = "PSXCLASSIC 1";
0051 
0052 static int       Caught_signo = -1;
0053 static siginfo_t Caught_siginfo = { -1, -1, };
0054 
0055 static void handler(int signo)
0056 {
0057   Caught_signo = signo;
0058 }
0059 
0060 static void handler_info(int signo, siginfo_t *info, void *context)
0061 {
0062   Caught_signo = signo;
0063   Caught_siginfo = *info;
0064 }
0065 
0066 static rtems_task test_task(rtems_task_argument arg)
0067 {
0068   int sc;
0069   struct sigaction new_action;
0070   sigset_t mask;
0071   void *addr;
0072   size_t size;
0073   int value;
0074   struct sched_param param;
0075   cpu_set_t set;
0076   pthread_attr_t attr;
0077 
0078   printf("test_task starting...\n");
0079 
0080   value = -1;
0081   memset( &param, -1, sizeof( param ) );
0082   sc = pthread_getschedparam( pthread_self(), &value, &param );
0083   rtems_test_assert( sc == 0 );
0084   rtems_test_assert( value == SCHED_FIFO );
0085   rtems_test_assert(
0086     param.sched_priority == sched_get_priority_max( SCHED_FIFO )
0087   );
0088 
0089   sc = pthread_setschedparam( pthread_self(), value, &param );
0090   rtems_test_assert( sc == 0 );
0091 
0092   sc = pthread_getattr_np( pthread_self(), &attr );
0093   rtems_test_assert( sc == 0 );
0094 
0095   addr = NULL;
0096   size = 0;
0097   sc = pthread_attr_getstack( &attr, &addr, &size );
0098   rtems_test_assert( sc == 0 );
0099   rtems_test_assert( addr != NULL );
0100   rtems_test_assert( size >= RTEMS_MINIMUM_STACK_SIZE );
0101   rtems_test_assert(
0102     size <= RTEMS_MINIMUM_STACK_SIZE + CPU_STACK_ALIGNMENT -
0103       CPU_HEAP_ALIGNMENT
0104   );
0105 
0106   value = -1;
0107   sc = pthread_attr_getscope( &attr, &value );
0108   rtems_test_assert( sc == 0 );
0109   rtems_test_assert( value == PTHREAD_SCOPE_PROCESS );
0110 
0111   value = -1;
0112   sc = pthread_attr_getinheritsched( &attr, &value );
0113   rtems_test_assert( sc == 0 );
0114   rtems_test_assert( value == PTHREAD_EXPLICIT_SCHED );
0115 
0116   value = -1;
0117   sc = pthread_attr_getschedpolicy( &attr, &value );
0118   rtems_test_assert( sc == 0 );
0119   rtems_test_assert( value == SCHED_FIFO );
0120 
0121   memset( &param, -1, sizeof( param ) );
0122   sc = pthread_attr_getschedparam( &attr, &param );
0123   rtems_test_assert( sc == 0 );
0124   rtems_test_assert(
0125     param.sched_priority == sched_get_priority_max( SCHED_FIFO )
0126   );
0127 
0128   size = 1;
0129   sc = pthread_attr_getguardsize( &attr, &size );
0130   rtems_test_assert( sc == 0 );
0131   rtems_test_assert( size == 0 );
0132 
0133   value = -1;
0134   sc = pthread_attr_getdetachstate( &attr, &value );
0135   rtems_test_assert( sc == 0 );
0136   rtems_test_assert( value == PTHREAD_CREATE_JOINABLE );
0137 
0138   CPU_ZERO( &set );
0139   sc = pthread_attr_getaffinity_np( &attr, sizeof( set ), &set );
0140   rtems_test_assert( sc == 0 );
0141   rtems_test_assert( CPU_ISSET( 0, &set ) );
0142   rtems_test_assert( CPU_COUNT( &set ) == 1 );
0143 
0144   sc = pthread_attr_destroy( &attr );
0145   rtems_test_assert( sc == 0 );
0146 
0147   sc = sigemptyset (&new_action.sa_mask);
0148   rtems_test_assert( sc == 0 );
0149 
0150   sc = sigfillset  (&new_action.sa_mask);
0151   rtems_test_assert( sc == 0 );
0152 
0153   sc = sigdelset   (&new_action.sa_mask, SIGUSR1);
0154   rtems_test_assert( sc == 0 );
0155 
0156   new_action.sa_handler = handler;
0157   new_action.sa_flags = SA_SIGINFO;
0158   new_action.sa_sigaction = handler_info;
0159 
0160   sc = sigaction(SIGUSR1,&new_action,NULL);
0161   rtems_test_assert( sc == 0 );
0162 
0163   sc = sigemptyset(&mask);
0164   rtems_test_assert( sc == 0 );
0165 
0166   sc = sigaddset(&mask, SIGUSR1);
0167   rtems_test_assert( sc == 0 );
0168 
0169   sc = pthread_sigmask( SIG_UNBLOCK, &mask, NULL);
0170   rtems_test_assert( sc == 0 );
0171 
0172   printf("test_task waiting for signal...\n");
0173 
0174   while(1) {
0175     sleep(1);
0176     if ( Caught_siginfo.si_signo != -1 ) {
0177       printf( "Signal_info: %d si_signo= %d si_code= %d value= %d\n",
0178         Caught_signo,
0179         Caught_siginfo.si_signo,
0180         Caught_siginfo.si_code,
0181         Caught_siginfo.si_value.sival_int
0182       );
0183       break;
0184     }
0185     if ( Caught_signo != -1 ) {
0186       printf( "Signal: %d caught\n", Caught_signo );
0187       break;
0188     }
0189   }
0190   puts( "test_task exiting thread" );
0191   pthread_exit( (void *) 123 );
0192 }
0193 
0194 
0195 static rtems_id create_task( void )
0196 {
0197   rtems_status_code sc;
0198   rtems_id          task_id;
0199 
0200   sc = rtems_task_create(
0201     rtems_build_name('T','E','S','T'),
0202     1,
0203     RTEMS_MINIMUM_STACK_SIZE,
0204     RTEMS_DEFAULT_MODES,
0205     RTEMS_DEFAULT_ATTRIBUTES,
0206     &task_id
0207   );
0208   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0209 
0210   sc = rtems_task_start( task_id,  test_task, 0 );
0211   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0212 
0213   return task_id;
0214 }
0215 
0216 static rtems_task Init( rtems_task_argument arg )
0217 {
0218   rtems_id  task_id;
0219   int       status;
0220   void     *retval;
0221 
0222   TEST_BEGIN();
0223 
0224   task_id = create_task();
0225 
0226   puts( "Init - pthread_equal on Classic Ids" );
0227   status = pthread_equal( task_id, task_id );
0228   rtems_test_assert( status != 0 );
0229   
0230   puts( "Init - pthread_cancel on Classic Task" );
0231   status = pthread_cancel( task_id );
0232   rtems_test_assert( status == 0 );
0233   
0234   status = pthread_detach( task_id );
0235   rtems_test_assert( status == 0 );
0236 
0237   retval = (void *) 456;
0238   status = pthread_join( task_id, &retval );
0239   rtems_test_assert( status == ESRCH );
0240   rtems_test_assert( retval == (void *) 456 );
0241 
0242   status = pthread_kill( task_id, SIGUSR1 );
0243   rtems_test_assert( status == ESRCH );
0244 
0245   task_id = create_task();
0246 
0247   status = pthread_kill( task_id, SIGUSR1 );
0248   rtems_test_assert( status == 0 );
0249 
0250   status = pthread_join( task_id, &retval );
0251   rtems_test_assert( status == 0 );
0252   rtems_test_assert( retval == (void *) 123 );
0253 
0254   TEST_END();
0255   exit(0);
0256 }
0257 
0258 /* configuration information */
0259 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0260 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0261 
0262 #define CONFIGURE_MAXIMUM_TASKS 2
0263 
0264 #define CONFIGURE_INIT_TASK_INITIAL_MODES \
0265   (RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_ASR | RTEMS_INTERRUPT_LEVEL(0))
0266 
0267 #define CONFIGURE_INIT_TASK_PRIORITY 4
0268 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0269 
0270 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0271 
0272 #define CONFIGURE_UNIFIED_WORK_AREAS
0273 
0274 #define CONFIGURE_INIT
0275 #include <rtems/confdefs.h>
0276 /* end of file */