add --snaphot option for Fastbot and WeTester

This commit is contained in:
tingsu 2021-08-27 23:00:49 +08:00
parent 2c4643f932
commit 8857f32923
4 changed files with 241 additions and 44 deletions

179
LOGIN_APPS.md Normal file
View File

@ -0,0 +1,179 @@
This file describes how to test the apps with login by using the snapshot feature of Android emulator.
Please create a fresh emulator with 'Nexus 7' for each crash bug before do the following instructions.
```
$ cd scripts/
$ emulator -avd Android7.1 -no-window &
$ adb devices
List of devices attached
emulator-5554 device
```
```
$ bash -x copy_dummy_documents.sh emulator-5554
+ '[' 1 -eq 0 ']'
+ AVD_SERIAL=emulator-5554
+ adb -s emulator-5554 push ../dummy_documents/Android_logo.jpg /sdcard/Pictures/
../dummy_documents/Android_logo.jpg: 1 file pushed, 0 skipped. 265.3 MB/s (64185 bytes in 0.000s)
+ adb -s emulator-5554 push ../dummy_documents/Android_robot.png /sdcard/Pictures/
../dummy_documents/Android_robot.png: 1 file pushed, 0 skipped. 156.0 MB/s (13418 bytes in 0.000s)
+ adb -s emulator-5554 push ../dummy_documents/droidbot_utg.png /sdcard/Pictures/
../dummy_documents/droidbot_utg.png: 1 file pushed, 0 skipped. 1578.5 MB/s (269533 bytes in 0.000s)
+ adb -s emulator-5554 push ../dummy_documents/Heartbeat.mp3 /sdcard/Music/
../dummy_documents/Heartbeat.mp3: 1 file pushed, 0 skipped. 3237.9 MB/s (1739320 bytes in 0.001s)
+ adb -s emulator-5554 push ../dummy_documents/intermission.mp3 /sdcard/Music/
../dummy_documents/intermission.mp3: 1 file pushed, 0 skipped. 2437.7 MB/s (995735 bytes in 0.000s)
+ adb -s emulator-5554 push ../dummy_documents/sample_iPod.m4v /sdcard/Movies/
../dummy_documents/sample_iPod.m4v: 1 file pushed, 0 skipped. 3265.6 MB/s (2236480 bytes in 0.001s)
+ adb -s emulator-5554 push ../dummy_documents/sample_mpeg4.mp4 /sdcard/Movies/
../dummy_documents/sample_mpeg4.mp4: 1 file pushed, 0 skipped. 1598.5 MB/s (245779 bytes in 0.000s)
+ adb -s emulator-5554 push ../dummy_documents/sample_sorenson.mov /sdcard/Movies/
../dummy_documents/sample_sorenson.mov: 1 file pushed, 0 skipped. 995.8 MB/s (82395 bytes in 0.000s)
+ adb -s emulator-5554 push ../dummy_documents/sample.3gp /sdcard/Movies/
../dummy_documents/sample.3gp: 1 file pushed, 0 skipped. 235.0 MB/s (28561 bytes in 0.000s)
+ adb -s emulator-5554 push ../dummy_documents/DroidBot_documentation.docx /sdcard/Download/
../dummy_documents/DroidBot_documentation.docx: 1 file pushed, 0 skipped. 1160.3 MB/s (107623 bytes in 0.000s)
+ adb -s emulator-5554 push ../dummy_documents/DroidBot_documentation.pdf /sdcard/Download/
../dummy_documents/DroidBot_documentation.pdf: 1 file pushed, 0 skipped. 712.1 MB/s (69660 bytes in 0.000s)
+ adb -s emulator-5554 push ../dummy_documents/password.txt /sdcard/Download/
../dummy_documents/password.txt: 1 file pushed, 0 skipped. 1.6 MB/s (52 bytes in 0.000s)
+ adb -s emulator-5554 push ../dummy_documents/sample_3GPP.3gp.zip /sdcard/Download/
../dummy_documents/sample_3GPP.3gp.zip: 1 file pushed, 0 skipped. 249.9 MB/s (26491 bytes in 0.000s)
```
```
$ adb -s emulator-5554 install -g ../WordPress/WordPress-vanilla-debug--#8659.apk
$ python3 ../WordPress/login-#8659.py emulator-5554
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
{'package': 'org.wordpress.android', 'activity': 'org.wordpress.android.ui.accounts.LoginActivity'}
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
[D 210827 22:22:49 __init__:600] kill process(ps): uiautomator
[D 210827 22:22:50 __init__:618] uiautomator-v2 is starting ... left: 40.0s
[D 210827 22:22:51 __init__:618] uiautomator-v2 is starting ... left: 39.0s
[D 210827 22:22:52 __init__:618] uiautomator-v2 is starting ... left: 38.0s
[D 210827 22:22:53 __init__:618] uiautomator-v2 is starting ... left: 37.0s
[D 210827 22:22:54 __init__:618] uiautomator-v2 is starting ... left: 36.0s
[D 210827 22:22:55 __init__:618] uiautomator-v2 is starting ... left: 35.0s
[D 210827 22:22:56 __init__:618] uiautomator-v2 is starting ... left: 34.0s
[I 210827 22:22:56 __init__:583] uiautomator back to normal
SUCCESS: press login button
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
SUCCESS: press login in via site address
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
SUCCESS: input site address
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
SUCCESS: press next
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
SUCCESS: input user name
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
SUCCESS: input password
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
SUCCESS: press next
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
wait 1 second ..
org.wordpress.android
org.wordpress.android.ui.accounts.LoginEpilogueActivity
****Login SUCCESS*****
../WordPress/login-#8659.py:76: DeprecationWarning: Call to deprecated method service. (You should use d.uiautomator.start() instead) -- Deprecated since version 3.0.0.
d.service("uiautomator").stop()
../WordPress/login-#8659.py:78: DeprecationWarning: Call to deprecated method service. (You should use d.uiautomator.start() instead) -- Deprecated since version 3.0.0.
out = d.service("uiautomator").running()
DISCONNECT UIAUTOMATOR2 SUCCESS
```
- Stop the machine (i.e., snapshot the machine state)
```
$ adb -s emulator-5554 emu kill
```
- Run a tool on this bug
```
python3 themis.py --no-headless --avd Android7.1 --apk ../nextcloud/nextcloud-#5173.apk --time 10m -o ../monkey-results/ --login ../nextcloud/login-#5173.py --monkey --snapshot
```

