111819Sjulian/*
211819Sjulian* Copyright (c) 2005, Bull S.A..  All rights reserved.
311819Sjulian* Created by: Sebastien Decugis
411819Sjulian
511819Sjulian* This program is free software; you can redistribute it and/or modify it
611819Sjulian* under the terms of version 2 of the GNU General Public License as
711819Sjulian* published by the Free Software Foundation.
811819Sjulian*
911819Sjulian* This program is distributed in the hope that it would be useful, but
1011819Sjulian* WITHOUT ANY WARRANTY; without even the implied warranty of
1111819Sjulian* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1211819Sjulian*
1311819Sjulian* You should have received a copy of the GNU General Public License along
1411819Sjulian* with this program; if not, write the Free Software Foundation, Inc., 59
1511819Sjulian* Temple Place - Suite 330, Boston MA 02111-1307, USA.
1611819Sjulian
1711819Sjulian
1811819Sjulian* This sample test aims to check the following assertions:
1911819Sjulian*
2011819Sjulian* If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal
2111819Sjulian* handling function.
2211819Sjulian
2311819Sjulian* The steps are:
2411819Sjulian* -> register a handler for SIGVTALRM without SA_SIGINFO, and a known function
2511819Sjulian*   as sa��handler
2611819Sjulian* -> raise SIGVTALRM, and check the function has been called.
2711819Sjulian
2811819Sjulian* The test fails if the function is not called
2911819Sjulian*/
3011819Sjulian
3111819Sjulian
3211819Sjulian/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
3311819Sjulian#define _POSIX_C_SOURCE 200112L
3412057Sjulian
3512057Sjulian/******************************************************************************/
3638373Sbde/*************************** standard includes ********************************/
3711819Sjulian/******************************************************************************/
3811819Sjulian#include <pthread.h>
3932350Seivind#include <stdarg.h>
4030806Sbde#include <stdio.h>
4130806Sbde#include <stdlib.h>
4211819Sjulian#include <string.h>
4311819Sjulian#include <unistd.h>
4411819Sjulian
4511819Sjulian#include <signal.h>
4611819Sjulian#include <errno.h>
4711819Sjulian
4811819Sjulian/******************************************************************************/
4911819Sjulian/***************************   Test framework   *******************************/
5030806Sbde/******************************************************************************/
5111819Sjulian#include "testfrmw.h"
5211819Sjulian#include "testfrmw.c"
5311819Sjulian/* This header is responsible for defining the following macros:
5411819Sjulian * UNRESOLVED(ret, descr);
5511819Sjulian *    where descr is a description of the error and ret is an int
5611819Sjulian *   (error code for example)
5715239Sbde * FAILED(descr);
5825652Sjhay *    where descr is a short text saying why the test has failed.
5925652Sjhay * PASSED();
6025652Sjhay *    No parameter.
6115239Sbde *
6215239Sbde * Both three macros shall terminate the calling process.
6311819Sjulian * The testcase shall not terminate in any other maneer.
6411819Sjulian *
6511819Sjulian * The other file defines the functions
6611819Sjulian * void output_init()
6711819Sjulian * void output(char * string, ...)
6811819Sjulian *
6911819Sjulian * Those may be used to output information.
7011819Sjulian */
7111819Sjulian
7211819Sjulian/******************************************************************************/
7311819Sjulian/**************************** Configuration ***********************************/
7411819Sjulian/******************************************************************************/
7511819Sjulian#ifndef VERBOSE
7611819Sjulian#define VERBOSE 1
7711819Sjulian#endif
7811819Sjulian
7911819Sjulian#define SIGNAL SIGVTALRM
8011819Sjulian
8111819Sjulian/******************************************************************************/
8211819Sjulian/***************************    Test case   ***********************************/
8311819Sjulian/******************************************************************************/
8411819Sjulian
8511819Sjulianint called = 0;
8625652Sjhayvoid handler( int sig )
8711819Sjulian{
8811819Sjulian	called = 1;
8925652Sjhay}
9025652Sjhay
9111819Sjulian/* main function */
9211819Sjulianint main()
9325652Sjhay{
9411819Sjulian	int ret;
9511819Sjulian
9611819Sjulian	struct sigaction sa;
9725652Sjhay
9825652Sjhay	/* Initialize output */
9925652Sjhay	output_init();
10025652Sjhay
10125652Sjhay	/* Set the signal handler */
10238373Sbde	sa.sa_flags = 0;
10311819Sjulian	sa.sa_handler = handler;
10411819Sjulian	ret = sigemptyset( &sa.sa_mask );
10514093Swollman
10611819Sjulian	if ( ret != 0 )
10711819Sjulian	{
10811819Sjulian		UNRESOLVED( ret, "Failed to empty signal set" );
10911819Sjulian	}
11011819Sjulian
11111819Sjulian	/* Install the signal handler for SIGVTALRM */
11225652Sjhay	ret = sigaction( SIGNAL, &sa, 0 );
11311819Sjulian
11411819Sjulian	if ( ret != 0 )
11511819Sjulian	{
11611819Sjulian		UNRESOLVED( ret, "Failed to set signal handler" );
11711819Sjulian	}
11811819Sjulian
11911819Sjulian	if ( called )
12011819Sjulian	{
12111819Sjulian		FAILED( "The signal handler has been called when no signal was raised" );
12211819Sjulian	}
12311819Sjulian
12411819Sjulian	ret = raise( SIGNAL );
12511819Sjulian
12611819Sjulian	if ( ret != 0 )
12711819Sjulian	{
12811819Sjulian		UNRESOLVED( ret, "Failed to raise SIGVTALRM" );
12911819Sjulian	}
13011819Sjulian
13111819Sjulian	if ( !called )
13211819Sjulian	{
13311819Sjulian		FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" );
13411819Sjulian	}
13511819Sjulian
13611819Sjulian
13711819Sjulian	/* Test passed */
13811819Sjulian#if VERBOSE > 0
13911819Sjulian
14011819Sjulian	output( "Test passed\n" );
14111819Sjulian
14211819Sjulian#endif
14311819Sjulian
14411819Sjulian	PASSED;
14511819Sjulian}
14625652Sjhay