From 25a43f7a5e49300a9b3ad37cacd4b32b032e8ba8 Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Sun, 2 Feb 2025 10:50:29 -0500 Subject: [PATCH] update --- src/kvraft1/kvraft_test.go | 2 +- src/kvraft1/rsm/rsm_test.go | 2 +- src/shardkv1/shardkv_test.go | 4 ++-- src/tester1/config.go | 28 ++++++++++++++++++++++++---- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/kvraft1/kvraft_test.go b/src/kvraft1/kvraft_test.go index 597b3b0..13d8c29 100644 --- a/src/kvraft1/kvraft_test.go +++ b/src/kvraft1/kvraft_test.go @@ -99,7 +99,7 @@ func (ts *Test) GenericTest() { // requests and had time to checkpoint. sz := ts.Config.Group(Gid).LogSize() if sz > 8*ts.maxraftstate { - ts.Fatalf("logs were not trimmed (%v > 8*%v)", sz, ts.maxraftstate) + ts.t.Fatalf("logs were not trimmed (%v > 8*%v)", sz, ts.maxraftstate) } } if ts.maxraftstate < 0 { diff --git a/src/kvraft1/rsm/rsm_test.go b/src/kvraft1/rsm/rsm_test.go index a21be74..cf87c00 100644 --- a/src/kvraft1/rsm/rsm_test.go +++ b/src/kvraft1/rsm/rsm_test.go @@ -14,7 +14,7 @@ func TestBasic(t *testing.T) { for i := 0; i < 10; i++ { r := ts.one() if r.N != i+1 { - ts.Fatalf("expected %d instead of %d", i, r.N) + ts.t.Fatalf("expected %d instead of %d", i, r.N) } ts.checkCounter(r.N, NSRV) } diff --git a/src/shardkv1/shardkv_test.go b/src/shardkv1/shardkv_test.go index 3b70d58..24ae2c0 100644 --- a/src/shardkv1/shardkv_test.go +++ b/src/shardkv1/shardkv_test.go @@ -33,10 +33,10 @@ func TestStaticOneShardGroup5A(t *testing.T) { // Read the initial configuration and check it cfg, v, err := sck.Query() if err != rpc.OK { - ts.Fatalf("Query failed %v", err) + ts.t.Fatalf("Query failed %v", err) } if v != 1 || cfg.Num != 1 || cfg.Shards[0] != shardcfg.Gid1 { - ts.Fatalf("Static wrong %v %v", cfg, v) + ts.t.Fatalf("Static wrong %v %v", cfg, v) } cfg.CheckConfig(t, []tester.Tgid{shardcfg.Gid1}) diff --git a/src/tester1/config.go b/src/tester1/config.go index d213b7c..939df47 100644 --- a/src/tester1/config.go +++ b/src/tester1/config.go @@ -4,11 +4,12 @@ import ( crand "crypto/rand" "encoding/base64" "fmt" - // "log" + //"log" "math/big" "math/rand" "runtime" - "runtime/debug" + // "runtime/debug" + "strings" "sync" "sync/atomic" "testing" @@ -137,8 +138,27 @@ func (cfg *Config) End() { } func (cfg *Config) Fatalf(format string, args ...any) { - debug.PrintStack() - cfg.t.Fatalf(format, args...) + const maxStackLen = 50 + fmt.Printf("Fatal: ") + fmt.Printf(format, args...) + fmt.Println("") + var pc [maxStackLen]uintptr + // Skip two extra frames to account for this function + // and runtime.Callers itself. + n := runtime.Callers(2, pc[:]) + if n == 0 { + panic("testing: zero callers found") + } + frames := runtime.CallersFrames(pc[:n]) + var frame runtime.Frame + for more := true; more; { + frame, more = frames.Next() + // Print only frames in our test files + if strings.Contains(frame.File, "test.go") { + fmt.Printf(" %v:%d\n", frame.File, frame.Line) + } + } + cfg.t.FailNow() } func Randstring(n int) string {