1/* 2* Copyright (c) 2005, 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., 59 15* Temple Place - Suite 330, Boston MA 02111-1307, USA. 16 17 18* This sample test aims to check the following assertions: 19* 20* If SA_SIGINFO is set in sa_flags and Real Time Signals extension is supported, 21* sa_sigaction is used as the signal handling function. 22 23* The steps are: 24* -> test for RTS extension 25* -> register a handler for SIGABRT with SA_SIGINFO, and a known function 26* as sa_sigaction 27* -> raise SIGABRT, and check the function has been called. 28 29* The test fails if the function is not called 30*/ 31 32 33/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ 34#define _POSIX_C_SOURCE 200112L 35 36/******************************************************************************/ 37/*************************** standard includes ********************************/ 38/******************************************************************************/ 39#include <pthread.h> 40#include <stdarg.h> 41#include <stdio.h> 42#include <stdlib.h> 43#include <string.h> 44#include <unistd.h> 45 46#include <signal.h> 47#include <errno.h> 48 49/******************************************************************************/ 50/*************************** Test framework *******************************/ 51/******************************************************************************/ 52#include "testfrmw.h" 53#include "testfrmw.c" 54/* This header is responsible for defining the following macros: 55 * UNRESOLVED(ret, descr); 56 * where descr is a description of the error and ret is an int 57 * (error code for example) 58 * FAILED(descr); 59 * where descr is a short text saying why the test has failed. 60 * PASSED(); 61 * No parameter. 62 * 63 * Both three macros shall terminate the calling process. 64 * The testcase shall not terminate in any other maneer. 65 * 66 * The other file defines the functions 67 * void output_init() 68 * void output(char * string, ...) 69 * 70 * Those may be used to output information. 71 */ 72 73/******************************************************************************/ 74/**************************** Configuration ***********************************/ 75/******************************************************************************/ 76#ifndef VERBOSE 77#define VERBOSE 1 78#endif 79 80#define SIGNAL SIGABRT 81 82/******************************************************************************/ 83/*************************** Test case ***********************************/ 84/******************************************************************************/ 85 86int called = 0; 87void handler( int sig, siginfo_t *info, void *context ) 88{ 89 if ( info->si_signo != SIGNAL ) 90 { 91 FAILED( "Wrong signal generated?" ); 92 } 93 94 called = 1; 95} 96 97/* main function */ 98int main() 99{ 100 int ret; 101 long rts; 102 103 struct sigaction sa; 104 105 /* Initialize output */ 106 output_init(); 107 108 /* Test the RTS extension */ 109 rts = sysconf( _SC_REALTIME_SIGNALS ); 110 111 if ( rts < 0L ) 112 { 113 UNTESTED( "This test needs the RTS extension" ); 114 } 115 116 /* Set the signal handler */ 117 sa.sa_flags = SA_SIGINFO; 118 119 sa.sa_sigaction = handler; 120 121 ret = sigemptyset( &sa.sa_mask ); 122 123 if ( ret != 0 ) 124 { 125 UNRESOLVED( ret, "Failed to empty signal set" ); 126 } 127 128 /* Install the signal handler for SIGABRT */ 129 ret = sigaction( SIGNAL, &sa, 0 ); 130 131 if ( ret != 0 ) 132 { 133 UNRESOLVED( ret, "Failed to set signal handler" ); 134 } 135 136 if ( called ) 137 { 138 FAILED( "The signal handler has been called when no signal was raised" ); 139 } 140 141 ret = raise( SIGNAL ); 142 143 if ( ret != 0 ) 144 { 145 UNRESOLVED( ret, "Failed to raise SIGABRT" ); 146 } 147 148 if ( !called ) 149 { 150 FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); 151 } 152 153 154 /* Test passed */ 155#if VERBOSE > 0 156 157 output( "Test passed\n" ); 158 159#endif 160 161 PASSED; 162} 163