AztecProtocol/barretenberg

Running unit tests in GTest via wasmtime

Opened this issue · 0 comments

You try to run, e.g., the transcript tests through wasmtime you will see an error like

% wasmtime run --env WASM_BACKTRACE_DETAILS=1  -Wthreads=y -Sthreads=y --dir=.. ./bin/transcript_tests                                                    ~/aztec-packages/barretenberg/cpp/build-wasm-threads cg/browser-civc + cody-box
Error: failed to run main module `./bin/transcript_tests`

Caused by:
    0: failed to invoke command default
    1: error while executing at wasm backtrace:
           0:  0xc51 - transcript_tests!undefined_weak:main
           1: 0x41e24 - transcript_tests!__main_void
           2:  0xd09 - transcript_tests!_start
       note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information
    2: wasm trap: wasm `unreachable` instruction executed

This can be solved by adding

int main(int argc, char** argv)
{
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

to the bottom of the test file, but googling shows there is another solution which is to link againts gtest_main.