问题
I'm trying to automate the full CTS setup and execution with python & monkeyrunner on Ubuntu and most of it has gone very well. As the very final step, I try executing the following python command to start the CTS on a specific device:
cts_tradefed_script = "./android-cts/tools/cts-tradefed"
process = subprocess.Popen([cts_tradefed_script, "run", "cts", "-s", '"' + serialno + '"', "--plan", "CTS"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
which is the equivalent of:
./android-cts/tools/cts-tradefed run cts -s "R32CB054TSZ" --plan CTS
in the command-line and I get:
Android CTS 4.2_r4
No commands for non-interactive mode; exiting.
06-17 17:32:32 I/: Detected new device R32CB054TSZ
Saved log to /tmp/tradefed_global_log_9173619073367947049.txt
06-17 17:32:32 I/CommandScheduler: All done
The CTS tests don't execute. Is there a command I'm forgetting or is this not possible using Python?
回答1:
cts_tradefed_script = "./android-cts/tools/cts-tradefed"
process = subprocess.Popen([cts_tradefed_script + " " + serialno], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Edit: script was not necessary. Just enter everything as a concatenated String.
回答2:
The problem with non-interactive is that you cannot run more than a command, so you should try to run in interactive mode.
To run in interactive mode this is one way:
#pip install paramiko
import paramiko
import time
def run_remote_command(channel, command):
channel.send(command)
whole_output = ""
while True:
if channel.recv_ready():
output = channel.recv(1024)
whole_output+=output
else:
time.sleep(0.5)
if not(channel.recv_ready()):
return whole_output
server ="fill you own here"
username = "fill you own here"
password = "fill you own here"
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(server, 22 ,username, password)
channel =ssh.get_transport().open_session()
channel.get_pty()
channel.invoke_shell()
run_1 =run_remote_command(channel,"~/android/out/host/linux-x86/cts/android-cts/tools/cts-tradefed list devices" + "\n")
print run_1
run_2 =run_remote_command(channel,"run cts" + "\n")
print run_2
run_3 =run_remote_command(channel,"l i" + "\n")
print run_3
来源:https://stackoverflow.com/questions/17159057/automating-android-cts-with-python