Skip to content

Commit 3ce9971

Browse files
kripkenradekdoulik
authored andcommitted
Testing: Write out and read back in the big binary in c-api-kitchen-sink.c (WebAssembly#6217)
1 parent 6524a5e commit 3ce9971

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

test/example/c-api-kitchen-sink.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1526,10 +1526,28 @@ void test_core() {
15261526
BinaryenModulePrint(module);
15271527

15281528
// Verify it validates
1529-
assert(BinaryenModuleValidate(module));
1529+
int valid = BinaryenModuleValidate(module);
1530+
assert(valid);
1531+
1532+
// Verify no error occurs when writing out the code to binary.
1533+
size_t bufferSize = 10 * 1024 * 1024;
1534+
char* buffer = malloc(bufferSize);
1535+
size_t written = BinaryenModuleWrite(module, buffer, bufferSize);
1536+
// We wrote bytes, and we did not reach the end of the buffer (which would
1537+
// truncate).
1538+
assert(written > 0 && written < bufferSize);
15301539

15311540
// Clean up the module, which owns all the objects we created above
15321541
BinaryenModuleDispose(module);
1542+
1543+
// See we can read the bytes and get a valid module from there.
1544+
BinaryenModuleRef readModule = BinaryenModuleRead(buffer, written);
1545+
BinaryenModuleSetFeatures(readModule, BinaryenFeatureAll());
1546+
valid = BinaryenModuleValidate(readModule);
1547+
assert(valid);
1548+
BinaryenModuleDispose(readModule);
1549+
1550+
free(buffer);
15331551
}
15341552

15351553
void test_unreachable() {

0 commit comments

Comments
 (0)