Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add internal tests for WASI threads #1963

Merged
merged 7 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: remove prints from different threads causing data races
  • Loading branch information
eloparco committed Mar 8, 2023
commit 1ccc5c5e8e00aa501817211d652e969286dd78ee
5 changes: 0 additions & 5 deletions core/iwasm/libraries/wasi-threads/test/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ void
terminate_process()
{
/* Wait for all other threads (including main thread) to be ready */
printf("Waiting before terminating\n");
for (int i = 0; i < NUM_THREADS; i++)
sem_wait(&sem);

printf("Force termination\n");
if (termination_by_trap)
__builtin_trap();
else
Expand All @@ -80,7 +78,6 @@ __wasi_thread_start_C(int thread_id, int *start_arg)
terminate_process();
}
else {
printf("Thread running\n");
start_job();
}
}
Expand Down Expand Up @@ -116,11 +113,9 @@ test_termination(bool trap, bool main, blocking_task_type_t task_type)
assert(thread_id > 0 && "Failed to create thread");

if (termination_in_main_thread) {
printf("Force termination (main thread)\n");
terminate_process();
}
else {
printf("Main thread running\n");
start_job();
}
}
2 changes: 1 addition & 1 deletion core/iwasm/libraries/wasi-threads/test/global_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ main(int argc, char **argv)
assert(g_count == (NUM_THREADS * NUM_ITER)
&& "Global count not updated correctly");

assert(pthread_mutex_destroy(&mutex) == 0 && "Failed to init mutex");
assert(pthread_mutex_destroy(&mutex) == 0 && "Failed to destroy mutex");
return EXIT_SUCCESS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ main(int argc, char **argv)
for (int i = 0; i < NUM_THREADS; i++) {
assert(start_args_init(&data[i].base)
&& "Stack allocation for thread failed");
data[i].count = count;
__atomic_store_n(&data[i].count, count, __ATOMIC_SEQ_CST);
data[i].iteration = i;

thread_ids[i] = __wasi_thread_spawn(&data[i]);
Expand Down