Changeset 8c5cc6b2 in rtems for testsuites/psxtests/psxsem01


Ignore:
Timestamp:
Nov 18, 1999, 7:51:13 PM (20 years ago)
Author:
Jennifer Averett <Jennifer.Averett@…>
Branches:
4.10, 4.11, 4.8, 4.9, master
Children:
c38f5f16
Parents:
23168f53
Message:

Added test code for named semaphores and moved to use of directive_failed
family of macros to produce better checks and diagnostic messages.

Location:
testsuites/psxtests/psxsem01
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • testsuites/psxtests/psxsem01/init.c

    r23168f53 r8c5cc6b2  
    44#include <fcntl.h>
    55#include <time.h>
     6#include <tmacros.h>
    67
    78void *POSIX_Init(
     
    1819  sem_t           testsem;
    1920  struct timespec waittime;
     21  char            failure_msg[80];
    2022
    2123  puts( "\n\n*** POSIX SEMAPHORE MANAGER TEST 1 ***" );
     
    2426  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_SEMAPHORES; i++) {
    2527    status = sem_init(&sems[i], 0, i);
    26     assert( status == 0 );
     28    sprintf(failure_msg, "sem_init %d", i );
     29    fatal_directive_status( status, 0, failure_msg);
    2730  }
    2831  puts( "Init: sem_init - UNSUCCESSFUL (ENOSPC)" );
    2932  status = sem_init(&sem2, 0, 1);
    30   assert( (status == -1) && (errno == ENOSPC) );
     33  fatal_directive_status( status, -1, "sem_init error return status");
     34  fatal_directive_status( errno, ENOSPC, "sem_init errorno ENOSPC" );
    3135 
    3236  puts( "Init: sem_init - UNSUCCESSFUL (ENOSYS -- pshared not supported)" );
    3337  status = sem_init(&sem2, 1, 1);
    34   assert( (status == -1) && (errno == ENOSYS) );
     38  fatal_directive_status( status, -1, "sem_init error return status");
     39  fatal_directive_status( errno, ENOSYS, "sem_init errno set to ENOSYS");
    3540 
    3641  puts( "Init: sem_getvalue - SUCCESSFUL ");
    3742  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_SEMAPHORES; i++) {
    3843    status = sem_getvalue(&sems[i], &value);
    39     assert( (status == 0) && (value == i) );
     44    sprintf( failure_msg, "sem_getvalue %d", i );
     45    fatal_directive_status( status, 0, failure_msg );
     46    fatal_directive_status( value, i, "sem_getvalue correct value" );
    4047  }
    4148  puts( "Init: sem_getvalue - UNSUCCESSFUL ");
    4249  status = sem_getvalue(&sem2, &value);
    43   assert( (status == -1) && (errno == EINVAL) );
     50  fatal_directive_status( status, -1, "sem_init error return status");
     51  fatal_directive_status( errno, EINVAL, "sem_getvalue errno EINVAL");
    4452
    4553  puts( "Init: sem_destroy - SUCCESSFUL" );
    4654  status = sem_destroy(&sems[0]);
    47   assert( status == 0 );
     55  fatal_directive_status( status, 0, "sem_destroy semaphore 0");
    4856
    4957  puts( "Init: sem_destroy - UNSUCCESSFUL (EINVAL)" );
    5058  status = sem_destroy(&sem2);
    51   assert( (status == -1) && (errno == EINVAL) );
     59  fatal_directive_status( status, -1, "sem_init error return status");
     60  fatal_directive_status( errno, EINVAL, "sem_destroy errno EINVAL");
    5261
    5362  puts( "Init: sem_wait - SUCCESSFUL" );
    5463  status = sem_wait(&sems[1]);
    55   assert( status == 0);
     64  fatal_directive_status( status, 0, "sem_wait semaphore 1");
    5665
    5766  puts( "Init: sem_wait - UNSUCCESSFUL (EINVAL)" );
    5867  status = sem_wait(&sem2);
    59   assert( (status == -1) && (errno == EINVAL) );
     68  fatal_directive_status( status, -1, "sem_init error return status");
     69  fatal_directive_status( errno, EINVAL, "sem_wait errno EINVAL");
    6070
    6171  puts( "Init: sem_post - SUCCESSFUL" );
    6272  status = sem_post(&sems[1]);
    63   assert( status == 0 );
     73  fatal_directive_status( status, 0, "sem_post semaphore 1");
    6474
    6575  puts( "Init: sem_wait - SUCCESSFUL (after a sem_post)" );
    6676  status = sem_wait(&sems[1]);
    67   assert( status == 0 );
     77  fatal_directive_status( status, 0, "sem_wait semaphore 1");
    6878
    6979  puts( "Init: sem_trywait - SUCCESSFUL" );
    7080  status = sem_trywait(&sems[2]);
    71   assert( status == 0 );
     81  fatal_directive_status( status, 0, "sem_trywait semaphore 2");
    7282
    7383  puts( "Init: sem_trywait - UNSUCCESSFUL (EAGAIN)" );
    7484  status = sem_trywait(&sems[1]);
    75   assert( (status == -1) && (errno == EAGAIN) );
     85  fatal_directive_status( status, -1, "sem_init error return status");
     86  fatal_directive_status( errno, EAGAIN, "sem_trywait errno EAGAIN");
    7687
    7788  puts( "Init: sem_trywait - UNSUCCESSFUL (EINVAL)" );
    7889  status = sem_trywait(&sem2);
    79   assert( (status == -1) && (errno == EINVAL) );
     90  fatal_directive_status( status, -1, "sem_init error return status");
     91  fatal_directive_status( errno, EINVAL, "sem_trywait errno EINVAL");
    8092
    8193  puts( "Init: sem_timedwait - SUCCESSFUL" );
     
    8395  waittime.tv_nsec = 100;
    8496  status = sem_timedwait(&sems[2], &waittime);
    85   assert( status == 0 );
     97  fatal_directive_status( status, 0, "sem_timedwait semaphore 2");
    8698
    8799  puts( "Init: sem_timedwait - UNSUCCESSFUL (ETIMEDOUT)" );
    88100  status = sem_timedwait(&sems[1], &waittime);
    89   assert( (status == -1) && (errno == ETIMEDOUT) );
     101  fatal_directive_status( status, -1, "sem_init error return status");
     102  fatal_directive_status( errno, ETIMEDOUT, "sem_init errno ETIMEDOUT");
    90103
    91104  puts( "Init: sem_timedwait - UNSUCCESSFUL (EINVAL)" );
    92105  status = sem_timedwait(&sem2, &waittime);
    93   assert( (status == -1) && (errno == EINVAL) );
     106  fatal_directive_status( status, -1, "sem_init error return status");
     107  fatal_directive_status( errno, EINVAL, "sem_init errno EINVAL");
    94108
    95109  puts( "Init: sem_post - UNSUCCESSFUL (EINVAL)" );
    96110  status = sem_post(&sem2);
    97   assert( (status == -1) && (errno == EINVAL) );
     111  fatal_directive_status( status, -1, "sem_init error return status");
     112  fatal_directive_status( errno, EINVAL, "sem_post errno EINVAL");
    98113
    99114  puts( "Init: sem_destroy - SUCCESSFUL" );
    100115  for (i = 1; i < CONFIGURE_MAXIMUM_POSIX_SEMAPHORES; i++) {
    101116    status = sem_destroy(&sems[i]);
    102     assert( status == 0);
     117    sprintf( failure_msg, "sem_destroy %d", i );
     118    fatal_directive_status( status, 0, failure_msg );
    103119  }
    104120
    105121  /* Modes are currently unsupported */
    106122
    107   puts( "Init: sem_open - SUCCESSFUL" );
     123  /*
     124   * Validate all sem_open return paths.
     125   */
     126
     127  puts( "Init: sem_open - sem1 SUCCESSFUL" );
    108128  n_sem1 = sem_open("sem1", O_CREAT, 00777, 1);
    109129  assert( n_sem1 != SEM_FAILED );
     
    111131  puts( "Init: sem_open - UNSUCCESSFUL (EEXIST)" );
    112132  n_sem2 = sem_open("sem1", O_CREAT | O_EXCL, 00777, 1);
    113   assert( (n_sem2 == SEM_FAILED) && (errno == EEXIST) );
     133  fatal_directive_status(
     134    (int) n_sem2, (int ) SEM_FAILED, "sem_open error return status" );
     135  fatal_directive_status( errno, EEXIST,  "sem_open errno EEXIST");
     136
     137  /*
     138   * Validate we can wait on a semaphore opened with sem_open.
     139   */
     140
     141  puts( "Init: sem_wait on sem1" );
     142  status = sem_wait(n_sem1);
     143  fatal_directive_status( status, 0, "sem_wait opened semaphore");
     144
     145#if 0
     146  puts( "Init: sem_unlink - sem1 SUCCESSFUL" );
     147  status = sem_unlink( "sem1" );
     148  fatal_directive_status( status, 0, "sem_unlink locked semaphore");
     149
     150  puts( "Init: sem_open - Reopen sem1 SUCCESSFUL with a different id" );
     151  n_sem2 = sem_open( "sem1", O_CREAT | O_EXCL, 00777, 1);
     152  assert( n_sem2 != SEM_FAILED );
     153#endif
     154
     155  /*
     156   * Validate we can call close on a semaphore opened with sem_open.
     157   */
    114158
    115159  puts( "Init: sem_close - SUCCESSFUL" );
    116   status = sem_close(n_sem1);
    117   assert( status == 0);
     160  status = sem_close( n_sem1 );
     161  fatal_directive_status( status, 0, "sem_close semaphore");
    118162
    119163  /*
     164   * Notes: 
     165   *  Calls to sem_close when sem_link has not been previously called shall
     166   *  have no effect on the state of the semaphore.
     167   *
     168   *
     169 
    120170  puts( "Init: sem_close - UNSUCCESSFUL (EINVAL)" );
    121171  status = sem_close(n_sem2);
    122   assert( (status == -1) && (errno == EINVAL) );
     172  fatal_directive_status( status, -1, "sem_init error return status");
     173  fatal_directive_status( errno, EINVAL, "sem_close errno EINVAL");
    123174
    124175  puts( "Init: sem_unlink - SUCCESSFUL" );
    125176  status = sem_unlink("sem1");
    126   assert( status == 0 );
     177  fatal_directive_status( status, 0, "sem_unlink semaphore");
    127178
    128179  puts( "Init: sem_unlink - UNSUCCESSFUL (ENOENT)" );
    129180  status = sem_unlink("sem2");
     181  fatal_directive_status( status, -1, "sem_init error return status");
     182  fatal_directive_status( errno, ENOENT, "sem_unlink errno ENOENT");
    130183  assert( (status == -1) && (errno == ENOENT) );
    131184  */
     
    138191  return NULL; /* just so the compiler thinks we returned something */
    139192}
     193
     194
     195
  • testsuites/psxtests/psxsem01/system.h

    r23168f53 r8c5cc6b2  
    2121#include <sched.h>
    2222#include <semaphore.h>
     23#include <tmacros.h>
    2324
    2425void *POSIX_Init(
     
    4243#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES  10
    4344
     45#define CONFIGURE_POSIX_INIT_THREAD_TABLE
     46#define CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE \
     47        (RTEMS_MINIMUM_STACK_SIZE * 4)
     48
    4449#include <confdefs.h>
    4550
    4651/* global variables */
    47 
    48 #ifdef CONFIGURE_INIT
    49 #define TEST_EXTERN
    50 #else
    51 #define TEST_EXTERN extern
    52 #endif
    5352
    5453TEST_EXTERN pthread_t        Init_id;
     
    5655
    5756/* end of include file */
     57
Note: See TracChangeset for help on using the changeset viewer.