• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright (C) 2017 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
16# usage: generate_vts_test.sh <tests>
17
18set -Eeuo pipefail
19
20NNAPI_VERSION="
21V1_0
22V1_1
23V1_2
24"
25
26cd "$(dirname $0)"
27
28VTS_PATH=`realpath ../`
29function generate_one_testcase {
30  # Generate one testcase
31  BASENAME=`basename -s .mod.py $1`
32  $VTS_PATH/../../tools/test_generator/vts_generator.py ./`basename $1`\
33    -m $VTS_PATH/generated/vts_models/$BASENAME.model.cpp \
34    -e $VTS_PATH/generated/examples/$BASENAME.example.cpp
35}
36
37function generate_wrapper {
38  for ver in $NNAPI_VERSION;
39  do
40    VER_DIR=$VTS_PATH/specs/$ver
41    [ ! -d $VER_DIR ] && continue
42    pushd $VER_DIR > /dev/null
43    OUTFILE=$VTS_PATH/generated/all_generated_${ver}_vts_tests.cpp
44    echo "// clang-format off" > $OUTFILE
45    echo "// DO NOT EDIT;" >> $OUTFILE
46    echo "// Generated by ml/nn/runtime/test/specs/generate_vts_test.sh" >> $OUTFILE
47    for f in $@;
48    do
49      if [ -f $(basename $f) ]; then
50        generate_one_testcase $f >> $OUTFILE
51        if [ $? -ne 0 ]; then
52          echo "Failed processing $f"
53          return $?
54        fi
55      fi
56    done
57    popd > /dev/null
58  done
59}
60
61function generate_spec_dirs {
62  for ver in $NNAPI_VERSION;
63  do
64    VER_DIR=$VTS_PATH/specs/$ver
65    [ ! -d $VER_DIR ] && continue
66    OUTFILE=$VTS_PATH/generated/all_generated_${ver}_vts_tests.cpp
67    echo "// clang-format off" > $OUTFILE
68    echo "// DO NOT EDIT;" >> $OUTFILE
69    echo "// Generated by ml/nn/runtime/test/specs/generate_vts_test.sh" >> $OUTFILE
70    $VTS_PATH/../../tools/test_generator/vts_generator.py $VER_DIR \
71      -m $VTS_PATH/generated/vts_models -e $VTS_PATH/generated/examples >> $OUTFILE
72    echo "Generated file in $VTS_PATH/generated/"`basename $OUTFILE`
73  done
74}
75
76if [ $# -eq 0 ]; then
77  generate_spec_dirs
78else
79  FILES="$@"
80  generate_wrapper $FILES
81fi
82