1#!/usr/bin/env python3 2# Copyright (C) 2020 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import argparse 17import os 18import sys 19import unittest 20 21from test import api_integrationtest 22from test import bigtrace_api_integrationtest 23from test import query_result_iterator_unittest 24from test import resolver_unittest 25from test import stdlib_unittest 26 27ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 28sys.path.append(os.path.join(ROOT_DIR)) 29 30 31def main(): 32 try: 33 import numpy 34 import pandas 35 except ModuleNotFoundError: 36 print('Cannot proceed. Please `pip3 install pandas numpy`', file=sys.stderr) 37 return 1 38 39 # Set paths to trace_processor_shell and root directory as environment 40 # variables 41 parser = argparse.ArgumentParser() 42 parser.add_argument("host_out_path", type=str) 43 host_out_path = parser.parse_args().host_out_path 44 os.environ["SHELL_PATH"] = f"{host_out_path}/trace_processor_shell" 45 os.environ["ORCHESTRATOR_PATH"] = f"{host_out_path}/orchestrator_main" 46 os.environ["WORKER_PATH"] = f"{host_out_path}/worker_main" 47 os.environ["ROOT_DIR"] = ROOT_DIR 48 49 loader = unittest.TestLoader() 50 suite = unittest.TestSuite() 51 52 # Add all relevant tests to test suite 53 suite.addTests(loader.loadTestsFromModule(query_result_iterator_unittest)) 54 suite.addTests(loader.loadTestsFromModule(resolver_unittest)) 55 suite.addTests(loader.loadTestsFromModule(api_integrationtest)) 56 suite.addTests(loader.loadTestsFromModule(stdlib_unittest)) 57 if os.path.exists(os.environ["WORKER_PATH"]): 58 suite.addTests(loader.loadTestsFromModule(bigtrace_api_integrationtest)) 59 60 # Initialise runner to run all tests in suite 61 runner = unittest.TextTestRunner(verbosity=3) 62 result = runner.run(suite) 63 64 return 0 if result.wasSuccessful() else 1 65 66 67if __name__ == '__main__': 68 sys.exit(main()) 69