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 * Error condition API test for the clock_id parameter of the 9 * clock_settime() function. 10 * 11 * Test calling clock_settime() with the following clock_id values: 12 * MIN INT = INT32_MIN 13 * MAX INT = INT32_MAX 14 * MIN INT - 1 = 2147483647 (this is what gcc will set to) 15 * MAX INT + 1 = -2147483647 (this is what gcc will set to) 16 * unassigned value = -1073743192 (ex. of what gcc will set to) 17 * unassigned value = 1073743192 (ex. of what gcc will set to) 18 * -1 19 * 17 (currently not = to any clock) 20 * 21 * The date chosen is Nov 12, 2002 ~11:13am (date when test was first 22 * written). 23 */ 24 #include <stdio.h> 25 #include <time.h> 26 #include <errno.h> 27 #include <stdint.h> 28 #include <unistd.h> 29 #include "posixtest.h" 30 31 #define TESTTIME 1037128358 32 33 #define NUMINVALIDTESTS 8 34 35 static int invalid_tests[NUMINVALIDTESTS] = { 36 INT32_MIN, INT32_MAX, 2147483647, -2147483647, -1073743192, 37 1073743192, -1, 17 38 }; 39 40 int main(void) 41 { 42 struct timespec tpset; 43 int i; 44 int failure = 0; 45 46 tpset.tv_sec = TESTTIME; 47 tpset.tv_nsec = 0; 48 49 if (geteuid() != 0) { 50 printf("Test must be run as superuser\n"); 51 return PTS_UNRESOLVED; 52 } 53 54 for (i = 0; i < NUMINVALIDTESTS; i++) { 55 if (clock_settime(invalid_tests[i], &tpset) == -1) { 56 if (EINVAL != errno) { 57 printf("errno != EINVAL\n"); 58 failure = 1; 59 } 60 } else { 61 printf("clock_settime() did not return -1\n"); 62 failure = 1; 63 } 64 } 65 66 if (failure) { 67 printf("At least one test FAILED -- see above\n"); 68 return PTS_FAIL; 69 } 70 71 printf("All tests PASSED\n"); 72 return PTS_PASS; 73 } 74