diff options
author | Alon Zakai <azakai@google.com> | 2024-01-09 13:40:05 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-09 21:40:05 +0000 |
commit | 20b1ccc05987cf28f0d7f8b413e06a6c44decf04 (patch) | |
tree | b638f4125c6d0c6438053a0c565cbd6038fbd80d /test/example | |
parent | 75145b78b8b9cdabd98af849821f34dee0168466 (diff) | |
download | binaryen-20b1ccc05987cf28f0d7f8b413e06a6c44decf04.tar.gz binaryen-20b1ccc05987cf28f0d7f8b413e06a6c44decf04.tar.bz2 binaryen-20b1ccc05987cf28f0d7f8b413e06a6c44decf04.zip |
Testing: Write out and read back in the big binary in c-api-kitchen-sink.c (#6217)
Diffstat (limited to 'test/example')
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index d3368a6b1..f91733a8d 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -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() { |