View File

@ -7,6 +7,7 @@ OUTPUT_DIR=$4
TEST_TIME=$5 # e.g., 10s, 10m, 10h
HEADLESS=$6 # e.g., -no-window
LOGIN_SCRIPT=$7 # the script for app login via uiautomator2
IS_SNAPSHOT=$8
FASTBOT_TOOL=../tools/
@ -71,14 +72,19 @@ if [[ $LOGIN_SCRIPT != "" ]]
then
echo "** APP LOGIN (${AVD_SERIAL})"
# enable if use the login script
sleep 5 # wait for a few seconds before installation to avoid such error: "adb: connect error for write: closed"
adb -s $AVD_SERIAL install -g $APK_FILE &> $result_dir/install.log
echo "** INSTALL APP (${AVD_SERIAL})"
python3 $LOGIN_SCRIPT ${AVD_SERIAL} 2>&1 | tee $result_dir/login.log
if [[ $IS_SNAPSHOT != "True" ]]
then
# enable if use the snapshot (already login, do not need to install the app)
echo " *** Login SUCCESS ****" >> $result_dir/login.log
# enable if use the login script
sleep 5 # wait for a few seconds before installation to avoid such error: "adb: connect error for write: closed"
adb -s $AVD_SERIAL install -g $APK_FILE &> $result_dir/install.log
echo "** INSTALL APP (${AVD_SERIAL})"
python3 $LOGIN_SCRIPT ${AVD_SERIAL} 2>&1 | tee $result_dir/login.log
else
# enable if use the snapshot (already login, do not need to install the app)
echo " *** Login SUCCESS ****" >> $result_dir/login.log
fi
else
# install the app

View File

@ -7,6 +7,7 @@ OUTPUT_DIR=$4
TEST_TIME=$5 # e.g., 10s, 10m, 10h
HEADLESS=$6 # e.g., -no-window
LOGIN_SCRIPT=$7 # the script for app login via uiautomator2
IS_SNAPSHOT=$8
WETEST_TOOL=../tools
@ -71,14 +72,18 @@ if [[ $LOGIN_SCRIPT != "" ]]
then
echo "** APP LOGIN (${AVD_SERIAL})"
# enable if use the login script
sleep 5 # wait for a few seconds before installation to avoid such error: "adb: connect error for write: closed"
adb -s $AVD_SERIAL install -g $APK_FILE &> $result_dir/install.log
echo "** INSTALL APP (${AVD_SERIAL})"
python3 $LOGIN_SCRIPT ${AVD_SERIAL} 2>&1 | tee $result_dir/login.log
if [[ $IS_SNAPSHOT != "True" ]]
then
# enable if use the login script
sleep 5 # wait for a few seconds before installation to avoid such error: "adb: connect error for write: closed"
adb -s $AVD_SERIAL install -g $APK_FILE &> $result_dir/install.log
echo "** INSTALL APP (${AVD_SERIAL})"
python3 $LOGIN_SCRIPT ${AVD_SERIAL} 2>&1 | tee $result_dir/login.log
# enable if use the snapshot (already login, do not need to install the app)
echo " *** Login SUCCESS ****" >> $result_dir/login.log
else
# enable if use the snapshot (already login, do not need to install the app)
echo " *** Login SUCCESS ****" >> $result_dir/login.log
fi
else
# install the app

View File

