File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff 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
15351553void test_unreachable () {
You can’t perform that action at this time.
0 commit comments