1/*
2 * Copyright (c) 2002, Intel Corporation. All rights reserved.
3 * Created by:  julie.n.fleischer REMOVE-THIS AT intel DOT com
4 * This file is licensed under the GPL license.  For the full content
5 * of this license, see the COPYING file at the top level of this
6 * source tree.
7 *
8 * Test to see if timer_settime() sets errno = EINVAL when timerid =
9 * a timer ID of a deleted timer.  Since this is a "may" assertion, either
10 * way is a pass.
11 *
12 * For this test, signal SIGTOTEST will be used.
13 * Clock CLOCK_REALTIME will be used.
14 */
15
16#include <time.h>
17#include <signal.h>
18#include <stdio.h>
19#include <errno.h>
20#include "posixtest.h"
21
22#define SIGTOTEST SIGALRM
23
24int main(void)
25{
26	struct sigevent ev;
27	timer_t tid;
28	struct itimerspec its;
29
30	its.it_interval.tv_sec = 0;
31	its.it_interval.tv_nsec = 0;
32	its.it_value.tv_sec = 0;
33	its.it_value.tv_nsec = 0;
34
35	ev.sigev_notify = SIGEV_SIGNAL;
36	ev.sigev_signo = SIGTOTEST;
37
38	if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
39		perror("timer_create() did not return success\n");
40		return PTS_UNRESOLVED;
41	}
42	if (timer_delete(tid) != 0) {
43		perror("timer_delete() did not return success\n");
44		return PTS_UNRESOLVED;
45	}
46
47	if (timer_settime(tid, 0, &its, NULL) == -1) {
48		if (EINVAL == errno) {
49			printf("fcn returned -1 and errno==EINVAL\n");
50			return PTS_PASS;
51		} else {
52			printf("fcn returned -1 but errno!=EINVAL\n");
53			printf("Test FAILED\n");
54			return PTS_FAIL;
55		}
56	}
57	printf("fcn did not return -1\n");
58	return PTS_PASS;
59}
60