1#!/bin/bash
2#
3# Copyright 2018 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
17TEST_FRAMEWORK_DIR=`dirname $0`
18TEST_FRAMEWORK_DIR=`dirname $TEST_FRAMEWORK_DIR`
19
20if [ -z "$ANDROID_BUILD_TOP" ]; then
21    echo "Missing ANDROID_BUILD_TOP env variable. Run 'lunch' first."
22    exit 1
23fi
24
25touch $ANDROID_BUILD_TOP/test/vti/__init__.py
26
27avoid_list=(
28  # known failures
29  "./harnesses/host_controller/console_test.py"
30  "./harnesses/host_controller/invocation_thread_test.py"
31  # not unit tests
32  "./harnesses/host_controller/command_processor/command_test.py"
33  )
34
35#######################################
36# Checks if a given file is included in the list of files to avoid
37# Globals:
38# Arguments:
39#   $1: list of files to avoid
40#   $2: the given file
41# Returns:
42#   SUCCESS, if the given file exists in the list
43#   FAILURE, otherwise
44#######################################
45function contains_file() {
46  local -n arr=$1
47  for avoid in "${arr[@]}"; do
48    if [ "$2" = "$avoid" ]; then
49      return  # contains
50    fi
51  done
52  false  # not contains
53}
54
55# Runs all unit tests under test/framework.
56for t in $(find $TEST_FRAMEWORK_DIR -type f -name "*_test.py");
57do
58    if contains_file avoid_list $t; then
59        continue
60    fi
61    echo "UNIT TEST", $t
62    echo PYTHONPATH=$ANDROID_BUILD_TOP/test/framework/harnesses:$ANDROID_BUILD_TOP/test python $t;
63    PYTHONPATH=$ANDROID_BUILD_TOP/test/framework/harnesses:$ANDROID_BUILD_TOP/test python $t;
64done
65