From 3daba99b79afb2f9d2270efd8b88255680243de9 Mon Sep 17 00:00:00 2001 From: ThinhNX Date: Wed, 10 Jul 2024 23:28:04 +0700 Subject: [PATCH 1/9] feat:gno gno test now has gasused instead of time --- gnovm/cmd/gno/test.go | 25 +++++++++++++++++-------- gnovm/stdlibs/testing/testing.gno | 10 +++++++--- gnovm/tests/file.go | 20 +++++++++++++------- gnovm/tests/file_test.go | 4 +++- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index 5884463a552..e7973bff009 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -11,6 +11,7 @@ import ( "path/filepath" "runtime/debug" "sort" + "strconv" "strings" "text/template" "time" @@ -25,6 +26,7 @@ import ( "github.com/gnolang/gno/tm2/pkg/errors" "github.com/gnolang/gno/tm2/pkg/random" "github.com/gnolang/gno/tm2/pkg/std" + "github.com/gnolang/gno/tm2/pkg/store" "github.com/gnolang/gno/tm2/pkg/testutils" ) @@ -194,7 +196,7 @@ func execTest(cfg *testCfg, args []string, io commands.IO) error { sort.Strings(pkg.FiletestGnoFiles) startedAt := time.Now() - err = gnoTestPkg(pkg.Dir, pkg.TestGnoFiles, pkg.FiletestGnoFiles, cfg, io) + gasUsed, err := gnoTestPkg(pkg.Dir, pkg.TestGnoFiles, pkg.FiletestGnoFiles, cfg, io) duration := time.Since(startedAt) dstr := fmtDuration(duration) @@ -205,7 +207,7 @@ func execTest(cfg *testCfg, args []string, io commands.IO) error { io.ErrPrintfln("FAIL") testErrCount++ } else { - io.ErrPrintfln("ok %s \t%s", pkg.Dir, dstr) + io.ErrPrintfln("ok %s \ttotal gas used: %s", pkg.Dir, strconv.Itoa(int(gasUsed))) } } if testErrCount > 0 || buildErrCount > 0 { @@ -222,7 +224,7 @@ func gnoTestPkg( filetestFiles []string, cfg *testCfg, io commands.IO, -) error { +) (int64, error) { var ( verbose = cfg.verbose rootDir = cfg.rootDir @@ -234,7 +236,7 @@ func gnoTestPkg( stderr = io.Err() errs error ) - + gasUsed := int64(0) mode := tests.ImportModeStdlibsOnly if cfg.withNativeFallback { // XXX: display a warn? @@ -271,7 +273,7 @@ func gnoTestPkg( }) if hasError { - return commands.ExitCodeError(1) + return gasUsed, commands.ExitCodeError(1) } testPkgName := getPkgNameFromFileset(ifiles) @@ -287,6 +289,8 @@ func gnoTestPkg( } m := tests.TestMachine(testStore, stdout, gnoPkgPath) + // initial new gasMeter + m.GasMeter = store.NewGasMeter(10000 * 1000 * 1000) if printRuntimeMetrics { // from tm2/pkg/sdk/vm/keeper.go // XXX: make maxAllocTx configurable. @@ -295,7 +299,10 @@ func gnoTestPkg( m.Alloc = gno.NewAllocator(maxAllocTx) } m.RunMemPackage(memPkg, true) + bGasUsed := m.GasMeter.GasConsumed() err := runTestFiles(m, tfiles, memPkg.Name, verbose, printRuntimeMetrics, runFlag, io) + aGasUsed := m.GasMeter.GasConsumed() + gasUsed += (aGasUsed - bGasUsed) if err != nil { errs = multierr.Append(errs, err) } @@ -357,7 +364,9 @@ func gnoTestPkg( } testFilePath := filepath.Join(pkgPath, testFileName) - err := tests.RunFileTest(rootDir, testFilePath, tests.WithSyncWanted(cfg.updateGoldenTests)) + var err error + gasUsedInThisPeriod, err := tests.RunFileTest(rootDir, testFilePath, tests.WithSyncWanted(cfg.updateGoldenTests)) + gasUsed += gasUsedInThisPeriod duration := time.Since(startedAt) dstr := fmtDuration(duration) @@ -375,13 +384,13 @@ func gnoTestPkg( } if verbose { - io.ErrPrintfln("--- PASS: %s (%s)", testName, dstr) + io.ErrPrintfln("--- PASS: %s (%s) with GasUsed: %v", testName, dstr, gasUsedInThisPeriod) } // XXX: add per-test metrics } } - return errs + return gasUsed, errs } // attempts to determine the full gno pkg path by analyzing the directory. diff --git a/gnovm/stdlibs/testing/testing.gno b/gnovm/stdlibs/testing/testing.gno index 6e55c5cc283..0bc2b6540b7 100644 --- a/gnovm/stdlibs/testing/testing.gno +++ b/gnovm/stdlibs/testing/testing.gno @@ -7,6 +7,8 @@ import ( "os" "strconv" "strings" + // gno "github.com/gnolang/gno/gnovm/pkg/gnolang" + // "github.com/gnolang/gno/tm2/pkg/store" ) // ---------------------------------------- @@ -326,7 +328,9 @@ func tRunner(t *T, fn testingFunc, verbose bool) { if !t.shouldRun(t.name) { return } - + // m := gno.NewMachine("", nil) + // m.GasMeter = store.NewGasMeter(10000 * 1000 * 1000) + // gasStart := 0 start := unixNano() defer func() { @@ -341,7 +345,7 @@ func tRunner(t *T, fn testingFunc, verbose bool) { dur := unixNano() - start t.dur = formatDur(dur) - + // gasUsed := m.GasMeter.GasConsumed() if t.verbose { switch { case t.Failed(): @@ -349,7 +353,7 @@ func tRunner(t *T, fn testingFunc, verbose bool) { case t.skipped: fmt.Fprintf(os.Stderr, "--- SKIP: %s (%s)\n", t.name, t.dur) case t.verbose: - fmt.Fprintf(os.Stderr, "--- PASS: %s (%s)\n", t.name, t.dur) + fmt.Fprintf(os.Stderr, "--- PASS: %s \n", t.name) } } }() diff --git a/gnovm/tests/file.go b/gnovm/tests/file.go index 8ab60145bd5..2233bcbfa3e 100644 --- a/gnovm/tests/file.go +++ b/gnovm/tests/file.go @@ -20,6 +20,7 @@ import ( osm "github.com/gnolang/gno/tm2/pkg/os" "github.com/gnolang/gno/tm2/pkg/sdk" "github.com/gnolang/gno/tm2/pkg/std" + "github.com/gnolang/gno/tm2/pkg/store/types" "github.com/pmezard/go-difflib/difflib" ) @@ -103,8 +104,9 @@ func WithSyncWanted(v bool) RunFileTestOption { // RunFileTest executes the filetest at the given path, using rootDir as // the directory where to find the "stdlibs" directory. -func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error { +func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) (int64, error) { var f runFileTestOptions + var gasUsed = int64(0) for _, opt := range opts { opt(&f) } @@ -124,7 +126,9 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error { store := TestStore(rootDir, "./files", stdin, stdout, stderr, mode) store.SetLogStoreOps(true) m := testMachineCustom(store, pkgPath, stdout, maxAlloc, send) - + // set a gasMeter for machine that runs the tests, consider the limit of this + m.GasMeter = types.NewGasMeter(10000 * 1000 * 1000) + beforeGas := m.GasMeter.GasConsumed() // TODO support stdlib groups, but make testing safe; // e.g. not be able to make network connections. // interp.New(interp.Options{GoPath: goPath, Stdout: &stdout, Stderr: &stderr}) @@ -133,7 +137,7 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error { // m.Use(unsafe.Symbols) bz, err := os.ReadFile(path) if err != nil { - return err + return gasUsed, err } { // Validate result, errors, etc. var pnc interface{} @@ -279,7 +283,7 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error { // NOTE: ignores any gno.GetDebugErrors(). gno.ClearDebugErrors() - return nil // nothing more to do. + return gasUsed, nil // nothing more to do. } else { // record errors when errWanted is empty and pnc not nil if pnc != nil { @@ -307,7 +311,7 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error { panic(fmt.Sprintf("fail on %s: got unexpected debug error(s): %v", path, gno.GetDebugErrors())) } // pnc is nil, errWanted empty, no gno debug errors - return nil + return gasUsed, nil } case "Output": // panic if got unexpected error @@ -374,10 +378,12 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error { } } default: - return nil + return gasUsed, nil } } } + afterGas := m.GasMeter.GasConsumed() + gasUsed = afterGas - beforeGas // Check that machine is empty. err = m.CheckEmpty() @@ -387,7 +393,7 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error { } panic(fmt.Sprintf("fail on %s: machine not empty after main: %v", path, err)) } - return nil + return gasUsed, nil } func wantedFromComment(p string) (directives []string, pkgPath, res, err, rops string, maxAlloc int64, send std.Coins) { diff --git a/gnovm/tests/file_test.go b/gnovm/tests/file_test.go index 4313fd88645..08454072e22 100644 --- a/gnovm/tests/file_test.go +++ b/gnovm/tests/file_test.go @@ -2,6 +2,7 @@ package tests import ( "flag" + "fmt" "io/fs" "os" "path" @@ -137,8 +138,9 @@ func runFileTest(t *testing.T, path string, opts ...RunFileTestOption) { logger = t.Log } rootDir := filepath.Join("..", "..") - err := RunFileTest(rootDir, path, append(opts, WithLoggerFunc(logger))...) + _, err := RunFileTest(rootDir, path, append(opts, WithLoggerFunc(logger))...) if err != nil { t.Fatalf("got error: %v", err) } + // fmt.Printf("GasUsed runFileTest: %v\n", gasUsed) } From e8865434ee7716f9100a78c549cf2eb8ecc2bffc Mon Sep 17 00:00:00 2001 From: ThinhNX Date: Wed, 10 Jul 2024 23:40:38 +0700 Subject: [PATCH 2/9] update --- gnovm/cmd/gno/test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index e7973bff009..780ba1b429b 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -207,7 +207,7 @@ func execTest(cfg *testCfg, args []string, io commands.IO) error { io.ErrPrintfln("FAIL") testErrCount++ } else { - io.ErrPrintfln("ok %s \ttotal gas used: %s", pkg.Dir, strconv.Itoa(int(gasUsed))) + io.ErrPrintfln("ok %s \ttotal gas used: %d", pkg.Dir, gasUsed) } } if testErrCount > 0 || buildErrCount > 0 { @@ -384,7 +384,7 @@ func gnoTestPkg( } if verbose { - io.ErrPrintfln("--- PASS: %s (%s) with GasUsed: %v", testName, dstr, gasUsedInThisPeriod) + io.ErrPrintfln("--- PASS: %s (%s) with GasUsed: %d", testName, dstr, gasUsedInThisPeriod) } // XXX: add per-test metrics } From 01c8eefcea4e4b79de89654ee09df59a2ffea47d Mon Sep 17 00:00:00 2001 From: ThinhNX Date: Wed, 10 Jul 2024 23:52:23 +0700 Subject: [PATCH 3/9] update --- gnovm/cmd/gno/test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index 780ba1b429b..fac9ed088c3 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -11,7 +11,6 @@ import ( "path/filepath" "runtime/debug" "sort" - "strconv" "strings" "text/template" "time" From b65b34744867a1b4a505e772295e77a5450d3e40 Mon Sep 17 00:00:00 2001 From: ThinhNX Date: Wed, 10 Jul 2024 23:55:28 +0700 Subject: [PATCH 4/9] remove typing err --- gnovm/tests/file_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/gnovm/tests/file_test.go b/gnovm/tests/file_test.go index 08454072e22..448a8c29906 100644 --- a/gnovm/tests/file_test.go +++ b/gnovm/tests/file_test.go @@ -2,7 +2,6 @@ package tests import ( "flag" - "fmt" "io/fs" "os" "path" From 6c525fc4ef68ed6b68e4f25f8a1f59462d34ec8b Mon Sep 17 00:00:00 2001 From: ThinhNX Date: Tue, 16 Jul 2024 11:18:32 +0700 Subject: [PATCH 5/9] gofumpted --- gnovm/tests/file.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/tests/file.go b/gnovm/tests/file.go index 2233bcbfa3e..c606f1f7b1a 100644 --- a/gnovm/tests/file.go +++ b/gnovm/tests/file.go @@ -106,7 +106,7 @@ func WithSyncWanted(v bool) RunFileTestOption { // the directory where to find the "stdlibs" directory. func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) (int64, error) { var f runFileTestOptions - var gasUsed = int64(0) + gasUsed := int64(0) for _, opt := range opts { opt(&f) } From ca995ff976803c6ce5dea1ad7d8f80ea93dbccbc Mon Sep 17 00:00:00 2001 From: ThinhNX Date: Wed, 24 Jul 2024 05:28:28 +0700 Subject: [PATCH 6/9] refact coding style --- gnovm/cmd/gno/test.go | 10 +++++----- gnovm/stdlibs/testing/testing.gno | 3 --- gnovm/tests/file.go | 4 ++-- gnovm/tests/file_test.go | 1 - 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index fac9ed088c3..cbd2b44a36f 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -235,7 +235,7 @@ func gnoTestPkg( stderr = io.Err() errs error ) - gasUsed := int64(0) + var gasUsed int64 mode := tests.ImportModeStdlibsOnly if cfg.withNativeFallback { // XXX: display a warn? @@ -289,7 +289,7 @@ func gnoTestPkg( m := tests.TestMachine(testStore, stdout, gnoPkgPath) // initial new gasMeter - m.GasMeter = store.NewGasMeter(10000 * 1000 * 1000) + m.GasMeter = store.NewGasMeter(10_000_000_000) if printRuntimeMetrics { // from tm2/pkg/sdk/vm/keeper.go // XXX: make maxAllocTx configurable. @@ -298,10 +298,10 @@ func gnoTestPkg( m.Alloc = gno.NewAllocator(maxAllocTx) } m.RunMemPackage(memPkg, true) - bGasUsed := m.GasMeter.GasConsumed() + beforeGasUsed := m.GasMeter.GasConsumed() err := runTestFiles(m, tfiles, memPkg.Name, verbose, printRuntimeMetrics, runFlag, io) - aGasUsed := m.GasMeter.GasConsumed() - gasUsed += (aGasUsed - bGasUsed) + afterGasUsed := m.GasMeter.GasConsumed() + gasUsed += (afterGasUsed - beforeGasUsed) if err != nil { errs = multierr.Append(errs, err) } diff --git a/gnovm/stdlibs/testing/testing.gno b/gnovm/stdlibs/testing/testing.gno index 0bc2b6540b7..e96d36d2c36 100644 --- a/gnovm/stdlibs/testing/testing.gno +++ b/gnovm/stdlibs/testing/testing.gno @@ -328,9 +328,6 @@ func tRunner(t *T, fn testingFunc, verbose bool) { if !t.shouldRun(t.name) { return } - // m := gno.NewMachine("", nil) - // m.GasMeter = store.NewGasMeter(10000 * 1000 * 1000) - // gasStart := 0 start := unixNano() defer func() { diff --git a/gnovm/tests/file.go b/gnovm/tests/file.go index c606f1f7b1a..72de1f25d9a 100644 --- a/gnovm/tests/file.go +++ b/gnovm/tests/file.go @@ -106,7 +106,7 @@ func WithSyncWanted(v bool) RunFileTestOption { // the directory where to find the "stdlibs" directory. func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) (int64, error) { var f runFileTestOptions - gasUsed := int64(0) + var gasUsed int64 for _, opt := range opts { opt(&f) } @@ -126,7 +126,7 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) (int64, store := TestStore(rootDir, "./files", stdin, stdout, stderr, mode) store.SetLogStoreOps(true) m := testMachineCustom(store, pkgPath, stdout, maxAlloc, send) - // set a gasMeter for machine that runs the tests, consider the limit of this + // Set a gas meter for machine that runs the tests. m.GasMeter = types.NewGasMeter(10000 * 1000 * 1000) beforeGas := m.GasMeter.GasConsumed() // TODO support stdlib groups, but make testing safe; diff --git a/gnovm/tests/file_test.go b/gnovm/tests/file_test.go index 448a8c29906..1609c3c506d 100644 --- a/gnovm/tests/file_test.go +++ b/gnovm/tests/file_test.go @@ -141,5 +141,4 @@ func runFileTest(t *testing.T, path string, opts ...RunFileTestOption) { if err != nil { t.Fatalf("got error: %v", err) } - // fmt.Printf("GasUsed runFileTest: %v\n", gasUsed) } From 73bf52dce33222e0141d0a1df9f08ec856359261 Mon Sep 17 00:00:00 2001 From: ThinhNX Date: Sat, 10 Aug 2024 16:23:22 +0700 Subject: [PATCH 7/9] fix linter --- gnovm/tests/file.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gnovm/tests/file.go b/gnovm/tests/file.go index 24eb0892f12..fb9b761ea3a 100644 --- a/gnovm/tests/file.go +++ b/gnovm/tests/file.go @@ -129,7 +129,6 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) (int64, // Set a gas meter for machine that runs the tests. m.GasMeter = types.NewGasMeter(10000 * 1000 * 1000) beforeGas := m.GasMeter.GasConsumed() - checkMachineIsEmpty := true // TODO support stdlib groups, but make testing safe; // e.g. not be able to make network connections. @@ -288,8 +287,7 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) (int64, // NOTE: ignores any gno.GetDebugErrors(). gno.ClearDebugErrors() checkMachineIsEmpty = false // nothing more to do. - return gasUsed, nil // nothing more to do. - + return gasUsed, nil } else { // record errors when errWanted is empty and pnc not nil if pnc != nil { @@ -319,7 +317,6 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) (int64, // pnc is nil, errWanted empty, no gno debug errors checkMachineIsEmpty = false return gasUsed, nil - } case "Output": // panic if got unexpected error From 0cc91ce5d302e0cb838c98cb6517632b326ca28e Mon Sep 17 00:00:00 2001 From: ThinhNX Date: Sat, 10 Aug 2024 17:02:20 +0700 Subject: [PATCH 8/9] fix current testcase expectation with gasUsed information --- gnovm/cmd/gno/testdata/gno_test/error_correct.txtar | 2 +- gnovm/cmd/gno/testdata/gno_test/minim2.txtar | 3 ++- gnovm/cmd/gno/testdata/gno_test/minim3.txtar | 3 ++- gnovm/cmd/gno/testdata/gno_test/output_correct.txtar | 3 ++- gnovm/cmd/gno/testdata/gno_test/output_sync.txtar | 3 ++- gnovm/cmd/gno/testdata/gno_test/realm_correct.txtar | 3 ++- gnovm/cmd/gno/testdata/gno_test/realm_sync.txtar | 3 ++- gnovm/cmd/gno/testdata/gno_test/valid_filetest.txtar | 7 ++++--- gnovm/cmd/gno/testdata/gno_test/valid_test.txtar | 5 +++-- 9 files changed, 20 insertions(+), 12 deletions(-) diff --git a/gnovm/cmd/gno/testdata/gno_test/error_correct.txtar b/gnovm/cmd/gno/testdata/gno_test/error_correct.txtar index 20a399881be..e5976fd2aaa 100644 --- a/gnovm/cmd/gno/testdata/gno_test/error_correct.txtar +++ b/gnovm/cmd/gno/testdata/gno_test/error_correct.txtar @@ -5,7 +5,7 @@ gno test -v . stdout 'Machine\.RunMain\(\) panic: oups' stderr '=== RUN file/x_filetest.gno' stderr '--- PASS: file/x_filetest.gno \(\d\.\d\ds\)' -stderr 'ok \. \d\.\d\ds' +stderr 'ok . total gas used: 0' -- x_filetest.gno -- package main diff --git a/gnovm/cmd/gno/testdata/gno_test/minim2.txtar b/gnovm/cmd/gno/testdata/gno_test/minim2.txtar index 3c4d1d085f0..6d4df27d63b 100644 --- a/gnovm/cmd/gno/testdata/gno_test/minim2.txtar +++ b/gnovm/cmd/gno/testdata/gno_test/minim2.txtar @@ -3,7 +3,8 @@ gno test . ! stdout .+ -stderr 'ok \. \d\.\d\ds' +# expected gasUsed information +stderr 'ok . total gas used: 11' -- minim.gno -- package minim diff --git a/gnovm/cmd/gno/testdata/gno_test/minim3.txtar b/gnovm/cmd/gno/testdata/gno_test/minim3.txtar index ac8ae0c41d4..d7fc3e38318 100644 --- a/gnovm/cmd/gno/testdata/gno_test/minim3.txtar +++ b/gnovm/cmd/gno/testdata/gno_test/minim3.txtar @@ -3,7 +3,8 @@ gno test . ! stdout .+ -stderr 'ok \. \d\.\d\ds' +# expected gasUsed information +stderr 'ok . total gas used: 10' -- minim.gno -- package minim diff --git a/gnovm/cmd/gno/testdata/gno_test/output_correct.txtar b/gnovm/cmd/gno/testdata/gno_test/output_correct.txtar index e734dad7934..47ba3f9a01c 100644 --- a/gnovm/cmd/gno/testdata/gno_test/output_correct.txtar +++ b/gnovm/cmd/gno/testdata/gno_test/output_correct.txtar @@ -5,7 +5,8 @@ gno test -v . ! stdout .+ # stdout should be empty stderr '=== RUN file/x_filetest.gno' stderr '--- PASS: file/x_filetest.gno \(\d\.\d\ds\)' -stderr 'ok \. \d\.\d\ds' +# expected gasUsed information +stderr 'ok . total gas used: 28' -- x_filetest.gno -- package main diff --git a/gnovm/cmd/gno/testdata/gno_test/output_sync.txtar b/gnovm/cmd/gno/testdata/gno_test/output_sync.txtar index 45e6e5c79be..47ac7574c68 100644 --- a/gnovm/cmd/gno/testdata/gno_test/output_sync.txtar +++ b/gnovm/cmd/gno/testdata/gno_test/output_sync.txtar @@ -5,7 +5,8 @@ gno test -v . -update-golden-tests ! stdout .+ # stdout should be empty stderr '=== RUN file/x_filetest.gno' stderr '--- PASS: file/x_filetest.gno \(\d\.\d\ds\)' -stderr 'ok \. \d\.\d\ds' +# expected gasUsed information +stderr 'ok . total gas used: 28' cmp x_filetest.gno x_filetest.gno.golden diff --git a/gnovm/cmd/gno/testdata/gno_test/realm_correct.txtar b/gnovm/cmd/gno/testdata/gno_test/realm_correct.txtar index 99e6fccd42d..38a3315a51c 100644 --- a/gnovm/cmd/gno/testdata/gno_test/realm_correct.txtar +++ b/gnovm/cmd/gno/testdata/gno_test/realm_correct.txtar @@ -5,7 +5,8 @@ gno test -v . ! stdout .+ # stdout should be empty stderr '=== RUN file/x_filetest.gno' stderr '--- PASS: file/x_filetest.gno \(\d\.\d\ds\)' -stderr 'ok \. \d\.\d\ds' +# expected gasUsed information +stderr 'ok . total gas used: 17' -- x_filetest.gno -- // PKGPATH: gno.land/r/x diff --git a/gnovm/cmd/gno/testdata/gno_test/realm_sync.txtar b/gnovm/cmd/gno/testdata/gno_test/realm_sync.txtar index 3d27ab4fde0..025840ccb84 100644 --- a/gnovm/cmd/gno/testdata/gno_test/realm_sync.txtar +++ b/gnovm/cmd/gno/testdata/gno_test/realm_sync.txtar @@ -5,7 +5,8 @@ gno test -v . -update-golden-tests ! stdout .+ # stdout should be empty stderr '=== RUN file/x_filetest.gno' stderr '--- PASS: file/x_filetest.gno \(\d\.\d\ds\)' -stderr 'ok \. \d\.\d\ds' +# expected gasUsed information +stderr 'ok . total gas used: 17' cmp x_filetest.gno x_filetest.gno.golden diff --git a/gnovm/cmd/gno/testdata/gno_test/valid_filetest.txtar b/gnovm/cmd/gno/testdata/gno_test/valid_filetest.txtar index 02ae3f72304..58ef2ef207b 100644 --- a/gnovm/cmd/gno/testdata/gno_test/valid_filetest.txtar +++ b/gnovm/cmd/gno/testdata/gno_test/valid_filetest.txtar @@ -1,16 +1,17 @@ # Test with a valid _filetest.gno file - +# add the expectation of gasUsed information in stdout gno test . ! stdout .+ -stderr 'ok \. \d\.\d\ds' +stderr 'ok . total gas used: 19' gno test -v . ! stdout .+ stderr '=== RUN file/valid_filetest.gno' stderr '--- PASS: file/valid_filetest.gno \(\d\.\d\ds\)' -stderr 'ok \. \d\.\d\ds' +# expected gasUsed information +stderr 'ok . total gas used: 19' -- valid.gno -- package valid diff --git a/gnovm/cmd/gno/testdata/gno_test/valid_test.txtar b/gnovm/cmd/gno/testdata/gno_test/valid_test.txtar index 9590626776c..d0dade7e864 100644 --- a/gnovm/cmd/gno/testdata/gno_test/valid_test.txtar +++ b/gnovm/cmd/gno/testdata/gno_test/valid_test.txtar @@ -3,12 +3,13 @@ gno test . ! stdout .+ -stderr 'ok \. \d\.\d\ds' +# expected gasUsed information +stderr 'ok . total gas used: 353' gno test ./... ! stdout .+ -stderr 'ok \. \d\.\d\ds' +stderr 'ok . total gas used: 353' -- valid.gno -- package valid From 6e31307bdcd2f192e1d6aab62bdc82993086681c Mon Sep 17 00:00:00 2001 From: ThinhNX Date: Tue, 13 Aug 2024 09:17:28 +0700 Subject: [PATCH 9/9] re-adding duration of test executing duration --- gnovm/cmd/gno/test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index cbd2b44a36f..5ee49d82aa9 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -206,7 +206,7 @@ func execTest(cfg *testCfg, args []string, io commands.IO) error { io.ErrPrintfln("FAIL") testErrCount++ } else { - io.ErrPrintfln("ok %s \ttotal gas used: %d", pkg.Dir, gasUsed) + io.ErrPrintfln("ok %s \ttotal gas used: %d \t(%s)", pkg.Dir, gasUsed, dstr) } } if testErrCount > 0 || buildErrCount > 0 { @@ -383,7 +383,7 @@ func gnoTestPkg( } if verbose { - io.ErrPrintfln("--- PASS: %s (%s) with GasUsed: %d", testName, dstr, gasUsedInThisPeriod) + io.ErrPrintfln("--- PASS: %s (%s) with gas used: %d", testName, dstr, gasUsedInThisPeriod) } // XXX: add per-test metrics }