xref: /aosp_15_r20/cts/apps/CameraITS/build/envsetup.sh (revision b7c941bb3fa97aba169d73cee0bed2de8ac964bf)
1# Copyright 2013 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# This file should be sourced from bash. Sets environment variables for
16# running tests, and also checks that a number of dependences are present
17# and that the unit tests for the modules passed (indicating that the setup
18# is correct).
19
20export CAMERA_ITS_TOP=$PWD
21echo "CAMERA_ITS_TOP=$PWD"
22
23[[ "${BASH_SOURCE[0]}" != "${0}" ]] || \
24    { echo ">> Script must be sourced with 'source $0'" >&2; exit 1; }
25
26command -v adb >/dev/null 2>&1 || \
27    echo ">> Require adb executable to be in path" >&2
28
29command -v python >/dev/null 2>&1 || \
30    echo ">> Require python executable to be in path" >&2
31
32python -V 2>&1 | grep -q "Python 3.*" || \
33    echo ">> Require python version 3" >&2
34
35for M in numpy PIL matplotlib scipy.stats scipy.spatial serial
36do
37    python -c "import $M" >/dev/null 2>&1 || \
38        echo ">> Require Python $M module" >&2
39done
40
41for N in 'PIL Image' 'matplotlib pylab'
42do
43    IFS=' ' read module submodule <<< "$N"
44    python -c "from $module import $submodule" >/dev/null 2>&1 || \
45        echo ">> Require Python $module module $submodule submodule" >&2
46done
47
48CV2_VER=$(python -c "
49try:
50    import cv2
51    print(cv2.__version__)
52except:
53    print(\"N/A\")
54")
55
56echo "$CV2_VER" | grep -q -e "^3.*" -e "^4.*" || \
57    echo ">> Require python opencv version greater than 3 or 4. Got $CV2_VER" >&2
58
59export PYTHONPATH="$PWD/utils:$PYTHONPATH"
60export PYTHONPATH="$PWD/tests:$PYTHONPATH"
61
62for M in sensor_fusion_utils capture_request_utils opencv_processing_utils image_processing_utils its_session_utils image_fov_utils zoom_capture_utils imu_processing_utils
63do
64    python "utils/${M}_tests.py" 2>&1 | grep -q "OK" || \
65        echo ">> Unit test for $M failed" >&2
66done
67
68export PYTHONPATH="$PWD/feature_verification_utils:$PYTHONPATH"
69python -c "import feature_combination_info_pb2" >/dev/null 2>&1 || \
70  echo ">> Require Python feature_combination_info_pb2 module. ('source feature_verification_utils/update.sh')" >&2
71
72for M in run_all_unit_tests
73do
74    python "tools/$M.py" 2>&1 | grep -q "OK" || \
75        echo ">> Unit test for $M failed" >&2
76done
77
78echo -e "\n*****Please execute below adb command on your dut before running the tests*****\n"
79echo -e "adb -s <device_id> shell am compat enable ALLOW_TEST_API_ACCESS com.android.cts.verifier\n\n"
80echo -e "If using an environment manager, please run the command \"rename_libtinfo\" to handle cleanup.\n\n"
81
82# Function to rename libtinfo.so.6 (if using an environment manager)
83function rename_libtinfo() {
84    echo "Trying to rename libtinfo.so.6"
85    python_paths=$(which python)
86    for python_path in $python_paths
87    do
88      env_dir=${python_path%/python*}"/../../"
89      files_to_rename=$(find $env_dir -name 'libtinfo.so.6')
90      for f in $files_to_rename
91      do
92          echo "Renaming potentially problematic file $f"
93          mv "$f" "$f.bak"
94      done
95    done
96}
97
98