Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ int __clock_gettime(clockid_t clock_id, struct timespec *tp) {
if (tp == NULL)
return 0;

if (clock_id == CLOCK_MONOTONIC) {
if (clock_id->id == CLOCKID_MONOTONIC) {
monotonic_clock_instant_t ns = monotonic_clock_now();
*tp = instant_to_timespec(ns);
} else if (clock_id == CLOCK_REALTIME) {
} else if (clock_id->id == CLOCKID_REALTIME) {
wasilibc_timestamp_t time_result;
#ifdef __wasip2__
wall_clock_now(&time_result);
Expand Down
11 changes: 11 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,23 @@ add_wasilibc_test(futex_wait_mismatch.c)
add_wasilibc_test(futex_flags.c)
if (NOT TEST_WITH_V8)
add_wasilibc_test(futex_wait_timeout.c)

# This is tested without a shared library to assist with setting test
# properties, and this is expected to trap on non-threaded targets
# since futex can't block.
add_wasilibc_test(pthread_timedwait_block.c NOSHARED)
if (NOT WASILIBC_MULTITHREADING)
set_tests_properties(pthread_timedwait_block.wasm PROPERTIES
PASS_REGULAR_EXPRESSION "wasm `unreachable` instruction executed")
endif()
endif()
if (WASILIBC_MULTITHREADING AND NOT TEST_WITH_V8)
add_wasilibc_test(futex_wake_one.c)
add_wasilibc_test(futex_wake_all.c)
endif()



# ========= wasi-libc tests for non-main entrypoints =========================

function(add_wit_bindgen_library name wit world out_dir)
Expand Down
24 changes: 24 additions & 0 deletions test/src/pthread_timedwait_block.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "test.h"
#include <errno.h>
#include <pthread.h>
#include <semaphore.h>
#include <string.h>

#define TEST(c) \
do { \
if (!(c)) \
t_error("%s failed\n", #c); \
} while (0)

int main(void) {
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
struct timespec now;
TEST(clock_gettime(CLOCK_REALTIME, &now) == 0);
now.tv_nsec += 50 * 1000000;
if (now.tv_nsec >= 1000000000) {
now.tv_sec++;
now.tv_nsec -= 1000000000;
}
TEST(pthread_cond_timedwait(&cond, NULL, &now) == ETIMEDOUT);
return t_status;
}