dict_test = {1: 'fail', 2: 'fail', 3: 'fail', 4: 'fail', 5: 'fail', 6: 'fail', 7: 'pass', 8: 'pass', 9: 'pass',
10: 'pass'}
def bin_check(dict_test: dict, mid):
if int(dict_test[mid]) > 10:
return "pass"
else:
return "fail"
print(dict_test.get[mid])
case_name = 'a.txt'
def change_type(case_name):
with open(case_name, 'r') as file:
param_list = [line.strip() for line in file]
my_dict = {idx: value for idx, value in enumerate(param_list)}
return my_dict
def bi_check(low, high, dict_test):
'''
:param low:
:param high:
:param dict_test:
:return:
'''
print('low-------------------------------', low)
print('high------------------------------', high)
if low + 1 >= high:
return
mid = (low + high) // 2
print('mid is ', mid)
print('value is',dict_test[mid])
mid_result = bin_check(dict_test, mid)
if mid_result == 'pass':
high = mid
print(mid, ':pass')
if mid_result == 'fail':
low = mid
print(mid, ':fail')
print('----------------------------------------------------------------------end')
bi_check(low, high, dict_test)
dict_test = change_type(case_name)
print(dict_test)
low = 0
high = len(dict_test) - 1
bi_check(low, high, dict_test)
import subprocess
import os
import sys
cur_path = os.path.abspath(os.path.dirname(__file__))
run_num = 0
def change_type(case_txt):
with open(case_txt, 'r') as file:
param_list = [line.strip() for line in file if line.count("_") == 2]
my_dict = [{'cann_pack_name': i, 'result': ''} for i in param_list]
return my_dict
def down_cann_pak_pre(cann_pack_name):
os.chdir(cur_path)
os.system('rm -rf {}'.format(cann_pack_name))
os.system('mkdir {}'.format(cann_pack_name))
os.system('cp download_only.py {}'.format(cann_pack_name))
os.chdir(os.path.join(cur_path, cann_pack_name))
os.system('pwd')
os.system('python3 download_only.py {}'.format(cann_pack_name))
def check_CANN_package(cann_pack_name, cann_lsit):
is_re_down = 'no'
for cann_name in cann_lsit:
file_path = "/".join([cur_path, cann_pack_name, cann_name])
print(file_path)
if os.path.isfile(file_path):
file_size = os.path.getsize(file_path)
file_size = file_size // (1024 * 1024)
if file_size >= 1:
print('文件-----[{:<60}] [{:<10}]MB status=[OK]'.format(cann_name, file_size))
else:
print('文件-----[{:<60}] [{:<10}]MB status=[Fail]'.format(cann_name, file_size))
is_re_down = 'yes'
else:
is_re_down = 'yes'
print('is_re_down is ', is_re_down)
return is_re_down
def install_package(cann_pack_name):
os.chdir(cur_path)
os.system('cp install_only.sh {}'.format(cann_pack_name))
os.system('pwd')
os.chdir(os.path.join(cur_path, cann_pack_name))
os.system('pwd')
os.system("./install_only.sh")
def excute_order(case_name, cann_pack_name):
os.chdir(cur_path)
result = subprocess.run(['./zrexfu.sh', case_name, cann_pack_name])
if result.returncode == 0:
print('pass')
return "pass"
elif result.returncode == 1:
print('fail')
return "fail"
def re_change_type(case_name_de):
with open(case_txt, 'r') as file:
param_list = [line.strip() for line in file]
my_dict = {idx: value for idx, value in enumerate(param_list)}
def test_excute_order(j, dict_test):
cann_package = dict_test[j]['cann_pack_name']
if '20240620_' in cann_package:
case_result = 'pass'
elif '20240621_' in cann_package:
case_result = 'fail'
else:
print('key值是', dict_test[j]['cann_pack_name'])
return case_result
def bi_check(low, high, case_name, dict_test, dict_test_ori):
'''
low:二分的开始
high:二分结束
case_name:二分的用例名字
dict_test:二分的数据都在里面
dect_test_ori:二分数据的记录,更新结果。
'''
for j in dict_test_ori:
print(j)
global run_num
run_num = run_num + 1
print('low-------------------------------', low, dict_test[low])
print('high------------------------------', high, dict_test[high])
if low + 1 >= high:
print('----------------------------结果如下---------------------------------')
for i in dict_test_ori:
print(i)
sys.exit()
mid = (low + high) // 2
print('mid is ', mid)
cann_pack_name = dict_test[mid]["cann_pack_name"]
print('*****************************************************************************************')
print(f'This is the [ {run_num} ] check , and cann_pack_name is [{cann_pack_name}]')
print('*****************************************************************************************')
down_cann_pak_pre(cann_pack_name)
result_is_rerun = check_CANN_package(cann_pack_name, cann_lsit=cann_lsit_date)
if result_is_rerun == 'yes':
for i in range(len(dict_test_ori)):
if dict_test_ori[i]['cann_pack_name'] == cann_pack_name:
dict_test_ori[i]['result'] = 'lost_package' + str(run_num)
print(dict_test_ori[i]['result'], "********lost_package***********")
a = dict_test.pop(mid)
print('This cann_pack is not satisfy needs', a)
high = high - 1
bi_check(low, high, case_name, dict_test, dict_test_ori)
install_package(cann_pack_name)
mid_result = excute_order(case_name, cann_pack_name)
if mid_result == 'pass':
high = mid
print(f'{high}:{cann_pack_name} :pass')
for i in range(len(dict_test_ori)):
if dict_test_ori[i]['cann_pack_name'] == cann_pack_name:
dict_test_ori[i]['result'] = 'pass' + str(run_num)
elif mid_result == 'fail':
low = mid
print(f'{low}:{cann_pack_name} :fail')
for i in range(len(dict_test_ori)):
if dict_test_ori[i]['cann_pack_name'] == cann_pack_name:
dict_test_ori[i]['result'] = 'fail' + str(run_num)
else:
print(f'{dict_test_ori[mid]} Did not get reuslt ')
return
print('----------------------------------------------------------------------end')
bi_check(low,high, case_name, dict_test, dict_test_ori)
if __name__ == '__main__':
case_txt = 'a.txt'
file_path = "/".join([cur_path, case_txt])
if not os.path.isfile(file_path):
print('--------------------------缺少{},需要把数据放到{}这个文件里---------------------------'.format(case_txt,
case_txt))
exit()
dict_test = change_type(case_txt)
dict_test_ori = change_type(case_txt)
print(dict_test)
for i in dict_test:
print(i)
low = 0
high = len(dict_test) - 1
run_num = 0
cann1 = 'CANN-aoe-7.3.t10.0.b528-linux.x86_64.run'
cann2 = 'CANN-compiler-7.3.t10.0.b528-linux.x86_64.run'
cann3 = 'CANN-fwkplugin-7.3.t10.0.b528-linux.x86_64.run'
cann4 = 'CANN-hccl-7.3.t10.0.b528-linux.x86_64.run'
cann5 = 'CANN-opp-7.3.t10.0.b528-linux.x86_64.run'
cann6 = 'CANN-runtime-7.3.t10.0.b528-linux.x86_64.run'
cann7 = 'CANN-toolkit-7.3.t10.0.b528-linux.x86_64.run'
case_name = 'case21_op_while_staticShape_atmFalse_infer'
cann_lsit_date = [cann1, cann2, cann3, cann4, cann5, cann6, cann7]
print('本次二分的用例是', case_name)
user_input = input("确认运行输入YES:")
if user_input == 'YES':
bi_check(low, high, case_name, dict_test, dict_test_ori)
else:
print("----------------退出程序---------------------")
import subprocess
import os
import sys
cur_path = os.path.abspath(os.path.dirname(__file__))
run_num = 0
def change_type(case_txt):
with open(case_txt, 'r') as file:
param_list = [line.strip() for line in file if line.count("_") == 2]
my_dict = [{'cann_pack_name': i, 'result': ''} for i in param_list]
return my_dict
def down_cann_pak_pre(cann_pack_name):
os.chdir(cur_path)
os.system('rm -rf {}'.format(cann_pack_name))
os.system('mkdir {}'.format(cann_pack_name))
os.system('cp download_only.py {}'.format(cann_pack_name))
os.chdir(os.path.join(cur_path, cann_pack_name))
os.system('pwd')
os.system('python3 download_only.py {}'.format(cann_pack_name))
def check_CANN_package(cann_pack_name, cann_lsit):
is_re_down = 'no'
for cann_name in cann_lsit:
file_path = "/".join([cur_path, cann_pack_name, cann_name])
print(file_path)
if os.path.isfile(file_path):
file_size = os.path.getsize(file_path)
file_size = file_size // (1024 * 1024)
if file_size >= 1:
print('文件-----[{:<60}] [{:<10}]MB status=[OK]'.format(cann_name, file_size))
else:
print('文件-----[{:<60}] [{:<10}]MB status=[Fail]'.format(cann_name, file_size))
is_re_down = 'yes'
else:
is_re_down = 'yes'
print('is_re_down is ', is_re_down)
return is_re_down
def install_package(cann_pack_name):
os.chdir(cur_path)
os.system('cp install_only.sh {}'.format(cann_pack_name))
os.system('pwd')
os.chdir(os.path.join(cur_path, cann_pack_name))
os.system('pwd')
os.system("./install_only.sh")
def excute_order(case_name, cann_pack_name):
os.chdir(cur_path)
result = subprocess.run(['./zrexfu.sh', case_name, cann_pack_name])
if result.returncode == 0:
print('------pass------')
return "pass"
elif result.returncode == 1:
print('-------fail--------')
return "fail"
def test_excute_order(j, dict_test):
cann_package = dict_test[j]['cann_pack_name']
if '20240620_' in cann_package:
case_result = 'pass'
elif '20240621_' in cann_package:
case_result = 'fail'
else:
print('key值是', dict_test[j]['cann_pack_name'])
return case_result
def bi_check(low, high, case_name, dict_test, dict_test_ori):
'''
low:二分的开始
high:二分结束
case_name:二分的用例名字
dict_test:实时二分的数据都在里面
dect_test_ori:记录二分数据的记录,更新结果。
'''
for i in dict_test_ori:
print(i)
global run_num
run_num = run_num + 1
print('low-------------------------------', low, dict_test[low])
print('high------------------------------', high, dict_test[high])
if low + 1 >= high:
print('----------------------------结果如下---------------------------------')
for i in dict_test_ori:
print(i)
sys.exit()
mid = (low + high) // 2
print('mid is ', mid)
cann_pack_name = dict_test[mid]["cann_pack_name"]
print('*****************************************************************************************')
print(f'This is the [ {run_num} ] check , and cann_pack_name is [{cann_pack_name}]')
print('*****************************************************************************************')
down_cann_pak_pre(cann_pack_name)
result_is_rerun = check_CANN_package(cann_pack_name, cann_lsit=cann_lsit_date)
if result_is_rerun == 'yes':
for i in range(len(dict_test_ori)):
if dict_test_ori[i]['cann_pack_name'] == cann_pack_name:
dict_test_ori[i]['result'] = 'lost_package' + str(run_num)
print(dict_test_ori[i]['result'], "********lost_package***********")
a = dict_test.pop(mid)
print('This cann_pack is not satisfy needs', a)
high = high - 1
bi_check(low, high, case_name, dict_test, dict_test_ori)
install_package(cann_pack_name)
mid_result = excute_order(case_name, cann_pack_name)
if mid_result == 'pass':
high = mid
print(f'{high}:{cann_pack_name} :pass')
for i in range(len(dict_test_ori)):
if dict_test_ori[i]['cann_pack_name'] == cann_pack_name:
dict_test_ori[i]['result'] = 'pass' + str(run_num)
elif mid_result == 'fail':
low = mid
print(f'{low}:{cann_pack_name} :fail')
for i in range(len(dict_test_ori)):
if dict_test_ori[i]['cann_pack_name'] == cann_pack_name:
dict_test_ori[i]['result'] = 'fail' + str(run_num)
else:
print(f'{dict_test_ori[mid]} Did not get reuslt ')
return
print('----------------------------------------------------------------------end')
bi_check(low, high, case_name, dict_test, dict_test_ori)
if __name__ == '__main__':
if len(sys.argv) != 2:
exit('运行参数有误,按照python3 xxxx.py case_name 方式运行')
case_name = sys.argv[1]
case_txt = 'a.txt'
file_path = "/".join([cur_path, case_txt])
if not os.path.isfile(file_path):
print('--------------------------缺少{},需要把数据放到{}这个文件里---------------------------'.format(case_txt,
case_txt))
exit()
dict_test = change_type(case_txt)
dict_test_ori = change_type(case_txt)
print(dict_test)
for index, item in enumerate(dict_test_ori, start=0):
print(f"{index} :{item}")
low = 0
high = len(dict_test) - 1
run_num = 0
cann1 = 'CANN-aoe-7.3.t10.0.b528-linux.x86_64.run'
cann2 = 'CANN-compiler-7.3.t10.0.b528-linux.x86_64.run'
cann3 = 'CANN-fwkplugin-7.3.t10.0.b528-linux.x86_64.run'
cann4 = 'CANN-hccl-7.3.t10.0.b528-linux.x86_64.run'
cann5 = 'CANN-opp-7.3.t10.0.b528-linux.x86_64.run'
cann6 = 'CANN-runtime-7.3.t10.0.b528-linux.x86_64.run'
cann7 = 'CANN-toolkit-7.3.t10.0.b528-linux.x86_64.run'
cann_lsit_date = [cann1, cann2, cann3, cann4, cann5, cann6, cann7]
case_name = sys.argv[1]
if len(cann_lsit_date) > 0:
print('本次二分必须安装的包如下:')
for i in cann_lsit_date:
print(i)
print('本次二分的用例是', case_name)
user_input = input("确认运行输入YES:")
if user_input == 'YES':
bi_check(low, high, case_name, dict_test, dict_test_ori)
else:
print("----------------退出程序---------------------")