Skip to content
Snippets Groups Projects
Commit 5ee9930b authored by Jaswant Panchumarti (Kitware)'s avatar Jaswant Panchumarti (Kitware)
Browse files

Post exit code from unit tests when asyncify=on

- with asyncify, the python server always got an exit code of `1`
  because `main` implicitly returned 1.
- as a result, exit code is specially handled so that `ctest` can decide whether the test failed or passed.
parent f2b4e73a
No related merge requests found
......@@ -9,4 +9,15 @@ SET(CMAKE_TESTDRIVER_BEFORE_TESTMAIN
vtkLogger::Init(ac, av);
")
SET(CMAKE_TESTDRIVER_AFTER_TESTMAIN "")
SET(CMAKE_TESTDRIVER_AFTER_TESTMAIN
"
#if defined(__EMSCRIPTEN__)
// When asyncify is used, emscripten sets up the wasm module
// such that the `main` function always returns 1.
// Explicitly post the test's exit code back to the server.
if (emscripten_has_asyncify())
{
vtkEmscriptenTestUtilities::PostExitCode(result);
}
#endif
")
......@@ -89,5 +89,10 @@ void vtkEmscriptenTestUtilities::DumpFile(
const auto* bytes = reinterpret_cast<const uint8_t*>(data);
vtkDumpFile(hostFilePath.c_str(), bytes, n);
}
void vtkEmscriptenTestUtilities::PostExitCode(int code)
{
vtkPostExitCode(code);
}
VTK_ABI_NAMESPACE_END
#endif // __EMSCRIPTEN__
......@@ -10,6 +10,8 @@
#include <cstdint> // for uint8_t
#include <string> // for string
#include <emscripten/emscripten.h> // for emscripten_ API
VTK_ABI_NAMESPACE_BEGIN
class VTKTESTINGCORE_EXPORT vtkEmscriptenTestUtilities
......@@ -24,12 +26,16 @@ public:
const std::string& hostFilePath, const std::string& sandboxedFilePath);
static std::string PreloadDataFile(const std::string& hostFilePath);
static void DumpFile(const std::string& hostFilePath, const void* data, std::size_t n);
static void PostExitCode(int code);
};
// These functions are implemented externally in javascript.
// The static methods of vtkEmscriptenTestUtilities call into these methods.
extern "C"
{
void* vtkPreloadDataFileIntoMemory(const char* hostFilePath);
void vtkDumpFile(const char* hostFilePath, const uint8_t* data, size_t nbytes);
void vtkPostExitCode(int code);
}
VTK_ABI_NAMESPACE_END
......
......@@ -55,6 +55,15 @@ var vtkEmscriptenTestUtilities = {
const byteArray = HEAPU8.subarray(data, data + nbytes);
req.send(new Uint8Array(byteArray));
},
/**
* Send the exit code to the server.
*/
vtkPostExitCode__sig: "vi",
vtkPostExitCode: (code) => {
// this function is defined in Testing/WebAssembly/templates/index.html
finalize(code)
},
};
mergeInto(LibraryManager.library, vtkEmscriptenTestUtilities);
......@@ -14,7 +14,8 @@
#include <vtkLogger.h> // for logging
#include "vtkWindowsTestUtilities.h" // for windows stack trace
#include "vtkEmscriptenTestUtilities.h" // for wasm I/O and exit helper
#include "vtkWindowsTestUtilities.h" // for windows stack trace
#endif
// VTK-HeaderTest-Exclude: vtkTestDriver.h
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment