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 clock_getres() sets errno=EINVAL if clock_id does not 9 * refer to a known clock. 10 */ 11#include <errno.h> 12#include <stdio.h> 13#include <stdlib.h> 14#include <string.h> 15#include <time.h> 16#include <unistd.h> 17#include <sys/wait.h> 18#include "posixtest.h" 19 20static clockid_t get_invalid_clock_id() 21{ 22#if _POSIX_CPUTIME == -1 23 printf("clock_getcpuclockid() not supported\n"); 24 exit(PTS_UNTESTED); 25#else 26 clockid_t clockID; 27 int error; 28 29 if (sysconf(_SC_CPUTIME) == -1) { 30 printf("clock_getcpuclockid() not supported\n"); 31 exit(PTS_UNTESTED); 32 } 33 34 int pid = fork(); 35 if (pid < 0) { 36 perror("fork() failed"); 37 exit(PTS_UNRESOLVED); 38 } 39 40 if (pid == 0) { 41 // child -- just wait a second 42 sleep(1); 43 exit(0); 44 } 45 46 // parent -- get the child's CPU clock ID 47 error = clock_getcpuclockid(pid, &clockID); 48 if (error != 0) { 49 printf("clock_getcpuclockid() failed: %s\n", strerror(error)); 50 exit(PTS_UNRESOLVED); 51 } 52 53 // wait for the child 54 if (wait(NULL) != pid) { 55 perror("wait() failed"); 56 exit(PTS_UNRESOLVED); 57 } 58 59 return clockID; 60#endif 61} 62 63int main(int argc, char *argv[]) 64{ 65 struct timespec res; 66 clockid_t invalidClockID; 67 68 invalidClockID = get_invalid_clock_id(); 69 70 if (clock_getres(invalidClockID, &res) == -1) { 71 if (EINVAL == errno) { 72 printf("Test PASSED\n"); 73 return PTS_PASS; 74 } else { 75 printf("errno != EINVAL\n"); 76 return PTS_FAIL; 77 } 78 } else { 79 printf("clock_getres() did not return -1\n"); 80 return PTS_UNRESOLVED; 81 } 82 83 return PTS_UNRESOLVED; 84} 85