python自动化测试locksetting/gatekeeper/keymaster/vts等
生活随笔
收集整理的這篇文章主要介紹了
python自动化测试locksetting/gatekeeper/keymaster/vts等
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
test@test-pc:~/workspace/share/testcase/test_tee$ tree .
.
├── resource
│ ├── googlekey
│ │ ├── default_googlekey.bin
│ │ └── kmsetkey_ca
│ └── vts_testcase
│ ├── VtsHalBiometricsFaceV1_0TargetTest
│ │ ├── arm
│ │ │ └── VtsHalBiometricsFaceV1_0TargetTest
│ │ ├── arm64
│ │ │ └── VtsHalBiometricsFaceV1_0TargetTest
│ │ └── VtsHalBiometricsFaceV1_0TargetTest.config
│ ├── VtsHalBiometricsFingerprintV2_1TargetTest
│ │ ├── arm
│ │ │ └── VtsHalBiometricsFingerprintV2_1TargetTest
│ │ ├── arm64
│ │ │ └── VtsHalBiometricsFingerprintV2_1TargetTest
│ │ └── VtsHalBiometricsFingerprintV2_1TargetTest.config
│ ├── VtsHalBiometricsFingerprintV2_2TargetTest
│ │ ├── arm
│ │ │ └── VtsHalBiometricsFingerprintV2_2TargetTest
│ │ ├── arm64
│ │ │ └── VtsHalBiometricsFingerprintV2_2TargetTest
│ │ └── VtsHalBiometricsFingerprintV2_2TargetTest.config
│ ├── VtsHalGatekeeperV1_0TargetTest
│ │ ├── arm
│ │ │ └── VtsHalGatekeeperV1_0TargetTest
│ │ ├── arm64
│ │ │ └── VtsHalGatekeeperV1_0TargetTest
│ │ └── VtsHalGatekeeperV1_0TargetTest.config
│ ├── VtsHalKeymasterV3_0TargetTest
│ │ ├── arm
│ │ │ └── VtsHalKeymasterV3_0TargetTest
│ │ ├── arm64
│ │ │ └── VtsHalKeymasterV3_0TargetTest
│ │ └── VtsHalKeymasterV3_0TargetTest.config
│ ├── VtsHalKeymasterV4_0TargetTest
│ │ ├── arm
│ │ │ └── VtsHalKeymasterV4_0TargetTest
│ │ ├── arm64
│ │ │ └── VtsHalKeymasterV4_0TargetTest
│ │ └── VtsHalKeymasterV4_0TargetTest.config
│ └── VtsHalKeymasterV4_1TargetTest
│ ├── arm
│ │ └── VtsHalKeymasterV4_1TargetTest
│ ├── arm64
│ │ └── VtsHalKeymasterV4_1TargetTest
│ └── VtsHalKeymasterV4_1TargetTest.config
├── tee.json
└── tee_test.py24 directories, 25 files
# coding=utf8# python tran_projects/common/tee/tools/tee_info.pyimport sys
import os
import shutil
import time
import random
import subprocess
import getoptimport jsondebug = 0g_verify = 0
g_enroll = 0test_vts_gatekeeper = False
test_vts_keymaster = False
test_press_locksetting = False
test_press_keymaster = False
test_press_count = 1report_list = ["gatekeeper","keymaster3.0-arm","keymaster3.0-arm64","keymaster4.0-arm","keymaster4.0-arm64","keymaster4.1-arm","keymaster4.1-arm64"]
report_result = {}locksetting = {"every_enroll":{"correct_verify": 10,"incorrect_verify": 5}
}def print_report():print("\n===============================================")print("result report:")for line in report_list:if line not in report_result:continueprint("\t[result][vts] test %s %s" % (line,report_result[line]))print("===============================================")def getRandomSet(bits):num_set = [chr(i) for i in range(48,58)]char_set = [chr(i) for i in range(97,123)]total_set = num_set + char_setvalue_set = "".join(random.sample(total_set, bits))return value_setdef generated_numbers(type):if type == "pin":return random.randint(1000,99999999)elif type == "password":return getRandomSet(8)elif type == "pattern":return "12369"else:return "0000"
def generated_cipher(type):while True:res = generated_numbers(type)if res != "1478":return resdef get_args(argv):global test_vts_gatekeeperglobal test_vts_keymasterglobal test_press_locksettingglobal test_press_keymasterglobal test_press_counttry:opts, args = getopt.getopt(argv,"hv:p:n:",["--help=","--vts=","--press="])except getopt.GetoptError:print('test.py -v keymaster/gatekeeper/all')sys.exit(2)for opt, arg in opts:if opt == ("-h", "--help"):print('test.py -v <vts_testcase>, vts_testcase:gatekeeper,keymaster,all')if opt in ("-v", "--vts"):if arg == "gatekeeper" or arg == "all":test_vts_gatekeeper = Trueif arg == "keymaster" or arg == "all":test_vts_keymaster = Trueif opt in ("-p", "--press"):if arg == "locksetting" or arg == "all":test_press_locksetting = Trueif arg == "keymaster" or arg == "all":test_press_keymaster = Trueif opt in ("-n"):test_press_count = argdef test_locksetting_pattern(testcount):for num in range(0,testcount):#new_pd = random.randint(1236,99999999)old_pd = 12369new_pd = 1236os.system("adb shell locksettings set-pattern --old %s %s" % (old_pd, new_pd))old_pd = 1236new_pd = 12369os.system("adb shell locksettings set-pattern --old %s %s" % (old_pd, new_pd))def test_locksetting_pin(type,testcount):global g_verifyif debug == 1:new_pd = "2222"type = "pin"else:new_pd = generated_cipher(type)os.system("adb shell locksettings set-%s %s" % (type, new_pd))for num in range(0,testcount):old_pd = new_pdif debug == 1:if new_pd == "2222":new_pd = "1111"else:new_pd = "2222"else:new_pd = generated_cipher(type)output = subprocess.getstatusoutput("adb shell locksettings set-%s --old %s %s" % (type, old_pd, new_pd))for verify_count in range(0,locksetting["every_enroll"]["correct_verify"]):output = subprocess.getstatusoutput("adb shell cmd lock_settings verify --old %s" % (new_pd))if 0 == output[0] and "Lock credential verified successfully" == output[1]:g_verify = g_verify + 1print("Use the correct %s : Lock credential verified successfully. ---(pass_count=%s)pass" % (type,g_verify))else:print("%s error not as expected!!!! exit!!!" % (type))sys.exit(2)for verify_count in range(0,locksetting["every_enroll"]["incorrect_verify"]):temp_pd = "1478"output = subprocess.getstatusoutput("adb shell cmd lock_settings verify --old %s" % (temp_pd))print(output)if "Old password '1478' didn't match" in output:g_verify = g_verify + 1print("Use the incorrect %s : Old password '1478' didn't match. ---(pass_count=%s)pass" % (type,g_verify))elif "Request throttled" in output:g_verify = g_verify + 1print("Wrong %s exceeds and need wait for 30s : Request throttled. ---(pass_count=%s)pass" % (type,g_verify))time.sleep(30)else:print("%s correct not as expected!!!! exit!!!" % (type))sys.exit(2)os.system("adb shell locksettings clear --old %s" % (new_pd))def test_keymaster_use_vts(testcount):output = subprocess.getstatusoutput("adb root")output = subprocess.getstatusoutput("adb push resource/googlekey/default_googlekey.bin /data")output = subprocess.getstatusoutput("adb push resource/googlekey/kmsetkey_ca /data")output = subprocess.getstatusoutput("adb shell \"chmod 777 data/kmsetkey_ca\"")output = subprocess.getstatusoutput("adb shell ./data/kmsetkey_ca -i ./data/default_googlekey.bin")# for keymaster 4.0 - arm64print("Start to test keymaster4.0-arm64. It will take a few minutes. Please wait patiently.")output = subprocess.getstatusoutput("adb push resource/vts_testcase/VtsHalKeymasterV4_0TargetTest/arm64/VtsHalKeymasterV4_0TargetTest /data")output = subprocess.getstatusoutput("adb shell \"chmod 777 /data/VtsHalKeymasterV4_0TargetTest\"")output = subprocess.getstatusoutput("adb shell ./data/VtsHalKeymasterV4_0TargetTest --gtest_break_on_failure")for line in output:print(line)print("\n\n")if "[ PASSED ]" in str(output[1]):print("test_keymaster 4.0 - arm64 --pass")report_result["keymaster4.0-arm64"] = "Pass"else:print("test_keymaster 4.0 - arm64 --failed")report_result["keymaster4.0-arm64"] = "fail"# for keymaster 4.0 - armprint("Start to test keymaster4.0-arm. It will take a few minutes. Please wait patiently.")output = subprocess.getstatusoutput("adb push resource/vts_testcase/VtsHalKeymasterV4_0TargetTest/arm/VtsHalKeymasterV4_0TargetTest /data")output = subprocess.getstatusoutput("adb shell \"chmod 777 /data/VtsHalKeymasterV4_0TargetTest\"")output = subprocess.getstatusoutput("adb shell ./data/VtsHalKeymasterV4_0TargetTest --gtest_break_on_failure")for line in output:print(line)print("\n\n")if "[ PASSED ]" in str(output[1]):print("test_keymaster 4.0 - arm --pass")report_result["keymaster4.0-arm"] = "Pass"else:print("test_keymaster 4.0 - arm --failed")report_result["keymaster4.0-arm"] = "fail"# for keymaster 4.1 - arm64print("Start to test keymaster4.1-arm64. It will take a few minutes. Please wait patiently.")output = subprocess.getstatusoutput("adb push resource/vts_testcase/VtsHalKeymasterV4_1TargetTest/arm64/VtsHalKeymasterV4_1TargetTest /data")output = subprocess.getstatusoutput("adb shell \"chmod 777 /data/VtsHalKeymasterV4_1TargetTest\"")output = subprocess.getstatusoutput("adb shell ./data/VtsHalKeymasterV4_1TargetTest --gtest_break_on_failure")for line in output:print(line)print("\n\n")if "[ PASSED ]" in str(output[1]):print("test_keymaster 4.1 - arm64 --pass")report_result["keymaster4.1-arm64"] = "Pass"else:print("test_keymaster 4.1 - arm64 --failed")report_result["keymaster4.1-arm64"] = "fail"# for keymaster 4.1 - armprint("Start to test keymaster4.1-arm. It will take a few minutes. Please wait patiently.")output = subprocess.getstatusoutput("adb push resource/vts_testcase/VtsHalKeymasterV4_1TargetTest/arm/VtsHalKeymasterV4_1TargetTest /data")output = subprocess.getstatusoutput("adb shell \"chmod 777 /data/VtsHalKeymasterV4_1TargetTest\"")output = subprocess.getstatusoutput("adb shell ./data/VtsHalKeymasterV4_1TargetTest --gtest_break_on_failure")for line in output:print(line)print("\n\n")if "[ PASSED ]" in str(output[1]):print("test_keymaster 4.1 - arm --pass")report_result["keymaster4.1-arm"] = "Pass"else:print("test_keymaster 4.1 - arm --failed")report_result["keymaster4.1-arm"] = "fail"# for keymaster 3.0 - arm64print("Start to test keymaster3.0-arm64. It will take a few minutes. Please wait patiently.")output = subprocess.getstatusoutput("adb push resource/vts_testcase/VtsHalKeymasterV3_0TargetTest/arm64/VtsHalKeymasterV3_0TargetTest /data")output = subprocess.getstatusoutput("adb shell \"chmod 777 /data/VtsHalKeymasterV3_0TargetTest\"")output = subprocess.getstatusoutput("adb shell ./data/VtsHalKeymasterV3_0TargetTest --gtest_break_on_failure")for line in output:print(line)print("\n\n")if "[ PASSED ]" in str(output[1]):print("test_keymaster 3.0 - arm64 --pass")report_result["keymaster3.0-arm64"] = "Pass"else:print("test_keymaster 3.0 - arm64 --failed")report_result["keymaster3.0-arm64"] = "fail"# for keymaster 3.0 - armprint("Start to test keymaster3.0-arm. It will take a few minutes. Please wait patiently.")output = subprocess.getstatusoutput("adb push resource/vts_testcase/VtsHalKeymasterV3_0TargetTest/arm/VtsHalKeymasterV3_0TargetTest /data")output = subprocess.getstatusoutput("adb shell \"chmod 777 /data/VtsHalKeymasterV3_0TargetTest\"")output = subprocess.getstatusoutput("adb shell ./data/VtsHalKeymasterV3_0TargetTest --gtest_break_on_failure")for line in output:print(line)print("\n\n")if "[ PASSED ]" in str(output[1]):print("test_keymaster 3.0 - arm --pass")report_result["keymaster3.0-arm"] = "Pass"else:print("test_keymaster 3.0 - arm --failed")report_result["keymaster3.0-arm"] = "fail"def test_gatekeeper_use_vts(testcount):print("Start to test gatekeeper. It will take a few minutes. Please wait patiently.")output = subprocess.getstatusoutput("adb root")output = subprocess.getstatusoutput("adb push resource/vts_testcase/VtsHalGatekeeperV1_0TargetTest/arm64/VtsHalGatekeeperV1_0TargetTest /data")output = subprocess.getstatusoutput("adb shell \"chmod 777 /data/VtsHalGatekeeperV1_0TargetTest\"")output = subprocess.getstatusoutput("adb shell ./data/VtsHalGatekeeperV1_0TargetTest")for line in output:print(line)print("\n\n")if "[ PASSED ]" in str(output[1]):print("test_gatekeeper_use_vts--pass")report_result["gatekeeper"] = "Pass"else:print("test_gatekeeper_use_vts--failed")report_result["gatekeeper"] = "Fail"if __name__ == '__main__':print(str(sys.argv[0]) + " enter")get_args(sys.argv[1:])if test_press_locksetting == True:test_locksetting_pin("pattern", test_press_count)test_locksetting_pin("password", test_press_count)test_locksetting_pin("pin", test_press_count)print("Total testcase : %s pass" % (g_verify))if test_vts_gatekeeper == True or test_press_locksetting == True:test_gatekeeper_use_vts(test_press_count)if test_vts_keymaster == True or test_press_keymaster == True:test_keymaster_use_vts(test_press_count)if test_press_locksetting == False and test_press_keymaster == False and test_vts_gatekeeper == False and test_vts_keymaster == False:test_keymaster_use_vts(test_press_count)test_gatekeeper_use_vts(test_press_count)print_report()time.sleep(30)else:print_report()
總結
以上是生活随笔為你收集整理的python自动化测试locksetting/gatekeeper/keymaster/vts等的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [待]-optee的native_int
- 下一篇: [Issue Fixed]-GCC编译[