From 4e0d19258845ddbfe0c446fe9abe5b9bf4721b31 Mon Sep 17 00:00:00 2001 From: Pavel Zbitskiy Date: Tue, 16 Mar 2021 16:37:10 -0400 Subject: [PATCH] tealdbg: listen on specified address --- cmd/tealdbg/main.go | 6 +- cmd/tealdbg/server.go | 4 +- cmd/tealdbg/server_test.go | 2 +- .../e2e-go/cli/tealdbg/expect/tealdbgTest.exp | 84 ++++++------------- 4 files changed, 31 insertions(+), 65 deletions(-) diff --git a/cmd/tealdbg/main.go b/cmd/tealdbg/main.go index 96763d3ab1..60a090cccc 100644 --- a/cmd/tealdbg/main.go +++ b/cmd/tealdbg/main.go @@ -135,6 +135,7 @@ var roundNumber uint64 var timestamp int64 var runMode runModeValue = runModeValue{makeCobraStringValue("auto", []string{"signature", "application"})} var port int +var iface string var noFirstRun bool var noBrowserCheck bool var noSourceMap bool @@ -146,6 +147,7 @@ var listenForDrReq bool func init() { rootCmd.PersistentFlags().VarP(&frontend, "frontend", "f", "Frontend to use: "+frontend.AllowedString()) rootCmd.PersistentFlags().IntVar(&port, "remote-debugging-port", 9392, "Port to listen on") + rootCmd.PersistentFlags().StringVar(&iface, "listen", "127.0.0.1", "Network interface to listen on") rootCmd.PersistentFlags().BoolVar(&noFirstRun, "no-first-run", false, "") rootCmd.PersistentFlags().MarkHidden("no-first-run") rootCmd.PersistentFlags().BoolVar(&noBrowserCheck, "no-default-browser-check", false, "") @@ -172,7 +174,7 @@ func init() { } func debugRemote() { - ds := makeDebugServer(port, &frontend, nil) + ds := makeDebugServer(iface, port, &frontend, nil) err := ds.startRemote() if err != nil { log.Fatalln(err.Error()) @@ -277,7 +279,7 @@ func debugLocal(args []string) { ListenForDrReq: listenForDrReq, } - ds := makeDebugServer(port, &frontend, &dp) + ds := makeDebugServer(iface, port, &frontend, &dp) err = ds.startDebug() if err != nil { diff --git a/cmd/tealdbg/server.go b/cmd/tealdbg/server.go index c47208a056..f207285948 100644 --- a/cmd/tealdbg/server.go +++ b/cmd/tealdbg/server.go @@ -90,11 +90,11 @@ type FrontendFactory interface { Make(router *mux.Router, appAddress string) (da DebugAdapter) } -func makeDebugServer(port int, ff FrontendFactory, dp *DebugParams) DebugServer { +func makeDebugServer(iface string, port int, ff FrontendFactory, dp *DebugParams) DebugServer { debugger := MakeDebugger() router := mux.NewRouter() - appAddress := fmt.Sprintf("127.0.0.1:%d", port) + appAddress := fmt.Sprintf("%s:%d", iface, port) da := ff.Make(router, appAddress) debugger.AddAdapter(da) diff --git a/cmd/tealdbg/server_test.go b/cmd/tealdbg/server_test.go index 99ff96af72..aa138b30b3 100644 --- a/cmd/tealdbg/server_test.go +++ b/cmd/tealdbg/server_test.go @@ -111,7 +111,7 @@ func serverTestImpl(t *testing.T, run func(t *testing.T, ds *DebugServer) bool, var ds DebugServer for attempt < 5 && !started { port = rand.Intn(maxPortNum-minPortNum) + minPortNum - ds = makeDebugServer(port, &mockFactory{}, dp) + ds = makeDebugServer("127.0.0.1", port, &mockFactory{}, dp) started = run(t, &ds) attempt++ } diff --git a/test/e2e-go/cli/tealdbg/expect/tealdbgTest.exp b/test/e2e-go/cli/tealdbg/expect/tealdbgTest.exp index 7be2f90668..49367fec93 100644 --- a/test/e2e-go/cli/tealdbg/expect/tealdbgTest.exp +++ b/test/e2e-go/cli/tealdbg/expect/tealdbgTest.exp @@ -2,29 +2,14 @@ set err 0 log_user 1 -if { [catch { - - set TEST_ALGO_DIR [lindex $argv 0] - set timeout 30 - - set TEST_DIR $TEST_ALGO_DIR - exec mkdir -p $TEST_DIR - - set TEAL_PROG_FILE "$TEST_DIR/trivial.teal" - - # this is ConsensusV25 - set PROTOCOL_VERSION_2 "https://github.com/algorandfoundation/specs/tree/bea19289bf41217d2c0af30522fa222ef1366466" - - # this is ConsensusV26 - set PROTOCOL_VERSION_3 "https://github.com/algorandfoundation/specs/tree/ac2255d586c4474d4ebcf3809acccb59b7ef34ff" - - # run the test using version 2: - - exec printf "#pragma version 2\nint 1\ndup\n+\n" > $TEAL_PROG_FILE +# workaround for scoping issue in TestTealdbg and setting URL inside expect_background's re scope +set URL "" +proc TestTealdbg { TEAL_PROG_FILE PROTOCOL_VERSION ARGS } { + variable URL set URL "" set PASSED 0 - spawn tealdbg debug -v $TEAL_PROG_FILE -p $PROTOCOL_VERSION_2 + spawn tealdbg debug -v $TEAL_PROG_FILE -p $PROTOCOL_VERSION {*}[lrange $ARGS 0 end] expect_background { timeout { puts "tealdbg debug timed out"; exit 1 } -re {CDT debugger listening on: (ws://[.a-z0-9:/]+)} { set URL $expect_out(1,string); } @@ -63,53 +48,32 @@ if { [catch { puts "Shutting down tealdbg" close -i $tealdbg_spawn_id - exec rm $TEAL_PROG_FILE +} - # run the test using version 3: +if { [catch { - exec printf "#pragma version 3\nint 1\ndup\n+\n" > $TEAL_PROG_FILE + set TEST_ALGO_DIR [lindex $argv 0] + set timeout 30 - set URL "" - set PASSED 0 - spawn tealdbg debug -v $TEAL_PROG_FILE -p $PROTOCOL_VERSION_3 - expect_background { - timeout { puts "tealdbg debug timed out"; exit 1 } - -re {CDT debugger listening on: (ws://[.a-z0-9:/]+)} { set URL $expect_out(1,string); } - eof { - catch wait result - if { [lindex $result 3] != 0 } { - puts "returned error code is [lindex $result 3]" - exit 1 - } - } - } - set tealdbg_spawn_id $spawn_id + set TEST_DIR $TEST_ALGO_DIR + exec mkdir -p $TEST_DIR - # wait until URL is set or timeout - set it 0 - while { $it < 10 && $URL == "" } { - set it [expr {$it + 1}] - sleep 1 - } - if { $URL == "" } { - puts "ERROR: URL is not set after timeout" - exit 1 - } + set TEAL_PROG_FILE "$TEST_DIR/trivial.teal" + # this is ConsensusV25 + set PROTOCOL_VERSION_2 "https://github.com/algorandfoundation/specs/tree/bea19289bf41217d2c0af30522fa222ef1366466" - spawn cdtmock $URL - expect { - timeout { puts "cdt-mock debug timed out"; exit 1 } - -re {Debugger.paused} { set PASSED 1; } - eof { catch wait result; if { [lindex $result 3] == 0 } { puts "Expected non-zero exit code"; exit [lindex $result 3] } } - } + # this is ConsensusV26 + set PROTOCOL_VERSION_3 "https://github.com/algorandfoundation/specs/tree/ac2255d586c4474d4ebcf3809acccb59b7ef34ff" - if { $PASSED == 0 } { - puts "ERROR: have not found 'Debugger.paused' in cdtmock output" - exit 1 - } + # run the test using version 2: + exec printf "#pragma version 2\nint 1\ndup\n+\n" > $TEAL_PROG_FILE + TestTealdbg $TEAL_PROG_FILE $PROTOCOL_VERSION_2 "" - puts "Shutting down tealdbg" - close -i $tealdbg_spawn_id + # run the test using version 3: + exec printf "#pragma version 3\nint 1\ndup\n+\n" > $TEAL_PROG_FILE + TestTealdbg $TEAL_PROG_FILE $PROTOCOL_VERSION_3 "--remote-debugging-port 9392 --listen 127.0.0.1" + + exec rm $TEAL_PROG_FILE } EXCEPTION ] } { puts "ERROR in teadbgTest: $EXCEPTION"