Skip to content

Commit

Permalink
Got tests to run w/emscripten! (3 failures)
Browse files Browse the repository at this point in the history
CppTests:
test cases:    499 |    496 passed | 3 failed
assertions: 682799 | 682794 passed | 5 failed

failed tests:
    >>> Query Functions
    >>> RealClockSource
    >>> Continuous Fast Push

C4Tests:
All tests passed (791941 assertions in 155 test cases)
  • Loading branch information
snej committed Jun 14, 2024
1 parent 105e4cb commit 9d8f60e
Show file tree
Hide file tree
Showing 16 changed files with 179 additions and 88 deletions.
16 changes: 15 additions & 1 deletion C/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,25 @@ add_executable(
c4CertificateTest.cc

${TOP}LiteCore/tests/main.cpp
${TOP}Crypto/SecureRandomize.cc
${TOP}LiteCore/Support/TestsCommon.cc
${TOP}vendor/fleece/ObjC/slice+CoreFoundation.cc
)

if (NOT EMSCRIPTEN)
# These files contain internal functionality that isn't exported from the LiteCore shared lib.
# But C4Tests use these, so we have to compile them into its binary.
# This doesn't apply to Emscripten, bc WASM doesn't have shared libs; all linking is static.
target_sources(
C4Tests PRIVATE
${TOP}Crypto/SecureRandomize.cc
${TOP}LiteCore/Support/Error.cc
${TOP}LiteCore/Support/FilePath.cc
${TOP}LiteCore/Support/LogDecoder.cc
${TOP}LiteCore/Support/Logging_Stub.cc
${TOP}LiteCore/Support/StringUtil.cc
)
endif()

get_directory_property(this_targets DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} BUILDSYSTEM_TARGETS)
set(LITECORE_TARGETS ${LITECORE_TARGETS} ${this_targets} PARENT_SCOPE)
setup_build()
Expand Down
2 changes: 2 additions & 0 deletions C/tests/c4PerfTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ class PerfTest : public C4Test {
input += "_helium_macos";
#elif defined(__linux__)
input += "_helium_linux";
#elif defined(__EMSCRIPTEN__)
input += "_helium_emscripten";
#else
# error "Unknown platform"
#endif
Expand Down
10 changes: 6 additions & 4 deletions C/tests/cmake/platform_emscripten.cmake
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
function(setup_build)
target_sources(
C4Tests PRIVATE
${TOP}Crypto/mbedUtils.cc
${TOP}LiteCore/Unix/strlcat.c
)

target_link_libraries(
C4Tests PRIVATE
mbedcrypto
mbedx509
)

target_compile_options(
C4Tests PRIVATE
"-pthread"
"-fwasm-exceptions"
)

target_link_options(
Expand All @@ -19,7 +22,6 @@ function(setup_build)
"SHELL:-s EXIT_RUNTIME=1"
"SHELL:-s PTHREAD_POOL_SIZE=24"
"SHELL:-s ALLOW_MEMORY_GROWTH=1"
"SHELL:-s DEMANGLE_SUPPORT=1"
"SHELL:-s WASM_BIGINT=1"
"-lnodefs.js"
"-lnoderawfs.js"
Expand Down
116 changes: 59 additions & 57 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@ if(BUILD_ENTERPRISE)
)
endif()

if(MSVC)
if(EMSCRIPTEN)
# Emscripten does not actually support shared libraries and instead
# just builds a static library for compatibility with existing
# build setups. We just set this property to suppress a CMake warning.
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)

include("${PROJECT_SOURCE_DIR}/cmake/platform_emscripten.cmake")
elseif(MSVC)
add_definitions(-DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0A00)
if(WINDOWS_STORE)
message(FATAL_ERROR "UWP no longer supported")
Expand All @@ -141,13 +148,6 @@ elseif(ANDROID)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
option(LITECORE_DYNAMIC_ICU "If enabled, search for ICU at runtime so as not to depend on a specific version" OFF)
include("${PROJECT_SOURCE_DIR}/cmake/platform_linux_desktop.cmake")
elseif(EMSCRIPTEN)
# Emscripten does not actually support shared libraries and instead
# just builds a static library for compatibility with existing
# build setups. We just set this property to suppress a CMake warning.
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)

include("${PROJECT_SOURCE_DIR}/cmake/platform_emscripten.cmake")
else()
message(FATAL_ERROR "Unable to determine a supported platform from ${CMAKE_SYSTEM_NAME}")
endif(MSVC)
Expand Down Expand Up @@ -340,60 +340,62 @@ install(FILES ${FLEECE_HEADERS} DESTINATION include/fleece)

### Support Libraries (Add functionality, but add nothing to official API)

add_subdirectory(REST EXCLUDE_FROM_ALL)

