Back to home page

LXR

 
 

    


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

0001 /*
0002  * SPDX-License-Identifier: BSD-2-Clause
0003  *
0004  * Copyright (C) 2018, Himanshu Sekhar Nayak
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031 
0032 #include <pthread.h>
0033 #include <timesys.h>
0034 #include <rtems/btimer.h>
0035 #include <tmacros.h>
0036 #include <sched.h>
0037 #include "test_support.h"
0038 
0039 const char rtems_test_name[] = "PSXTMMUTEXATTR01";
0040 
0041 /* forward declarations to avoid warnings */
0042 static void *POSIX_Init(void *argument);
0043 
0044 static pthread_mutexattr_t attr;
0045 
0046 static void benchmark_create_pthread_mutexattr(void)
0047 {
0048   benchmark_timer_t end_time;
0049   int               status;
0050 
0051   benchmark_timer_initialize();
0052   status = pthread_mutexattr_init( &attr );
0053   end_time = benchmark_timer_read();
0054   rtems_test_assert( status == 0 );
0055 
0056   put_time(
0057     "pthread_mutexattr_init: only case",
0058     end_time,
0059     1,        /* Only executed once */
0060     0,
0061     0
0062   );
0063 
0064 }
0065 
0066 static void benchmark_pthread_mutexattr_setprioceiling(void)
0067 {
0068   benchmark_timer_t end_time;
0069   int               status;
0070 
0071   benchmark_timer_initialize();
0072   status = pthread_mutexattr_setprioceiling( &attr, SCHED_FIFO);
0073   end_time = benchmark_timer_read();
0074   rtems_test_assert( status == 0 );
0075 
0076   put_time(
0077     "pthread_mutexattr_setprioceiling: only case",
0078     end_time,
0079     1,        /* Only executed once */
0080     0,
0081     0
0082   );
0083 
0084 }
0085 
0086 static void benchmark_pthread_mutexattr_getprioceiling(void)
0087 {
0088   benchmark_timer_t end_time;
0089   int               status;
0090   int               prioceiling;
0091 
0092   benchmark_timer_initialize();
0093   status = pthread_mutexattr_getprioceiling( &attr, &prioceiling);
0094   end_time = benchmark_timer_read();
0095   rtems_test_assert( status == 0 );
0096   rtems_test_assert( prioceiling == SCHED_FIFO);
0097 
0098   put_time(
0099     "pthread_mutexattr_getprioceiling: only case",
0100     end_time,
0101     1,        /* Only executed once */
0102     0,
0103     0
0104   );
0105 
0106 }
0107 
0108 static void benchmark_pthread_mutexattr_setprotocol(void)
0109 {
0110   benchmark_timer_t end_time;
0111   int               status;
0112 
0113   benchmark_timer_initialize();
0114   status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_INHERIT );
0115   end_time = benchmark_timer_read();
0116   rtems_test_assert( status == 0 );
0117 
0118   put_time(
0119     "pthread_mutexattr_setprotocol: only case",
0120     end_time,
0121     1,        /* Only executed once */
0122     0,
0123     0
0124   );
0125 
0126 }
0127 
0128 static void benchmark_pthread_mutexattr_getprotocol(void)
0129 {
0130   benchmark_timer_t end_time;
0131   int               status;
0132   int               protocol;
0133 
0134   benchmark_timer_initialize();
0135   status = pthread_mutexattr_getprotocol( &attr, &protocol );
0136   end_time = benchmark_timer_read();
0137   rtems_test_assert( status == 0 );
0138   rtems_test_assert( protocol == PTHREAD_PRIO_INHERIT );
0139 
0140   put_time(
0141     "pthread_mutexattr_getprotocol: only case",
0142     end_time,
0143     1,        /* Only executed once */
0144     0,
0145     0
0146   );
0147 
0148 }
0149 
0150 static void benchmark_pthread_mutexattr_setpshared(void)
0151 {
0152   benchmark_timer_t end_time;
0153   int               status;
0154 
0155   benchmark_timer_initialize();
0156   status = pthread_mutexattr_setpshared( &attr, PTHREAD_PROCESS_PRIVATE );
0157   end_time = benchmark_timer_read();
0158   rtems_test_assert( status == 0 );
0159 
0160   put_time(
0161     "pthread_mutexattr_setpshared: only case",
0162     end_time,
0163     1,        /* Only executed once */
0164     0,
0165     0
0166   );
0167 
0168 }
0169 
0170 static void benchmark_pthread_mutexattr_getpshared(void)
0171 {
0172   benchmark_timer_t end_time;
0173   int               status;
0174   int               pshared;
0175 
0176   benchmark_timer_initialize();
0177   status = pthread_mutexattr_getpshared( &attr, &pshared );
0178   end_time = benchmark_timer_read();
0179   rtems_test_assert( status == 0 );
0180   rtems_test_assert( pshared == PTHREAD_PROCESS_PRIVATE );
0181 
0182   put_time(
0183     "pthread_mutexattr_getpshared: only case",
0184     end_time,
0185     1,        /* Only executed once */
0186     0,
0187     0
0188   );
0189 
0190 }
0191 
0192 static void benchmark_pthread_mutexattr_settype(void)
0193 {
0194   benchmark_timer_t end_time;
0195   int               status;
0196 
0197   benchmark_timer_initialize();
0198   status = pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_DEFAULT );
0199   end_time = benchmark_timer_read();
0200   rtems_test_assert( status == 0 );
0201 
0202   put_time(
0203     "pthread_mutexattr_settype: only case",
0204     end_time,
0205     1,        /* Only executed once */
0206     0,
0207     0
0208   );
0209 
0210 }
0211 
0212 static void benchmark_pthread_mutexattr_gettype(void)
0213 {
0214   benchmark_timer_t end_time;
0215   int               status;
0216   int               type;
0217 
0218   benchmark_timer_initialize();
0219   status = pthread_mutexattr_gettype( &attr, &type );
0220   end_time = benchmark_timer_read();
0221   rtems_test_assert( status == 0 );
0222   rtems_test_assert( type == PTHREAD_MUTEX_DEFAULT );
0223 
0224   put_time(
0225     "pthread_mutexattr_gettype: only case",
0226     end_time,
0227     1,        /* Only executed once */
0228     0,
0229     0
0230   );
0231 
0232 }
0233 
0234 static void benchmark_destroy_pthread_mutexattr(void)
0235 {
0236   benchmark_timer_t end_time;
0237   int               status;
0238 
0239   benchmark_timer_initialize();
0240   status = pthread_mutexattr_destroy( &attr );
0241   end_time = benchmark_timer_read();
0242   rtems_test_assert( status == 0 );
0243 
0244   put_time(
0245     "pthread_mutexattr_destroy: only case",
0246     end_time,
0247     1,        /* Only executed once */
0248     0,
0249     0
0250   );
0251 
0252 }
0253 
0254 void *POSIX_Init(
0255   void *argument
0256 )
0257 {
0258 
0259   TEST_BEGIN();
0260 
0261   benchmark_create_pthread_mutexattr();
0262   benchmark_pthread_mutexattr_setprioceiling();
0263   benchmark_pthread_mutexattr_getprioceiling();
0264   benchmark_pthread_mutexattr_setprotocol();
0265   benchmark_pthread_mutexattr_getprotocol();
0266   benchmark_pthread_mutexattr_setpshared();
0267   benchmark_pthread_mutexattr_getpshared();
0268   benchmark_pthread_mutexattr_settype();
0269   benchmark_pthread_mutexattr_gettype();
0270   benchmark_destroy_pthread_mutexattr();
0271 
0272   TEST_END();
0273   rtems_test_exit(0);
0274 }
0275 
0276 /* configuration information */
0277 
0278 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0279 #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
0280 
0281 
0282 #define CONFIGURE_MAXIMUM_POSIX_THREADS     1
0283 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0284 
0285 #define CONFIGURE_INIT
0286 
0287 #include <rtems/confdefs.h>
0288 /* end of file */