Add internal tests for WASI threads (#1963)
Add internal tests for WASI threads. These tests are run in addition to the ones in the proposal: https://github.com/WebAssembly/wasi-threads/tree/main/test/testsuite. The purpose is to test additional and more complex scenarios.
This commit is contained in:
@ -33,7 +33,7 @@ __wasi_thread_start_C(int thread_id, int *start_arg)
|
||||
data->value += 8;
|
||||
printf("Updated value: %d\n", data->value);
|
||||
|
||||
data->th_ready = 1;
|
||||
__atomic_store_n(&data->th_ready, 1, __ATOMIC_SEQ_CST);
|
||||
__builtin_wasm_memory_atomic_notify(&data->th_ready, 1);
|
||||
}
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <semaphore.h>
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
|
||||
#define TIMEOUT_SECONDS 10
|
||||
#define NUM_THREADS 3
|
||||
static sem_t sem;
|
||||
static pthread_barrier_t barrier;
|
||||
|
||||
typedef struct {
|
||||
start_args_t base;
|
||||
@ -49,9 +49,10 @@ run_long_task()
|
||||
void
|
||||
start_job()
|
||||
{
|
||||
sem_post(&sem);
|
||||
run_long_task(); /* Wait to be interrupted */
|
||||
assert(false && "Unreachable");
|
||||
/* Wait for all threads (including the main thread) to be ready */
|
||||
pthread_barrier_wait(&barrier);
|
||||
run_long_task(); /* Task to be interrupted */
|
||||
assert(false && "Thread termination test failed");
|
||||
}
|
||||
|
||||
void
|
||||
@ -59,8 +60,7 @@ 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);
|
||||
pthread_barrier_wait(&barrier);
|
||||
|
||||
printf("Force termination\n");
|
||||
#if TEST_TERMINATION_BY_TRAP == 1
|
||||
@ -91,8 +91,8 @@ main(int argc, char **argv)
|
||||
int thread_id = -1, i;
|
||||
shared_t data[NUM_THREADS] = { 0 };
|
||||
|
||||
if (sem_init(&sem, 0, 0) != 0) {
|
||||
printf("Failed to init semaphore\n");
|
||||
if (pthread_barrier_init(&barrier, NULL, NUM_THREADS + 1) != 0) {
|
||||
printf("Failed to init barrier\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user