| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: t_timeleft.c,v 1.1 2017/12/08 01:19:29 christos Exp $ */ | | 1 | /* $NetBSD: t_timeleft.c,v 1.2 2017/12/30 17:06:27 martin Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2017 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2017 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Christos Zoulas. | | 8 | * by Christos Zoulas. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -22,27 +22,27 @@ | | | @@ -22,27 +22,27 @@ |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __COPYRIGHT("@(#) Copyright (c) 2008\ | | 33 | __COPYRIGHT("@(#) Copyright (c) 2008\ |
34 | The NetBSD Foundation, inc. All rights reserved."); | | 34 | The NetBSD Foundation, inc. All rights reserved."); |
35 | __RCSID("$NetBSD: t_timeleft.c,v 1.1 2017/12/08 01:19:29 christos Exp $"); | | 35 | __RCSID("$NetBSD: t_timeleft.c,v 1.2 2017/12/30 17:06:27 martin Exp $"); |
36 | | | 36 | |
37 | #include <sys/types.h> | | 37 | #include <sys/types.h> |
38 | #include <sys/select.h> | | 38 | #include <sys/select.h> |
39 | | | 39 | |
40 | #include <atf-c.h> | | 40 | #include <atf-c.h> |
41 | #include <time.h> | | 41 | #include <time.h> |
42 | #include <errno.h> | | 42 | #include <errno.h> |
43 | #include <lwp.h> | | 43 | #include <lwp.h> |
44 | #include <signal.h> | | 44 | #include <signal.h> |
45 | #include <pthread.h> | | 45 | #include <pthread.h> |
46 | #include <stdio.h> | | 46 | #include <stdio.h> |
47 | #include <sched.h> | | 47 | #include <sched.h> |
48 | #include <unistd.h> | | 48 | #include <unistd.h> |
| @@ -74,27 +74,27 @@ timeleft_pselect(struct timespec *ts) | | | @@ -74,27 +74,27 @@ timeleft_pselect(struct timespec *ts) |
74 | | | 74 | |
75 | static void * | | 75 | static void * |
76 | runner(void *arg) | | 76 | runner(void *arg) |
77 | { | | 77 | { |
78 | struct info *i = arg; | | 78 | struct info *i = arg; |
79 | (*i->fun)(&i->ts); | | 79 | (*i->fun)(&i->ts); |
80 | return NULL; | | 80 | return NULL; |
81 | } | | 81 | } |
82 | | | 82 | |
83 | static void | | 83 | static void |
84 | tester(void (*fun)(struct timespec *)) | | 84 | tester(void (*fun)(struct timespec *)) |
85 | { | | 85 | { |
86 | const struct timespec ts = { 5, 0 }; | | 86 | const struct timespec ts = { 5, 0 }; |
87 | const struct timespec sts = { 0, 1000000 }; | | 87 | const struct timespec sts = { 0, 2000000 }; |
88 | struct info i = { fun, ts }; | | 88 | struct info i = { fun, ts }; |
89 | pthread_t thr; | | 89 | pthread_t thr; |
90 | | | 90 | |
91 | ATF_REQUIRE(signal(SIGINT, sighandler) == 0); | | 91 | ATF_REQUIRE(signal(SIGINT, sighandler) == 0); |
92 | ATF_REQUIRE(pthread_create(&thr, NULL, runner, &i) == 0); | | 92 | ATF_REQUIRE(pthread_create(&thr, NULL, runner, &i) == 0); |
93 | | | 93 | |
94 | nanosleep(&sts, NULL); | | 94 | nanosleep(&sts, NULL); |
95 | pthread_kill(thr, SIGINT); | | 95 | pthread_kill(thr, SIGINT); |
96 | printf("Orig time %ju.%lu\n", (intmax_t)ts.tv_sec, ts.tv_nsec); | | 96 | printf("Orig time %ju.%lu\n", (intmax_t)ts.tv_sec, ts.tv_nsec); |
97 | printf("Time left %ju.%lu\n", (intmax_t)i.ts.tv_sec, i.ts.tv_nsec); | | 97 | printf("Time left %ju.%lu\n", (intmax_t)i.ts.tv_sec, i.ts.tv_nsec); |
98 | ATF_REQUIRE(timespeccmp(&i.ts, &ts, <)); | | 98 | ATF_REQUIRE(timespeccmp(&i.ts, &ts, <)); |
99 | } | | 99 | } |
100 | | | 100 | |