1/*
2 * Copyright (c) 2002, Intel Corporation. All rights reserved.
3 * Created by:  bing.wei.liu 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 pthread_condattr_setclock()
9 *
10 *  If it is called with a clock_id argument that refers to a CPU-time clock, the call
11 *  shall fail.
12 *
13 * Steps:
14 * 1.  Initialize a pthread_condattr_t object
15 * 2.  Get the cpu clock id
16 * 3.  Call pthread_condattr_setclock passing this clock id to it
17 * 4.  It should fail.
18 *
19 */
20
21# define _XOPEN_SOURCE  600
22
23#include <pthread.h>
24#include <unistd.h>
25#include <stdio.h>
26#include <errno.h>
27#include <time.h>
28#include "posixtest.h"
29
30int main()
31{
32
33	#if _POSIX_CPUTIME == -1
34		printf("_POSIX_CPUTIME unsupported\n");
35		return PTS_UNSUPPORTED;
36	#endif
37
38	pthread_condattr_t condattr;
39	clockid_t clockid;
40	int rc;
41
42	if (sysconf(_SC_CPUTIME) == -1) {
43		printf("_POSIX_CPUTIME unsupported\n");
44		return PTS_UNSUPPORTED;
45	}
46
47	/* Initialize a cond attributes object */
48	if((rc=pthread_condattr_init(&condattr)) != 0)
49	{
50		fprintf(stderr,"Error at pthread_condattr_init(), rc=%d\n",rc);
51		printf("Test FAILED\n");
52		return PTS_FAIL;
53	}
54
55	/* Get the cpu clock id */
56
57	if (clock_getcpuclockid(getpid(), &clockid) != 0)
58	{
59		printf("clock_getcpuclockid() failed\n");
60		return PTS_FAIL;
61	}
62
63	rc = pthread_condattr_setclock(&condattr, clockid);
64	if(rc != EINVAL)
65	{
66		printf("Test FAILED: Expected EINVAL when passing a cpu clock id, instead it returned: %d \n", rc);
67		return PTS_FAIL;
68	}
69
70	printf("Test PASSED\n");
71	return PTS_PASS;
72}
73