测试时总有一些场景需要内存不足才能触发,脚本可以推送一些文件到车机里面直到内存不足。测试完成后记得清除掉这些文件,不然无法进行安装apk
import time
import adbutils.errors
remote_storage = 'sdcard/file_test'
adb = adbutils.AdbClient(host="127.0.0.1", port=5037)
device = adb.device()
def mkdir_remote_storage():
""" 创建设备测试目录 """
output = device.shell('ls -l ' + remote_storage)
if output.endswith('No such file or directory'):
device.shell('mkdir ' + remote_storage)
def begin_push_file(file_path: str):
""" 开始push文件进设备 """
mkdir_remote_storage()
try:
for i in range(10000 * 10000):
print('开始推送测试数据, 成功数量: ' + str(i + 1))
filename = 'test_' + time.strftime('%y%m%d%H%M%S') + ''
device.sync.push(file_path, remote_storage + '/' + filename)
except adbutils.errors.AdbError as e:
print('内存不足...' + str(e))
def clear():
""" 清空测试数据 """
print('begin clear ' + remote_storage)
device.shell('rm -rf ' + remote_storage)
print('设备满存储内存工具')
print('[1]开始模拟满存储内存测试')
print('[2]清空测试数据')
test_type = input('请输入要测试的类型: ')
if test_type == '1':
test_data_path = input('请输入要塞入设备的文件路径: ')
begin_push_file(test_data_path)
else:
clear()
一般推送要点时间的(最好用有线adb,wifi adb会很慢),如果这里显示内存不足了,测试时发现还是内存有空间,可以换小点的文件进行推送,进一步压缩内存空间