| 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 |
// Wasm page size. |
| 13 |
const pageSize = 64 * 1024 |
| 14 |
|
| 15 |
// Expect less than 3 MB + 1 page of memory usage for a small wasm |
| 16 |
// program. This reflects the current allocator. If the allocator |
| 17 |
// changes, update this value. |
| 18 |
const want = 3<<20 + pageSize |
| 19 |
|
| 20 |
var w = io.Discard |
| 21 |
|
| 22 |
func main() { |
| 23 |
fmt.Fprintln(w, "hello world") |
| 24 |
|
| 25 |
sz := uintptr(currentMemory()) * pageSize |
| 26 |
if sz > want { |
| 27 |
fmt.Printf("FAIL: unexpected memory size %d, want <= %d\n", sz, want) |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
func currentMemory() int32 // implemented in assembly |