Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c24910d7 authored by Charlie Boutier's avatar Charlie Boutier
Browse files

Avatar: Use atest instead of custom avatar_runner

Test: avatar atest
Bug: 266742574
Change-Id: If2c6c4b4416225d517dcfe2262e634b92e103a62
parent 39a4eebe
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -32,14 +32,3 @@ python_test_host {
    },
    data: ["config.yml"],
}

python_binary_host {
    name: "avatar_runner",
    main: "runner.py",
    srcs: [
        "runner.py",
    ],
    libs: [
        "libavatar"
    ],
}
+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
        <option name="dep-module" value="ansicolors" />
        <option name="dep-module" value="websockets" />
        <option name="dep-module" value="bitstruct" />
        <option name="dep-module" value="cryptography" />
    </target_preparer>
    <test class="com.android.tradefed.testtype.mobly.MoblyBinaryHostTest">
        <option name="mobly-par-file-name" value="avatar" />
+5 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
import avatar
import asyncio
import grpc
import sys
import logging

from concurrent import futures
@@ -330,5 +331,9 @@ class ExampleTest(base_test.BaseTestClass):


if __name__ == '__main__':
    # MoblyBinaryHostTest pass test_runner arguments after a "--"
    # to make it work with rewrite argv to skip the "--"
    index = sys.argv.index('--')
    sys.argv = sys.argv[:1] + sys.argv[index + 1:]
    logging.basicConfig(level=logging.DEBUG)
    test_runner.main()
 No newline at end of file

android/pandora/test/runner.py

deleted100644 → 0
+0 −116
Original line number Diff line number Diff line
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys
import logging
import argparse
import subprocess

from re import sub
from pathlib import Path
from genericpath import exists
from multiprocessing import Process

ANDROID_BUILD_TOP = os.getenv("ANDROID_BUILD_TOP")
TARGET_PRODUCT = os.getenv("TARGET_PRODUCT")
TARGET_BUILD_VARIANT = os.getenv("TARGET_BUILD_VARIANT")
ANDROID_PRODUCT_OUT = os.getenv("ANDROID_PRODUCT_OUT")
PANDORA_CF_APK = Path(
    f'{ANDROID_BUILD_TOP}/out/target/product/vsoc_x86_64/testcases/PandoraServer/x86_64/PandoraServer.apk'
)


def build_pandora_server():
  target = TARGET_PRODUCT if TARGET_BUILD_VARIANT == "release" else f'{TARGET_PRODUCT}-{TARGET_BUILD_VARIANT}'
  logging.debug(f'build_pandora_server: {target}')
  pandora_server_cmd = f'source build/envsetup.sh && lunch {target} && make PandoraServer'
  subprocess.run(pandora_server_cmd,
                 cwd=ANDROID_BUILD_TOP,
                 shell=True,
                 executable='/bin/bash',
                 check=True)


def install_pandora_server(serial):
  logging.debug('Install PandoraServer.apk')
  pandora_apk_path = Path(
      f'{ANDROID_PRODUCT_OUT}/testcases/PandoraServer/x86_64/PandoraServer.apk')
  if not pandora_apk_path.exists():
    logging.error(
        f"PandoraServer apk is not build or the path is wrong: {pandora_apk_path}"
    )
    sys.exit(1)
  install_apk_cmd = ['adb', 'install', '-r', '-g', str(pandora_apk_path)]
  if args.serial != "":
    install_apk_cmd.append(f'-s {serial}')
  subprocess.run(install_apk_cmd, check=True)


def instrument_pandora_server():
  logging.debug('instrument_pandora_server')
  instrument_cmd = 'adb shell am instrument --no-hidden-api-checks -w com.android.pandora/.Main'
  instrument_process = Process(
      target=lambda: subprocess.run(instrument_cmd, shell=True, check=True))
  instrument_process.start()
  return instrument_process


def run_test(args):
  logging.debug(f'run_test config: {args.config} test: {args.test}')
  test_cmd = ['python3', args.test, '-c', args.config]
  if args.verbose:
    test_cmd.append('--verbose')
  test_cmd.extend(args.mobly_args)
  p = subprocess.Popen(test_cmd)
  p.wait(timeout=args.timeout)
  p.terminate()


def run(args):
  if not args.skip_build:
    build_pandora_server()
  install_pandora_server(args.serial)
  instrument_process = instrument_pandora_server()
  run_test(args)
  instrument_process.terminate()


if __name__ == '__main__':
  parser = argparse.ArgumentParser()
  parser.add_argument("test", type=str, help="Test script path")
  parser.add_argument("config", type=str, help="Test config file path")
  parser.add_argument("--skip-build",
                      action="store_true",
                      help="Skip the build of the PandoraServer.apk")
  parser.add_argument("-s",
                      "--serial",
                      type=str,
                      default="",
                      help="Use device with given serial")
  parser.add_argument("-m",
                      "--timeout",
                      type=int,
                      default=1800000,
                      help="Mobly test timeout")
  parser.add_argument("-v",
                      "--verbose",
                      action="store_true",
                      help="Set console logger level to DEBUG")
  parser.add_argument("mobly_args", nargs='*')
  args = parser.parse_args()
  console_level = logging.DEBUG if args.verbose else logging.INFO
  logging.basicConfig(level=console_level)
  logging.info("/!\\ Remember to rebuild the avatar_runner each time you modify avatar (m avatar_runner). /!\\")
  run(args)