6-3.c revision 1b8a2eaac9978e1f9a829e5e38dc39c892c77c75
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_gettime() sets errno = EINVAL when timerid =
9 * a timer ID of a deleted timer.  Since this assertion is a "may"
10 * assertion, either way is a pass.
11 *
12 * For this test, signal SIGCONT 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
22int main(int argc, char *argv[])
23{
24	struct sigevent ev;
25	timer_t tid;
26	struct itimerspec its;
27
28	ev.sigev_notify = SIGEV_SIGNAL;
29	ev.sigev_signo = SIGCONT;
30
31	if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
32		perror("timer_create() did not return success\n");
33		return PTS_UNRESOLVED;
34	}
35	if (timer_delete(tid) != 0) {
36		perror("timer_delete() did not return success\n");
37		return PTS_UNRESOLVED;
38	}
39
40	if (timer_gettime(tid, &its) == -1) {
41		if (EINVAL == errno) {
42			printf("fcn returned -1 and errno==EINVAL\n");
43			return PTS_PASS;
44		} else {
45			printf("fcn returned -1 but errno!=EINVAL\n");
46			printf("Test FAILED\n");
47			return PTS_FAIL;
48		}
49	}
50	printf("fcn did not return -1\n");
51	return PTS_PASS;
52}
53