-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from MaxDesiatov/maxd/expose-memory
Expose a way to allocate a memory from host
- Loading branch information
Showing
2 changed files
with
66 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import XCTest | ||
|
||
@testable import WasmKit | ||
|
||
final class HostModuleTests: XCTestCase { | ||
func testImportMemory() throws { | ||
let runtime = Runtime() | ||
let memoryType = MemoryType(min: 1, max: nil) | ||
let memoryAddr = runtime.store.allocate(memoryType: memoryType) | ||
try runtime.store.register(HostModule(memories: ["memory": memoryAddr]), as: "env") | ||
|
||
let module = Module( | ||
imports: [ | ||
Import(module: "env", name: "memory", descriptor: .memory(memoryType)) | ||
] | ||
) | ||
XCTAssertNoThrow(try runtime.instantiate(module: module)) | ||
// Ensure the allocated address is valid | ||
_ = runtime.store.memory(at: memoryAddr) | ||
} | ||
} |