11556Srgrimes/*
21556Srgrimes
31556Srgrimes * Copyright (c) 2002-2003, Intel Corporation. All rights reserved.
41556Srgrimes * Created by:  rusty.lynch REMOVE-THIS AT intel DOT com
51556Srgrimes * This file is licensed under the GPL license.  For the full content
61556Srgrimes * of this license, see the COPYING file at the top level of this
71556Srgrimes * source tree.
81556Srgrimes
91556Srgrimes  Test case for assertion #13 of the sigaction system call that verifies
101556Srgrimes  signal-catching functions are executed on the current stack if the
111556Srgrimes  SA_ONSTACK flag is cleared in the sigaction.sa_flags parameter to the
121556Srgrimes  sigaction function call.
131556Srgrimes
141556Srgrimes  NOTE: This test case does not attempt to verify the proper operation
151556Srgrimes        of sigaltstack.
161556Srgrimes*/
171556Srgrimes
181556Srgrimes#define _XOPEN_SOURCE 600
191556Srgrimes
201556Srgrimes#include <signal.h>
211556Srgrimes#include <stdio.h>
221556Srgrimes#include <stdlib.h>
231556Srgrimes#include "posixtest.h"
241556Srgrimes
251556Srgrimesstack_t current;
261556Srgrimes
271556Srgrimesvoid handler(int signo)
281556Srgrimes{
291556Srgrimes	stack_t oss;
301556Srgrimes
311556Srgrimes	printf("Caught SIGPROF\n");
3217987Speter
3350471Speter	if (sigaltstack((stack_t *)0, &oss) == -1) {
341556Srgrimes		perror("Unexpected error while attempting to setup test "
351556Srgrimes		       "pre-conditions");
361556Srgrimes		exit(-1);
371556Srgrimes	}
381556Srgrimes
391556Srgrimes	if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) {
401556Srgrimes		printf("Test FAILED\n");
411556Srgrimes		exit(-1);
421556Srgrimes	}
431556Srgrimes}
441556Srgrimes
45200956Sjillesint main()
46{
47	struct sigaction act;
48
49	act.sa_handler = handler;
50	act.sa_flags = 0;
51	sigemptyset(&act.sa_mask);
52	if (sigaction(SIGPROF,  &act, 0) == -1) {
53		perror("Unexpected error while attempting to setup test "
54		       "pre-conditions");
55		return PTS_UNRESOLVED;
56	}
57
58	if (sigaltstack((stack_t *)0, &current) == -1) {
59		perror("Unexpected error while attempting to setup test "
60		       "pre-conditions");
61		return PTS_UNRESOLVED;
62	}
63
64	if (raise(SIGPROF) == -1) {
65		perror("Unexpected error while attempting to setup test "
66		       "pre-conditions");
67		return PTS_UNRESOLVED;
68	}
69
70	printf("Test PASSED\n");
71	return PTS_PASS;
72}
73
74