From 174bf303af88cb6adda87b026862aef9cd6f4ef5 Mon Sep 17 00:00:00 2001 From: spiritlhl <103393591+spiritLHLS@users.noreply.github.com> Date: Wed, 24 Sep 2025 16:02:55 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E5=86=85=E5=AD=98?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=96=B9=E6=B3=95=E4=B8=BAstream=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E4=BF=AE=E5=A4=8D=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 3 +- go.sum | 6 ++-- goecs.go | 4 +-- memorytest/memorytest.go | 63 +++++++++++++++++++++++++++++++---- memorytest/memorytest_test.go | 2 +- 5 files changed, 66 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 6080d50..aae407b 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/oneclickvirt/defaultset v0.0.2-20240624082446 github.com/oneclickvirt/disktest v0.0.10-20250924030424 github.com/oneclickvirt/gostun v0.0.5-20250727155022 - github.com/oneclickvirt/memorytest v0.0.9-20250808065154 + github.com/oneclickvirt/memorytest v0.0.10-20250924154648 github.com/oneclickvirt/nt3 v0.0.8-20250811123903 github.com/oneclickvirt/pingtest v0.0.8-20250728015259 github.com/oneclickvirt/portchecker v0.0.3-20250728015900 @@ -61,6 +61,7 @@ require ( github.com/oneclickvirt/dd v0.0.2-20250808062818 // indirect github.com/oneclickvirt/fio v0.0.2-20250808045755 // indirect github.com/oneclickvirt/mbw v0.0.1-20250808061222 // indirect + github.com/oneclickvirt/stream v0.0.2-20250924154001 // indirect github.com/oschwald/maxminddb-golang v1.13.1 // indirect github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/pion/dtls/v2 v2.2.7 // indirect diff --git a/go.sum b/go.sum index 775a082..2976a9c 100644 --- a/go.sum +++ b/go.sum @@ -116,8 +116,8 @@ github.com/oneclickvirt/gostun v0.0.5-20250727155022 h1:/e3gSUrOp1tg/1NTRx+P8B51 github.com/oneclickvirt/gostun v0.0.5-20250727155022/go.mod h1:pfp7MFZJK9n/KTLAVqqFcCAns4xqMykmjI+1UeF/vdE= github.com/oneclickvirt/mbw v0.0.1-20250808061222 h1:WGXOe6QvHiDRhPVMI0VcctjzW08kGvJf50yq5YeZCtw= github.com/oneclickvirt/mbw v0.0.1-20250808061222/go.mod h1:0Vq6NRpyLmGUdfHfL3uDcFsuZhi7KlG+OCs5ky2757Y= -github.com/oneclickvirt/memorytest v0.0.9-20250808065154 h1:mjYOvpFz2mpDU9MNjj66oIDcc2r6+zoW8veP616/+4Q= -github.com/oneclickvirt/memorytest v0.0.9-20250808065154/go.mod h1:DBxiVZX7mWCe0Fy+qu57ENheLo00sLfjKzvxiICrUtU= +github.com/oneclickvirt/memorytest v0.0.10-20250924154648 h1:trk6oZ7xs1eVtr+6oIv5IX8LDVtEMG+E6GVzQ810BtU= +github.com/oneclickvirt/memorytest v0.0.10-20250924154648/go.mod h1:4kiHsEWkW9r3/1ZcV5xIweU0smiKP0IRfQj74AUIiVI= github.com/oneclickvirt/nt3 v0.0.8-20250811123903 h1:ubSPLh/DSrXj+tOgmRABgi2vrVmbmjjSne+NrVFNmNc= github.com/oneclickvirt/nt3 v0.0.8-20250811123903/go.mod h1:F1v+6xInBKnbUa8gV1M40R1HOzxg+obtduNhx3CTnmA= github.com/oneclickvirt/pingtest v0.0.8-20250728015259 h1:egoxZRZBOWN3JqBwqEsULDyRo2/dpGMeWcmV3U87zig= @@ -128,6 +128,8 @@ github.com/oneclickvirt/security v0.0.6-20250823030124 h1:3RjpJNfKV7anN6GJs0ky2B github.com/oneclickvirt/security v0.0.6-20250823030124/go.mod h1:RSMooIlb4H/kLrGWNvUyOgdzQKgYKVv+LzWGlsPsLW4= github.com/oneclickvirt/speedtest v0.0.10-20250728015734 h1:HKO7/JQ74ueXA8Wo8NIvcK9DphbEG/YTfAAVz/akSiY= github.com/oneclickvirt/speedtest v0.0.10-20250728015734/go.mod h1:0W8vnMbA3iucXLXFdGfe9Ia6RPS0izRO7jvu/SnH1P8= +github.com/oneclickvirt/stream v0.0.2-20250924154001 h1:GuJWdiPkoK84+y/+oHKr2Ghl3c/MzS9Z5m1nM+lMmy4= +github.com/oneclickvirt/stream v0.0.2-20250924154001/go.mod h1:oWaizaHTC2VQciBC9RfaLbAOf8qeR6n20/gY7QxriDE= github.com/oschwald/maxminddb-golang v1.13.1 h1:G3wwjdN9JmIK2o/ermkHM+98oX5fS+k5MbwsmL4MRQE= github.com/oschwald/maxminddb-golang v1.13.1/go.mod h1:K4pgV9N/GcK694KSTmVSDTODk4IsCNThNdTmnaBZ/F8= github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= diff --git a/goecs.go b/goecs.go index c5c18c7..764d161 100644 --- a/goecs.go +++ b/goecs.go @@ -39,7 +39,7 @@ import ( ) var ( - ecsVersion = "v0.1.88" + ecsVersion = "v0.1.89" menuMode bool onlyChinaTest bool input, choice string @@ -139,7 +139,7 @@ func parseFlags() { goecsFlag.BoolVar(&speedTestStatus, "speed", true, "Enable/Disable speed test") goecsFlag.StringVar(&cpuTestMethod, "cpum", "sysbench", "Set CPU test method (supported: sysbench, geekbench, winsat)") goecsFlag.StringVar(&cpuTestThreadMode, "cput", "multi", "Set CPU test thread mode (supported: single, multi)") - goecsFlag.StringVar(&memoryTestMethod, "memorym", "sysbench", "Set memory test method (supported: sysbench, dd, winsat)") + goecsFlag.StringVar(&memoryTestMethod, "memorym", "stream", "Set memory test method (supported: stream, sysbench, dd, winsat, auto)") goecsFlag.StringVar(&diskTestMethod, "diskm", "fio", "Set disk test method (supported: fio, dd, winsat)") goecsFlag.StringVar(&diskTestPath, "diskp", "", "Set disk test path, e.g., -diskp /root") goecsFlag.BoolVar(&diskMultiCheck, "diskmc", false, "Enable/Disable multiple disk checks, e.g., -diskmc=false") diff --git a/memorytest/memorytest.go b/memorytest/memorytest.go index 496e879..18a5195 100644 --- a/memorytest/memorytest.go +++ b/memorytest/memorytest.go @@ -8,27 +8,78 @@ import ( ) func MemoryTest(language, testMethod string) (realTestMethod, res string) { + testMethod = strings.ToLower(testMethod) + if testMethod == "" { + testMethod = "auto" + } if runtime.GOOS == "windows" { - if testMethod != "winsat" && testMethod != "" { + switch testMethod { + case "stream": + res = memory.WinsatTest(language) + realTestMethod = "winsat" + case "dd": + res = memory.WindowsDDTest(language) + if res == "" || strings.TrimSpace(res) == "" { + res += memory.WinsatTest(language) + realTestMethod = "winsat" + } else { + realTestMethod = "dd" + } + case "sysbench": + res = memory.WinsatTest(language) + realTestMethod = "winsat" + case "auto", "winsat": + res = memory.WinsatTest(language) + realTestMethod = "winsat" + default: + res = memory.WinsatTest(language) realTestMethod = "winsat" } - res += memory.WinsatTest(language) } else { switch testMethod { + case "stream": + res = memory.StreamTest(language) + if res == "" || strings.TrimSpace(res) == "" { + res += memory.DDTest(language) + realTestMethod = "dd" + } else { + realTestMethod = "stream" + } + case "dd": + res = memory.DDTest(language) + realTestMethod = "dd" case "sysbench": res = memory.SysBenchTest(language) - if res == "" { + if res == "" || strings.TrimSpace(res) == "" { res += memory.DDTest(language) realTestMethod = "dd" } else { realTestMethod = "sysbench" } - case "dd": + case "auto": + res = memory.StreamTest(language) + if res == "" || strings.TrimSpace(res) == "" { + res = memory.DDTest(language) + if res == "" || strings.TrimSpace(res) == "" { + res = memory.SysBenchTest(language) + if res == "" || strings.TrimSpace(res) == "" { + realTestMethod = "" + } else { + realTestMethod = "sysbench" + } + } else { + realTestMethod = "dd" + } + } else { + realTestMethod = "stream" + } + case "winsat": + // winsat 仅 Windows 支持,非 Windows fallback 到 dd res = memory.DDTest(language) realTestMethod = "dd" default: - res += memory.DDTest(language) - realTestMethod = "dd" + res = "Unsupported test method" + realTestMethod = "" } } if !strings.Contains(res, "\n") && res != "" { diff --git a/memorytest/memorytest_test.go b/memorytest/memorytest_test.go index 8642825..aed6be1 100644 --- a/memorytest/memorytest_test.go +++ b/memorytest/memorytest_test.go @@ -6,6 +6,6 @@ import ( ) func Test(t *testing.T) { - _, res := MemoryTest("zh", "sysbench") + _, res := MemoryTest("zh", "stream") fmt.Print(res) }