Home | History | Annotate | Download | only in pthread_exit
      1 /*
      2  * Copyright (c) 2004, Bull S.A..  All rights reserved.
      3  * Created by: Sebastien Decugis
      4 
      5  * This program is free software; you can redistribute it and/or modify it
      6  * under the terms of version 2 of the GNU General Public License as
      7  * published by the Free Software Foundation.
      8  *
      9  * This program is distributed in the hope that it would be useful, but
     10  * WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     12  *
     13  * You should have received a copy of the GNU General Public License along
     14  * with this program; if not, write the Free Software Foundation, Inc.,
     15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     16 
     17  * This sample test aims to check the following assertion:
     18  *
     19  * The pthread_exit() routine never returns to its caller
     20 
     21  * The steps are:
     22  *
     23  * -> create some threads with different attributes
     24  * -> in the thread call pthread_exit
     25  * -> if the function returns, the test fails.
     26  */
     27 
     28 /********************************************************************************************/
     29 /****************************** standard includes *****************************************/
     30 /********************************************************************************************/
     31 #include <pthread.h>
     32 #include <stdarg.h>
     33 #include <stdio.h>
     34 #include <stdlib.h>
     35 #include <string.h>
     36 #include <unistd.h>
     37 
     38 #include <sched.h>
     39 #include <semaphore.h>
     40 #include <errno.h>
     41 #include <assert.h>
     42 
     43  /********************************************************************************************/
     44 /******************************   Test framework   *****************************************/
     45 /********************************************************************************************/
     46 #include "../testfrmw/testfrmw.h"
     47 #include "../testfrmw/testfrmw.c"
     48  /* This header is responsible for defining the following macros:
     49   * UNRESOLVED(ret, descr);
     50   *    where descr is a description of the error and ret is an int (error code for example)
     51   * FAILED(descr);
     52   *    where descr is a short text saying why the test has failed.
     53   * PASSED();
     54   *    No parameter.
     55   *
     56   * Both three macros shall terminate the calling process.
     57   * The testcase shall not terminate in any other maneer.
     58   *
     59   * The other file defines the functions
     60   * void output_init()
     61   * void output(char * string, ...)
     62   *
     63   * Those may be used to output information.
     64   */
     65 
     66 /********************************************************************************************/
     67 /********************************** Configuration ******************************************/
     68 /********************************************************************************************/
     69 #ifndef VERBOSE
     70 #define VERBOSE 1
     71 #endif
     72 
     73 /********************************************************************************************/
     74 /***********************************    Test cases  *****************************************/
     75 /********************************************************************************************/
     76 
     77 /* main is defined in the next file */
     78 #define STD_MAIN
     79 #include "../testfrmw/threads_scenarii.c"
     80 
     81 /* This file will define the following objects:
     82  * scenarii: array of struct __scenario type.
     83  * NSCENAR : macro giving the total # of scenarii
     84  * scenar_init(): function to call before use the scenarii array.
     85  * scenar_fini(): function to call after end of use of the scenarii array.
     86  */
     87 
     88 /********************************************************************************************/
     89 /***********************************    Real Test   *****************************************/
     90 /********************************************************************************************/
     91 
     92 /* Thread routine */
     93 void *threaded(void *arg)
     94 {
     95 	int ret = 0;
     96 
     97 	/* Signal we're done (especially in case of a detached thread) */
     98 	do {
     99 		ret = sem_post(&scenarii[sc].sem);
    100 	}
    101 	while ((ret == -1) && (errno == EINTR));
    102 	if (ret == -1) {
    103 		UNRESOLVED(errno, "Failed to wait for the semaphore");
    104 	}
    105 
    106 	pthread_exit(arg);
    107 
    108 	FAILED("pthread_exit() returned");
    109 
    110 	/* Compiler complaisance */
    111 	return NULL;
    112 }
    113