lab.nexedi.com/kirr/go123@v0.0.0-20240207185015-8299741fa871/xruntime/xruntime_test.go (about) 1 // Copyright (C) 2015-2017 Nexedi SA and Contributors. 2 // Kirill Smelkov <kirr@nexedi.com> 3 // 4 // This program is free software: you can Use, Study, Modify and Redistribute 5 // it under the terms of the GNU General Public License version 3, or (at your 6 // option) any later version, as published by the Free Software Foundation. 7 // 8 // You can also Link and Combine this program with other software covered by 9 // the terms of any of the Free Software licenses or any of the Open Source 10 // Initiative approved licenses and Convey the resulting work. Corresponding 11 // source of such a combination shall include the source code for all other 12 // software used. 13 // 14 // This program is distributed WITHOUT ANY WARRANTY; without even the implied 15 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 // 17 // See COPYING file for full licensing terms. 18 // See https://www.nexedi.com/licensing for rationale and options. 19 20 package xruntime 21 22 import ( 23 "runtime" 24 "testing" 25 26 "lab.nexedi.com/kirr/go123/my" 27 ) 28 29 func f333(tb1, tb2 *[]runtime.Frame) { 30 // NOTE keeping tb1 and tb2 updates on the same line - so that .Line in both frames is the same 31 *tb1 = append(*tb1, my.Frame()); *tb2 = Traceback(1) 32 } 33 34 func f222(tb1, tb2 *[]runtime.Frame) { 35 *tb1 = append(*tb1, my.Frame()); f333(tb1, tb2) 36 } 37 38 func f111(tb1, tb2 *[]runtime.Frame) { 39 *tb1 = append(*tb1, my.Frame()); f222(tb1, tb2) 40 } 41 42 func TestTraceback(t *testing.T) { 43 var tb1, tb2 []runtime.Frame 44 f111(&tb1, &tb2) 45 46 if len(tb1) != 3 { 47 t.Fatalf("len(tb1) = %v ; must be 3", len(tb1)) 48 } 49 50 tb1[0], tb1[1], tb1[2] = tb1[2], tb1[1], tb1[0] // reverse 51 52 for i, f1 := range tb1 { 53 f2 := tb2[i] 54 55 // pc are different; everything else must be the same 56 f1.PC = 0 57 f2.PC = 0 58 59 if f1 != f2 { 60 t.Errorf("traceback #%v:\nhave %v\nwant %v", i, f2, f1) 61 } 62 } 63 }