添加环境依赖配置;
添加测试用例生成;
This commit is contained in:
@@ -10,7 +10,7 @@ from tools.IntelHex import file_Bin_to_IntelHex
|
||||
from func_frame import make_frame_modbus, check_frame_modbus, print_display
|
||||
from func_upgrade import GenerateImage_DLSP001_p280039, GeneratePackage_DLSP001_p280039
|
||||
|
||||
modbus_map = {
|
||||
ParamMap_LaminaController = {
|
||||
# 1 - Hex
|
||||
# 2 - Int16
|
||||
# 3 - lnt32
|
||||
@@ -138,7 +138,7 @@ class LaminaController:
|
||||
'type' : 'modbus',
|
||||
'data' : {
|
||||
'addr_dev' : addr_modbus,
|
||||
'data_define': modbus_map,
|
||||
'data_define': ParamMap_LaminaController,
|
||||
},
|
||||
}
|
||||
self.output = {
|
||||
@@ -693,7 +693,7 @@ if __name__=='__main__':
|
||||
"Log": {'com_name': None,
|
||||
# 'addr_645': [0x01, 0x00, 0x00, 0x00, 0x00, 0x40],
|
||||
},
|
||||
"Debug": {'com_name': 'COM3', 'baudrate': 115200, 'parity': 'N', 'bytesize': 8, 'stopbits': 1,
|
||||
"Debug": {'com_name': 'COM5', 'baudrate': 115200, 'parity': 'N', 'bytesize': 8, 'stopbits': 1,
|
||||
# 'addr_645': [0x01, 0x02, 0x03, 0x04, 0x05, 0x06],
|
||||
'frame_print': True,
|
||||
'time_out': 0.5, 'retry': 3},
|
||||
@@ -719,14 +719,12 @@ if __name__=='__main__':
|
||||
""" 升级流程 """
|
||||
path_project = Path("D:\WorkingProject\LightStackOptimizer\software\lamina_controller_dsp\lamina_controller_dsp")
|
||||
file_hex = path_project / "DEBUG\lamina_controller_dsp.hex"
|
||||
# file_hex = Path(r"C:\Users\wrqal\Documents\WXWork\1688856624403708\Cache\File\2024-09\lamina_controller_dsp(1).hex")
|
||||
if not file_hex.exists():
|
||||
raise Exception("工程编译目标文件不存在.")
|
||||
file_package = make_Pakeage(file_hex)
|
||||
|
||||
dev_lamina.frame_write_one(0x60, 0)
|
||||
time.sleep(1)
|
||||
if dev_lamina.frame_update(file_package):
|
||||
if dev_lamina.frame_update(file_hex, makefile=True):
|
||||
time.sleep(6)
|
||||
dev_lamina.frame_read(0x0100, 0x20)
|
||||
# dev_lamina.frame_write_one(0x52, 0x01)
|
||||
|
||||
194
source/test_devController.py
Normal file
194
source/test_devController.py
Normal file
@@ -0,0 +1,194 @@
|
||||
import time
|
||||
|
||||
from dev_LaminaController import LaminaController
|
||||
from dev_LaminaController import ParamMap_LaminaController
|
||||
|
||||
|
||||
def test_communication(device: LaminaController, time_out=2):
|
||||
""" 通信成功率测试 """
|
||||
time_start = time.time()
|
||||
param_saved = device.flag_print, device.retry, device.time_out
|
||||
device.flag_print = False
|
||||
device.retry = 1
|
||||
try:
|
||||
while True:
|
||||
device.frame_read(0x0C, 0x20)
|
||||
print(f"Time Stamp: {time.ctime()}")
|
||||
print(f"Success Frame: {device.log['read']}")
|
||||
print(f"Failed Frame: {device.log['send'] - device.log['read']}")
|
||||
print(f"Max Series Failed Frame: {device.log['keep-fail']}")
|
||||
time.sleep(time_out)
|
||||
finally:
|
||||
time_end = time.time()
|
||||
print("Test Result: ")
|
||||
print(f"Time Start: {time.strftime(r'%Y-%m-%d %H:%M:%S', time.localtime(time_start))}, \tTime End: {time.strftime(r'%Y-%m-%d %H:%M:%S', time.localtime(time_end))}")
|
||||
print(f"Time Elapsed: {time_end - time_start}")
|
||||
print(f"Success Rate: {device.log['read'] / device.log['send'] * 100}%")
|
||||
device.flag_print, device.retry, device.time_out = param_saved
|
||||
|
||||
|
||||
def test_parameters(device:LaminaController, ParamMap:dict, ParamCase:dict):
|
||||
""" 参数读写测试 """
|
||||
pass
|
||||
|
||||
def frame_write(device:LaminaController, address, info, value):
|
||||
""" 整合参数写入接口 """
|
||||
length = 2 if info[1] in [3, 6] else 1
|
||||
length = info[2] if info[1] in [4, 5, 7] else length
|
||||
if length == 1:
|
||||
return device.frame_write_one(address, value)
|
||||
elif length == 2:
|
||||
return device.frame_write_dual(address, value)
|
||||
else:
|
||||
return device.frame_write_str(address, value)
|
||||
def frame_read(device:LaminaController, address, info):
|
||||
""" 整合参数读取接口 """
|
||||
length = 2 if info[1] in [3, 6] else 1
|
||||
length = info[2] if info[1] in [4, 5, 7] else length
|
||||
if device.frame_read(address, length):
|
||||
return device.output['Regs'][address]
|
||||
else:
|
||||
return None
|
||||
|
||||
def check_result(device:LaminaController, item_param, value, result:bool):
|
||||
""" 测试参数写入结果 """
|
||||
addr_param, info_param = item_param
|
||||
len_param = 2 if info_param[1] in [3, 6] else 1
|
||||
len_param = info_param[2] if info_param[1] in [4, 5, 7] else len_param
|
||||
|
||||
device.frame_write_one(addr_param, value)
|
||||
device.frame_read(addr_param, len_param)
|
||||
|
||||
output_value = device.output['Regs'][addr_param]
|
||||
if result:
|
||||
assert value == output_value
|
||||
else:
|
||||
assert value != output_value
|
||||
|
||||
for addr_param, info_param in ParamMap.items():
|
||||
if addr_param in ParamCase.keys():
|
||||
itemCase = ParamCase[addr_param]
|
||||
list_case = []
|
||||
if 0 in itemCase.keys():
|
||||
""" 常规读写用例测试 """
|
||||
for data_write, data_read in itemCase[0]:
|
||||
list_case.append((data_write, data_read, True))
|
||||
if 1 in itemCase.keys():
|
||||
""" 写入范围用例测试 """
|
||||
deadzone = 0.5
|
||||
val_min, val_max = itemCase[1]
|
||||
if 2 in itemCase.keys():
|
||||
""" 存在大小约束相关项 """
|
||||
list_case_relate = []
|
||||
mode_relate, addr_relate, deadzone = itemCase[2]
|
||||
val_relate = frame_read(device, addr_relate, ParamCase[addr_relate])
|
||||
if mode_relate == 1:
|
||||
if val_relate > val_min:
|
||||
list_case_relate.append((val_min - deadzone, val_min - deadzone, True))
|
||||
val_min = val_relate
|
||||
else:
|
||||
val_min
|
||||
elif mode_relate == 2:
|
||||
if val_relate < val_max:
|
||||
list_case_relate.append((val_max + deadzone, val_max + deadzone, True))
|
||||
val_max = val_relate
|
||||
else:
|
||||
val_max
|
||||
list_case.append((val_min - deadzone, val_min - deadzone, False))
|
||||
list_case.append((val_min, val_min, True))
|
||||
list_case.append((val_min + deadzone, val_min + deadzone, True))
|
||||
list_case.append((val_max + deadzone, val_max + deadzone, False))
|
||||
list_case.append((val_max, val_max, True))
|
||||
list_case.append((val_max - deadzone, val_max - deadzone, True))
|
||||
|
||||
|
||||
|
||||
current_value = frame_read(device, addr_param, info_param)
|
||||
frame_write(device, addr_param, info_param, val_min - 1)
|
||||
result = frame_read(device, addr_param, info_param)
|
||||
assert result == current_value
|
||||
frame_write(device, addr_param, info_param, val_min - 0.5)
|
||||
result = frame_read(device, addr_param, info_param)
|
||||
assert result == current_value
|
||||
frame_write(device, addr_param, info_param, val_min)
|
||||
result = frame_read(device, addr_param, info_param)
|
||||
assert result == val_min
|
||||
current_value = result
|
||||
frame_write(device, addr_param, info_param, val_max + 1)
|
||||
result = frame_read(device, addr_param, info_param)
|
||||
assert result == current_value
|
||||
frame_write(device, addr_param, info_param, val_max + 0.5)
|
||||
result = frame_read(device, addr_param, info_param)
|
||||
assert result == current_value
|
||||
frame_write(device, addr_param, info_param, val_max)
|
||||
result = frame_read(device, addr_param, info_param)
|
||||
assert result == val_max
|
||||
if 2 in itemCase.keys():
|
||||
""" 大小关联用例测试 """
|
||||
if itemCase[0] == 0:
|
||||
""" 数值相等关联项 """
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
mode_config = {
|
||||
"Log": {'com_name': None,
|
||||
# 'addr_645': [0x01, 0x00, 0x00, 0x00, 0x00, 0x40],
|
||||
},
|
||||
"Debug": {'com_name': 'COM5',
|
||||
# 'addr_645': [0x01, 0x02, 0x03, 0x04, 0x05, 0x06],
|
||||
# 'frame_print': True,
|
||||
'time_out': 0.5, 'retry': 3},
|
||||
}
|
||||
|
||||
TestCase = {
|
||||
# 测试用例定义
|
||||
# 0 - 正常写入数据序列; [(写入数据, 读取数据)]
|
||||
# 1 - 范围限制测试; (最小值, 最大值)
|
||||
# 2 - 相关大小限制测试; ((0-等于, 1-小于, 2-大于), 相关值地址, 死区范围)
|
||||
0x60: {0: [(0, 0), (1, 1), (2, 1), (0xFF, 1)]},
|
||||
0x61: {0: [(60.0, 60.0)], 1: (40, 60), 2: (1, 0x62, 0.5)},
|
||||
0x62: {0: [(440.0, 440.0)], 1: (350, 560), 2: (2, 0x61, 0.5)},
|
||||
0x63: {},
|
||||
0x64: {},
|
||||
0x65: {},
|
||||
0x66: {},
|
||||
0x67: {},
|
||||
0x68: {},
|
||||
0x69: {},
|
||||
0x6A: {},
|
||||
0x6C: {},
|
||||
0x6E: {},
|
||||
0x70: {},
|
||||
0x71: {},
|
||||
0x72: {},
|
||||
0x73: {},
|
||||
0x74: {},
|
||||
0x75: {},
|
||||
0x76: {},
|
||||
0x78: {},
|
||||
0x7A: {},
|
||||
0x7B: {},
|
||||
0x7C: {},
|
||||
0x7D: {},
|
||||
0x7E: {},
|
||||
0x7F: {},
|
||||
0x80: {},
|
||||
0x81: {},
|
||||
0x82: {},
|
||||
0x83: {},
|
||||
0x84: {},
|
||||
0x85: {},
|
||||
0x86: {},
|
||||
0x88: {},
|
||||
0x8A: {},
|
||||
0x8B: {},
|
||||
0x170: {},
|
||||
0x180: {},
|
||||
0x190: {},
|
||||
}
|
||||
dev_lamina = LaminaController(**mode_config['Debug'])
|
||||
test_parameters(dev_lamina, ParamMap_LaminaController, TestCase)
|
||||
|
||||
if __name__== "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user