set(
LC_WEBSOCKET_SRC
Networking/HTTP/HTTPTypes.cc
Networking/HTTP/HTTPLogic.cc
Networking/NetworkInterfaces.cc
Networking/Poller.cc
Networking/TCPSocket.cc
Networking/TLSContext.cc
Networking/WebSockets/BuiltInWebSocket.cc
vendor/sockpp/src/acceptor.cpp
vendor/sockpp/src/connector.cpp
vendor/sockpp/src/datagram_socket.cpp
vendor/sockpp/src/exception.cpp
vendor/sockpp/src/inet_address.cpp
vendor/sockpp/src/inet6_address.cpp
vendor/sockpp/src/mbedtls_context.cpp
vendor/sockpp/src/socket.cpp
vendor/sockpp/src/stream_socket.cpp
)
if (NOT EMSCRIPTEN)
add_subdirectory(REST EXCLUDE_FROM_ALL)

add_library(LiteCoreWebSocket STATIC EXCLUDE_FROM_ALL ${LC_WEBSOCKET_SRC})
target_include_directories(
LiteCoreWebSocket PRIVATE
C
C/include
C/Cpp_include
Crypto
LiteCore/Support
Networking
Networking/BLIP/
Networking/HTTP
Networking/WebSockets
Replicator
REST
vendor/fleece/Fleece/Support
vendor/fleece/API
vendor/sockpp/include
vendor/mbedtls/include
vendor/mbedtls/crypto/include
)
set(
LC_WEBSOCKET_SRC
Networking/HTTP/HTTPTypes.cc
Networking/HTTP/HTTPLogic.cc
Networking/NetworkInterfaces.cc
Networking/Poller.cc
Networking/TCPSocket.cc
Networking/TLSContext.cc
Networking/WebSockets/BuiltInWebSocket.cc
vendor/sockpp/src/acceptor.cpp
vendor/sockpp/src/connector.cpp
vendor/sockpp/src/datagram_socket.cpp
vendor/sockpp/src/exception.cpp
vendor/sockpp/src/inet_address.cpp
vendor/sockpp/src/inet6_address.cpp
vendor/sockpp/src/mbedtls_context.cpp
vendor/sockpp/src/socket.cpp
vendor/sockpp/src/stream_socket.cpp
)

target_link_libraries(
LiteCoreWebSocket PUBLIC
LiteCoreObjects
)
add_library(LiteCoreWebSocket STATIC EXCLUDE_FROM_ALL ${LC_WEBSOCKET_SRC})
target_include_directories(
LiteCoreWebSocket PRIVATE
C
C/include
C/Cpp_include
Crypto
LiteCore/Support
Networking
Networking/BLIP/
Networking/HTTP
Networking/WebSockets
Replicator
REST
vendor/fleece/Fleece/Support
vendor/fleece/API
vendor/sockpp/include
vendor/mbedtls/include
vendor/mbedtls/crypto/include
)

