Source file test/wasmmemsize.dir/main.go
1 // Copyright 2024 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "fmt" 9 "io" 10 ) 11 12 // Expect 8 MB of memory usage for a small wasm program. 13 // This reflects the current allocator. We test an exact 14 // value here, but if the allocator changes, we can update 15 // or relax this. 16 const want = 8 << 20 17 18 var w = io.Discard 19 20 func main() { 21 fmt.Fprintln(w, "hello world") 22 23 const pageSize = 64 * 1024 24 sz := uintptr(currentMemory()) * pageSize 25 if sz != want { 26 fmt.Printf("FAIL: unexpected memory size %d, want %d\n", sz, want) 27 } 28 } 29 30 func currentMemory() int32 // implemented in assembly 31