Branch Coverage

SocketAlarm_watcher.c
Criterion Covered Total %
branch 81 170 47.6


line true false branch
7 0 0 int unused= write(2, len <= 0? "error\n":buffer, len <= 0? 6 : len);
0 0 int unused= write(2, len <= 0? "error\n":buffer, len <= 0? 6 : len);
19 23 1 while (do_watch()) {}
30 0 24 if (pthread_mutex_lock(&watch_list_mutex))
37 24 0 capacity= watch_list_count > 1024? 1024 : watch_list_count+1;
38 0 24 buckets= capacity < 16? 16 : capacity < 128? 32 : 64;
0 0 buckets= capacity < 16? 16 : capacity < 128? 32 : 64;
39 24 0 sz= sizeof(struct pollfd) * capacity + POLLFD_RBHASH_SIZEOF(capacity, buckets);
48 179 24 for (i= 0, n= watch_list_count; i < n && n_poll < capacity; i++) {
179 0 for (i= 0, n= watch_list_count; i < n && n_poll < capacity; i++) {
52 57 122 if (alarm->cur_action >= alarm->action_count)
56 0 122 if (alarm->wake_ts.tv_nsec != -1) {
57 0 0 if (wake_time.tv_nsec == -1
58 0 0 || wake_time.tv_sec > alarm->wake_ts.tv_sec
59 0 0 || (wake_time.tv_sec == alarm->wake_ts.tv_sec && wake_time.tv_nsec > alarm->wake_ts.tv_nsec)
0 0 || (wake_time.tv_sec == alarm->wake_ts.tv_sec && wake_time.tv_nsec > alarm->wake_ts.tv_nsec)
69 0 122 if (poll_i < 0) { // corrupt datastruct, should never happen
73 122 0 if (poll_i == n_poll) { // using the new uninitialized one?
81 122 0 if (events & EVENT_SHUT)
84 0 122 if (events & EVENT_EOF) {
87 0 0 if (alarm->unwaitable) // will be set if found data queued in the buffer
92 0 122 if (events & EVENT_IN)
94 0 122 if (events & EVENT_PRI)
96 0 122 if (events & EVENT_CLOSE) {
107 0 24 if (wake_time.tv_nsec != -1) {
109 0 0 if (lazy_build_now_ts(&now_ts)) {
113 0 0 if (wake_delay < delay)
118 0 24 if (poll(pollset, n_poll, delay < 0? 0 : delay) < 0) {
122 146 24 for (i= 0; i < n_poll; i++) {
135 12 12 if (pollset[0].revents & POLLIN) {
138 0 12 if (ret != 1) { // should never fail
142 1 11 if (msg == CONTROL_TERMINATE) {// intentional exit
152 0 12 if (pthread_mutex_lock(&watch_list_mutex))
154 102 12 for (i= 0, n= watch_list_count; i < n; i++) {
157 57 45 if (alarm->cur_action == -1) {
163 57 0 if (fstat(fd, &statbuf) != 0
164 57 0 || statbuf.st_dev != alarm->watch_fd_dev
165 0 57 || statbuf.st_ino != alarm->watch_fd_ino
170 0 0 if (alarm->event_mask & EVENT_CLOSE)
178 0 57 if (poll_i < 0)
183 45 12 trigger= ((alarm->event_mask & EVENT_SHUT) && (revents &
190 0 45 || ((alarm->event_mask & EVENT_IN) && (revents & POLLIN))
0 0 || ((alarm->event_mask & EVENT_IN) && (revents & POLLIN))
191 57 0 || ((alarm->event_mask & EVENT_PRI) && (revents & POLLPRI));
0 45 || ((alarm->event_mask & EVENT_PRI) && (revents & POLLPRI));
0 0 || ((alarm->event_mask & EVENT_PRI) && (revents & POLLPRI));
193 45 12 if (!trigger && (alarm->event_mask & EVENT_EOF) && (alarm->unwaitable || (revents & POLLIN))) {
0 45 if (!trigger && (alarm->event_mask & EVENT_EOF) && (alarm->unwaitable || (revents & POLLIN))) {
0 0 if (!trigger && (alarm->event_mask & EVENT_EOF) && (alarm->unwaitable || (revents & POLLIN))) {
0 0 if (!trigger && (alarm->event_mask & EVENT_EOF) && (alarm->unwaitable || (revents & POLLIN))) {
195 0 0 if (avail == 0)
205 12 45 if (trigger) {
206 12 0 if ((fstat(fd, &statbuf) != 0
207 12 0 || statbuf.st_dev != alarm->watch_fd_dev
208 0 12 || statbuf.st_ino != alarm->watch_fd_ino
209 0 0 ) && !(alarm->event_mask & EVENT_CLOSE)
216 45 12 if (!trigger)
230 0 12 if (pthread_mutex_lock(&watch_list_mutex))
233 1 11 if (!watch_list) {
239 45 11 for (i= watch_list_count-1; i >= 0; --i) {
240 0 45 if (watch_list[i]->cur_action >= watch_list[i]->action_count) {
242 0 0 if (--watch_list_count > i) {
250 0 11 if (watch_list_count >= watch_list_alloc) {
257 12 0 if (i < 0) { // only add if not already added
267 1 11 if (control_pipe[1] < 0) {
272 0 1 if (pipe(control_pipe) != 0)
276 0 1 else if (pthread_sigmask(SIG_SETMASK, &mask, &orig) != 0)
278 0 1 else if (pthread_create(&watch_thread, NULL, (void*(*)(void*)) watch_thread_main, NULL) != 0)
280 0 1 else if (pthread_sigmask(SIG_SETMASK, &orig, NULL) != 0)
284 0 11 if (write(control_pipe[1], &msg, 1) != 1)
288 0 12 if (error)
295 0 3 if (pthread_mutex_lock(&watch_list_mutex))
298 3 0 if (cur_action_out) *cur_action_out= alarm->cur_action;
306 0 28 if (pthread_mutex_lock(&watch_list_mutex))
309 12 28 for (i= watch_list_count-1; i >= 0; --i) {
310 12 0 if (watch_list[i]->cur_action >= watch_list[i]->action_count) {
312 0 12 if (--watch_list_count > i) {
320 0 28 if (i >= 0) {
322 0 0 if (i < watch_list_count-1) {
331 0 0 if (control_pipe[1] >= 0) {
333 0 0 if (write(control_pipe[1], &msg, 1) != 1) {
349 0 6 if (pthread_mutex_lock(&watch_list_mutex))
351 0 6 for (i= 0; i < watch_list_count; i++) {
358 1 5 if (control_pipe[1] >= 0) {
360 0 1 if (write(control_pipe[1], &msg, 1) != 1)