1 /* 2 * Copyright (c) 2004, Bull S.A.. All rights reserved. 3 * Created by: Sebastien Decugis 4 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of version 2 of the GNU General Public License as 7 * published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope that it would be useful, but 10 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 * 13 * You should have received a copy of the GNU General Public License along 14 * with this program; if not, write the Free Software Foundation, Inc., 15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 17 * This sample test aims to check the following assertion: 18 * 19 * Interval timers are reset in the child process. 20 21 * The steps are: 22 * -> create an interval timer in the parent process 23 * -> fork 24 * -> check the timer has been cleared in child. 25 26 * The test fails if the timer is running in the child. 27 28 */ 29 30 /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ 31 #define _POSIX_C_SOURCE 200112L 32 33 /* The interval timers are an XSI feature */ 34 #ifndef WITHOUT_XOPEN 35 #define _XOPEN_SOURCE 600 36 #endif 37 38 #include <pthread.h> 39 #include <stdarg.h> 40 #include <stdio.h> 41 #include <stdlib.h> 42 #include <string.h> 43 #include <unistd.h> 44 45 #include <sys/wait.h> 46 #include <errno.h> 47 48 #include <sys/time.h> 49 50 #include "../testfrmw/testfrmw.h" 51 #include "../testfrmw/testfrmw.c" 52 53 #ifndef VERBOSE 54 #define VERBOSE 1 55 #endif 56 57 #ifndef WITHOUT_XOPEN 58 59 int main(void) 60 { 61 int ret, status; 62 pid_t child, ctl; 63 64 struct itimerval it; 65 66 output_init(); 67 68 /* Create the interval timer */ 69 it.it_interval.tv_sec = 15; 70 it.it_interval.tv_usec = 0; 71 it.it_value.tv_sec = 10; 72 it.it_value.tv_usec = 0; 73 74 ret = setitimer(ITIMER_REAL, &it, NULL); 75 76 if (ret != 0) { 77 UNRESOLVED(errno, 78 "Failed to set interval timer for ITIMER_REAL"); 79 } 80 81 ret = setitimer(ITIMER_VIRTUAL, &it, NULL); 82 83 if (ret != 0) { 84 UNRESOLVED(errno, 85 "Failed to set interval timer for ITIMER_VIRTUAL"); 86 } 87 88 ret = setitimer(ITIMER_PROF, &it, NULL); 89 90 if (ret != 0) { 91 UNRESOLVED(errno, 92 "Failed to set interval timer for ITIMER_PROF"); 93 } 94 #if VERBOSE > 0 95 output("All interval timers are set.\n"); 96 97 #endif 98 99 /* Create the child */ 100 child = fork(); 101 102 if (child == -1) { 103 UNRESOLVED(errno, "Failed to fork"); 104 } 105 106 /* child */ 107 if (child == 0) { 108 /* Check we get the correct information: timer is reset */ 109 ret = getitimer(ITIMER_REAL, &it); 110 111 if (ret != 0) { 112 UNRESOLVED(errno, 113 "Failed to read ITIMER_REAL in child"); 114 } 115 116 if (it.it_value.tv_sec != 0) { 117 FAILED("Timer ITIMER_REAL was not reset in child"); 118 } 119 120 ret = getitimer(ITIMER_VIRTUAL, &it); 121 122 if (ret != 0) { 123 UNRESOLVED(errno, 124 "Failed to read ITIMER_VIRTUAL in child"); 125 } 126 127 if (it.it_value.tv_sec != 0) { 128 FAILED("Timer ITIMER_VIRTUAL was not reset in child"); 129 } 130 131 ret = getitimer(ITIMER_PROF, &it); 132 133 if (ret != 0) { 134 UNRESOLVED(errno, 135 "Failed to read ITIMER_PROF in child"); 136 } 137 138 if (it.it_value.tv_sec != 0) { 139 FAILED("Timer ITIMER_PROF was not reset in child"); 140 } 141 142 /* We're done */ 143 exit(PTS_PASS); 144 } 145 146 /* Parent joins the child */ 147 ctl = waitpid(child, &status, 0); 148 149 if (ctl != child) { 150 UNRESOLVED(errno, "Waitpid returned the wrong PID"); 151 } 152 153 if (!WIFEXITED(status) || (WEXITSTATUS(status) != PTS_PASS)) { 154 FAILED("Child exited abnormally"); 155 } 156 157 #if VERBOSE > 0 158 output("Test passed\n"); 159 #endif 160 161 PASSED; 162 } 163 164 #else /* WITHOUT_XOPEN */ 165 int main(void) 166 { 167 output_init(); 168 UNTESTED("This testcase requires XSI features"); 169 } 170 #endif 171