Skip to content

Commit

Permalink
tealdbg: listen on specified address
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy committed Mar 16, 2021
1 parent 1ff4f33 commit 4e0d192
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 65 deletions.
6 changes: 4 additions & 2 deletions cmd/tealdbg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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, "")
Expand All @@ -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())
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/tealdbg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/tealdbg/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
}
Expand Down
84 changes: 24 additions & 60 deletions test/e2e-go/cli/tealdbg/expect/tealdbgTest.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 4e0d192

Please sign in to comment.