diff options
author | Sven Göthel <[email protected]> | 2024-07-17 07:52:41 +0200 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-07-17 07:52:41 +0200 |
commit | e39636b7562727d66421d1d53e9921aacdd8c879 (patch) | |
tree | ecdba5e58a966ac261523d8ff4736aa6b6cf84f7 /include/catch2_jau/jau | |
parent | 222ec623dd7202979715e4f7354362a697863781 (diff) |
Wasm: Add prelim support unit tests with STANDALONE_WASM (emscripten); cmake: Restructure to project/target settings (from global)
Diffstat (limited to 'include/catch2_jau/jau')
-rw-r--r-- | include/catch2_jau/jau/test/catch2_my_main.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/include/catch2_jau/jau/test/catch2_my_main.cpp b/include/catch2_jau/jau/test/catch2_my_main.cpp index ea343b3..5e73931 100644 --- a/include/catch2_jau/jau/test/catch2_my_main.cpp +++ b/include/catch2_jau/jau/test/catch2_my_main.cpp @@ -35,6 +35,52 @@ #include <vector> +#if defined(__EMSCRIPTEN__) +extern "C" { + #include <unistd.h> + #include <sys/random.h> + #include <errno.h> + + ssize_t getrandom(void* buffer, size_t len, unsigned int flags) { + (void)flags; + char *pos = (char*)buffer; + for(size_t i=0; i<len; ++i) { + *pos = (char)(i%255); + pos++; + } + return len; + } + int getentropy(void *buffer, size_t len) + { + // int cs; + int ret = 0; + char *pos = (char*)buffer; + + if (len > 256) { + errno = EIO; + return -1; + } + + // pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); + + while (len) { + ret = getrandom(pos, len, 0); + if (ret < 0) { + if (errno == EINTR) continue; + else break; + } + pos += ret; + len -= ret; + ret = 0; + } + + // pthread_setcancelstate(cs, 0); + + return ret; + } +} +#endif // __EMSCRIPTEN__ + #define CATCH_AMALGAMATED_CUSTOM_MAIN 1 #include <catch2/catch_amalgamated.hpp> |