if(LITECORE_PERF_TESTING_MODE)
target_compile_definitions(
target_link_libraries(
LiteCoreWebSocket PUBLIC
LITECORE_PERF_TESTING_MODE
LiteCoreObjects
)
endif()

if(LITECORE_PERF_TESTING_MODE)
target_compile_definitions(
LiteCoreWebSocket PUBLIC
LITECORE_PERF_TESTING_MODE
)
endif()
endif() # NOT EMSCRIPTEN

### TESTS:

Expand Down
1 change: 1 addition & 0 deletions LiteCore/Storage/UnicodeCollator_JS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace litecore {

using namespace std;
using namespace emscripten;
using namespace fleece;

class JSCollationContext : public CollationContext {
public:
Expand Down
8 changes: 4 additions & 4 deletions LiteCore/Support/ThreadUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
# ifndef HAVE_PTHREAD_THREADID_NP
# include <sys/syscall.h>
# endif
# ifndef HAVE_PTHREAD_GETNAME_NP
# include <sys/prctl.h>
# endif
# ifdef __EMSCRIPTEN__
# include <emscripten/threading.h>
# elif !defined(HAVE_PTHREAD_GETNAME_NP)
# include <sys/prctl.h>
# endif

namespace litecore {
Expand All @@ -55,10 +54,11 @@ namespace litecore {
std::string GetThreadName() {
std::string retVal;
std::stringstream s;
char name[256];
# if defined(HAVE_PTHREAD_GETNAME_NP)
char name[256];
if ( pthread_getname_np(pthread_self(), name, 255) == 0 && name[0] != 0 ) { s << name << " "; }
# elif defined(HAVE_PRCTL)
char name[256];
if ( prctl(PR_GET_NAME, name, 0, 0, 0) == 0 ) { s << name << " "; }
# else
s << "<unknown thread name> ";
Expand Down
32 changes: 22 additions & 10 deletions LiteCore/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ add_executable(
UpgraderTest.cc
VectorQueryTest.cc
VersionVectorTest.cc
${TOP}REST/tests/RESTListenerTest.cc
${TOP}REST/tests/RESTClientTest.cc
${TOP}REST/tests/SyncListenerTest.cc
${TOP}vendor/fleece/Tests/API_ValueTests.cc
${TOP}vendor/fleece/Tests/DeltaTests.cc
${TOP}vendor/fleece/Tests/EncoderTests.cc
Expand All @@ -89,13 +86,8 @@ add_executable(
${TOP}Replicator/tests/DBAccessTestWrapper.cc
${TOP}Replicator/tests/PropertyEncryptionTests.cc
${TOP}Replicator/tests/ReplicatorLoopbackTest.cc
${TOP}Replicator/tests/ReplicatorAPITest.cc
${TOP}Replicator/tests/ReplicatorSGTest.cc
${TOP}Replicator/tests/ReplicatorCollectionTest.cc
${TOP}Replicator/tests/ReplicatorCollectionSGTest.cc
${TOP}Replicator/tests/ReplicatorSG30Test.cc
${TOP}Replicator/tests/ReplicatorVVUpgradeTest.cc
${TOP}Replicator/tests/SG.cc
${TOP}Replicator/tests/SGTestUser.cc
${TOP}Replicator/tests/ReplParams.cc
${TOP}C/tests/c4Test.cc
Expand All @@ -105,6 +97,20 @@ add_executable(
main.cpp
)

if (NOT EMSCRIPTEN)
target_sources(
CppTests PRIVATE
${TOP}REST/tests/RESTListenerTest.cc
${TOP}REST/tests/RESTClientTest.cc
${TOP}REST/tests/SyncListenerTest.cc
${TOP}Replicator/tests/ReplicatorAPITest.cc
${TOP}Replicator/tests/ReplicatorSGTest.cc
${TOP}Replicator/tests/ReplicatorCollectionSGTest.cc
${TOP}Replicator/tests/ReplicatorSG30Test.cc
${TOP}Replicator/tests/SG.cc
)
endif()

get_directory_property(this_targets DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} BUILDSYSTEM_TARGETS)
set(LITECORE_TARGETS ${LITECORE_TARGETS} ${this_targets} PARENT_SCOPE)
setup_build()
Expand Down Expand Up @@ -159,6 +165,12 @@ target_link_libraries(
LiteCoreUnitTesting
FleeceObjects
BLIPObjects
LiteCoreREST_Static
LiteCoreWebSocket
)

if (NOT EMSCRIPTEN)
target_link_libraries(
CppTests PRIVATE
LiteCoreREST_Static
LiteCoreWebSocket
)
endif()
6 changes: 4 additions & 2 deletions LiteCore/tests/DataFileTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,13 @@ N_WAY_TEST_CASE_METHOD(DataFileTestFixture, "DataFile Compact", "[DataFile]") {

TEST_CASE("CanonicalPath") {
#ifdef __EMSCRIPTEN__
// clang-format off
auto isMacOs = (bool)EM_ASM_INT({
if ( typeof require == = 'undefined' ) return false;
if ( typeof require === 'undefined' ) return false;
const process = require('process');
return process.platform == = 'darwin';
return process.platform === 'darwin';
});
// clang-format on
#endif

#ifdef _MSC_VER
Expand Down
2 changes: 1 addition & 1 deletion LiteCore/tests/LiteCoreTest.hh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ std::string stringWithFormat(const char* format, ...) __printflike(1, 2);
*/
template <size_t numDigits>
static std::string randomDigitString() {
static_assert(1 < numDigits <= 64);
static_assert(1 < numDigits && numDigits <= 64);
static_assert(numDigits % 2 == 0);
auto appendEightDigits = [](std::stringstream& sstr) {
auto now = std::chrono::high_resolution_clock::now();
Expand Down
7 changes: 6 additions & 1 deletion LiteCore/tests/cmake/platform_emscripten.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ function(setup_build)
${TOP}LiteCore/Unix
)

target_compile_options(
CppTests PRIVATE
"-pthread"
"-fwasm-exceptions"
)

target_link_options(
CppTests PRIVATE
"-pthread"
Expand All @@ -13,7 +19,6 @@ function(setup_build)
"SHELL:-s EXIT_RUNTIME=1"
"SHELL:-s PTHREAD_POOL_SIZE=24"
"SHELL:-s ALLOW_MEMORY_GROWTH=1"
"SHELL:-s DEMANGLE_SUPPORT=1"
"SHELL:-s WASM_BIGINT=1"
"-lnodefs.js"
"-lnoderawfs.js"
Expand Down
4 changes: 2 additions & 2 deletions Networking/BLIP/cmake/platform_emscripten.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ endfunction()
function(setup_build)
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../../vendor/zlib" "vendor/zlib")
target_include_directories(
BLIPStatic PRIVATE
BLIPObjects PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/../../vendor/zlib"
"${CMAKE_CURRENT_BINARY_DIR}/vendor/zlib"
${LITECORE_LOCATION}/LiteCore/Unix
)

target_link_libraries(
BLIPStatic INTERFACE
BLIPObjects INTERFACE
zlibstatic
)
endfunction()
1 change: 1 addition & 0 deletions Replicator/tests/CookieStoreTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ TEST_CASE("Cookie Parser Failure", "[cookies]") {
"name=value; Max-Age=",
};
for ( const auto& badCookie : badCookies ) {
ExpectingExceptions x;
INFO("Checking " << badCookie);
Cookie c(badCookie, "example.com", "/");
CHECK(!c);
Expand Down
Loading

0 comments on commit 9d8f60e

Please sign in to comment.