tingsu / Stoat

Stoat (STochastic model App Tester) - an automatic testing tool for android apps
https://tingsu.github.io/files/fse17-stoat.pdf
143 stars 37 forks source link

BindException at beginning of MCMC #3

Closed ms1995 closed 6 years ago

ms1995 commented 6 years ago

Got the following message from STDERR after the MCMC starts:

java.net.BindException: Address already in use (Bind failed)
    at java.net.PlainSocketImpl.socketBind(Native Method)
    at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
    at java.net.ServerSocket.bind(ServerSocket.java:375)
    at java.net.ServerSocket.<init>(ServerSocket.java:237)
    at java.net.ServerSocket.<init>(ServerSocket.java:128)
    at i.c(Unknown Source)
    at i.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:748)

The following from STDOUT:

[TestManager] I: this is *1* th iteration in MCMC sampling.
[AgentController] I: get the generated test suite from MCMCSampler, total 30 tests.
[AgentController] I: the testManager is waiting for the code coverage from controller ...
[AgentController] I: wait for line coverage result ... 
[SocketServer] I: a client connected to this server. 
[SocketServer] I: received an app state from [a3e]: 

Stoat will just halt without doing anything on the device.

tingsu commented 6 years ago

can you tell more information about the environment of this run, ubuntu or mac os? and what is your command line?

ms1995 commented 6 years ago

Its Ubuntu 14.04. Using the following cmd,

ruby run_stoat_testing.rb --disable_auto_install --max_event 99999999 --model_time 0.1h --mcmc_time 0.1h --app_dir $APK_PATH --real_device_serial $DEV_ID --stoat_port 2000

Interestingly this was working sometime ago (although I got another error message from ruby side as specified below, but the tool turned out to be working).

./bin/rec.rb:83:in `initialize': Cannot assign requested address - connect(2) for "localhost" port 2000 (Errno::EADDRNOTAVAIL)

Note that static analysis has been disabled. FSM building worked fine.

ms1995 commented 6 years ago

Some more info: I got the following message from STDOUT for the problematic run:

[TestManager] I: this is *1* th iteration in MCMC sampling.
[AgentController] I: get the generated test suite from MCMCSampler, total 30 tests.
[AgentController] I: the testManager is waiting for the code coverage from controller ...
[AgentController] I: wait for line coverage result ... 
[SocketServer] I: a client connected to this server. 
[SocketServer] I: received an app state from [a3e]: 

For a previous successful run, it went like this,

[TestManager] I: this is *1* th iteration in MCMC sampling.
[AgentController] I: get the generated test suite from MCMCSampler, total 30 tests.
[AgentController] I: the testManager is waiting for the code coverage from controller ...
[AgentController] I: wait for line coverage result ... 
[AgentController] I: a client connected to this server. 
[AgentController] I: line = REQ_TS
[AgentController] I: total 30 test sequences
[AgentController] I: the whole test suite has been sent.
tingsu commented 6 years ago

From your message, I guess the port 2000 is occupied so it cannot continue on the mcmc sampling. So please check whether they are any remaining processes that have not been killed by using the command "ps" in the terminal. Stoat should kill all remaining processes at a fresh start.

ms1995 commented 6 years ago

Thanks for the reply! Unfortunately I can make sure port 2000 was not occupied by any other program. I also tried changing the port number, but without luck. Besides, if the port was occupied, then Stoat should've failed when building FSM.

I suspect SocketServer was not correctly shut down so AgentController cannot grab that port. However I have no source code of Server.jar so I cannot see why in details.

ms1995 commented 6 years ago

I found that the problem was caused by commenting out codes in cleanup(). The original implementation simply kills all java, adb, and sleep processes on the system, causing problems in my environments (since I had other java and adb processes running with Stoat). Here I'm providing a quick (not elegant) fix of cleanup() for both issues:

execute_shell_cmd("for pid in $(ps a | grep 'Server.jar' | awk '{print $1}'); do kill -9 $pid; done")
tingsu commented 6 years ago

Nice to hear your problem has been fixed and also your patch suggestion. I will include this in Stoat.