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 that timer_create() sets errno to EAGAIN if the system doesn't
9 * have enough queuing resources to honor this request or the creation
10 * of the timer would exceed the allowable timers that the calling process
11 * can create.
12 *
13 * Finding the true limits of the system would be a stress test, so this
14 * test will make a best attempt by going up to TIMER_MAX.  If this
15 * does not work, test will output PASS and say that results were
16 * inconclusive.
17 *
18 * For this test, signal SIGALRM will be used, clock CLOCK_REALTIME
19 * will be used.
20 */
21
22#include <time.h>
23#include <signal.h>
24#include <stdio.h>
25#include <errno.h>
26#include <limits.h>
27#include "posixtest.h"
28
29int main(void)
30{
31#ifdef TIMER_MAX
32	struct sigevent ev;
33	timer_t tid;
34	int i;
35
36	ev.sigev_notify = SIGEV_SIGNAL;
37	ev.sigev_signo = SIGALRM;
38
39	for (i = 0; i < TIMER_MAX + 1; i++) {
40		if (timer_create(CLOCK_REALTIME, &ev, &tid) == -1) {
41			printf("Stopped after %d timers.\n", i);
42			if (EAGAIN == errno) {
43				printf("Test PASSED\n");
44				return PTS_PASS;
45			} else {
46				printf("errno != EAGAIN\n");
47				printf("Test FAILED\n");
48				return PTS_FAIL;
49			}
50		}
51
52	}
53
54	printf("timer_create() with > TIMER_MAX timers created\n");
55	printf("Test INCONCLUSIVE - mark as PASS\n");
56	return PTS_PASS;
57#else
58	return PTS_PASS;
59#endif
60}
61