From be764b4a34090ec00671aa9fd58841f47c33e327 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Fri, 14 May 2021 11:42:01 -0700 Subject: simpleperf: add --only-host-test option in do_test.py. Add option to only run host tests, which are much faster than running all tests. Also import Iterator from typing to run on python3.8. Bug: 185526771 Test: run scripts/test/test.py --only-host-test. Change-Id: Idd7225eb21cc48f6e5db100d387227c33e0b8039 --- simpleperf/scripts/debug_unwind_reporter.py | 3 +-- simpleperf/scripts/simpleperf_utils.py | 3 +-- simpleperf/scripts/test/do_test.py | 22 ++++++++++++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/simpleperf/scripts/debug_unwind_reporter.py b/simpleperf/scripts/debug_unwind_reporter.py index 7a291b27..238c9acd 100755 --- a/simpleperf/scripts/debug_unwind_reporter.py +++ b/simpleperf/scripts/debug_unwind_reporter.py @@ -37,10 +37,9 @@ Below is an example using debug_unwind_reporter.py: import argparse from collections import Counter, defaultdict -from collections.abc import Iterator from simpleperf_utils import ArgParseFormatter from texttable import Texttable -from typing import List, Dict +from typing import Dict, Iterator, List class CallChainNode: diff --git a/simpleperf/scripts/simpleperf_utils.py b/simpleperf/scripts/simpleperf_utils.py index 65652210..cf50fcb2 100644 --- a/simpleperf/scripts/simpleperf_utils.py +++ b/simpleperf/scripts/simpleperf_utils.py @@ -20,7 +20,6 @@ from __future__ import annotations import argparse -from collections.abc import Iterator import logging import os import os.path @@ -30,7 +29,7 @@ import shutil import subprocess import sys import time -from typing import Dict, List, Optional, Set, Union +from typing import Dict, Iterator, List, Optional, Set, Union def get_script_dir() -> str: diff --git a/simpleperf/scripts/test/do_test.py b/simpleperf/scripts/test/do_test.py index b2886b65..946390df 100755 --- a/simpleperf/scripts/test/do_test.py +++ b/simpleperf/scripts/test/do_test.py @@ -65,7 +65,8 @@ def get_args() -> argparse.Namespace: parser.add_argument( '-d', '--device', nargs='+', help='set devices used to run tests. Each device in format name:serial-number') - parser.add_argument('--list-tests', action='store_true', help='List all tests.') + parser.add_argument('--only-host-test', action='store_true', help='Only run host tests') + parser.add_argument('--list-tests', action='store_true', help='List tests') parser.add_argument('--ndk-path', type=extant_dir, help='Set the path of a ndk release') parser.add_argument('-p', '--pattern', nargs='+', help='Run tests matching the selected pattern.') @@ -86,8 +87,16 @@ def get_all_tests() -> List[str]: return sorted(tests) -def get_filtered_tests(test_from: Optional[str], test_pattern: Optional[List[str]]) -> List[str]: - tests = get_all_tests() +def get_host_tests() -> List[str]: + def filter_fn(test: str) -> bool: + return get_test_type(test) == 'host_test' + return list(filter(filter_fn, get_all_tests())) + + +def get_filtered_tests( + tests: List[str], + test_from: Optional[str], + test_pattern: Optional[List[str]]) -> List[str]: if test_from: try: tests = tests[tests.index(test_from):] @@ -466,12 +475,13 @@ def run_tests_in_child_process(tests: List[str], args: argparse.Namespace) -> bo def main() -> bool: args = get_args() + tests = get_host_tests() if args.only_host_test else get_all_tests() + tests = get_filtered_tests(tests, args.test_from, args.pattern) + if args.list_tests: - print('\n'.join(get_all_tests())) + print('\n'.join(tests)) return True - tests = get_filtered_tests(args.test_from, args.pattern) - test_dir = Path(args.test_dir).resolve() remove(test_dir) test_dir.mkdir(parents=True) -- cgit v1.2.3