add auto generated test folder to components:
1. add test cases and related scripts 2. add CI config files read README.md for detail
This commit is contained in:
+130
@@ -0,0 +1,130 @@
|
||||
from TCAction import TCActionBase
|
||||
from NativeLog import NativeLog
|
||||
from TCAction import CmdHandler
|
||||
import time
|
||||
|
||||
|
||||
ATCmdList = ["GMR",
|
||||
"UART=115200,8,1,0,0",
|
||||
"CWMODE=3",
|
||||
"CWJAP=\"TL_WR845N_T\",\"1234567890\"",
|
||||
"CWLAP",
|
||||
"CWQAP",
|
||||
"CWSAP=\"asdf\",\"123456789\",5,3",
|
||||
"CWLIF",
|
||||
"CWDHCP=3",
|
||||
"AT+CWAUTOCONN",
|
||||
"CIPSTAMAC=\"18:fe:34:97:f3:43\"",
|
||||
"CIPAPMAC=\"1a:fe:34:97:f3:43\"",
|
||||
"CIPSTA=\"192.168.1.2\"",
|
||||
"CIPAP=\"192.168.4.1\"",
|
||||
"CIPSTATUS",
|
||||
"CIPSTART=\"UDP\",\"192.168.1.4\",6531,7895,1",
|
||||
"CIPSTART=\"TCP\",\"192.168.1.4\",6531",
|
||||
"CIPCLOSE",
|
||||
"CIFSR",
|
||||
"CIPMUX=1",
|
||||
"CIPSERVER=1,4567",
|
||||
"CIPMODE=0",
|
||||
"CIPSTO=7200",
|
||||
"PING=\"192.168.1.4\""]
|
||||
|
||||
|
||||
class CmdInterruptTest(TCActionBase.CommonTCActionBase):
|
||||
|
||||
def __init__(self, name, test_env, cmd_set, timeout=20, log_path=TCActionBase.LOG_PATH):
|
||||
TCActionBase.CommonTCActionBase.__init__(self, name, test_env, cmd_set=cmd_set,
|
||||
timeout=timeout, log_path=log_path)
|
||||
|
||||
self.result_cntx = TCActionBase.ResultCheckContext(self, test_env, self.tc_name)
|
||||
pass
|
||||
|
||||
def load_and_exe_one_step(self, checker_stings, test_action_strings, fail_string,
|
||||
check_freq=0.1, check_time=50, sleep_time=0.1):
|
||||
# set checker for next executing step
|
||||
checkers = CmdHandler.parse_results(checker_stings, self.test_env)
|
||||
self.result_cntx.set_next_step(checkers, check_time, check_freq)
|
||||
# execute 1 step
|
||||
for action_string in test_action_strings:
|
||||
test_action = CmdHandler.parse_action(action_string, self.test_env)
|
||||
CmdHandler.do_actions(test_action, self.test_env)
|
||||
time.sleep(sleep_time)
|
||||
|
||||
ret = self.wait_to_execute()
|
||||
|
||||
if ret is False: # # timeout
|
||||
self.result_cntx.set_result(fail_string)
|
||||
if ret == check_time:
|
||||
self.result_cntx.set_result(fail_string)
|
||||
ret = False
|
||||
|
||||
self.require_waiting()
|
||||
|
||||
return ret
|
||||
|
||||
def execute(self):
|
||||
TCActionBase.TCActionBase.execute(self)
|
||||
self.result_cntx.start()
|
||||
|
||||
# step 1, sleep time 0.1
|
||||
for cmd1 in ATCmdList:
|
||||
# check if match CMD - AT - busy - OK/ERROR pattern
|
||||
checker_stings = ["ATR AT1 C busy", "ATR AT1 R *"]
|
||||
test_action_string = ["ATS AT1 AT+%s" % cmd1, "ATS AT1 AT"]
|
||||
fail_string = "Fail, Fail on step 1"
|
||||
if self.load_and_exe_one_step(checker_stings, test_action_string,
|
||||
fail_string, sleep_time=0.1) is False:
|
||||
# check again if match CMD - OK/ERROR - AT - OK pattern
|
||||
checker_stings = ["ATR AT1 R *", "ATR AT1 C AT L OK"]
|
||||
test_action_string = ["ATS AT1 AT+%s" % cmd1, "ATS AT1 AT"]
|
||||
fail_string = "Fail, Fail on step 1"
|
||||
if self.load_and_exe_one_step(checker_stings, test_action_string,
|
||||
fail_string, sleep_time=0.1) is False:
|
||||
NativeLog.add_trace_critical("CMD Fail: AT+%s; sleep time is 0.1" % cmd1)
|
||||
|
||||
# step 2, sleep time 0
|
||||
for cmd1 in ATCmdList:
|
||||
# check if match CMD - AT - busy - OK/ERROR pattern
|
||||
checker_stings = ["ATR AT1 C busy", "ATR AT1 R *"]
|
||||
test_action_string = ["ATS AT1 AT+%s" % cmd1, "ATS AT1 AT"]
|
||||
fail_string = "Fail, Fail on step 1"
|
||||
if self.load_and_exe_one_step(checker_stings, test_action_string,
|
||||
fail_string, sleep_time=0.1) is False:
|
||||
# check again if match CMD - OK/ERROR - AT - OK pattern
|
||||
checker_stings = ["ATR AT1 R *", "ATR AT1 C AT L OK"]
|
||||
test_action_string = ["ATS AT1 AT+%s" % cmd1, "ATS AT1 AT"]
|
||||
fail_string = "Fail, Fail on step 1"
|
||||
if self.load_and_exe_one_step(checker_stings, test_action_string,
|
||||
fail_string, sleep_time=0.1) is False:
|
||||
NativeLog.add_trace_critical("CMD Fail: AT+%s; sleep time is 0" % cmd1)
|
||||
|
||||
# step 3, cat string
|
||||
for cmd1 in ATCmdList:
|
||||
# check if match CMD - AT - busy - OK/ERROR pattern
|
||||
checker_stings = ["ATR AT1 C busy", "ATR AT1 R *"]
|
||||
test_action_string = ["ATSO AT1 AT+%s\r\nAT\r\n" % cmd1]
|
||||
fail_string = "Fail, Fail on step 1"
|
||||
if self.load_and_exe_one_step(checker_stings, test_action_string,
|
||||
fail_string, sleep_time=0.1) is False:
|
||||
# check again if match CMD - OK/ERROR - AT - OK pattern
|
||||
checker_stings = ["ATR AT1 R *", "ATR AT1 C AT L OK"]
|
||||
test_action_string = ["ATS AT1 AT+%s" % cmd1, "ATS AT1 AT"]
|
||||
fail_string = "Fail, Fail on step 1"
|
||||
if self.load_and_exe_one_step(checker_stings, test_action_string,
|
||||
fail_string, sleep_time=0.1) is False:
|
||||
NativeLog.add_trace_critical("CMD Fail: AT+%s; cat string" % cmd1)
|
||||
|
||||
# finally, execute done
|
||||
self.result_cntx.set_result("Succeed")
|
||||
|
||||
def result_check(self, port_name, data):
|
||||
TCActionBase.CommonTCActionBase.result_check(self, port_name, data)
|
||||
self.result_cntx.append_data(port_name, data)
|
||||
|
||||
|
||||
def main():
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
from TCAction import TCActionBase
|
||||
import time
|
||||
import re
|
||||
|
||||
|
||||
class LAP(TCActionBase.CommonTCActionBase):
|
||||
def __init__(self, name, test_env, cmd_set, timeout=30, log_path=TCActionBase.LOG_PATH):
|
||||
TCActionBase.CommonTCActionBase.__init__(self, name, test_env, cmd_set=cmd_set,
|
||||
timeout=timeout, log_path=log_path)
|
||||
# load param from excel
|
||||
for i in range(1, len(cmd_set)):
|
||||
if cmd_set[i][0] != "dummy":
|
||||
cmd_string = "self." + cmd_set[i][0]
|
||||
exec cmd_string
|
||||
self.result_cntx = TCActionBase.ResultCheckContext(self, test_env, self.tc_name)
|
||||
pass
|
||||
|
||||
def cleanup(self):
|
||||
# restore set LAPOPT
|
||||
if self.load_and_exe_one_step(["R AT1 L OK"],
|
||||
["ATS AT1 AT+CWLAPOPT=0,127"],
|
||||
"Failed to set LAP option") is False:
|
||||
return
|
||||
|
||||
def execute(self):
|
||||
TCActionBase.TCActionBase.execute(self)
|
||||
self.result_cntx.start()
|
||||
|
||||
# step 1. set LAPOPT
|
||||
if self.load_and_exe_one_step(["R AT1 L OK"],
|
||||
["ATS AT1 AT+CWLAPOPT=1,4"],
|
||||
"Failed to set LAP option") is False:
|
||||
return
|
||||
|
||||
# step 2. LAP
|
||||
if self.load_and_exe_one_step(["R AT1 A <lap_result>:([[^OK]]+)OK"], # [] is list generator, use [[]] for []
|
||||
["ATS AT1 AT+CWLAP"],
|
||||
"Failed to LAP") is False:
|
||||
return
|
||||
lap_result = self.get_parameter("lap_result")
|
||||
rssi_list = re.findall("CWLAP:\((-\d+)\)", lap_result)
|
||||
if len(rssi_list) > 1:
|
||||
for i in range(len(rssi_list)-1):
|
||||
if int(rssi_list[i]) < int(rssi_list[i+1]):
|
||||
break
|
||||
else:
|
||||
self.result_cntx.set_result("Succeed")
|
||||
else:
|
||||
self.result_cntx.set_result("Succeed")
|
||||
pass
|
||||
|
||||
def result_check(self, port_name, data):
|
||||
TCActionBase.CommonTCActionBase.result_check(self, port_name, data)
|
||||
self.result_cntx.append_data(port_name, data)
|
||||
pass
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
from TCAction import TCActionBase
|
||||
from TCAction import CmdHandler
|
||||
from NativeLog import NativeLog
|
||||
import time
|
||||
import threading
|
||||
import sys
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('iso-8859-1') # # use encoding that with 1 Byte length and contain 256 chars
|
||||
|
||||
|
||||
VALIDATION_STRING = "".join([chr((m+65) % 256) for m in range(256)]) # make it start from 'A'
|
||||
|
||||
|
||||
class ResultCheckCntx(TCActionBase.ResultCheckContext):
|
||||
|
||||
def __init__(self, test_action, test_env, name):
|
||||
TCActionBase.ResultCheckContext.__init__(self, test_action, test_env, name)
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
tx_result = -1
|
||||
rx_result = -1
|
||||
|
||||
while True:
|
||||
exit_flag = self.wait_exit_event(2)
|
||||
# force exit
|
||||
if exit_flag is True:
|
||||
break
|
||||
try:
|
||||
self.lock_data()
|
||||
rx_port = filter(lambda x: x[0] == "AT1", self.data_cache)
|
||||
tx_port = filter(lambda x: x[0] == "SOC2", self.data_cache)
|
||||
finally:
|
||||
self.unlock_data()
|
||||
|
||||
if len(rx_port) == 1:
|
||||
data = rx_port[0][1]
|
||||
rx_result = data.find(VALIDATION_STRING)
|
||||
if len(tx_port) == 1:
|
||||
data = tx_port[0][1]
|
||||
tx_result = data.find(VALIDATION_STRING)
|
||||
|
||||
if tx_result != -1:
|
||||
self.test_action.tx_check_done.set()
|
||||
if rx_result != -1:
|
||||
self.test_action.rx_check_done.set()
|
||||
|
||||
|
||||
class SendDataValidation(TCActionBase.CommonTCActionBase):
|
||||
|
||||
def __init__(self, name, test_env, cmd_set, timeout=30, log_path=TCActionBase.LOG_PATH):
|
||||
TCActionBase.CommonTCActionBase.__init__(self, name, test_env, cmd_set=cmd_set,
|
||||
timeout=timeout, log_path=log_path)
|
||||
# load param from excel
|
||||
for i in range(1, len(cmd_set)):
|
||||
if cmd_set[i][0] != "dummy":
|
||||
cmd_string = "self." + cmd_set[i][0]
|
||||
exec cmd_string
|
||||
self.result_cntx = TCActionBase.ResultCheckContext(self, test_env, self.tc_name)
|
||||
self.timestamp = time.strftime("%d%H%M%S", time.localtime())
|
||||
self.tx_check_done = threading.Event()
|
||||
self.rx_check_done = threading.Event()
|
||||
|
||||
pass
|
||||
|
||||
def execute(self):
|
||||
TCActionBase.TCActionBase.execute(self)
|
||||
self.result_cntx.start()
|
||||
|
||||
try:
|
||||
# configurable params
|
||||
# enable target TCP TX
|
||||
tx_enable = self.tx_enable
|
||||
# enable target TCP RX
|
||||
rx_enable = self.rx_enable
|
||||
# transparent mode select
|
||||
is_transparent_mode = self.is_transparent_mode
|
||||
# configurable params
|
||||
except StandardError, e:
|
||||
NativeLog.add_trace_critical("Error configuration for TCPTransparent script, error is %s" % e)
|
||||
raise StandardError("Error configuration")
|
||||
|
||||
# step1 create PC server
|
||||
checker_stings = ["SOCR SOC_COM L OK"]
|
||||
test_action_string = ["SOC SOC1 LISTEN <test_tcp_port1>"]
|
||||
fail_string = "Fail, Fail on create PC server"
|
||||
if self.load_and_exe_one_step(checker_stings, test_action_string, fail_string) is False:
|
||||
return
|
||||
|
||||
# step2 target connect, switch to transparent
|
||||
checker_stings = ["SOCR SOC1 C +ACCEPT", "ATR AT1 NC CLOSE L OK"]
|
||||
test_action_strings = ["ATC AT1 CIPSTART \"TCP\" <pc_ip> <test_tcp_port1>"]
|
||||
fail_string = "Fail, Fail on connect to PC server"
|
||||
if self.load_and_exe_one_step(checker_stings, test_action_strings, fail_string) is False:
|
||||
return
|
||||
|
||||
checker_stings = ["SOCR SOC_COM L OK"]
|
||||
test_action_strings = ["SOC SOC1 ACCEPT SOC2"]
|
||||
if self.load_and_exe_one_step(checker_stings, test_action_strings, fail_string) is False:
|
||||
return
|
||||
|
||||
# set to transparent mode
|
||||
if is_transparent_mode is True:
|
||||
checker_stings = ["ATR AT1 L OK"]
|
||||
test_action_strings = ["ATS AT1 AT+CIPMODE=1"]
|
||||
if self.load_and_exe_one_step(checker_stings, test_action_strings, fail_string) is False:
|
||||
return
|
||||
|
||||
checker_stings = ["ATR AT1 C >"]
|
||||
test_action_strings = ["ATS AT1 AT+CIPSEND"]
|
||||
if self.load_and_exe_one_step(checker_stings, test_action_strings, fail_string) is False:
|
||||
return
|
||||
else:
|
||||
checker_stings = ["ATR AT1 C >"]
|
||||
test_action_strings = ["ATS AT1 AT+CIPSEND=256"]
|
||||
if self.load_and_exe_one_step(checker_stings, test_action_strings, fail_string) is False:
|
||||
return
|
||||
|
||||
# step 3
|
||||
|
||||
# switch to new result check context
|
||||
self.result_cntx.stop_thread()
|
||||
self.result_cntx.join()
|
||||
self.result_cntx = ResultCheckCntx(self, self.test_env, self.tc_name)
|
||||
self.result_cntx.start()
|
||||
|
||||
# step 3 send data
|
||||
if rx_enable is True:
|
||||
test_action = CmdHandler.parse_action("SOC SOC2 SEND 256", self.test_env)
|
||||
CmdHandler.do_actions(test_action[0], self.test_env)
|
||||
self.rx_check_done.wait(5)
|
||||
if self.rx_check_done.isSet() is False:
|
||||
# rx fail
|
||||
return
|
||||
# flush all data
|
||||
self.result_cntx.data_flush()
|
||||
self.tx_check_done.clear()
|
||||
|
||||
if tx_enable is True:
|
||||
test_action = CmdHandler.parse_action("ATSN AT1 256", self.test_env)
|
||||
CmdHandler.do_actions(test_action[0], self.test_env)
|
||||
self.tx_check_done.wait(5)
|
||||
if self.tx_check_done.isSet() is False:
|
||||
# tx fail
|
||||
return
|
||||
|
||||
# finally, execute done
|
||||
self.result_cntx.set_result("Succeed")
|
||||
|
||||
def result_check(self, port_name, data):
|
||||
TCActionBase.CommonTCActionBase.result_check(self, port_name, data)
|
||||
self.result_cntx.append_data(port_name, data)
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
import socket
|
||||
import serial
|
||||
|
||||
from TCAction import PerformanceTCBase
|
||||
from TCAction import TCActionBase
|
||||
from NativeLog import NativeLog
|
||||
|
||||
|
||||
class UARTTest(PerformanceTCBase.PerformanceTCBase):
|
||||
def __init__(self, name, test_env, cmd_set, timeout=30, log_path=TCActionBase.LOG_PATH):
|
||||
PerformanceTCBase.PerformanceTCBase.__init__(self, name, test_env, cmd_set=cmd_set,
|
||||
timeout=timeout, log_path=log_path)
|
||||
self.test_mode = "command"
|
||||
self.baudrate = None
|
||||
self.bytesize = None
|
||||
self.parity = None
|
||||
self.stopbits = None
|
||||
self.xonxoff = None
|
||||
self.rtscts = None
|
||||
|
||||
# load param from excel
|
||||
for i in range(1, len(cmd_set)):
|
||||
if cmd_set[i][0] != "dummy":
|
||||
cmd_string = "self." + cmd_set[i][0]
|
||||
exec cmd_string
|
||||
self.result_cntx = TCActionBase.ResultCheckContext(self, test_env, self.tc_name)
|
||||
pass
|
||||
|
||||
def cleanup(self):
|
||||
# restore UART config
|
||||
self.restore_serial_port("AT1")
|
||||
PerformanceTCBase.PerformanceTCBase.cleanup(self)
|
||||
|
||||
STOP_BITS = {
|
||||
1: serial.STOPBITS_ONE,
|
||||
2: serial.STOPBITS_ONE_POINT_FIVE,
|
||||
3: serial.STOPBITS_TWO,
|
||||
}
|
||||
BYTE_SIZE = {
|
||||
5: serial.FIVEBITS,
|
||||
6: serial.SIXBITS,
|
||||
7: serial.SEVENBITS,
|
||||
8: serial.EIGHTBITS,
|
||||
}
|
||||
PARITY = {
|
||||
0: serial.PARITY_NONE,
|
||||
1: serial.PARITY_ODD,
|
||||
2: serial.PARITY_EVEN,
|
||||
}
|
||||
RTSCTS = {}
|
||||
|
||||
def config_serial_port(self):
|
||||
port = self.test_env.get_port_by_name("AT1")
|
||||
kwargs = dict()
|
||||
if self.baudrate is not None:
|
||||
kwargs["baudrate"] = self.baudrate
|
||||
if self.bytesize is not None:
|
||||
kwargs["bytesize"] = self.BYTE_SIZE[self.bytesize]
|
||||
if self.parity is not None:
|
||||
kwargs["parity"] = self.PARITY[self.parity]
|
||||
if self.stopbits is not None:
|
||||
kwargs["stopbits"] = self.STOP_BITS[self.stopbits]
|
||||
if self.xonxoff is not None:
|
||||
kwargs["xonxoff"] = self.xonxoff
|
||||
if self.rtscts is not None:
|
||||
kwargs["rtscts"] = self.rtscts
|
||||
NativeLog.add_prompt_trace("[change PC UART config] %s" % kwargs)
|
||||
port.reconfig(**kwargs)
|
||||
|
||||
def send_commands(self):
|
||||
# first change UART config
|
||||
self.config_serial_port()
|
||||
# do send commands
|
||||
for i in range(1, 256):
|
||||
cmd = bytes().join([chr(x % 256) for x in range(i)])
|
||||
try:
|
||||
self.serial_write_line("AT1", cmd)
|
||||
except StandardError, e:
|
||||
NativeLog.add_exception_log(e)
|
||||
pass
|
||||
self.flush_data("AT1")
|
||||
# restore UART config
|
||||
self.restore_serial_port("AT1")
|
||||
|
||||
def send_data(self):
|
||||
# create TCP connection and enter send mode
|
||||
pc_ip = self.get_parameter("pc_ip")
|
||||
tcp_port = self.get_parameter("test_tcp_port1")
|
||||
server_sock = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
|
||||
server_sock.bind((pc_ip, tcp_port))
|
||||
server_sock.settimeout(10)
|
||||
server_sock.listen(5)
|
||||
self.serial_write_line("AT1", "AT+CIPSTART=\"TCP\",\"%s\",%s" % (pc_ip, tcp_port))
|
||||
self.check_response("AT1", "OK")
|
||||
sock, addr = server_sock.accept()
|
||||
server_sock.close()
|
||||
self.serial_write_line("AT1", "AT+CIPSEND=1460")
|
||||
self.check_response("AT1", ">")
|
||||
# change UART config
|
||||
self.config_serial_port()
|
||||
# send data
|
||||
try:
|
||||
self.serial_write("AT1", bytes().join([chr(x % 256) for x in range(146000)]))
|
||||
except StandardError, e:
|
||||
NativeLog.add_exception_log(e)
|
||||
pass
|
||||
sock.send("A"*1460)
|
||||
# restore UART config
|
||||
sock.close()
|
||||
self.restore_serial_port("AT1")
|
||||
|
||||
def pass_through_mode(self):
|
||||
# create TCP connection and enter pass through mode
|
||||
pc_ip = self.get_parameter("pc_ip")
|
||||
tcp_port = self.get_parameter("test_tcp_port1")
|
||||
server_sock = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
|
||||
server_sock.bind((pc_ip, tcp_port))
|
||||
server_sock.settimeout(10)
|
||||
server_sock.listen(5)
|
||||
self.serial_write_line("AT1", "AT+CIPMODE=1")
|
||||
self.check_response("AT1", "OK")
|
||||
self.serial_write_line("AT1", "AT+CIPSTART=\"TCP\",\"%s\",%s" % (pc_ip, tcp_port))
|
||||
self.check_response("AT1", "OK")
|
||||
sock, addr = server_sock.accept()
|
||||
server_sock.close()
|
||||
self.serial_write_line("AT1", "AT+CIPSEND")
|
||||
self.check_response("AT1", ">")
|
||||
# change UART config
|
||||
self.config_serial_port()
|
||||
# send data
|
||||
try:
|
||||
self.serial_write("AT1", bytes().join([chr(x % 256) for x in range(146000)]))
|
||||
except StandardError, e:
|
||||
NativeLog.add_exception_log(e)
|
||||
pass
|
||||
sock.send("A" * 1460)
|
||||
# restore UART config
|
||||
sock.close()
|
||||
self.restore_serial_port("AT1")
|
||||
|
||||
def execute(self):
|
||||
TCActionBase.TCActionBase.execute(self)
|
||||
# test sending command
|
||||
try:
|
||||
if self.test_mode == "command":
|
||||
self.send_commands()
|
||||
elif self.test_mode == "send_data":
|
||||
self.send_data()
|
||||
elif self.test_mode == "pass_through":
|
||||
self.pass_through_mode()
|
||||
else:
|
||||
raise StandardError("test mode not supported: %s" % self.test_mode)
|
||||
self.set_result("Succeed")
|
||||
except StandardError, e:
|
||||
NativeLog.add_exception_log(e)
|
||||
self.set_result("Failed")
|
||||
|
||||
|
||||
def main():
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
__all__ = ["TCPClientMulti", "TCPClientSingle", "TCPServerMulti",
|
||||
"TCPTransparent", "UDPMulti", "UDPSingle"]
|
||||
Reference in New Issue
Block a user