| # |
| # Copyright (C) 2017 The Android Open Source Project |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| # usage: generate_vts_test.sh <tests> |
| # usage: HAL_VERSION=V1_0 generate_vts_test.sh <tests> |
| # usage: HAL_VERSION=all generate_vts_test.sh <tests> |
| |
| set -Eeuo pipefail |
| |
| NNAPI_VERSIONS="V1_0 V1_1 V1_2" |
| LATEST_NNAPI_VERSION="V1_2" |
| |
| # TODO: Refactor the script to make this a command-line flag. |
| HAL_VERSION="${HAL_VERSION:-$LATEST_NNAPI_VERSION}" |
| |
| if [[ "$HAL_VERSION" == "all" ]]; then |
| # Re-call this script with each version explicitly. |
| for ver in $NNAPI_VERSIONS; do |
| HAL_VERSION="$ver" "$0" "$@" |
| done |
| exit |
| elif [[ " $NNAPI_VERSIONS " != *" $HAL_VERSION "* || "$HAL_VERSION" == *" "* ]]; then |
| echo "Unknown HAL version: $HAL_VERSION; expected one of: $NNAPI_VERSIONS all" |
| exit 1 |
| fi |
| |
| echo "Generating VTS tests for HAL $HAL_VERSION" |
| |
| cd "$(dirname $0)" |
| |
| VTS_PATH=`realpath ../` |
| function generate_one_testcase { |
| # Generate one testcase |
| BASENAME=`basename -s .mod.py $1` |
| $VTS_PATH/../../tools/test_generator/vts_generator.py ./`basename $1` \ |
| --model $VTS_PATH/generated/vts/$HAL_VERSION/models/$BASENAME.model.cpp \ |
| --example $VTS_PATH/generated/examples/$BASENAME.example.cpp \ |
| --target_hal_version $HAL_VERSION |
| } |
| |
| function generate_wrapper { |
| for ver in $NNAPI_VERSIONS; |
| do |
| if [[ "$ver" > "$HAL_VERSION" ]]; then |
| break |
| fi |
| VER_DIR=$VTS_PATH/specs/$ver |
| [ ! -d $VER_DIR ] && continue |
| pushd $VER_DIR > /dev/null |
| OUTFILE=$VTS_PATH/generated/vts/$HAL_VERSION/all_generated_${ver}_vts_tests.cpp |
| echo "// clang-format off" > $OUTFILE |
| echo "// DO NOT EDIT;" >> $OUTFILE |
| echo "// Generated by ml/nn/runtime/test/specs/generate_vts_test.sh" >> $OUTFILE |
| for f in $@; |
| do |
| if [ -f $(basename $f) ]; then |
| generate_one_testcase $f >> $OUTFILE |
| if [ $? -ne 0 ]; then |
| echo "Failed processing $f" |
| return $? |
| fi |
| fi |
| done |
| popd > /dev/null |
| done |
| } |
| |
| function generate_spec_dirs { |
| for ver in $NNAPI_VERSIONS; |
| do |
| if [[ "$ver" > "$HAL_VERSION" ]]; then |
| break |
| fi |
| VER_DIR=$VTS_PATH/specs/$ver |
| [ ! -d $VER_DIR ] && continue |
| OUTFILE=$VTS_PATH/generated/vts/$HAL_VERSION/all_generated_${ver}_vts_tests.cpp |
| echo "// clang-format off" > $OUTFILE |
| echo "// DO NOT EDIT;" >> $OUTFILE |
| echo "// Generated by ml/nn/runtime/test/specs/generate_vts_test.sh" >> $OUTFILE |
| $VTS_PATH/../../tools/test_generator/vts_generator.py $VER_DIR \ |
| --model $VTS_PATH/generated/vts/$HAL_VERSION/models \ |
| --example $VTS_PATH/generated/examples \ |
| --target_hal_version $HAL_VERSION >> $OUTFILE |
| echo "Generated file in $VTS_PATH/generated/"`basename $OUTFILE` |
| done |
| } |
| |
| if [ $# -eq 0 ]; then |
| generate_spec_dirs |
| else |
| FILES="$@" |
| generate_wrapper $FILES |
| fi |