Home | History | Annotate | Download | only in fuzzing
      1 #!/bin/bash
      2 
      3 #
      4 # Copyright (C) 2019 The Android Open Source Project
      5 #
      6 # Licensed under the Apache License, Version 2.0 (the "License");
      7 # you may not use this file except in compliance with the License.
      8 # You may obtain a copy of the License at
      9 #
     10 #      http://www.apache.org/licenses/LICENSE-2.0
     11 #
     12 # Unless required by applicable law or agreed to in writing, software
     13 # distributed under the License is distributed on an "AS IS" BASIS,
     14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 # See the License for the specific language governing permissions and
     16 # limitations under the License.
     17 
     18 set -Eeuo pipefail
     19 
     20 TEST_NAME=$1
     21 SPEC_NAME=${TEST_NAME//[\/.]/_}
     22 
     23 GENERATOR_DIR=$ANDROID_BUILD_TOP/frameworks/ml/nn/tools/test_generator
     24 NNTEST_DIR=$ANDROID_PRODUCT_OUT/data/nativetest
     25 
     26 # Create tmp dir for spec dump.
     27 LOG_DIR=$(mktemp -d)/nnapi-fuzzing-logs
     28 mkdir -p $LOG_DIR
     29 echo Creating logs in $LOG_DIR
     30 
     31 # Save the fuzzer settings.
     32 DUMPSPEC=$(adb shell getprop debug.nn.fuzzer.dumpspec)
     33 LOGLEVEL=$(adb shell getprop debug.nn.fuzzer.log)
     34 
     35 if [[ "$DUMPSPEC" == "" ]]; then
     36     DUMPSPEC="0"
     37 fi
     38 
     39 if [[ "$LOGLEVEL" == "" ]]; then
     40     LOGLEVEL="SILENCE"
     41 fi
     42 
     43 # Set to dump the spec file after the test.
     44 adb shell setprop debug.nn.fuzzer.dumpspec 1
     45 adb shell setprop debug.nn.fuzzer.log silence
     46 
     47 # Run test.
     48 adb push $NNTEST_DIR/NeuralNetworksTest_static_fuzzing/NeuralNetworksTest_static_fuzzing /data/local/tmp
     49 adb shell /data/local/tmp/NeuralNetworksTest_static_fuzzing --gtest_filter=$TEST_NAME
     50 
     51 # Apply the previous settings.
     52 adb shell setprop debug.nn.fuzzer.dumpspec $DUMPSPEC
     53 adb shell setprop debug.nn.fuzzer.log $LOGLEVEL
     54 
     55 # Pull spec file, and generate HTML for visualization.
     56 adb pull /data/local/tmp/${SPEC_NAME}.mod.py $LOG_DIR
     57 $GENERATOR_DIR/spec_visualizer.py $LOG_DIR/${SPEC_NAME}.mod.py -o $LOG_DIR/${SPEC_NAME}.html
     58 
     59 google-chrome $LOG_DIR/${SPEC_NAME}.html
     60