目录结构
log:存放用例日志路径。
testcase:测试模板路径。
utils:工具类路径。
configs.py:工具配置文件。
main.py:工具函数入口。
工具使用
命令行执行:
python main.py
调试模式:
将autoTest通过pycharm加载。
全量测试:右键执行main.py。
部分测试:主入口修改debugMode = True,module_list中添加需要测试的模块,多个模块用逗号分隔。
以下是config.py实现
import os
import time
import serial.tools.list_ports
# 主函数用
basedir = os.path.split(os.path.realpath(__file__))[0]
utils_home = os.sep.join([basedir, 'utils'])
# test_template_home = os.sep.join([basedir, 'testcase', 'test_template_build_config_run.xls'])
test_template_home = os.sep.join([basedir, 'testcase', 'test_template_on_chip.xls'])
host_log_home = "/home/test/log"
run_time = time.strftime('%Y%m%d%H%M', time.localtime(time.time()))
# 测试相关配置
test_configs = {
'TEST_YES': 'Y',
'TEST_NO': 'N',
'SUCCESS': 'SUCCESS',
'FAIL': 'FAIL',
'TIMEOUT': 'TIMEOUT',
'COST': 'COST',
'sysIO_test': "upcie",
'no_testing_required': 'No Testing Required',
'registration_exception_0': "argv or run member is not equal to title or 1, please check",
'registration_exception_1': "argv or run member is not equal to title or 1, please examine",
'registration_exception_2': "Unknown command!"
}
# 服务器相关配置
host_configs = {
'serverIP': '192.168.0.125',
'serverPort': 22,
'username': 'root',
'password': '123456',
'answering_shell': True, # 是否开启应答式Shell(默认开启)
'ps3_reset_cmd': 'ps3_reset',
'apu_host': 'apu_host',
'apu_host_cmd': """cd /home/test/0315_host_linux_fpga_test0721/
sh apuhost.sh
time_sleep(5)""",
'host_ps3_rst_list': """cd /home/test/cs100_test/testscript
sh ps3F0HardResetOneTimeHBA.sh""",
'host_ps3_reset_info': 'Initiate a ps3_reset from the host',
"reboot_cmd": "reboot",
"reboot_cmd_info": "Initiate reboot from the host",
"reboot_cmd_result": "reboot success"
}
# 串口相关配置
serial_configs = {
'baunRate': 115200,
'port_list': list(serial.tools.list_ports.comports()),
}
TEST_YES, TEST_NO, SUCCESS, FAIL, TIMEOUT, COST, sysIO_test, no_testing_required, registration_exception_0, \
registration_exception_1, registration_exception_2 = test_configs['TEST_YES'], test_configs['TEST_NO'], \
test_configs['SUCCESS'], \
test_configs['FAIL'], test_configs['TIMEOUT'], \
test_configs['COST'], test_configs['sysIO_test'], \
test_configs['no_testing_required'], test_configs[
'registration_exception_0'], \
test_configs['registration_exception_1'], test_configs[
'registration_exception_2']
ip, port, username, password, answering, ps3_reset_cmd, host_ps3_rst_list, host_ps3_reset_info, reboot_cmd, \
reboot_cmd_info, reboot_cmd_result = host_configs['serverIP'], host_configs['serverPort'], host_configs['username'], \
host_configs['password'], host_configs['answering_shell'], \
host_configs['ps3_reset_cmd'], host_configs['host_ps3_rst_list'], \
host_configs['host_ps3_reset_info'], host_configs['reboot_cmd'], host_configs[
"reboot_cmd_info"], host_configs[
"reboot_cmd_result"]
apu_cmd = host_configs['apu_host']
apu_host_cmd = host_configs["apu_host_cmd"]
port_list, baunRate = serial_configs['port_list'], serial_configs['baunRate']
# 选择串口
port_list_name = []
if len(port_list) <= 0:
raise Exception("The serial port can't find!")
else:
for itms in port_list:
port_list_name.append(itms.device)
# com3串口
# print(port_list_name)
serialPort_case = port_list_name[-1]
print("The test port is %s" % serialPort_case)
if __name__ == '__main__':
print(type(reboot_cmd))