blob: 6350e80d36b55156b0772a030dbcfc43187750d6 [file] [log] [blame]
Doug Zongker73ae31c2009-12-09 17:01:45 -08001#!/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
13EMULATOR_PORT=5580
14DATA_DIR=$ANDROID_BUILD_TOP/bootable/recovery/testdata
15
16WORK_DIR=/data/local/tmp
17
18# set to 0 to use a device instead
19USE_EMULATOR=0
20
21# ------------------------
22
23if [ "$USE_EMULATOR" == 1 ]; then
24 emulator -wipe-data -noaudio -no-window -port $EMULATOR_PORT &
25 pid_emulator=$!
26 ADB="adb -s emulator-$EMULATOR_PORT "
27else
28 ADB="adb -d "
29fi
30
31echo "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.
36run_command() {
37 $ADB shell "$@" \; echo \$? | awk '{if (b) {print a}; a=$0; b=1} END {exit a}'
38}
39
40testname() {
41 echo
42 echo "::: testing $1 :::"
43 testname="$1"
44}
45
46fail() {
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
56cleanup() {
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
68expect_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
74expect_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
80expect_fail unsigned.zip
81expect_fail jarsigned.zip
82expect_succeed otasigned.zip
83expect_fail random.zip
84expect_fail fake-eocd.zip
85expect_fail alter-metadata.zip
86expect_fail alter-footer.zip
87
88# --------------- cleanup ----------------------
89
90cleanup
91
92echo
93echo PASS
94echo