10dc076565f772bb1953209fb69ea150b494aaa40robbiew/* 20dc076565f772bb1953209fb69ea150b494aaa40robbiew * Copyright (c) 2004, Bull S.A.. All rights reserved. 30dc076565f772bb1953209fb69ea150b494aaa40robbiew * Created by: Sebastien Decugis 40dc076565f772bb1953209fb69ea150b494aaa40robbiew 50dc076565f772bb1953209fb69ea150b494aaa40robbiew * This program is free software; you can redistribute it and/or modify it 60dc076565f772bb1953209fb69ea150b494aaa40robbiew * under the terms of version 2 of the GNU General Public License as 70dc076565f772bb1953209fb69ea150b494aaa40robbiew * published by the Free Software Foundation. 80dc076565f772bb1953209fb69ea150b494aaa40robbiew * 90dc076565f772bb1953209fb69ea150b494aaa40robbiew * This program is distributed in the hope that it would be useful, but 100dc076565f772bb1953209fb69ea150b494aaa40robbiew * WITHOUT ANY WARRANTY; without even the implied warranty of 110dc076565f772bb1953209fb69ea150b494aaa40robbiew * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 120dc076565f772bb1953209fb69ea150b494aaa40robbiew * 130dc076565f772bb1953209fb69ea150b494aaa40robbiew * You should have received a copy of the GNU General Public License along 14fed9641096e27f79a0f2d9adfe9839dd8d11dc0fWanlong Gao * with this program; if not, write the Free Software Foundation, Inc., 15fed9641096e27f79a0f2d9adfe9839dd8d11dc0fWanlong Gao * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 160dc076565f772bb1953209fb69ea150b494aaa40robbiew 170dc076565f772bb1953209fb69ea150b494aaa40robbiew * This sample test aims to check the following assertion: 180dc076565f772bb1953209fb69ea150b494aaa40robbiew * 190dc076565f772bb1953209fb69ea150b494aaa40robbiew * The pthread_exit() routine never returns to its caller 202c28215423293e443469a07ae7011135d058b671Garrett Cooper 210dc076565f772bb1953209fb69ea150b494aaa40robbiew * The steps are: 220dc076565f772bb1953209fb69ea150b494aaa40robbiew * 230dc076565f772bb1953209fb69ea150b494aaa40robbiew * -> create some threads with different attributes 240dc076565f772bb1953209fb69ea150b494aaa40robbiew * -> in the thread call pthread_exit 250dc076565f772bb1953209fb69ea150b494aaa40robbiew * -> if the function returns, the test fails. 260dc076565f772bb1953209fb69ea150b494aaa40robbiew */ 272c28215423293e443469a07ae7011135d058b671Garrett Cooper 280dc076565f772bb1953209fb69ea150b494aaa40robbiew /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ 29354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao#define _POSIX_C_SOURCE 200112L 302c28215423293e443469a07ae7011135d058b671Garrett Cooper 310dc076565f772bb1953209fb69ea150b494aaa40robbiew /* Some routines are part of the XSI Extensions */ 320dc076565f772bb1953209fb69ea150b494aaa40robbiew#ifndef WITHOUT_XOPEN 33354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao#define _XOPEN_SOURCE 600 340dc076565f772bb1953209fb69ea150b494aaa40robbiew#endif 350dc076565f772bb1953209fb69ea150b494aaa40robbiew 360dc076565f772bb1953209fb69ea150b494aaa40robbiew/********************************************************************************************/ 370dc076565f772bb1953209fb69ea150b494aaa40robbiew/****************************** standard includes *****************************************/ 380dc076565f772bb1953209fb69ea150b494aaa40robbiew/********************************************************************************************/ 39354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao#include <pthread.h> 40354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao#include <stdarg.h> 41354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao#include <stdio.h> 42354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao#include <stdlib.h> 43354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao#include <string.h> 44354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao#include <unistd.h> 45354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao 46354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao#include <sched.h> 47354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao#include <semaphore.h> 48354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao#include <errno.h> 49354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao#include <assert.h> 500dc076565f772bb1953209fb69ea150b494aaa40robbiew 510dc076565f772bb1953209fb69ea150b494aaa40robbiew /********************************************************************************************/ 520dc076565f772bb1953209fb69ea150b494aaa40robbiew/****************************** Test framework *****************************************/ 530dc076565f772bb1953209fb69ea150b494aaa40robbiew/********************************************************************************************/ 54354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao#include "../testfrmw/testfrmw.h" 55354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao#include "../testfrmw/testfrmw.c" 560dc076565f772bb1953209fb69ea150b494aaa40robbiew /* This header is responsible for defining the following macros: 572c28215423293e443469a07ae7011135d058b671Garrett Cooper * UNRESOLVED(ret, descr); 580dc076565f772bb1953209fb69ea150b494aaa40robbiew * where descr is a description of the error and ret is an int (error code for example) 590dc076565f772bb1953209fb69ea150b494aaa40robbiew * FAILED(descr); 600dc076565f772bb1953209fb69ea150b494aaa40robbiew * where descr is a short text saying why the test has failed. 610dc076565f772bb1953209fb69ea150b494aaa40robbiew * PASSED(); 620dc076565f772bb1953209fb69ea150b494aaa40robbiew * No parameter. 632c28215423293e443469a07ae7011135d058b671Garrett Cooper * 640dc076565f772bb1953209fb69ea150b494aaa40robbiew * Both three macros shall terminate the calling process. 650dc076565f772bb1953209fb69ea150b494aaa40robbiew * The testcase shall not terminate in any other maneer. 662c28215423293e443469a07ae7011135d058b671Garrett Cooper * 670dc076565f772bb1953209fb69ea150b494aaa40robbiew * The other file defines the functions 680dc076565f772bb1953209fb69ea150b494aaa40robbiew * void output_init() 690dc076565f772bb1953209fb69ea150b494aaa40robbiew * void output(char * string, ...) 702c28215423293e443469a07ae7011135d058b671Garrett Cooper * 710dc076565f772bb1953209fb69ea150b494aaa40robbiew * Those may be used to output information. 720dc076565f772bb1953209fb69ea150b494aaa40robbiew */ 730dc076565f772bb1953209fb69ea150b494aaa40robbiew 740dc076565f772bb1953209fb69ea150b494aaa40robbiew/********************************************************************************************/ 750dc076565f772bb1953209fb69ea150b494aaa40robbiew/********************************** Configuration ******************************************/ 760dc076565f772bb1953209fb69ea150b494aaa40robbiew/********************************************************************************************/ 770dc076565f772bb1953209fb69ea150b494aaa40robbiew#ifndef VERBOSE 780dc076565f772bb1953209fb69ea150b494aaa40robbiew#define VERBOSE 1 790dc076565f772bb1953209fb69ea150b494aaa40robbiew#endif 800dc076565f772bb1953209fb69ea150b494aaa40robbiew 810dc076565f772bb1953209fb69ea150b494aaa40robbiew/********************************************************************************************/ 820dc076565f772bb1953209fb69ea150b494aaa40robbiew/*********************************** Test cases *****************************************/ 830dc076565f772bb1953209fb69ea150b494aaa40robbiew/********************************************************************************************/ 840dc076565f772bb1953209fb69ea150b494aaa40robbiew 850dc076565f772bb1953209fb69ea150b494aaa40robbiew/* main is defined in the next file */ 860dc076565f772bb1953209fb69ea150b494aaa40robbiew#define STD_MAIN 878d9c084e1770f2719ef99a79416584c945cc775fWanlong Gao#include "../testfrmw/threads_scenarii.c" 880dc076565f772bb1953209fb69ea150b494aaa40robbiew 890dc076565f772bb1953209fb69ea150b494aaa40robbiew/* This file will define the following objects: 900dc076565f772bb1953209fb69ea150b494aaa40robbiew * scenarii: array of struct __scenario type. 910dc076565f772bb1953209fb69ea150b494aaa40robbiew * NSCENAR : macro giving the total # of scenarii 920dc076565f772bb1953209fb69ea150b494aaa40robbiew * scenar_init(): function to call before use the scenarii array. 930dc076565f772bb1953209fb69ea150b494aaa40robbiew * scenar_fini(): function to call after end of use of the scenarii array. 940dc076565f772bb1953209fb69ea150b494aaa40robbiew */ 950dc076565f772bb1953209fb69ea150b494aaa40robbiew 960dc076565f772bb1953209fb69ea150b494aaa40robbiew/********************************************************************************************/ 970dc076565f772bb1953209fb69ea150b494aaa40robbiew/*********************************** Real Test *****************************************/ 980dc076565f772bb1953209fb69ea150b494aaa40robbiew/********************************************************************************************/ 990dc076565f772bb1953209fb69ea150b494aaa40robbiew 1000dc076565f772bb1953209fb69ea150b494aaa40robbiew/* Thread routine */ 101354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaovoid *threaded(void *arg) 1020dc076565f772bb1953209fb69ea150b494aaa40robbiew{ 1030dc076565f772bb1953209fb69ea150b494aaa40robbiew int ret = 0; 1042c28215423293e443469a07ae7011135d058b671Garrett Cooper 1050dc076565f772bb1953209fb69ea150b494aaa40robbiew /* Signal we're done (especially in case of a detached thread) */ 106354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao do { 107354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao ret = sem_post(&scenarii[sc].sem); 108354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao } 1090dc076565f772bb1953209fb69ea150b494aaa40robbiew while ((ret == -1) && (errno == EINTR)); 110354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao if (ret == -1) { 111354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao UNRESOLVED(errno, "Failed to wait for the semaphore"); 112354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao } 1132c28215423293e443469a07ae7011135d058b671Garrett Cooper 1140dc076565f772bb1953209fb69ea150b494aaa40robbiew pthread_exit(arg); 1152c28215423293e443469a07ae7011135d058b671Garrett Cooper 1162c28215423293e443469a07ae7011135d058b671Garrett Cooper FAILED("pthread_exit() returned"); 1172c28215423293e443469a07ae7011135d058b671Garrett Cooper 1180dc076565f772bb1953209fb69ea150b494aaa40robbiew /* Compiler complaisance */ 1190dc076565f772bb1953209fb69ea150b494aaa40robbiew return NULL; 120ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman} 121