1#!/usr/bin/env python 2# 3# Copyright (C) 2025 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18import os 19import subprocess 20import sys 21 22""" 23This script runs all of Torq's unit tests specified in 24the Android.bp file. 25 26All tests can be run with: 27 ./torq_test 28 29You can filter to only run specific tests with: 30 ./torq_test torq_unit_test device_unit_test 31""" 32if __name__ == "__main__": 33 # Find the Android.bp file 34 script_dir = os.path.dirname(os.path.abspath(__file__)) 35 android_bp_path = os.path.join(script_dir, '..', 'Android.bp') 36 37 # Get all test names 38 tests = [] 39 has_pending_test = False 40 try: 41 with open(android_bp_path, 'r') as f: 42 for line in f: 43 text = line.strip() 44 if 'python_test_host' in text: 45 has_pending_test = True 46 elif has_pending_test and 'name' in text: 47 # parse the test host name 48 tests.append(text.split(':')[-1].strip()[1:-2]) 49 has_pending_test = False 50 except FileNotFoundError: 51 print(f"Error: Android.bp file not found at: {android_bp_path}") 52 sys.exit(1) 53 except Exception as e: 54 print(f"Error reading Android.bp: {e}") 55 sys.exit(1) 56 57 # Filter out unwanted tests 58 filter_tests = sys.argv[1:] 59 if len(filter_tests) > 0: 60 tests = list(filter(lambda e: e in filter_tests, tests)) 61 62 cmd = ['atest'] + tests 63 # Run atest for all the tests 64 subprocess.run(cmd) 65