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_settime() will return ovalue.it_value = the previous 9 * amount of time before the timer would have expired. 10 * - set up a timer to expire in TIMERSEC seconds 11 * - sleep for TIMERSEC-TIMELEFT seconds 12 * - set up a new timer 13 * - compare TIMELEFT and the value in ovalue.it_value and ensure they 14 * are within ACCEPTABLEDELTA of each other 15 * 16 * For this test, signal SIGCONT will be used so that the test will 17 * not abort. Clock CLOCK_REALTIME will be used. 18 */ 19 20#include <time.h> 21#include <signal.h> 22#include <stdio.h> 23#include <unistd.h> 24#include <stdlib.h> 25#include "posixtest.h" 26 27#define TIMERSEC 7 28#define TIMELEFT 5 29#define ACCEPTABLEDELTA 1 30 31int main(void) 32{ 33 struct sigevent ev; 34 timer_t tid; 35 struct itimerspec its, oits; 36 37 ev.sigev_notify = SIGEV_SIGNAL; 38 ev.sigev_signo = SIGCONT; 39 40 its.it_interval.tv_sec = 0; 41 its.it_interval.tv_nsec = 0; 42 its.it_value.tv_sec = TIMERSEC; 43 its.it_value.tv_nsec = 0; 44 45 if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { 46 perror("timer_create() did not return success\n"); 47 return PTS_UNRESOLVED; 48 } 49 50 if (timer_settime(tid, 0, &its, &oits) != 0) { 51 perror("timer_settime() did not return success\n"); 52 return PTS_UNRESOLVED; 53 } 54 55 sleep(TIMERSEC - TIMELEFT); 56 57 if (timer_settime(tid, 0, &its, &oits) != 0) { 58 perror("timer_settime() did not return success\n"); 59 return PTS_UNRESOLVED; 60 } 61 62 if (abs(oits.it_value.tv_sec - TIMELEFT) <= ACCEPTABLEDELTA) { 63 printf("Test PASSED\n"); 64 return PTS_PASS; 65 } 66 67 printf("Test FAILED: time left %d oits.it_value.tv_sec %d\n", 68 TIMELEFT, (int)oits.it_value.tv_sec); 69 return PTS_FAIL; 70} 71