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
1 change: 1 addition & 0 deletions cmake/ba-download.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function(ba_download target repo version)
if ((os STREQUAL windows) AND
((target STREQUAL wasm-component-ld) OR
(target STREQUAL wasm-tools) OR
(target STREQUAL wit-bindgen) OR
(target STREQUAL wasmtime)))
set(fmt zip)
elseif (target STREQUAL wasmtime)
Expand Down
50 changes: 47 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ set_source_files_properties("${LIBC_TEST}/src/common/print.c"
# * `LDFLAGS -a -b -c` - additional flags to pass to the linker
# * `SHARED` - link to the shared version of libc_test_support
# * `SHARED_LIBS` - extra libs to pass to `wasm-tools component link`
# * `WHOLE_ARCHIVE` - extra lib to link via cmake
function(add_test_executable executable_name src)
set(options SHARED)
set(oneValueArgs)
set(oneValueArgs WHOLE_ARCHIVE)
set(multiValueArgs LDFLAGS CFLAGS SHARED_LIBS INCLUDE DEPENDENCIES)
cmake_parse_arguments(PARSE_ARGV 1 arg "${options}" "${oneValueArgs}" "${multiValueArgs}")

Expand Down Expand Up @@ -185,6 +186,10 @@ function(add_test_executable executable_name src)
foreach(dep IN LISTS arg_DEPENDENCIES)
add_dependencies(${executable_name} ${dep})
endforeach()
foreach(lib IN LISTS arg_WHOLE_ARCHIVE)
target_link_libraries(${executable_name} PRIVATE
-Wl,--whole-archive ${lib} -Wl,--no-whole-archive)
endforeach()
endfunction()

# Adds a new test to run.
Expand All @@ -202,8 +207,8 @@ endfunction()
# * `SETJMP` - this test requires setjmp/longjmp
function(register_test test_name executable_name)
set(options FS NETWORK SETJMP)
set(oneValueArgs CLIENT PASS_REGULAR_EXPRESSION)
set(multiValueArgs ARGV ENV ENGINE_ARG)
set(oneValueArgs CLIENT PASS_REGULAR_EXPRESSION ENGINE_ARG)
set(multiValueArgs ARGV ENV)
cmake_parse_arguments(PARSE_ARGV 1 arg "${options}" "${oneValueArgs}" "${multiValueArgs}")

set(wasmtime_args)
Expand Down Expand Up @@ -578,6 +583,45 @@ if (WASILIBC_MULTITHREADING AND NOT TEST_WITH_V8)
add_wasilibc_test(futex_wake_all.c)
endif()

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

add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/entrypoint.c
${CMAKE_CURRENT_BINARY_DIR}/entrypoint.h
${CMAKE_CURRENT_BINARY_DIR}/entrypoint_component_type.o
COMMAND
${wit_bindgen} c ${CMAKE_CURRENT_SOURCE_DIR}/entrypoint.wit
--out-dir ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS wit-bindgen ${CMAKE_CURRENT_SOURCE_DIR}/entrypoint.wit
)
add_library(entrypoint_bindings STATIC EXCLUDE_FROM_ALL
${CMAKE_CURRENT_BINARY_DIR}/entrypoint.c
${CMAKE_CURRENT_BINARY_DIR}/entrypoint_component_type.o)

function(add_external_entrypoint_test test_file)
cmake_path(REPLACE_EXTENSION test_file wasm OUTPUT_VARIABLE test_name)
set(test_file "${CMAKE_CURRENT_SOURCE_DIR}/src/${test_file}")

if (WASI STREQUAL "p1")
set(extra_args
ENGINE_ARG --invoke=entrypoint
LDFLAGS -Wl,--export=entrypoint
)
else()
set(extra_args
ENGINE_ARG "--invoke=entrypoint()"
WHOLE_ARCHIVE entrypoint_bindings
)
endif()

if (NOT TEST_WITH_V8)
add_test_pair(${test_name} ${test_file} ${ARGN} ${extra_args})
endif()
endfunction()

add_external_entrypoint_test(external_entrypoint_pthread_tls.c)

# ========= sockets-related tests ===============================

if (NOT (WASI STREQUAL "p1"))
Expand Down
5 changes: 5 additions & 0 deletions test/entrypoint.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package wasilibc:test;

world entrypoint {
export entrypoint: func();
}
28 changes: 28 additions & 0 deletions test/src/external_entrypoint_pthread_tls.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "test.h"
#include <errno.h>
#include <pthread.h>
#include <semaphore.h>
#include <string.h>

#ifndef __wasip1__
#define entrypoint exports_entrypoint_entrypoint
#endif

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

static void dtor(void *ptr) {
(void)ptr;
__builtin_trap();
}

void entrypoint(void) {
pthread_key_t a, b;
TEST(pthread_key_create(&a, dtor) == 0);
TEST(pthread_key_create(&b, dtor) == 0);
TEST(pthread_key_delete(a) == 0);
TEST(pthread_key_delete(b) == 0);
}