mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Add *NSYNC unit test suite
This change also fixes the clock_nanosleep() api and polyfills futexes on Windows, Mac, and NetBSD using exponential backoff.
This commit is contained in:
parent
3421b9a580
commit
9849b4c7ba
51 changed files with 5505 additions and 1060 deletions
|
@ -17,9 +17,11 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "third_party/nsync/time.h"
|
||||
|
||||
TEST(_timespec_gte, test) {
|
||||
EXPECT_FALSE(_timespec_gte((struct timespec){1}, (struct timespec){2}));
|
||||
|
@ -72,6 +74,8 @@ TEST(_timespec_tomillis, test) {
|
|||
EXPECT_EQ(2123, _timespec_tomillis((struct timespec){2, 123000000}));
|
||||
EXPECT_EQ(INT64_MAX, _timespec_tomillis((struct timespec){INT64_MAX, 0}));
|
||||
EXPECT_EQ(INT64_MIN, _timespec_tomillis((struct timespec){INT64_MIN, 0}));
|
||||
EXPECT_EQ(INT64_MAX, _timespec_tomillis(
|
||||
(struct timespec){0x7fffffffffffffff, 999999999}));
|
||||
}
|
||||
|
||||
TEST(_timespec_tomicros, test) {
|
||||
|
|
|
@ -48,12 +48,6 @@ TEST(nanosleep, testNoSignalIsDelivered) {
|
|||
ASSERT_SYS(0, 0, nanosleep(&ts, 0));
|
||||
}
|
||||
|
||||
TEST(clock_nanosleep, testNoSignalIsDelivered) {
|
||||
struct timespec ts = {0, 1};
|
||||
ASSERT_SYS(0, 0, clock_nanosleep(CLOCK_REALTIME, 0, &ts, &ts));
|
||||
ASSERT_SYS(0, 0, clock_nanosleep(CLOCK_REALTIME, 0, &ts, 0));
|
||||
}
|
||||
|
||||
TEST(nanosleep, testInterrupt_remIsUpdated) {
|
||||
struct sigaction sa = {
|
||||
.sa_handler = OnAlrm,
|
||||
|
@ -68,3 +62,24 @@ TEST(nanosleep, testInterrupt_remIsUpdated) {
|
|||
ASSERT_GT(ts.tv_sec, 400);
|
||||
ASSERT_NE(0, ts.tv_nsec);
|
||||
}
|
||||
|
||||
TEST(clock_nanosleep, testNoSignalIsDelivered) {
|
||||
struct timespec ts = {0, 1};
|
||||
ASSERT_EQ(0, clock_nanosleep(CLOCK_REALTIME, 0, &ts, &ts));
|
||||
ASSERT_EQ(0, clock_nanosleep(CLOCK_REALTIME, 0, &ts, 0));
|
||||
}
|
||||
|
||||
TEST(clock_nanosleep, testInterrupt_remIsUpdated) {
|
||||
struct sigaction sa = {
|
||||
.sa_handler = OnAlrm,
|
||||
.sa_flags = SA_RESETHAND,
|
||||
};
|
||||
ASSERT_SYS(0, 0, sigaction(SIGALRM, &sa, 0));
|
||||
struct itimerval it = {{0, 0}, {0, 10000}}; // 10ms singleshot
|
||||
ASSERT_SYS(0, 0, setitimer(ITIMER_REAL, &it, 0));
|
||||
struct timespec ts = {500, 0};
|
||||
ASSERT_EQ(EINTR, clock_nanosleep(CLOCK_REALTIME, 0, &ts, &ts));
|
||||
ASSERT_LT(ts.tv_sec, 500);
|
||||
ASSERT_GT(ts.tv_sec, 400);
|
||||
ASSERT_NE(0, ts.tv_nsec);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue