• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from sys import argv
2import os
3import subprocess
4import time
5
6APK_DIR = '${ANDROID_PRODUCT_OUT}/system/app/AttestationTestTool/AttestationTestTool.apk'
7FAILURE_TAG = 'AttestationFail'
8FAILURE_PREFIX = 'Failure: '
9FINISHED_TAG = 'AttestationFinished'
10INFO_TAG = 'AttestationFailInfo'
11INFO_PREFIX = ' ' * len(FAILURE_PREFIX)
12devnull = open(os.devnull, 'wb')
13
14# Clear logcat
15subprocess.call('adb logcat -c', shell=True, stdout=devnull)
16subprocess.call('adb install -r ' + APK_DIR, shell=True, stdout=devnull)
17subprocess.call('adb shell am start -a android.intent.action.MAIN -n com.google.attestationexample/.AttestationActivity',
18                shell=True, stdout=devnull)
19finished = False
20read_retry = 0
21failures = 0
22while not finished and read_retry < 5:
23    time.sleep(1)
24    logcat = subprocess.check_output(['adb', 'logcat', '-d'], stderr=subprocess.STDOUT)
25    for line in logcat.split('\n'):
26        if INFO_TAG in line:
27            print INFO_PREFIX + line[line.index('AttestationFailInfo') + len('AttestationFailInfo:'):]
28        elif FAILURE_TAG in line:
29            failures += 1
30            print FAILURE_PREFIX + line[line.index('AttestationFail') + len('AttestationFail:'):]
31        elif FINISHED_TAG in line and not finished:
32            print 'Finished. Failures: ' + str(failures)
33            finished = True
34            break
35    read_retry += 1
36    if read_retry is 5:
37        print 'Attestation test did not complete, check logcat to determine the source of the error'
38subprocess.call('adb uninstall com.google.attestationexample', shell=True, stdout=devnull)
39