summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSurma <surma@surma.dev>2024-03-07 17:39:29 +0000
committerGitHub <noreply@github.com>2024-03-07 17:39:29 +0000
commitab9e3f75fcaae429e236bd50641e0d69e63cfdc2 (patch)
tree7ba8f348a612e4cf629b5b5e51486d5eee751fb7 /test
parent920cbc32603fdb8eff8f50283a1788812863f0d3 (diff)
downloadbinaryen-ab9e3f75fcaae429e236bd50641e0d69e63cfdc2.tar.gz
binaryen-ab9e3f75fcaae429e236bd50641e0d69e63cfdc2.tar.bz2
binaryen-ab9e3f75fcaae429e236bd50641e0d69e63cfdc2.zip
Expose features option in C API binary reading (#6380)
This allows reading a module that requires a particular feature set. The old API assumed only MVP features.
Diffstat (limited to 'test')
-rw-r--r--test/example/c-api-kitchen-sink.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c
index bf80833a0..e5b614bec 100644
--- a/test/example/c-api-kitchen-sink.c
+++ b/test/example/c-api-kitchen-sink.c
@@ -401,6 +401,32 @@ void test_features() {
printf("BinaryenFeatureAll: %d\n", BinaryenFeatureAll());
}
+void test_read_with_feature() {
+ BinaryenModuleRef module = BinaryenModuleCreate();
+ // Having multiple tables makes this module inherently not MVP compatible
+ // and requires the externref feature enabled to parse successfully.
+ BinaryenAddTable(module, "tab", 0, 100, BinaryenTypeFuncref());
+ BinaryenAddTable(module, "tab2", 0, 100, BinaryenTypeFuncref());
+
+ BinaryenFeatures features =
+ BinaryenFeatureMVP() | BinaryenFeatureReferenceTypes();
+ BinaryenModuleSetFeatures(module, features);
+
+ size_t bufferSize = 1024;
+ char* buffer = malloc(bufferSize);
+ size_t written = BinaryenModuleWrite(module, buffer, bufferSize);
+ BinaryenModuleDispose(module);
+
+ // See we can read the bytes and get a valid module from there.
+ BinaryenModuleRef readModule =
+ BinaryenModuleReadWithFeatures(buffer, written, features);
+ int valid = BinaryenModuleValidate(readModule);
+ assert(valid);
+ BinaryenModuleDispose(readModule);
+
+ free(buffer);
+}
+
void test_core() {
// Module creation