@ -73,10 +73,10 @@ def run_timemachine(apk, avd_serial, avd_name, output_dir, testing_time, screen_
def run_humanoid(apk, avd_serial, avd_name, output_dir, testing_time, screen_option, login_script):
command = 'bash -x run_humanoid.sh %s %s %s %s %s %s %s' % (apk, avd_serial, avd_name,
output_dir,
testing_time,
screen_option,
login_script)
output_dir,
testing_time,
screen_option,
login_script)
print('execute humanoid: %s' % command)
os.system(command)
@ -121,31 +121,35 @@ def run_qtesting(apk, avd_serial, avd_name, output_dir, testing_time, screen_opt
os.system(command)
def run_fastbot(apk, avd_serial, avd_name, output_dir, testing_time, screen_option, login_script):
command = 'bash -x run_fastbot.sh %s %s %s %s %s %s %s' % (os.path.abspath(apk), avd_serial, avd_name,
os.path.abspath(output_dir),
testing_time,
screen_option,
login_script)
def run_fastbot(apk, avd_serial, avd_name, output_dir, testing_time, screen_option, login_script, is_snapshot):
command = 'bash -x run_fastbot.sh %s %s %s %s %s %s %s %s' % (os.path.abspath(apk), avd_serial, avd_name,
os.path.abspath(output_dir),
testing_time,
screen_option,
login_script,
is_snapshot)
print('execute fastbot: %s' % command)
os.system(command)
def run_newmonkey(apk, avd_serial, avd_name, output_dir, testing_time, screen_option, login_script):
command = 'bash -x run_newmonkey.sh %s %s %s %s %s %s %s' % (os.path.abspath(apk), avd_serial, avd_name,
os.path.abspath(output_dir),
testing_time,
screen_option,
login_script)
def run_newmonkey(apk, avd_serial, avd_name, output_dir, testing_time, screen_option, login_script, is_snapshot):
command = 'bash -x run_newmonkey.sh %s %s %s %s %s %s %s %s' % (os.path.abspath(apk), avd_serial, avd_name,
os.path.abspath(output_dir),
testing_time,
screen_option,
login_script,
is_snapshot)
print('execute newmonkey: %s' % command)
os.system(command)
def run_wetest(apk, avd_serial, avd_name, output_dir, testing_time, screen_option, login_script):
command = 'bash -x run_wetest.sh %s %s %s %s %s %s %s' % (os.path.abspath(apk), avd_serial, avd_name,
os.path.abspath(output_dir),
testing_time,
screen_option,
login_script)
def run_wetest(apk, avd_serial, avd_name, output_dir, testing_time, screen_option, login_script, is_snapshot):
command = 'bash -x run_wetest.sh %s %s %s %s %s %s %s %s' % (os.path.abspath(apk), avd_serial, avd_name,
os.path.abspath(output_dir),
testing_time,
screen_option,
login_script,
is_snapshot)
print('execute wetest: %s' % command)
os.system(command)
@ -248,8 +252,8 @@ def main(args: Namespace):
login_script,))
elif args.humanoid:
p.apply_async(run_humanoid, args=(current_apk, avd_serial, args.avd_name,
args.o, args.time, screen_option,
login_script,))
args.o, args.time, screen_option,
login_script,))
elif args.weighted:
p.apply_async(run_weighted, args=(current_apk, avd_serial, args.avd_name,
args.o, args.time, screen_option,
@ -272,15 +276,15 @@ def main(args: Namespace):
elif args.fastbot:
p.apply_async(run_fastbot, args=(current_apk, avd_serial, args.avd_name,
args.o, args.time, screen_option,
login_script,))
login_script, args.snapshot,))
elif args.newmonkey:
p.apply_async(run_newmonkey, args=(current_apk, avd_serial, args.avd_name,
args.o, args.time, screen_option,
login_script,))
args.o, args.time, screen_option,
login_script, args.snapshot,))
elif args.wetest:
p.apply_async(run_wetest, args=(current_apk, avd_serial, args.avd_name,
args.o, args.time, screen_option,
login_script,))
args.o, args.time, screen_option,
login_script, args.snapshot,))
else:
pass
@ -300,7 +304,7 @@ if __name__ == '__main__':
ap.add_argument('--avd', type=str, dest='avd_name', help="the device name")
ap.add_argument('--apk', type=str, dest='apk')
ap.add_argument('-n', type=int, dest='number_of_devices', default=1,
help="number of emulators created for testing, default: 1")
help="number of emulators created for testing, default: 1")
ap.add_argument('--apk-list', type=str, dest='apk_list', help="list of apks under test")
ap.add_argument('-o', required=True, help="output dir")
ap.add_argument('--time', type=str, default='6h', help="the fuzzing time in hours (e.g., 6h), minutes (e.g., 6m),"
@ -309,6 +313,9 @@ if __name__ == '__main__':
ap.add_argument('--max-emu', type=int, default=16, help="the maximum allowed number of emulators")
ap.add_argument('--no-headless', dest='no_headless', default=False, action='store_true', help="show gui")
ap.add_argument('--login', type=str, dest='login_script', help="the script for app login")
ap.add_argument('--snapshot', default=False, action='store_true', help="use this option if the target app is "
"already installed in the emulator "
"and logged in")
ap.add_argument('--wait', type=int, dest='idle_time',
help="the idle time to wait before starting the fuzzing")