Home | History | Annotate | Download | only in recovery
      1 #!/bin/bash
      2 #
      3 # A test suite for applypatch.  Run in a client where you have done
      4 # envsetup, choosecombo, etc.
      5 #
      6 # DO NOT RUN THIS ON A DEVICE YOU CARE ABOUT.  It will mess up your
      7 # system partition.
      8 #
      9 #
     10 # TODO: find some way to get this run regularly along with the rest of
     11 # the tests.
     12 
     13 EMULATOR_PORT=5580
     14 DATA_DIR=$ANDROID_BUILD_TOP/bootable/recovery/testdata
     15 
     16 WORK_DIR=/data/local/tmp
     17 
     18 # set to 0 to use a device instead
     19 USE_EMULATOR=0
     20 
     21 # ------------------------
     22 
     23 if [ "$USE_EMULATOR" == 1 ]; then
     24   emulator -wipe-data -noaudio -no-window -port $EMULATOR_PORT &
     25   pid_emulator=$!
     26   ADB="adb -s emulator-$EMULATOR_PORT "
     27 else
     28   ADB="adb -d "
     29 fi
     30 
     31 echo "waiting to connect to device"
     32 $ADB wait-for-device
     33 
     34 # run a command on the device; exit with the exit status of the device
     35 # command.
     36 run_command() {
     37   $ADB shell "$@" \; echo \$? | awk '{if (b) {print a}; a=$0; b=1} END {exit a}'
     38 }
     39 
     40 testname() {
     41   echo
     42   echo "::: testing $1 :::"
     43   testname="$1"
     44 }
     45 
     46 fail() {
     47   echo
     48   echo FAIL: $testname
     49   echo
     50   [ "$open_pid" == "" ] || kill $open_pid
     51   [ "$pid_emulator" == "" ] || kill $pid_emulator
     52   exit 1
     53 }
     54 
     55 
     56 cleanup() {
     57   # not necessary if we're about to kill the emulator, but nice for
     58   # running on real devices or already-running emulators.
     59   run_command rm $WORK_DIR/verifier_test
     60   run_command rm $WORK_DIR/package.zip
     61 
     62   [ "$pid_emulator" == "" ] || kill $pid_emulator
     63 }
     64 
     65 $ADB push $ANDROID_PRODUCT_OUT/system/bin/verifier_test \
     66           $WORK_DIR/verifier_test
     67 
     68 expect_succeed() {
     69   testname "$1 (should succeed)"
     70   $ADB push $DATA_DIR/$1 $WORK_DIR/package.zip
     71   run_command $WORK_DIR/verifier_test $WORK_DIR/package.zip || fail
     72 }
     73 
     74 expect_fail() {
     75   testname "$1 (should fail)"
     76   $ADB push $DATA_DIR/$1 $WORK_DIR/package.zip
     77   run_command $WORK_DIR/verifier_test $WORK_DIR/package.zip && fail
     78 }
     79 
     80 expect_fail unsigned.zip
     81 expect_fail jarsigned.zip
     82 expect_succeed otasigned.zip
     83 expect_fail random.zip
     84 expect_fail fake-eocd.zip
     85 expect_fail alter-metadata.zip
     86 expect_fail alter-footer.zip
     87 
     88 # --------------- cleanup ----------------------
     89 
     90 cleanup
     91 
     92 echo
     93 echo PASS
     94 echo
     95