10dc076565f772bb1953209fb69ea150b494aaa40robbiew/*
20dc076565f772bb1953209fb69ea150b494aaa40robbiew * Copyright (c) 2002-2003, Intel Corporation. All rights reserved.
30dc076565f772bb1953209fb69ea150b494aaa40robbiew * Created by:  Rusty.Lnch REMOVE-THIS AT intel DOT com
40dc076565f772bb1953209fb69ea150b494aaa40robbiew * This file is licensed under the GPL license.  For the full content
52c28215423293e443469a07ae7011135d058b671Garrett Cooper * of this license, see the COPYING file at the top level of this
60dc076565f772bb1953209fb69ea150b494aaa40robbiew * source tree.
70dc076565f772bb1953209fb69ea150b494aaa40robbiew
80dc076565f772bb1953209fb69ea150b494aaa40robbiew  Test case for assertion #1 of the sigaction system call that shows
90dc076565f772bb1953209fb69ea150b494aaa40robbiew  sigaction (when used with a non-null act pointer) changes the action
100dc076565f772bb1953209fb69ea150b494aaa40robbiew  for a signal.
110dc076565f772bb1953209fb69ea150b494aaa40robbiew
120dc076565f772bb1953209fb69ea150b494aaa40robbiew  Steps:
130dc076565f772bb1953209fb69ea150b494aaa40robbiew  1. Initialize a global variable to indicate the signal
142c28215423293e443469a07ae7011135d058b671Garrett Cooper     handler has not been called. (A signal handler of the
150dc076565f772bb1953209fb69ea150b494aaa40robbiew     prototype "void func(int signo);" will set the global
162c28215423293e443469a07ae7011135d058b671Garrett Cooper     variable to indicate otherwise.
170dc076565f772bb1953209fb69ea150b494aaa40robbiew  2. Use sigaction to setup a signal handler for SIGTRAP
180dc076565f772bb1953209fb69ea150b494aaa40robbiew  3. Raise SIGTRAP.
190dc076565f772bb1953209fb69ea150b494aaa40robbiew  4. Verify the global indicates the signal was called.
200dc076565f772bb1953209fb69ea150b494aaa40robbiew*/
210dc076565f772bb1953209fb69ea150b494aaa40robbiew
220dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <signal.h>
230dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdio.h>
240dc076565f772bb1953209fb69ea150b494aaa40robbiew#include "posixtest.h"
250dc076565f772bb1953209fb69ea150b494aaa40robbiew
260dc076565f772bb1953209fb69ea150b494aaa40robbiewint handler_called = 0;
270dc076565f772bb1953209fb69ea150b494aaa40robbiew
280dc076565f772bb1953209fb69ea150b494aaa40robbiewvoid handler(int signo)
290dc076565f772bb1953209fb69ea150b494aaa40robbiew{
300dc076565f772bb1953209fb69ea150b494aaa40robbiew	handler_called = 1;
310dc076565f772bb1953209fb69ea150b494aaa40robbiew}
320dc076565f772bb1953209fb69ea150b494aaa40robbiew
334ca2bbdcd3003f3c8df4e6129e9c7b2bd1514f87Cyril Hrubisint main(void)
340dc076565f772bb1953209fb69ea150b494aaa40robbiew{
350dc076565f772bb1953209fb69ea150b494aaa40robbiew	struct sigaction act;
362c28215423293e443469a07ae7011135d058b671Garrett Cooper
370dc076565f772bb1953209fb69ea150b494aaa40robbiew	act.sa_handler = handler;
380dc076565f772bb1953209fb69ea150b494aaa40robbiew	act.sa_flags = 0;
390dc076565f772bb1953209fb69ea150b494aaa40robbiew	sigemptyset(&act.sa_mask);
40354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	if (sigaction(SIGTRAP, &act, 0) == -1) {
410dc076565f772bb1953209fb69ea150b494aaa40robbiew		perror("Unexpected error while attempting to setup test "
420dc076565f772bb1953209fb69ea150b494aaa40robbiew		       "pre-conditions");
430dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_UNRESOLVED;
440dc076565f772bb1953209fb69ea150b494aaa40robbiew	}
452c28215423293e443469a07ae7011135d058b671Garrett Cooper
460dc076565f772bb1953209fb69ea150b494aaa40robbiew	if (raise(SIGTRAP) == -1) {
470dc076565f772bb1953209fb69ea150b494aaa40robbiew		perror("Unexpected error while attempting to setup test "
480dc076565f772bb1953209fb69ea150b494aaa40robbiew		       "pre-conditions");
490dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_UNRESOLVED;
500dc076565f772bb1953209fb69ea150b494aaa40robbiew	}
510dc076565f772bb1953209fb69ea150b494aaa40robbiew
520dc076565f772bb1953209fb69ea150b494aaa40robbiew	if (handler_called) {
530dc076565f772bb1953209fb69ea150b494aaa40robbiew		printf("Test PASSED\n");
540dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_PASS;
550dc076565f772bb1953209fb69ea150b494aaa40robbiew	}
560dc076565f772bb1953209fb69ea150b494aaa40robbiew
570dc076565f772bb1953209fb69ea150b494aaa40robbiew	printf("Test FAILED\n");
582c28215423293e443469a07ae7011135d058b671Garrett Cooper	return PTS_FAIL;
59ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman}
60