【问题标题】:automating android CTS with python使用 python 自动化 android CTS
【发布时间】:2018-08-21 15:47:39
【问题描述】:

我正在尝试在 Ubuntu 上使用 python 和 monkeyrunner 自动执行完整的 CTS 设置和执行,其中大部分都进​​行得很顺利。作为最后一步,我尝试执行以下 python 命令以在特定设备上启动 CTS:

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)

相当于:

./android-cts/tools/cts-tradefed run cts -s "R32CB054TSZ" --plan CTS

在命令行中,我得到:

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

CTS 测试不执行。是否有我忘记的命令,或者这不能使用 Python 实现?

【问题讨论】:

    标签: android python scripting automation cts


    【解决方案1】:
    cts_tradefed_script = "./android-cts/tools/cts-tradefed"
    process = subprocess.Popen([cts_tradefed_script + " " + serialno], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    

    编辑:不需要脚本。只需将所有内容作为连接字符串输入即可。

    【讨论】:

    • 您是否自动化了完整的 CTS?您是如何制定新计划的。我被困在根据早期运行失败制定新计划。
    【解决方案2】:

    非交互的问题是你不能运行超过一个命令,所以你应该尝试在交互模式下运行。

    要在交互模式下运行,这是一种方式:

    #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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      • 2017-07-19
      • 2022-01-10
      • 1970-01-01
      相关资源
      最近更新 更多