You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行`go test -fuzz=Fuzz`进行Go模糊测试时提示内存不足的问题求助

执行go test -fuzz=Fuzz进行Go模糊测试时提示内存不足的问题求助

大家好,我按照Go的模糊测试相关教程写了测试代码,正常运行go test是完全没问题的,但执行go test -fuzz=Fuzz的时候碰到了内存不足的错误,具体信息如下,想请大家帮忙看看怎么解决这个问题。

错误日志

$ go test -fuzz=Fuzz
warning: the test binary was not built with coverage instrumentation, so fuzzing will run without coverage guidance and may be inefficient
--- FAIL: FuzzReverse (0.01s)
mapping temporary file C:\Users\use\AppData\Local\Temp\fuzz-2637883721: Not enough memory resources are available to process this command.
FAIL
exit status 1
FAIL    example/fuzz    0.031s

我的测试代码

package main

import (
    "testing"
    "unicode/utf8"
)

func FuzzReverse(f *testing.F) {
    testcases := []string{"Hello, world", " ", "!12345"}
    for _, tc := range testcases {
        f.Add(tc) // Use f.Add to provide a seed corpus
    }
    f.Fuzz(func(t *testing.T, orig string) {
        rev := Reverse(orig)
        doubleRev := Reverse(rev)
        if orig != doubleRev {
            t.Errorf("Before: %q, after: %q", orig, doubleRev)
        }
        if utf8.ValidString(orig) && !utf8.ValidString(rev) {
            t.Errorf("Reverse produced invalid UTF-8 string %q", rev)
        }
    })
}

正常测试结果与Go版本

普通测试可以正常通过:

$ go test
PASS
ok      example/fuzz    0.027s

我的Go版本信息:

$ go version
go version go1.23.0 windows/386

备注:内容来源于stack exchange,提问作者李晓川

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 08:59:30