Skip to content

Commit

Permalink
Testing: Write out and read back in the big binary in c-api-kitchen-s…
Browse files Browse the repository at this point in the history
…ink.c (WebAssembly#6217)
  • Loading branch information
kripken authored and radekdoulik committed Jul 12, 2024
1 parent 6524a5e commit 3ce9971
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/example/c-api-kitchen-sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1526,10 +1526,28 @@ void test_core() {
BinaryenModulePrint(module);

// Verify it validates
assert(BinaryenModuleValidate(module));
int valid = BinaryenModuleValidate(module);
assert(valid);

// Verify no error occurs when writing out the code to binary.
size_t bufferSize = 10 * 1024 * 1024;
char* buffer = malloc(bufferSize);
size_t written = BinaryenModuleWrite(module, buffer, bufferSize);
// We wrote bytes, and we did not reach the end of the buffer (which would
// truncate).
assert(written > 0 && written < bufferSize);

// Clean up the module, which owns all the objects we created above
BinaryenModuleDispose(module);

// See we can read the bytes and get a valid module from there.
BinaryenModuleRef readModule = BinaryenModuleRead(buffer, written);
BinaryenModuleSetFeatures(readModule, BinaryenFeatureAll());
valid = BinaryenModuleValidate(readModule);
assert(valid);
BinaryenModuleDispose(readModule);

free(buffer);
}

void test_unreachable() {
Expand Down

0 comments on commit 3ce9971

Please sign in to comment.