diff --git a/tools/testbed/TBframe.py b/tools/testbed/TBframe.py deleted file mode 100644 index 765629c1ed..0000000000 --- a/tools/testbed/TBframe.py +++ /dev/null @@ -1,144 +0,0 @@ -import hashlib - -DEBUG = False - -CLIENT_DEV = 'CDEV' -ALL_DEV = 'ADEV' -DEVICE_LOG = 'DLOG' -DEVICE_STATUS = 'DSTU' -DEVICE_CMD = 'DCMD' -DEVICE_ERASE = 'DERS' -DEVICE_PROGRAM = 'DPRG' -DEVICE_RESET = 'DRST' -DEVICE_START = 'DSTR' -DEVICE_STOP = 'DSTP' -DEVICE_ALLOC = 'DALC' -LOG_SUB = 'LGSB' -LOG_UNSUB = 'LGUS' -STATUS_SUB = 'STSB' -STATUS_UNSUB = 'STUS' -LOG_DOWNLOAD = 'LGDL' -FILE_BEGIN = 'FBGN' -FILE_DATA = 'FDTA' -FILE_END = 'FEND' -RESPONSE = 'RSPN' -HEARTBEAT = 'HTBT' -TYPE_NONE = 'NONE' -CLIENT_UUID = 'CUID' -CLIENT_TAG = 'CTAG' - -def is_valid_type(type): - #frequently used commands - if type == DEVICE_LOG: - return True - if type == DEVICE_STATUS: - return True - if type == HEARTBEAT: - return True - if type == DEVICE_CMD: - return True - if type == RESPONSE: - return True - if type == DEVICE_ERASE: - return True - if type == DEVICE_PROGRAM: - return True - if type == DEVICE_RESET: - return True - if type == DEVICE_START: - return True - if type == DEVICE_STOP: - return True - #less frequently used commands - if type == CLIENT_DEV: - return True - if type == ALL_DEV: - return True - if type == LOG_SUB: - return True - if type == LOG_UNSUB: - return True - if type == STATUS_SUB: - return True - if type == STATUS_UNSUB: - return True - if type == LOG_DOWNLOAD: - return True - if type == FILE_BEGIN: - return True - if type == FILE_DATA: - return True - if type == FILE_END: - return True - if type == DEVICE_ALLOC: - return True - if type == CLIENT_UUID: - return True - if type == CLIENT_TAG: - return True - return False - -def construct(type, value): - if is_valid_type(type) == False: - return '' - frame = '{' + type + ',' + '{0:04d}'.format(len(value)) + ',' + value + '}' - return frame - -def parse(msg): - sync = False - type = TYPE_NONE - length = 0 - value = '' - while msg != '': - if len(msg) < 12: - type = TYPE_NONE - length = 0 - value = '' - break; - # print msg - for i in range(len(msg)): - if msg[i] != '{': - continue - if (i + 12) > len(msg): - break; - if is_valid_type(msg[i+1: i+5]) == False: - continue - if msg[i + 5] != ',': - continue - if msg[i+6 : i+10].isdigit() == False: - continue - if msg[i+10] != ',': - continue - sync = True - if DEBUG and i > 0: - print "msg:{0}".format(msg) - print "discard:{0}".format(msg[0:i]) - msg = msg[i:] - break - if sync == False: - break - - type = msg[1:5] - length = int(msg[6:10]) - if len(msg) < length + 12: - type = TYPE_NONE - length = 0 - value = '' - break - if msg[length + 11] != '}': - sync = False - if DEBUG: - print msg[0:11],"Lose sync because of FOOTER error" - msg = msg[1:] - continue - value = msg[11:length+11] - msg = msg[length+12:] - break; - return type, length, value, msg - -def hash_of_file(filename): - h = hashlib.sha1() - with open(filename, 'rb', buffering=0) as f: - for b in iter(lambda : f.read(1024), b''): - h.update(b) - return h.hexdigest() diff --git a/tools/testbed/autotest.py b/tools/testbed/autotest.py deleted file mode 100644 index 968e50f115..0000000000 --- a/tools/testbed/autotest.py +++ /dev/null @@ -1,807 +0,0 @@ -#!/usr/bin/python - -import os, sys, time, socket, ssl, traceback, Queue -import subprocess, thread, threading, random, re, errno -from operator import itemgetter -from os import path -import TBframe as pkt -import datetime - -MAX_MSG_LENGTH = 8192 -ENCRYPT = True -DEBUG = True - -class ConnectionLost(Exception): - pass - -class Autotest: - def __init__(self): - self.keep_running = True - self.device_list= {} - self.service_socket = 0 - self.connected = False - self.output_queue = Queue.Queue(256) - self.response_queue = Queue.Queue(256) - self.subscribed = {} - self.subscribed_reverse = {} - self.filter = {} - self.filter_lock = threading.RLock() - self.filter_event = threading.Event() - self.filter_event.set() - self.esc_seq = re.compile(r'\x1b[^m]*m') - self.poll_str = '\x1b[t' - bytes = os.urandom(4) - for byte in bytes: - self.poll_str += '{0:02x}'.format(ord(byte)) - self.poll_str += 'm' - - def packet_send_thread(self): - heartbeat_timeout = time.time() + 10 - while self.keep_running: - try: - [type, content] = self.output_queue.get(block=True, timeout=0.1) - except Queue.Empty: - type = None - pass - if self.service_socket == None: - continue - if type == None: - if time.time() < heartbeat_timeout: - continue - heartbeat_timeout += 10 - data = pkt.construct(pkt.HEARTBEAT,'') - else: - data = pkt.construct(type, content) - try: - self.service_socket.send(data) - except: - self.connected = False - continue - - def send_packet(self, type, content, timeout=0.1): - if self.service_socket == None: - return False - try: - self.output_queue.put([type, content], True, timeout) - return True - except Queue.Full: - print 'error: output buffer full, drop packet [{0} {1}]'.format(type, content) - return False - - def get_devname_by_devstr(self, devstr): - if devstr in list(self.subscribed_reverse): - return self.subscribed_reverse[devstr] - return "" - - def response_filter(self, devname, logstr): - if self.filter_event.is_set() == True: - return - - if self.filter_lock.acquire(False) == False: - return - - try: - if len(self.filter) == 0: - self.filter_lock.release() - return - - if self.filter['devname'] != devname: - self.filter_lock.release() - return - - if self.filter['cmdstr'] != self.poll_str and self.poll_str not in logstr: - self.filter_lock.release() - return - - logstr = logstr.replace(self.poll_str, '') - - if self.filter['lines_exp'] == 0: - if self.filter['cmdstr'] in logstr: - self.filter['lines_num'] += 1 - self.filter_event.set() - else: - if self.filter['lines_num'] == 0: - if self.filter['cmdstr'] in logstr: - self.filter['lines_num'] += 1 - elif self.filter['lines_num'] <= self.filter['lines_exp']: - log = self.esc_seq.sub('', logstr) - log = log.replace("\r", "") - log = log.replace("\n", "") - if log != "": - for filterstr in self.filter['filters']: - if filterstr not in log: - continue - else: - self.filter['response'].append(log) - self.filter['lines_num'] += 1 - break - if self.filter['lines_num'] > self.filter['lines_exp']: - self.filter_event.set() - self.filter_lock.release() - except: - if DEBUG: traceback.print_exc() - self.filter_lock.release() - - def connect_to_server(self, server_ip, server_port): - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - if ENCRYPT: - certfile = path.join(path.dirname(path.abspath(__file__)), 'certificate.pem') - sock = ssl.wrap_socket(sock, cert_reqs=ssl.CERT_REQUIRED, ca_certs=certfile) - try: - sock.connect((server_ip, server_port)) - self.service_socket = sock - self.connected = True - return "success" - except: - return "fail" - - def server_interaction(self): - msg = '' - while self.keep_running: - try: - if self.connected == False: - raise ConnectionLost - - new_msg = self.service_socket.recv(MAX_MSG_LENGTH) - if new_msg == '': - raise ConnectionLost - break - - msg += new_msg - while msg != '': - type, length, value, msg = pkt.parse(msg) - if type == pkt.TYPE_NONE: - break - - #print type, length - if type == pkt.ALL_DEV: - new_list = {} - clients = value.split(':') - for c in clients: - if c == '': - continue - devs = c.split(',') - uuid = devs[0] - devs = devs[1:] - for d in devs: - if d == '': - continue - [dev, using] = d.split('|') - new_list[uuid + ',' + dev] = using - - for dev in list(new_list): - self.device_list[dev] = new_list[dev] - continue - if type == pkt.DEVICE_LOG: - dev = value.split(':')[0] - logtime = value.split(':')[1] - log = value[len(dev) + 1 + len(logtime) + 1:] - try: - logtime = float(logtime) - logtimestr = time.strftime("%Y-%m-%d %H-%M-%S", time.localtime(logtime)); - logtimestr += ("{0:.3f}".format(logtime-int(logtime)))[1:] - except: - continue - if dev not in list(self.device_list): - continue - devname = self.get_devname_by_devstr(dev) - if devname != "": - self.response_filter(devname, log) - if self.logfile != None: - log = logtimestr + ":" + devname + ":" + log - self.logfile.write(log) - continue - if type == pkt.RESPONSE: - type = value.split(',')[0] - value = value[len(type) + 1:] - try: - self.response_queue.put([type, value], False) - except: - pass - continue - except ConnectionLost: - self.connected = False - self.service_socket.close() - print 'connection to server lost, try reconnecting...' - while True: - result = self.connect_to_server(self.server_ip, self.server_port) - if result == 'success': - break - time.sleep(2) - print 'connection to server resumed' - random.seed() - time.sleep(1.2 + random.random()) - for devname in self.subscribed: - self.send_packet(pkt.LOG_SUB, self.subscribed[devname]) - self.send_packet(pkt.DEVICE_CMD, self.subscribed[devname] + ':help') - except socket.error as e: - if e.errno == errno.ECONNRESET: - print 'Warning: connection closed by server' - self.connected = False - continue - if DEBUG:traceback.print_exc() - break - except: - if DEBUG: traceback.print_exc() - break - self.keep_running = False; - - def wait_cmd_response(self, type, timeout): - while self.response_queue.empty() == False: - self.response_queue.get() - response = None - start = time.time() - while True: - try: - item = self.response_queue.get(False) - except: - item = None - if time.time() - start >= timeout: - break - if item == None: - time.sleep(0.01) - continue - if item[0] == type: - response = item[1] - break - return response - - def get_devstr_by_partialstr(self, partialstr): - devices = list(self.device_list) - devices.sort() - for devstr in devices: - if partialstr in devstr: - return devstr - return "" - - def send_file_to_client(self, devname, filepath): - #argument check - if devname not in self.subscribed: - print "{0} is not subscribed".format(devname) - return False - try: - expandfilepath = path.expanduser(filepath) - except: - print "{0} does not exist".format(filepath) - return False - if path.exists(expandfilepath) == False: - print "{0} does not exist".format(filepath) - return False - filepath = expandfilepath - - filehash = pkt.hash_of_file(filepath) - devstr = self.subscribed[devname] - - #send file begin - content = devstr + ':' + filehash + ':' + path.basename(filepath) - retry = 4 - while retry > 0: - self.send_packet(pkt.FILE_BEGIN, content) - response = self.wait_cmd_response(pkt.FILE_BEGIN, 0.6) - if response == None: #timeout - retry -= 1; - continue - if response == 'busy': - print "file transfer busy: wait..." - time.sleep(5) - continue - elif response == 'ok' or response == 'exist': - break - else: - print "file transfer error: unexpected response '{0}'".format(response) - return False - if retry == 0: - print 'file transfer error: retry timeout' - return False - if response == 'exist': - return True - - #send file data - seq = 0 - file = open(filepath,'r') - header = devstr + ':' + filehash + ':' + str(seq) + ':' - content = file.read(1024) - while(content): - retry = 4 - while retry > 0: - self.send_packet(pkt.FILE_DATA, header + content) - response = self.wait_cmd_response(pkt.FILE_DATA, 0.6) - if response == None: #timeout - retry -= 1; - continue - elif response != 'ok': - print('send data fragement {0} failed, error: {1}'.format(header, response)) - file.close() - return False - break - - if retry == 0: - file.close() - return False - - seq += 1 - header = devstr + ':' + filehash + ':' + str(seq) + ':' - content = file.read(1024) - file.close() - - #send file end - content = devstr + ':' + filehash + ':' + path.basename(filepath) - retry = 4 - while retry > 0: - self.send_packet(pkt.FILE_END, content) - response = self.wait_cmd_response(pkt.FILE_END, 0.6) - if response == None: #timeout - retry -= 1; - continue - elif response != 'ok': - print('send file failed, error: {0}'.format(response)) - return False - break - if retry == 0: - return False - return True - - def device_allocate(self, model, number, timeout, purpose='general', reserve='yes'): - """ request server to allocte free/ilde devices to do autotest - - arguments: - model : device model, example: 'mk3060', 'esp32' - number : number of devices to allocate - timeout: time (seconds) to wait before timeout - purpose: specify test purpose, example: 'alink' - - return: allocated device list; empty list if failed - """ - if self.connected == False: - return [] - content = ','.join([model, str(number), purpose, reserve]) - allocated = [] - timeout += time.time() - while time.time() < timeout: - self.send_packet(pkt.DEVICE_ALLOC, content) - response = self.wait_cmd_response(pkt.DEVICE_ALLOC, 0.8) - if response == None: #timeout - time.sleep(8) - continue - values = response.split(',') - if len(values) != 2: - print 'error: illegal allocate reponse - {0}'.format(response) - break - result = values[0] - allocated = values[1].split('|') - if result != 'success': #failed - allocated = [] - time.sleep(8) - continue - if len(allocated) != number: - print "error: allocated number does not equal requested" - allocated = [] - break - return allocated - - def device_subscribe(self, devices): - """ unsubscribe to devices, thus start receiving log from these devices - - arguments: - devices : the list of devices to subscribe - - return: Ture - succeed; False - failed - """ - if self.connected == False: - return False - for devname in list(devices): - devstr = self.get_devstr_by_partialstr(devices[devname]) - if devstr == "": - self.subscribed = {} - self.subscribed_reverse = {} - return False - else: - self.subscribed[devname] = devstr; - self.subscribed_reverse[devstr] = devname - for devname in devices: - self.send_packet(pkt.LOG_SUB, self.subscribed[devname]) - return True - - def device_unsubscribe(self, devices): - """ unsubscribe to devices, thus stop receiving log from these devices - - arguments: - devices : the list of devices to unsubscribe - - return: None - """ - for devname in list(devices): - if devname not in self.subscribed: - continue - self.send_packet(pkt.LOG_UNSUB, self.subscribed[devname]) - self.subscribed_reverse.pop(self.subscribed[devname]) - self.subscribed.pop(devname) - - def device_erase(self, devname): - """ erase device - - arguments: - devname : the device to be erased - - return: Ture - succeed; False - failed - """ - if self.connected == False: - return False - if devname not in self.subscribed: - print "error: device {0} not subscribed".format(devname) - return False - content = self.subscribed[devname] - self.send_packet(pkt.DEVICE_ERASE, content); - response = self.wait_cmd_response(pkt.DEVICE_ERASE, 120) - if response == "success": - ret = True - else: - ret = False - return ret - - def device_program(self, devname, address, filepath): - """ program device with a firmware file - - arguments: - devname : the device to be programmed - address : start address write the firware(in hex format), example: '0x13200' - filepath: firmware file path, only bin file is supported right now - - return: Ture - succeed; False - failed - """ - if self.connected == False: - return False - if devname not in self.subscribed: - print "error: device {0} not subscribed".format(devname) - return False - if address.startswith('0x') == False: - print "error: wrong address input {0}, address should start with 0x".format(address) - return False - try: - expandname = path.expanduser(filepath) - except: - print "{0} does not exist".format(filepath) - return False - if path.exists(expandname) == False: - print "{0} does not exist".format(filepath) - return False - - retry = 3 - while retry: - if self.send_file_to_client(devname, expandname) == False: - retry -= 1 - time.sleep(5) - else: - break - if retry == 0: - return False - - filehash = pkt.hash_of_file(expandname) - content = self.subscribed[devname] + ',' + address + ',' + filehash - self.send_packet(pkt.DEVICE_PROGRAM, content); - elapsed_time = time.time() - response = self.wait_cmd_response(pkt.DEVICE_PROGRAM, 270) - if response == "success": - ret = True - else: - ret = False - elapsed_time = time.time() - elapsed_time - print "Programming device {0} finished in {1:0.1f}S, result:{2}".format(devname, elapsed_time, ret==True and 'succeed' or 'failed') - return ret - - def device_control(self, devname, operation): - """ control device - - arguments: - operation : the control operation, which can be 'start', 'stop' or 'reset' - note: some device may not support 'start'/'stop' operation - - return: Ture - succeed; False - failed - """ - operations = {"start":pkt.DEVICE_START, "stop":pkt.DEVICE_STOP, "reset":pkt.DEVICE_RESET} - - if self.connected == False: - return False - if devname not in self.subscribed: - return False - if operation not in list(operations): - return False - - content = self.subscribed[devname] - self.send_packet(operations[operation], content) - response = self.wait_cmd_response(operations[operation], 10) - if response == "success": - return True - else: - return False - - def device_run_cmd(self, devname, args, response_lines = 0, timeout=0.8, filters=[""]): - """ run command at device - - arguments: - devname : the device to run command - args : command arguments, example: 'netmgr connect wifi_ssid wifi_passwd' - response_lines: number of response lines to wait for, default to 0 (do not wait response) - timeout : time (seconds) before wait reponses timeout, default to 0.8S - filter : filter applied to response, only response line containing filter item will be returned - by default, filter=[""] will match any response line - - return: list containing filtered responses - """ - - if self.connected == False: - return False - if devname not in self.subscribed: - return False - if len(args) == 0: - return False - content = self.subscribed[devname] - content += ':' + self.poll_str + args.replace(' ', '|') - with self.filter_lock: - self.filter['devname'] = devname - self.filter['cmdstr'] = args - self.filter['lines_exp'] = response_lines - self.filter['lines_num'] = 0 - self.filter['filters'] = filters - self.filter['response'] = [] - - retry = 3 - while retry > 0: - self.send_packet(pkt.DEVICE_CMD, content) - self.filter_event.clear() - self.filter_event.wait(timeout) - if self.filter['lines_num'] > 0: - break; - retry -= 1 - response = self.filter['response'] - with self.filter_lock: - self.filter = {} - return response - - def device_read_log(self, devname, lines, timeout=1, filters=[""]): - """ read device log ouput - - arguments: - devname : the device to read output from - response_lines: number of response lines to read - timeout : time (seconds) to wait before timeout, default to 1S - filter : filter applied to response, only log line containing filter item will be returned - by default, filter=[""] will match any response line - - return: list containing log lines - """ - - if self.connected == False: - return False - if devname not in self.subscribed: - return False - if lines <= 0: - return False - with self.filter_lock: - self.filter['devname'] = devname - self.filter['cmdstr'] = self.poll_str - self.filter['lines_exp'] = lines - self.filter['lines_num'] = 1 - self.filter['filters'] = filters - self.filter['response'] = [] - - self.filter_event.clear() - self.filter_event.wait(timeout) - response = self.filter['response'] - with self.filter_lock: - self.filter = {} - return response - - def start(self, server_ip, server_port, logname=None): - """ start Autotest moudle, establish connnection to server - - arguments: - server_ip : server ip/hostname to connect - server_port: server TCP port number to connect - logname : log file name(log saved at ./test/logname); logname=None means do not save log - - return: Ture - succeed; False - failed - """ - - self.server_ip = server_ip - self.server_port = server_port - result = self.connect_to_server(server_ip, server_port) - if result != 'success': - print "connect to server {0}:{1} failed".format(server_ip, server_port) - return False - - self.connected = True - self.logfile = None - if logname != None: - if path.exists('testlog') == False: - subprocess.call(['mkdir','testlog']) - - try: - self.logfile = open("testlog/"+logname, 'w'); - except: - print "open logfile {0} failed".format(logfile) - return False - - thread.start_new_thread(self.packet_send_thread, ()) - thread.start_new_thread(self.server_interaction, ()) - time.sleep(0.5) - return True - - def stop(self): - """ stop Autotest moudle, disconnect server and clean up - - return: Ture - succeed; False - failed - """ - - self.keep_running = False - time.sleep(0.2) - if self.connected: - self.service_socket.close() - if self.logfile != None: - self.logfile.close() - self.logfile = None - -class Testcase: - models = { - 'mk3060':'0x13200', - 'esp32':'0x10000', - 'stm32f429':'0x8000000', - 'stm32l432':'0x8000000', - 'stm32l475':'0x8000000', - 'stm32f103':'0x8000000', - 'stm32f091':'0x8000000', - 'starterkit':'0x8000000', - 'developerkit':'0x8000000', - 'esp8266': '0x1000', - 'lpc54018':'0x10000000', - 'lpc54102':'0x0', - 'lpc54114':'0x0', - 'lpc54628':'0x0', - 'nrf52832':'0x0', - 'atsaml21j18' :'0x0', - 'w600':'0x0', - 'mimxrt1052xxxxb':'0x60080000', - 'gd32f350rb':'0x8000000', - 'gd32f307vc':'0x8000000', - 'gd32f450zk':'0x8000000', - 'atsame54p20':'0x0', - 'mk3080':'0x19000', - 'nrf52832_xxaa':'0x0', - 'sv6266':'0x0', - 'csky':'0x10010800', - 'xr871':'0x0', - } - - ap_ssid = 'aos_test_01' - ap_pass = 'Alios@Embedded' - server = '11.238.148.46' - port = 34568 - model = 'unknown' - firmware = None - at=Autotest() - - def __init__(self, testname='default', argv=None): - if argv == None: - argv = sys.argv - self.parse_args(argv) - - now=time.strftime('%Y-%m-%d_%H-%M-%S') - self.logname = '{}@{}@{}.log'.format(testname, self.model, now) - - def parse_args(self, argv): - #parse input - i = 1 - while i < len(argv): - arg = sys.argv[i] - if arg.startswith('--firmware='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --firmware=firmware.bin'.format(arg) - self.firmware = args[1] - elif arg.startswith('--model='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --model=mk3060'.format(arg) - self.model = args[1] - elif arg.startswith('--server='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --server=192.168.10.16'.format(arg) - return [1, 'argument {0} error'.format(arg)] - self.server = args[1] - elif arg.startswith('--port='): - args = arg.split('=') - if len(args) != 2 or args[1].isdigit() == False: - print 'wrong argument {0} input, example: --port=34568'.format(arg) - return [1, 'argument {0} error'.format(arg)] - self.port = int(args[1]) - elif arg.startswith('--wifissid='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --wifissid=test_wifi'.format(arg) - self.ap_ssid = args[1] - elif arg.startswith('--wifipass='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --wifipass=test_password'.format(arg) - self.ap_pass = args[1] - elif arg=='--help': - print 'Usage: python {0} [--firmware=xxx.bin] [--wifissid=wifi_ssid] [--wifipass=password]'.format(sys.argv[0]) - return [0, 'help'] - i += 1 - - def start(self, number, purpose): - at = self.at - model = self.model - server = self.server - port = self.port - firmware = self.firmware - - if model not in self.models: - print "error: unsupported model {}".format(repr(model)) - return [1, 'unsupported model'] - - if at.start(server, port, self.logname) == False: - return [1, 'connect testbed failed'] - - #request device allocation - timeout = 10 - allocated = at.device_allocate(model, number, timeout, purpose) - if len(allocated) != number: - return [1, 'allocate device failed'] - devices={} #construct device list - for i in range(len(allocated)): - devices[chr(ord('A') + i)] = allocated[i] - print 'allocated:' - for device in sorted(list(devices)): - print ' {}: {}'.format(device, devices[device]) - - #subscribe - result = at.device_subscribe(devices) - if result == False: - print 'subscribe devices failed' - return [1, 'subscribe devices failed'] - - #reboot to capture the device (prevent others use it) - for device in sorted(list(devices)): - at.device_control(device, 'reset') - - #program devices - device_list = sorted(list(devices)) - address = self.models[model] - for device in device_list: - result = at.device_program(device, address, firmware) - self.app_start_time = time.time() - if result == False: - print 'program device failed' - return [1, 'program device failed'] - print 'program succeed' - return [0, 'succeed'] - - def stop(self): - self.at.stop() - - def get_model(self): - return self.model - - def get_firmware(self): - return self.firmware - - def get_log(self): - flog = open('testlog/' + self.logname, 'r') - return flog - - def dump_log(self): - flog = open('testlog/' + self.logname, 'r') - for line in flog: - try: - logtime = line.split(':')[0] - sec_int, sec_frac = logtime.split('.') - sec_int = time.mktime(time.strptime(sec_int, "%Y-%m-%d %H-%M-%S")) - sec_frac = float('0.' + sec_frac) - logtime = sec_int + sec_frac - if logtime >= self.app_start_time: - print line, - except: - print line, - flog.close() diff --git a/tools/testbed/certificate.pem b/tools/testbed/certificate.pem deleted file mode 100644 index b7a4db2118..0000000000 --- a/tools/testbed/certificate.pem +++ /dev/null @@ -1,24 +0,0 @@ ------BEGIN CERTIFICATE----- -MIID+zCCAuOgAwIBAgIJAPZBa3DV/8GqMA0GCSqGSIb3DQEBCwUAMIGTMQswCQYD -VQQGEwJDTjERMA8GA1UECAwIWmhlamlhbmcxETAPBgNVBAcMCEhhbmd6aG91MRUw -EwYDVQQKDAxBbGliYWJhIEluYy4xDDAKBgNVBAsMA0lvVDEQMA4GA1UEAwwHVGVz -dGJlZDEnMCUGCSqGSIb3DQEJARYYbGMxMjI3OThAYWxpYmFiYS1pbmMuY29tMB4X -DTE5MDMyMDA4MTkxNloXDTI0MDMxODA4MTkxNlowgZMxCzAJBgNVBAYTAkNOMREw -DwYDVQQIDAhaaGVqaWFuZzERMA8GA1UEBwwISGFuZ3pob3UxFTATBgNVBAoMDEFs -aWJhYmEgSW5jLjEMMAoGA1UECwwDSW9UMRAwDgYDVQQDDAdUZXN0YmVkMScwJQYJ -KoZIhvcNAQkBFhhsYzEyMjc5OEBhbGliYWJhLWluYy5jb20wggEiMA0GCSqGSIb3 -DQEBAQUAA4IBDwAwggEKAoIBAQCqM63srvw440V9THSjqh0npHxJ3enjFqY1/N8d -0ybiT9Upbzj2qSdvnrqriq48vKAHMYqLdObPY6x42qEKqPKFTFMTx2msdlCWgLHR -h0qIYH7JCXTHBZCqWbr3rK1+2dARq1GfQM2jyfBhqpQ432R/XtQr5AzuV6sEtM2I -IXH4J/XvADeOVZq8kEniU2o9yT0rus2N/iM6XfMzRS7derjlXh73rO2RJIwps5D6 -t8/mpXa5ZJ3PjnymAn2C79eNghiMR8t6DjiC9i4bMTXPSbqc+2q1YCVIr9XED4uC -S8Mri/1IRIi968/fyOZbfj5+Sh1ZoYOiT7USrNlBavrRyI7TAgMBAAGjUDBOMB0G -A1UdDgQWBBRdS8VX6QoBfl57PLHmIxwCL6DxPzAfBgNVHSMEGDAWgBRdS8VX6QoB -fl57PLHmIxwCL6DxPzAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAq -rulGlR+lAtRyCfX1N6cYBxkyc7S5kvLtp9nTO99S2qpsSoJhFtuKKR0POuxHkZUD -CT2EFz8gm51u9GTODDfqXL1Pg1Rgfh7TSBzjs9xyFu3lX4397xt86I+O4L7BUgQk -b5nl98e3f+Gc+7QqE4JS/GGLsEkgE3drZSufV+nHMuD0XXI2RMTIR1cyE252JQnQ -ncAu7gztLLB17+wKB884PQyNFU+Xftea4qK3jDHGg9nQ4j+GlB3k9Ug+f4xG+DYq -AhZIOqcp1tj36Imi7Lm1W8ldXdr9/WrV3gdUsJptUM02uvoJVrGBAEqWdf4EgMgU -9gTcS8mv6LlDBHXiM5l/ ------END CERTIFICATE----- diff --git a/tools/testbed/testscripts/TBframe.py b/tools/testbed/testscripts/TBframe.py deleted file mode 120000 index d4b4f24ee0..0000000000 --- a/tools/testbed/testscripts/TBframe.py +++ /dev/null @@ -1 +0,0 @@ -../TBframe.py \ No newline at end of file diff --git a/tools/testbed/testscripts/acapp_test.py b/tools/testbed/testscripts/acapp_test.py deleted file mode 100644 index a20fb047ca..0000000000 --- a/tools/testbed/testscripts/acapp_test.py +++ /dev/null @@ -1,38 +0,0 @@ -import os, sys, time -from autotest import Testcase - -required_devices = [ [1, 'general'] ] - -def main(firmware='acapp@mk3060-general.bin', model='mk3060'): - tc = Testcase('activation') - at = tc.at - - number, purpose = required_devices[0] - [ret, result] = tc.start(number, purpose) - if ret != 0: - tc.stop() - print '\nactivation test failed' - return [ret, result] - - keyword_filter = ['version_verify result:'] - number_of_responses = 1 - timeout = 20 - response = at.device_read_log('A', number_of_responses, timeout, keyword_filter) - - tc.stop() - - ret = 0; result = 'succeed' - if len(response) < number_of_responses or 'successed' not in response[0]: - print 'response:', repr(response) - ret = 1; result = 'failed' - - print '\nlogs:' - tc.dump_log() - - print '\nactivation test {}'.format(result) - - return [ret, result] - -if __name__ == '__main__': - [code, msg] = main() - sys.exit(code) diff --git a/tools/testbed/testscripts/autotest.py b/tools/testbed/testscripts/autotest.py deleted file mode 120000 index 2bdc4f8475..0000000000 --- a/tools/testbed/testscripts/autotest.py +++ /dev/null @@ -1 +0,0 @@ -../autotest.py \ No newline at end of file diff --git a/tools/testbed/testscripts/autoywss.cfg b/tools/testbed/testscripts/autoywss.cfg deleted file mode 100644 index 1f974404c7..0000000000 --- a/tools/testbed/testscripts/autoywss.cfg +++ /dev/null @@ -1,2 +0,0 @@ -#TC_ID(default) PHONE_DID PHONE_MODEL AP_MODEL AP_SSID AP_PASSWD -01, 66d755617d42, Xiamo Redmi HM Note2, test, Yuemewifi-3766, aos12345 diff --git a/tools/testbed/testscripts/autoywss.py b/tools/testbed/testscripts/autoywss.py deleted file mode 100644 index 91718e6c39..0000000000 --- a/tools/testbed/testscripts/autoywss.py +++ /dev/null @@ -1,521 +0,0 @@ -#!/usr/bin/python - -# -*- coding:utf-8 -*- - - -import os -import sys -import optparse -import time -import threading -import os, sys, time -from autotest import Autotest - - - -required_devices = [ [1, 'ywss'] ] -models = { - 'mk3060':'0x13200', - 'esp32':'0x10000', - 'esp8266': '0x1000', - 'starterkit': '0x8000000', - 'developerkit': '0x8000000' -} - - - -class LogMonitor(threading.Thread): - def __init__(self, phone_id, start_time_str): - threading.Thread.__init__(self) - self.phone_id = phone_id - self.start_time_str = start_time_str - - def run(self): - os.popen("adb -s " + self.phone_id + " logcat -c") - log_name = "wifi_connect_test_adb_log_" + self.phone_id + "_" + self.start_time_str + ".txt" - logcat_cmd = "adb -s " + self.phone_id + " logcat -v threadtime >> " + log_name - os.popen(logcat_cmd) - - - -def para_proc(log_file): - global IOT_DEVICE_INFO - global IOT_DEVICE_NAME - global BAUD_RATE - global TOTAL_COUNT - global TEST_CASE_LIST - global DEVICE_MODEL - global FIRMWARE # image to program onto device - global TEST_CASE_ID_LIST - TEST_CASE_ID_LIST = [] - global PHONE_DEVICE_ID_LIST - PHONE_DEVICE_ID_LIST = [] - global PHONE_MODEL_LIST - PHONE_MODEL_LIST = [] - global ACCESS_POINT_MODEL_LIST - ACCESS_POINT_MODEL_LIST = [] - global WIFI_SSID_LIST - WIFI_SSID_LIST = [] - global WIFI_PASSWORD_LIST - WIFI_PASSWORD_LIST = [] - - parser = optparse.OptionParser() - - parser.add_option('-i', '--iot-device-info', dest='IOT_DEVICE_INFO', default='IoTDevice', help='IoT Device Information') - parser.add_option('-n', '--iot-device-name', dest='IOT_DEVICE_NAME', default='VNHU6iQgPaBybZTSYQLN', help='IoT Device Name') - parser.add_option('-b', '--baud-rate', dest='BAUD_RATE', default=921600, help='IoT Device Baud Rate') - parser.add_option('-c', '--total-count', dest='TOTAL_COUNT', default=3, help='Total Wifi Connect Test Times') - parser.add_option('-t', '--test-case-list', dest='TEST_CASE_LIST', default='all', help='Test Case List') - parser.add_option('-m', '--model', dest='DEVICE_MODEL', default='mk3060', help='Device model') - parser.add_option('-f', '--firmware', dest='FIRMWARE', default='linkkitapp@mk3060-autoywss.bin', help='Firmware image to program onto device') - - (options, args) = parser.parse_args() - - try: - IOT_DEVICE_INFO = options.IOT_DEVICE_INFO - IOT_DEVICE_NAME = options.IOT_DEVICE_NAME - BAUD_RATE = (int) (options.BAUD_RATE) - TOTAL_COUNT = (int) (options.TOTAL_COUNT) - TEST_CASE_LIST = options.TEST_CASE_LIST.split(',') - DEVICE_MODEL = options.DEVICE_MODEL - FIRMWARE = options.FIRMWARE - except Exception as e: - print('invalid argument:{}'.format(e)) - sys.exit(1) - - try: - cfg_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'autoywss.cfg') - testbed_cfg_file = open(cfg_file_path, "r") - testbed_cfg_file_content = testbed_cfg_file.readlines() - - for test_case_index in range(0, len(TEST_CASE_LIST)): - for line in range(0, len(testbed_cfg_file_content)): - if testbed_cfg_file_content[line][0] == "#": - continue - else: - test_case_item_list = testbed_cfg_file_content[line].split(",") - if len(test_case_item_list) < 6: - continue - else: - if test_case_item_list[0].strip() == TEST_CASE_LIST[test_case_index].strip() or \ - "all" == TEST_CASE_LIST[test_case_index].strip(): - TEST_CASE_ID_LIST.append(test_case_item_list[0].strip()) - PHONE_DEVICE_ID_LIST.append(test_case_item_list[1].strip()) - PHONE_MODEL_LIST.append(test_case_item_list[2].strip()) - ACCESS_POINT_MODEL_LIST.append(test_case_item_list[3].strip()) - WIFI_SSID_LIST.append(test_case_item_list[4].strip()) - WIFI_PASSWORD_LIST.append(test_case_item_list[5].strip()) - print_write(log_file, testbed_cfg_file_content[line]) - - testbed_cfg_file.close() - except Exception as e: - print('Exception: {}'.format(e)) - sys.exit(1) - - - -def print_write(file_pointer, str): - print(str) - file_pointer.write(str) - file_pointer.flush() - - - -def device_reset(at, log_file): - global reset_success_count - - #my_serial.write_cmd_async("reset") - at.device_run_cmd('A', 'reset') - print_write(log_file, "Device to reset: reset\n") - - is_reset_finish = False - time_out_stamp = time.time() + 10 - while True: - tmp_reset_success_count = 0 - iot_device_file = open("./testlog/" + logname, "r") - iot_device_file_content = iot_device_file.readlines() - for line in range(0, len(iot_device_file_content)): - if "SSID cleared. Please reboot the system" in iot_device_file_content[line]: - tmp_reset_success_count += 1 - if tmp_reset_success_count > reset_success_count: - is_reset_finish = True - reset_success_count += 1 - print_write(log_file, "reset device succeed.\n") - break - iot_device_file.close() - - if time.time() > time_out_stamp: - print_write(log_file, "No reset success log found\n") - break - - if is_reset_finish: - time.sleep(5) - print_write(log_file, "Compete 5s wait after reset\n") - break - else: - time.sleep(0.5) - - - -def device_active_awss(at, log_file): - global active_awss_success_count - - at.device_run_cmd('A', "active_awss") - print_write(log_file, "Device into awss mode: active_awss\n") - - is_active_awss_finish = False - time_out_stamp = time.time() + 10 - while True: - tmp_active_awss_success_count = 0 - iot_device_file = open("./testlog/" + logname, "r") - iot_device_file_content = iot_device_file.readlines() - for line in range(0, len(iot_device_file_content)): - if "do_awss_active" in iot_device_file_content[line]: - tmp_active_awss_success_count += 1 - if tmp_active_awss_success_count > active_awss_success_count: - is_active_awss_finish = True - active_awss_success_count += 1 - print_write(log_file, "active awss succeed.\n") - break - iot_device_file.close() - - if time.time() > time_out_stamp: - print_write(log_file, "Device failed to find entering awss mode success log,\n") - break - - if is_active_awss_finish: - time.sleep(5) - print_write(log_file, "Complete 5s wait for awss_active\n") - break - else: - time.sleep(0.5) - - - -def app_init_wait(logcat_file_name, num): - global app_init_count - is_init_finish = False - app_init_result = False - time_out_stamp = time.time() + 90 - while True: - app_init_times = 0 - logcat_file = open(logcat_file_name, "r") - logcat_file_content = logcat_file.readlines() - for line in range(0, len(logcat_file_content)): - if "AWSS_CFG,mode:" in logcat_file_content[line]: - app_init_times += 1 - if "AWSS_RESULT, ready to start" in logcat_file_content[line] and app_init_times > app_init_count: - print_write(log_file, "App init succeed\n") - app_init_result = True - is_init_finish = True - break - if "AWSS_RESULT, exit deviceadd activity" in logcat_file_content[line] and app_init_times > app_init_count: - print_write(log_file, "APP init failed\n") - app_init_result = False - is_init_finish = True - break - logcat_file.close() - - if time.time() > time_out_stamp: - print_write(log_file, "APP init timeout\n") - break - - if is_init_finish: - break - else: - time.sleep(0.5) - app_init_count = app_init_times - - return app_init_result - - - -def app_connect_wait(logcat_file_name, num): - global app_init_count - global connect_test_success_count - is_connect_finish = False - connect_result = False - time_out_stamp = time.time() + 90 - while True: - connect_times = 0 - logcat_file = open(logcat_file_name, "r") - logcat_file_content = logcat_file.readlines() - for line in range(0, len(logcat_file_content)): - if "AWSS_CFG,mode:" in logcat_file_content[line]: - connect_times += 1 - if "AWSS_RESULT, bind success" in logcat_file_content[line] and connect_times >= app_init_count: - connect_result = True - is_connect_finish = True - connect_test_success_count += 1 - print_write(log_file, "Smart config succeed\n") - print_write(log_file, "Finished " + str(num + 1) + " times smart config test, of which " + str(connect_test_success_count) + " times succeed\n") - break - if "AWSS_RESULT, exit deviceadd activity" in logcat_file_content[line] and connect_times >= app_init_count: - connect_result = False - is_connect_finish = True - print_write(log_file, "Smart config failed\n") - print_write(log_file, "Finished " + str(num + 1) + " times smart config test, of which " + str(connect_test_success_count) + " times succeed\n") - break - logcat_file.close() - - if time.time() > time_out_stamp: - print_write(log_file, "90s timeout reached\n") - print_write(log_file, "Finished " + str(num + 1) + " times smart config, of which " + str(connect_test_success_count) + " times succeed\n") - break - - if is_connect_finish: - break - else: - time.sleep(0.5) - - - -def allocate_and_program_device(): - #request device allocation - number, purpose = required_devices[0] - timeout = 10 - allocated = at.device_allocate(str(DEVICE_MODEL), number, timeout, purpose) - if len(allocated) != number: - return 1 - - devices={'A':allocated[0]} #construct device list - print 'allocated:' - for device in devices: - print ' {}: {}'.format(device, devices[device]) - - #subscribe and reboot devices - result = at.device_subscribe(devices) - if result == False: - print 'subscribe devices failed' - return 1 - at.device_control('A', 'reset') #reboot to capture the device (prevent others use it) - - #program devices - device_list = list(devices) - device_list.sort() - dmodel = str(DEVICE_MODEL) - address = models[dmodel] - for device in device_list: - if dmodel in ['stm32l432', 'starterkit', 'developerkit']: - result = at.device_erase(device) - if result == False: - print 'erase device failed' - return 1 - - succeed = False; retry = 5 - for i in range(retry): - if at.device_program(device, address, str(FIRMWARE)) == True: - succeed = True - break - print 'program device failed, trying once more ...' - time.sleep(1) - if succeed == False: - print 'error: program device {0}:{1} failed'.format(device, devices[device]) - return 1 - - time.sleep(2) - app_start_time = time.time() - succeed = False; retry = 2 - for i in range(retry): - if at.device_control(device, 'reset') == True: - succeed = True - break - print 'failed to reset device, trying once more ...' - time.sleep(1) - if succeed == False: - print("device %s reset failed " % allocated[0]) - return 1 - time.sleep(3) - print 'program succeed' - - return 0 - - - -if __name__ == "__main__": - start_time_stamp = time.time() - start_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(start_time_stamp)) - start_time_str = time.strftime('%Y-%m-%d_%H-%M-%S',time.localtime(start_time_stamp)) - shell_content = os.popen("adb devices | grep -v List | grep device").read() - device_list = shell_content.split('\n') - log_file = open("wifi_connect_test_log_" + start_time_str + ".txt", "a+") - - para_proc(log_file) - - server = '11.238.148.46' - port = 34568 - at=Autotest() - global logname - logname = "iot_device_log.txt" - if at.start(server, port, logname) == False: - print("Open IoT Device Failed! Exit~") - sys.exit(1) - - ret = allocate_and_program_device() - if ret != 0: - print('Failed to allocate device. Exit~') - sys.exit(1) - - print_write(log_file, "Open IoT Device: OK\n") - - global reset_success_count - reset_success_count = 0 - global active_awss_success_count - active_awss_success_count = 0 - print_write(log_file, "Start IoT Device Logcat...\n\n") - - total_success_cnt = 0 - - for test_case_index in range(0, len(TEST_CASE_ID_LIST)): - print_write(log_file, "\n\n====================Test case ID: " + str(TEST_CASE_ID_LIST[test_case_index]) + ", Testing ...====================\n\n") - - test_case_id = TEST_CASE_ID_LIST[test_case_index] - phone_device_id = PHONE_DEVICE_ID_LIST[test_case_index] - phone_model = PHONE_MODEL_LIST[test_case_index] - access_point_model = ACCESS_POINT_MODEL_LIST[test_case_index] - wifi_ssid = WIFI_SSID_LIST[test_case_index] - wifi_password = WIFI_PASSWORD_LIST[test_case_index] - print_write(log_file, str(test_case_id) + ", " + str(phone_device_id) + ", " + str(phone_model) + ", " + str(access_point_model) + ", " + str(wifi_ssid) + ", " + str(wifi_password) + "\n") - - is_phone_exist = False - for index in range(0, len(device_list) - 1): - if phone_device_id in device_list[index]: - is_phone_exist = True - break - - if not is_phone_exist: - print_write(log_file, "In test case ID: " + test_case_id + " no phone found\n\n") - continue - - ps_ef_content = os.popen("ps -ef | grep 'adb -s " + phone_device_id + "'").read() - logcat_thread_list = ps_ef_content.split('\n') - for num in range(0, len(logcat_thread_list) - 1): - os.popen("kill " + logcat_thread_list[num].split()[1] + " > /dev/null 2>&1") - - log_thread = LogMonitor(phone_device_id, start_time_str + "_" + test_case_id) - log_thread.start() - time.sleep(3) - logcat_file_name = "wifi_connect_test_adb_log_" + phone_device_id + "_" + start_time_str + "_" + test_case_id + ".txt" - global app_init_count - app_init_count = 0 - global connect_test_success_count - connect_test_success_count = 0 - - for num in range(0, TOTAL_COUNT): - # try max TOTAL_COUNT times until success. - if connect_test_success_count > 0: - break - - ps_ef_content = os.popen("ps -ef | grep 'adb -s " + phone_device_id + "'").read() - logcat_thread_list = ps_ef_content.split('\n') - is_logcat_thread_active = False - for line in range(0, len(logcat_thread_list) - 1): - if "adb -s " + phone_device_id + " logcat -v threadtime" in logcat_thread_list[line]: - is_logcat_thread_active = True - break - if not is_logcat_thread_active: - print_write(log_file, "New logcat process\n") - log_thread = LogMonitor(phone_device_id, start_time_str + "_" + test_case_id) - log_thread.start() - time.sleep(3) - - print_write(log_file, "\n\n**********Phone ID: " + str(phone_device_id) + ", No. " + str(num + 1) + " times test**********\n\n") - - result_str = os.popen("adb -s " + phone_device_id + " shell am force-stop com.aliyun.iot.devicetools.iotdevicetools").read() - print_write(log_file, "Adb force terminate App: force-stop...\n") - - time.sleep(3) - print_write(log_file, "3s wait finished\n") - - os.popen("adb -s " + phone_device_id + " shell am start -n com.aliyun.iot.devicetools.iotdevicetools/.MainActivity").read() - print_write(log_file, "Adb start App: start...\n") - - time.sleep(3) - print_write(log_file, "3s wait finished\n") - - os.popen("adb -s " + phone_device_id + " shell am start -n com.aliyun.iot.devicetools.iotdevicetools/.DeviceAdd.MainDeviceAddActivity --es configs m:ForceAliLinkTypeBroadcast,s:" + str(wifi_ssid) + ",p:" + str(wifi_password) + "").read() - print_write(log_file, "Adb distribute config, init APP: start, configs...\n") - - if not app_init_wait(logcat_file_name, num): - continue - - device_reset(at, log_file) - - device_active_awss(at, log_file) - - os.popen("adb -s " + phone_device_id + " shell am broadcast -a startdeviceadd --es devicename " + str(IOT_DEVICE_NAME)).read() - print_write(log_file, "APP entering awss: broadcast\n") - - app_connect_wait(logcat_file_name, num) - - device_reset(at, log_file) - - at.device_run_cmd('A', "reboot") - print_write(log_file, "Device to reboot: reboot\n") - - result_str = os.popen("adb -s " + phone_device_id + " shell am force-stop com.aliyun.iot.devicetools.iotdevicetools").read() - print_write(log_file, "Adb force terminate App: force-stop...\n") - - time.sleep(10) - print_write(log_file, "10s wait finished\n\n\n\n\n") - - print '---------- The adb test log start ----------' - adb_file = open(logcat_file_name) - line = adb_file.readline() - while line: - print line - line = adb_file.readline() - print '---------- The adb test log end ----------' - adb_file.close() - - # ro.build.fingerprint=Coolpad/Coolpad7295A/Coolpad7295A:4.1.2/JZO54K/4.1.029.P0.141219.7295A:user/release-keys - try: - cmd_fp = os.popen("adb -s " + phone_device_id + " shell cat /system/build.prop | grep \"ro.build.fingerprint\"") - fp = cmd_fp.read() - fpl = fp.split("/") - - # ro.product.model=Coolpad 7295A - cmd_pro = os.popen("adb -s " + phone_device_id + " shell cat /system/build.prop | grep \"ro.product.model\"") - pro = cmd_pro.read() - - - device_brand = fpl[0].split("=")[1] - android_version = fpl[2].split(":")[1] - device_type = pro.split("\n")[0].split("=")[1].split("\r")[0] - except Exception as e: - device_brand = "Null" - android_version = "Null" - device_type = "Null" - print_write("Failed to obtain phone info\n") - - ps_ef_content = os.popen("ps -ef | grep 'adb -s " + phone_device_id + "'").read() - logcat_thread_list = ps_ef_content.split('\n') - for num in range(0, len(logcat_thread_list) - 1): - os.popen("kill " + logcat_thread_list[num].split()[1] + " > /dev/null 2>&1") - - if connect_test_success_count > 0: - total_success_cnt += 1 - print("====================Test case ID: " + str(TEST_CASE_ID_LIST[test_case_index]) + ", Succeed====================\n\n") - else: - print("====================Test case ID: " + str(TEST_CASE_ID_LIST[test_case_index]) + ", Failed====================\n\n") - - at.stop() - - print '---------- The device log start ----------' - with open("./testlog/" + logname) as f: - print(f.read()) - print '---------- The device log end ----------' - - os.popen("rm -f wifi_connect_test_adb_log_*") - os.popen("rm -f wifi_connect_test_log_*") - - test_case_cnt = len(TEST_CASE_ID_LIST) - print("\n======Test summary:======\n") - if total_success_cnt == test_case_cnt: - print(" All test cases passed.") - print(" !!!Test SUCCEED!!!\n") - sys.exit(0) - else: - print(" %d out of %d test cases failed." % (test_case_cnt - total_success_cnt, test_case_cnt)) - print("\n !!!Test FAILED!!!\n") - sys.exit(1) diff --git a/tools/testbed/testscripts/autoywss_zconfig.py b/tools/testbed/testscripts/autoywss_zconfig.py deleted file mode 100644 index f043882ed1..0000000000 --- a/tools/testbed/testscripts/autoywss_zconfig.py +++ /dev/null @@ -1,504 +0,0 @@ -#!/usr/bin/python - -import os, sys, optparse, time, threading -from autotest import Autotest - - -dev_registrar = 'registrar' -dev_enrollee = 'enrollee' -required_devices = [ [2, 'zywss'] ] -models = { - 'mk3060':'0x13200' -} - - -class LogMonitor(threading.Thread): - def __init__(self, phone_id, log_file_name): - threading.Thread.__init__(self) - self.phone_id = phone_id - self.log_file_name = log_file_name - - def run(self): - os.popen("adb -s " + self.phone_id + " logcat -c") - logcat_cmd = "adb -s " + self.phone_id + " logcat -v threadtime >> " + self.log_file_name - os.popen(logcat_cmd) - - -def parse_arg(): - global device_model - global fw_registrar - global fw_enrollee - global iot_device_name - global wifi_ssid - global wifi_password - - parser = optparse.OptionParser() - parser.add_option('-m', '--model', dest='device_model', default='mk3060', help='Device model') - parser.add_option('-f', '--firmware', dest='firmware', default='linkkitapp@mk3060-autoywss.bin', help='Firmware file to be programmed into device') - parser.add_option('-e', '--firmware-enrollee', dest='firmware_enrollee', default='linkkitapp@mk3060-enrollee.bin', help='Firmware file to be programmed into device') - parser.add_option('-n', '--iot-device-name', dest='iot_dev_name', default='VNHU6iQgPaBybZTSYQLN', help='IoT device name') - parser.add_option('-s', '--wifissid', dest='wifi_ssid', default='Yuemewifi-3766', help='WiFi SSID') - parser.add_option('-p', '--wifipass', dest='wifi_pw', default='aos12345', help='WiFi password') - - (options, args) = parser.parse_args() - try: - device_model = options.device_model - fw_registrar = options.firmware - fw_enrollee = options.firmware_enrollee - iot_device_name = options.iot_dev_name - wifi_ssid = options.wifi_ssid - wifi_password = options.wifi_pw - except Exception as e: - print('invalid argument:{}'.format(e)) - sys.exit(1) - - -def program_device(atobj, dmodel, devices, dev, addr, fw): - if dmodel in ['stm32', 'starterkit', 'developerkit']: - result = atobj.device_erase(dev) - if result == False: - print 'erase device failed' - return 1 - - succeed = False; retry = 5 - for i in range(retry): - if atobj.device_program(dev, addr, fw) == True: - succeed = True - break - print 'program device failed, trying once more ...' - time.sleep(1) - if succeed == False: - print 'error: program device {0}:{1} failed'.format(dev, devices[dev]) - return False - - time.sleep(2) - app_start_time = time.time() - succeed = False; retry = 2 - for i in range(retry): - if atobj.device_control(dev, 'reset') == True: - succeed = True - break - print 'failed to reset device, trying once more ...' - time.sleep(1) - if succeed == False: - print("error: reset device {0}:{1} failed".format(dev, devices[dev])) - return False - - time.sleep(3) - print 'program succeed' - - return True - - -def allocate_and_program_device(at, dmodel): - #request device allocation - number, purpose = required_devices[0] - timeout = 10 - allocated = at.device_allocate(str(dmodel), number, timeout, purpose) - if len(allocated) != number: - return 1 - - global zconfig_devices - - zconfig_devices = {dev_registrar:allocated[0], dev_enrollee:allocated[1]} #construct device list - print 'allocated:' - for device in zconfig_devices: - print ' {}: {}'.format(device, zconfig_devices[device]) - - #subscribe and reboot devices - result = at.device_subscribe(zconfig_devices) - if result == False: - print 'subscribe devices failed' - return 1 - at.device_control(dev_registrar, 'reset') #reboot to capture the device (prevent others use it) - at.device_control(dev_enrollee, 'reset') #reboot to capture the device (prevent others use it) - - if (program_device(at, dmodel, zconfig_devices, dev_registrar, models[dmodel], fw_registrar) == False or - program_device(at, dmodel, zconfig_devices, dev_enrollee, models[dmodel], fw_enrollee) == False): - return 1 - - return 0 - - -def print_device_log(): - print '---------- The device log start ----------' - with open("./testlog/" + dev_log_name) as f: - print(f.read()) - print '---------- The device log end ----------' - - -def print_test_summary(message): - print('\n=====Test Summary:=====\n') - print(" !!!" + str(message + "!!!\n")) - - -def go_exit(at, exit_code): - at.stop() - print('AT stopped.') - - os.popen("rm -f wifi_connect_test_adb_log_*") - os.popen("rm -f wifi_connect_test_log_*") - - print_device_log() - - if exit_code == 0: - summary_str = 'SUCCESS' - else: - summary_str = 'FAILED' - - print_test_summary(summary_str) - - print('We are going to exit, the adb process for now:') - print(os.popen("ps -elf|grep adb").read()) - - sys.exit(exit_code) - - -def get_first_availble_phone_id(): - phone_id = None - adb_devices = os.popen("adb devices | grep -v List | grep device").read() - - if adb_devices is not None: - phone_id = ((adb_devices.split('\n'))[0].split('\t'))[0] - - return phone_id - - -def kill_adb_thread(pid): - ps_ef_content = os.popen("ps -ef | grep 'adb -s " + pid + "'").read() - logcat_thread_list = ps_ef_content.split('\n') - for num in range(0, len(logcat_thread_list) - 1): - os.popen("kill " + logcat_thread_list[num].split()[1] + " > /dev/null 2>&1") - - -def app_init_wait(logcat_file_name): - global app_init_count - is_init_finish = False - app_init_result = False - time_out_stamp = time.time() + 90 - while True: - app_init_times = 0 - logcat_file = open(logcat_file_name, "r") - logcat_file_content = logcat_file.readlines() - for line in range(0, len(logcat_file_content)): - if "AWSS_CFG,mode:" in logcat_file_content[line]: - app_init_times += 1 - if "AWSS_RESULT, ready to start" in logcat_file_content[line] and app_init_times > app_init_count: - print("App init succeed.") - app_init_result = True - is_init_finish = True - break - if "AWSS_RESULT, exit deviceadd activity" in logcat_file_content[line]: - print("APP init failed.") - app_init_result = False - is_init_finish = True - break - logcat_file.close() - - if time.time() > time_out_stamp: - print("APP init timeout.") - break - - if is_init_finish: - break - else: - time.sleep(0.5) - app_init_count = app_init_times - - return app_init_result - - -def reset_device(at, device, log_file): - global reset_success_count - - print("Device to reset: " + device) - at.device_run_cmd(device, 'reset') - - is_reset_finish = False - time_out_stamp = time.time() + 10 - while True: - tmp_reset_success_count = 0 - iot_device_file = open(log_file, "r") - iot_device_file_content = iot_device_file.readlines() - for line in range(0, len(iot_device_file_content)): - to_match1 = ':' + device + ':' - to_match2 = 'SSID cleared. Please reboot the system' - if to_match2 in iot_device_file_content[line]: - tmp_reset_success_count += 1 - if tmp_reset_success_count > reset_success_count and to_match1 in iot_device_file_content[line]: - is_reset_finish = True - reset_success_count += 1 - print("reset device succeed.\n") - break - iot_device_file.close() - - if time.time() > time_out_stamp: - print("No reset success log found\n") - break - - if is_reset_finish: - time.sleep(5) - print("Compete 5s wait after reset\n") - break - else: - time.sleep(0.5) - - return is_reset_finish; - - -def do_active_awss(at, device, log_file): - global active_awss_success_count - - at.device_run_cmd(device, "active_awss") - print("Device into awss mode: active_awss.") - - is_active_awss_finish = False - time_out_stamp = time.time() + 10 - while True: - tmp_active_awss_success_count = 0 - iot_device_file = open(log_file, "r") - iot_device_file_content = iot_device_file.readlines() - for line in range(0, len(iot_device_file_content)): - to_match1 = ':' + device + ':' - to_match2 = 'do_awss_active' - if to_match1 in iot_device_file_content[line] and to_match2 in iot_device_file_content[line]: - tmp_active_awss_success_count += 1 - if tmp_active_awss_success_count > active_awss_success_count: - is_active_awss_finish = True - active_awss_success_count += 1 - print("active awss succeed.") - break - iot_device_file.close() - - if time.time() > time_out_stamp: - print("Device failed to find entering awss mode success log.") - break - - if is_active_awss_finish: - time.sleep(5) - print("Complete 5s wait for awss_active.") - break - else: - time.sleep(0.5) - - return is_active_awss_finish - - -def app_connect_wait(logcat_file_name): - global app_init_count - global connect_test_success_count - is_connect_finish = False - connect_result = False - time_out_stamp = time.time() + 90 - while True: - connect_times = 0 - logcat_file = open(logcat_file_name, "r") - logcat_file_content = logcat_file.readlines() - for line in range(0, len(logcat_file_content)): - if "AWSS_CFG,mode:" in logcat_file_content[line]: - connect_times += 1 - if "AWSS_RESULT, bind success" in logcat_file_content[line] and connect_times >= app_init_count: - connect_result = True - is_connect_finish = True - connect_test_success_count += 1 - print("Smart config succeed.") - break - if "AWSS_RESULT, exit deviceadd activity" in logcat_file_content[line] and connect_times >= app_init_count: - connect_result = False - is_connect_finish = True - print("Smart config failed.") - break - logcat_file.close() - - if time.time() > time_out_stamp: - print("90s timeout reached\n") - break - - if is_connect_finish: - break - else: - time.sleep(0.5) - - return connect_result - - -def do_smart_config(at, dev, dev_log, ssid, pw): - ret = {"code":1, "id":None} - - phone_id = get_first_availble_phone_id() - if phone_id is None: - print('Failed to find test phone.') - return ret - else: - ret["id"] = phone_id - print("Phone found, id is %s." % phone_id) - - kill_adb_thread(phone_id) - - print("Starting logcat thread ...") - time_stamp = time.time() - time_str = time.strftime('%Y-%m-%d_%H-%M-%S', time.localtime(time_stamp)) - adb_log_name = 'wifi_connect_test_adb_log_' + phone_id + time_str + '.txt' - log_thread = LogMonitor(phone_id, adb_log_name) - log_thread.start() - - time.sleep(3) - - ps_ef_content = os.popen("ps -ef | grep 'adb -s " + phone_id + "'").read() - logcat_thread_list = ps_ef_content.split('\n') - is_logcat_thread_active = False - for line in range(0, len(logcat_thread_list) - 1): - if "adb -s " + phone_id + " logcat -v threadtime" in logcat_thread_list[line]: - is_logcat_thread_active = True - break - - if is_logcat_thread_active == False: - print('Failed to start logcat thread.') - return ret - else: - print("Logcat thread started.") - - os.popen("adb -s " + phone_id + " shell am force-stop com.aliyun.iot.devicetools.iotdevicetools") - print("Adb force terminate App: force-stop ...") - - time.sleep(3) - - os.popen("adb -s " + phone_id + " shell am start -n com.aliyun.iot.devicetools.iotdevicetools/.MainActivity") - print("Adb start App: start ...\n") - - time.sleep(3) - - os.popen("adb -s " + phone_id + " shell am start -n com.aliyun.iot.devicetools.iotdevicetools/.DeviceAdd.MainDeviceAddActivity --es configs m:ForceAliLinkTypeBroadcast,s:" + str(ssid) + ",p:" + str(pw) + "") - print("Adb distribute config, init APP: start, configs ...\n") - - if not app_init_wait(adb_log_name): - print("Adb app failed to be started.") - return ret - - if not reset_device(at, dev, dev_log): - print("Failed to reset device.") - return ret - - if not do_active_awss(at, dev, dev_log): - print("Failed to do active awss.") - return ret - - os.popen("adb -s " + phone_id + " shell am broadcast -a startdeviceadd --es devicename " + str(iot_device_name)) - print("APP entering awss: broadcast.") - - if not app_connect_wait(adb_log_name): - print("Adb app failed to be connected.") - return ret - - print("APP smart config completed.") - - ret["code"] = 0 - return ret - - -def exit_smart_config(at, dev, pid): - print('Exiting smart config for device: ' + dev) - print("Resetting device ...") - at.device_run_cmd(dev, "reset") - - time.sleep(1) - - os.popen("adb -s " + pid + " shell am force-stop com.aliyun.iot.devicetools.iotdevicetools") - print("Adb force terminate App: force-stop ...") - - ps_ef_content = os.popen("ps -ef | grep 'adb -s " + pid + "'").read() - logcat_thread_list = ps_ef_content.split('\n') - for num in range(0, len(logcat_thread_list) - 1): - os.popen("kill " + logcat_thread_list[num].split()[1] + " > /dev/null 2>&1") - print('Adb logcat thread killed.') - - time.sleep(10) - print("10s wait finished.") - print('Finished exiting smart config for device: ' + dev) - - -def is_zconfig_success(at, reg_dev, enr_dname, log_file): - enrolle_found = False - iot_device_file = open(log_file, "r") - iot_device_file_content = iot_device_file.readlines() - for line in range(0, len(iot_device_file_content)): - to_match1 = ':' + reg_dev + ':' - to_match2 = 'new enrollee[' - if to_match1 in iot_device_file_content[line] and \ - to_match2 in iot_device_file_content[line] and \ - str(enr_dname) in iot_device_file_content[line]: - enrolle_found = True - print('Enrolle found OK.') - print(iot_device_file_content[line]) - break - - return enrolle_found - - -if __name__ == "__main__": - global reset_success_count - reset_success_count = 0 - global active_awss_success_count - active_awss_success_count = 0 - global app_init_count - app_init_count = 0 - global connect_test_success_count - connect_test_success_count = 0 - global device_model - global fw_registrar - global fw_enrollee - global iot_device_name - global wifi_ssid - global wifi_password - enrollee_dname = 'yo2zSNU51SgbXh9x4y7o' - - parse_arg() - - server = '11.238.148.46' - port = 34568 - at=Autotest() - global dev_log_name - dev_log_name = "iot_device_log.txt" - if at.start(server, port, dev_log_name) == False: - print("Open IoT Device Failed! Exit~") - sys.exit(1) - - ret = allocate_and_program_device(at, device_model) - if ret != 0: - print('Failed to allocate/program device. Exit~') - go_exit(at, 1) - - print("Open IoT Device: OK\n") - - sconfig_ret = do_smart_config(at, dev_registrar, "./testlog/" + dev_log_name, wifi_ssid, wifi_password) - if sconfig_ret["code"] != 0: - print('Smart config for registrar failed! Exit~') - if sconfig_ret["id"] is not None: - exit_smart_config(at, dev_registrar, sconfig_ret["id"]) - go_exit(at, 1) - else: - print('Registrar smart config completed.') - - if reset_device(at, dev_enrollee, "./testlog/" + dev_log_name) == False: - print('Enrollee reset failed, Exit!') - if sconfig_ret["id"] is not None: - exit_smart_config(at, dev_registrar, sconfig_ret["id"]) - go_exit(at, 1) - print('Reset enrollee device succeed.') - - time.sleep(10) - print('10s wait finished for enrollee to be found.') - - zconfig_fail = 0 - if is_zconfig_success(at, dev_registrar, enrollee_dname, "./testlog/" + dev_log_name) == False: - print('Zconfig result check failed, Exit!') - zconfig_fail = 1 - else: - print('Zconfig test succeed.') - - exit_smart_config(at, dev_registrar, sconfig_ret["id"]) - print('Registrar smart config exit.') - - print('The test result is ' + str(zconfig_fail)) - - go_exit(at, zconfig_fail) diff --git a/tools/testbed/testscripts/benchmark.py b/tools/testbed/testscripts/benchmark.py deleted file mode 100644 index 2bafa1a335..0000000000 --- a/tools/testbed/testscripts/benchmark.py +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/python - -import os, sys, time, re -from autotest import Testcase - -required_devices = [ [1, 'general'] ] - -ret = 0; result = 'succeed' - -#realtime start - -max_permit_absolute = float(0.6) -max_permit_relative = float(0.1) - -#if log with maxint_distime not include base_time -base_time = 'basetime' -maxint_distime = 'Max intrpt disable time' -realtime_standard_values = { - 'developerkit':{ - base_time:{ - 'sched_yield':'2.27', - 'sched_preempt':'4.51', - 'sync_sem_shuffling':'6.83', - 'sync_mutex_shuffling': '7.96', - 'message_queue_send': '1.60', - 'message_queue_rev': '1.61', - 'mem_tlf_alloc': '16.17', - 'mem_tlf_free': '8.56', - }, - maxint_distime:'5.30', - } - -} - -def realtime_deal(model,responses): - tmp_value = realtime_standard_values[model] - compare_value = tmp_value[base_time] - - for res in responses : - if maxint_distime in res: - compare_value = tmp_value - - - for res in responses : - for key,values in compare_value.items(): - if key in res : - testval = re.search("\s\d+(\.\d+)?",res).group(0).strip() - cmpval = compare_value[key] - if (float(testval) > float(cmpval)) and (float(testval) - float(cmpval) > max_permit_absolute) \ - and ((float(testval) - float(cmpval))/float(cmpval) > max_permit_relative): - print '\n\033[1;31m {}:fail, run val: {}, compare val: {} \033[0m!'.format(key, testval, cmpval) - ret = 1; result = 'failed' - else: - print '\n\033[1;30m {}:success, run val: {}, compare val: {} \033[0m!'.format(key, testval, cmpval) - - - -#realtime end - - -#pwr start - -def pwr_deal(model,responses): - idletmp = 0; - for res in responses : - if r'idle' in res: - idle = re.search("idle\s=\s\d+",res).group(0).strip() - idle = re.sub(r'idle\s=',"",idle) - idle = idle.strip() - if (int(idle) - int(idletmp)) > 10: - print '\n\033[1;31m pwr test fail, last count: {}, current val: {} \033[0m!'.format(idletmp, idle) - ret = 1; result = 'failed' - else: - print '\n\033[1;30m success, last count: {}, current val: {} \033[0m!'.format(idletmp, idle) - - idletmp = idle - -#pwr end - - -def main(firmware='benchmark.realtime_test@mk3060-general.bin', model='mk3060'): - tc = Testcase('benchmark.realtime_test') - at = tc.at - - dealfun = 0 - number, purpose = required_devices[0] - [ret, result] = tc.start(number, purpose) - if ret != 0: - tc.stop() - print '\nbenchmark test failed' - return [ret, result] - - model_test = tc.get_model() - firmware_test = tc.get_firmware() - number_of_responses = 200; timeout = 6 - filter = [""] - - if 'realtime_test' in firmware_test: - number_of_responses = 200; timeout = 6 - dealfun = realtime_deal - elif 'pwr_test' in firmware_test: - number_of_responses = 5; timeout = 20 - dealfun = pwr_deal - filter = ['idle ='] - - responses = at.device_read_log('A', number_of_responses, timeout, filter) - - tc.stop() #disconnect testbed server - - ret = 0; result = 'succeed' - if len(responses) <= 0: - print 'error: can not get {} lines of log containing {}'.format(number_of_responses, filter) - ret = 1; result = 'failed' - - dealfun(model_test,responses) - - print '\nlogs:' - tc.dump_log() - - print '\n{} {}'.format(firmware_test,result) - - return [ret, result] - -if __name__ == '__main__': - [code, msg] = main() - sys.exit(code) diff --git a/tools/testbed/testscripts/certificate.pem b/tools/testbed/testscripts/certificate.pem deleted file mode 120000 index 8702efbd48..0000000000 --- a/tools/testbed/testscripts/certificate.pem +++ /dev/null @@ -1 +0,0 @@ -../certificate.pem \ No newline at end of file diff --git a/tools/testbed/testscripts/coap_connect_test.py b/tools/testbed/testscripts/coap_connect_test.py deleted file mode 100644 index 784f9752bf..0000000000 --- a/tools/testbed/testscripts/coap_connect_test.py +++ /dev/null @@ -1,157 +0,0 @@ -import os, sys, time -from autotest import Autotest - -required_devices = [ [1, 'general'] ] -models = { - 'mk3060':'0x13200', - 'esp32':'0x10000', - 'esp8266': '0x1000' -} - -def main(firmware='coapapp@esp32-general.bin', model='esp32'): - ap_ssid = 'aos_test_01' - ap_pass = 'Alios@Embedded' - server = '11.238.148.46' - port = 34568 - - #parse input - i = 1 - while i < len(sys.argv): - arg = sys.argv[i] - if arg.startswith('--firmware='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --firmware=firmware.bin'.format(arg) - firmware = args[1] - elif arg.startswith('--model='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --model=mk3060'.format(arg) - model = args[1] - elif arg.startswith('--server='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --server=192.168.10.16'.format(arg) - return [1, 'argument {0} error'.format(arg)] - server = args[1] - elif arg.startswith('--port='): - args = arg.split('=') - if len(args) != 2 or args[1].isdigit() == False: - print 'wrong argument {0} input, example: --port=34568'.format(arg) - return [1, 'argument {0} error'.format(arg)] - port = int(args[1]) - elif arg.startswith('--wifissid='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --wifissid=test_wifi'.format(arg) - ap_ssid = args[1] - elif arg.startswith('--wifipass='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --wifipass=test_password'.format(arg) - ap_pass = args[1] - elif arg=='--help': - print 'Usage: python {0} [--firmware=xxx.bin] [--wifissid=wifi_ssid] [--wifipass=password]'.format(sys.argv[0]) - return [0, 'help'] - i += 1 - - if model not in models: - print "error: unsupported device model {0}".format(repr(model)) - return [1, 'unsupported model {}'.format(model)] - - at=Autotest() - logname=time.strftime('%Y-%m-%d@%H-%M') - logname = 'mqtt_test-' + logname +'.log' - if at.start(server, port, logname) == False: - return [1, 'connect testbed failed'] - - #request device allocation - number, purpose = required_devices[0] - timeout = 10 - allocated = at.device_allocate(model, number, timeout, purpose) - if len(allocated) != number: - return [1, 'allocate device failed'] - - devices={'A':allocated[0]} #construct device list - print 'allocated:' - for device in devices: - print ' {}: {}'.format(device, devices[device]) - - #subscribe and reboot devices - result = at.device_subscribe(devices) - if result == False: - print 'subscribe devices failed' - return [1, 'subscribe devices failed'] - at.device_control('A', 'reset') #reboot to capture the device (prevent others use it) - - #program devices - device_list = list(devices) - device_list.sort() - address = models[model] - for device in device_list: - result = at.device_program(device, address, firmware) - if result == False: - print 'program device failed' - return [1, 'program device failed'] - time.sleep(2) - app_start_time = time.time() - result = at.device_control(device, 'reset') - if result == False: - print("device %s reset failed " % allocated[0]) - return [1, 'reset device failed'] - time.sleep(3) - print 'program succeed' - - #connect device to alibaba cloud - at.device_run_cmd('A', 'netmgr clear') #run 'netmgr clear' command at device A - time.sleep(0.5) - at.device_control('A', 'reset') #control device A, let it reboot - time.sleep(5) #wait some time - at.device_run_cmd('A', 'netmgr connect {0} {1}'.format(ap_ssid, ap_pass)) #connect device A to wifi - time.sleep(20) #wait some time - - number_of_responses = 50 - timeout = 100 - filter = ['aos framework init', 'send msg: Len:', 'Message response code: 69'] - responses = at.device_read_log('A', number_of_responses, timeout, filter) - - #disconnect device from alibaba cloud - at.device_run_cmd('A', 'netmgr clear') #run 'netmgr clear' command at device A - time.sleep(0.5) - at.device_control('A', 'reset') #control device A, let it reboot - at.stop() - - ret = 0; result = 'succeed' - if len(responses) < number_of_responses: - print 'error: can not get {} lines of log containing {}'.format(number_of_responses, filter) - ret = 1; result = 'failed' - - for response in responses: - if 'aos framework init' not in response: - continue - print 'error: device restart detected' - ret = 1; result = 'failed' - break - - print '\nlogs:' - if result == 'succeed': - for response in responses: print response - else: - flog = open('testlog/' + logname, 'r') - line = flog.readline() - while line: - logtime = line.split(':')[0] - sec_int, sec_frac = logtime.split('.') - sec_int = time.mktime(time.strptime(sec_int, "%Y-%m-%d %H-%M-%S")) - sec_frac = float('0.' + sec_frac) - logtime = sec_int + sec_frac - if logtime >= app_start_time: - print line, - line = flog.readline() - - print '\ncoap test {}'.format(result) - return [ret, result] - -if __name__ == '__main__': - [code, msg] = main() - sys.exit(code) diff --git a/tools/testbed/testscripts/device.jar b/tools/testbed/testscripts/device.jar deleted file mode 100644 index e9c8424f72..0000000000 Binary files a/tools/testbed/testscripts/device.jar and /dev/null differ diff --git a/tools/testbed/testscripts/helloworld_test.py b/tools/testbed/testscripts/helloworld_test.py deleted file mode 100644 index b2fb254757..0000000000 --- a/tools/testbed/testscripts/helloworld_test.py +++ /dev/null @@ -1,38 +0,0 @@ -import os, sys, time -from autotest import Testcase - -required_devices = [ [1, 'general'] ] - -def main(firmware='helloworld@mk3060-general.bin', model='mk3060'): - tc = Testcase('helloworld') - at = tc.at - - number, purpose = required_devices[0] - [ret, result] = tc.start(number, purpose) - if ret != 0: - tc.stop() - print '\nhelloworld test failed' - return [ret, result] - - number_of_responses = 10; timeout = 60 - filter = ['helloworld', 'hello world!'] - responses = at.device_read_log('A', number_of_responses, timeout, filter) - - tc.stop() #disconnect testbed server - - ret = 0; result = 'succeed' - if len(responses) < number_of_responses: - print 'error: can not get {} lines of log containing {}'.format(number_of_responses, filter) - print "responses:\n{}".format('\n'.join(responses)) - ret = 1; result = 'failed' - - print '\nlogs:' - tc.dump_log() - - print '\nhelloworld test {}'.format(result) - - return [ret, result] - -if __name__ == '__main__': - [code, msg] = main() - sys.exit(code) diff --git a/tools/testbed/testscripts/kernel_test.py b/tools/testbed/testscripts/kernel_test.py deleted file mode 100644 index e2ffaa003e..0000000000 --- a/tools/testbed/testscripts/kernel_test.py +++ /dev/null @@ -1,40 +0,0 @@ -import os, sys, time -from autotest import Testcase - -required_devices = [ [1, 'general'] ] - -def main(firmware='yts@esp32-general.bin', model='esp32'): - tc = Testcase('kernel') - at = tc.at - - number, purpose = required_devices[0] - [ret, result] = tc.start(number, purpose) - if ret != 0: - tc.stop() - print '\nkernel test failed' - return [ret, result] - - timeout = 300 - at.device_run_cmd('A', 'yts_run') #run yts test - responses = at.device_read_log('A', 1, timeout, ['Tests completed with return value']) - - tc.stop() - - if len(responses) < 1: - print 'error: yts_run did not finish in {}S'.format(timeout) - ret = 1; result = 'failed' - elif 'return value 0' not in responses[0]: - print 'error: {}'.format(responses[0]) - ret = 1; result = 'failed' - else: - ret = 0; result = 'succeed' - - print '\nlogs:' - tc.dump_log() - - print '\nkernel test {}'.format(result) - return [ret, result] - -if __name__ == '__main__': - [code, msg] = main() - sys.exit(code) diff --git a/tools/testbed/testscripts/linkkit_connect_test.py b/tools/testbed/testscripts/linkkit_connect_test.py deleted file mode 100644 index 33dcd523c5..0000000000 --- a/tools/testbed/testscripts/linkkit_connect_test.py +++ /dev/null @@ -1,73 +0,0 @@ -import os, sys, time -from autotest import Testcase - -required_devices = [ [1, 'general'] ] - -def main(): - tc = Testcase('linkkit-connect') - ap_ssid = tc.ap_ssid - ap_pass = tc.ap_pass - at = tc.at - - number, purpose = required_devices[0] - [ret, result] = tc.start(number, purpose) - if ret != 0: - tc.stop() - print '\nlinkkit connect test failed' - return [ret, result] - - responses = at.device_read_log('A', 1, 16, ['Welcome to AliOS Things']) - if len(responses) == 0: - tc.stop() - print '\nlinkkit connect test failed: device boot up failed' - return [1, 'device failed to boot up'] - - response = at.device_run_cmd('A', 'kv get wifi', 1, 1, ['value is ']) - if len(response) > 0: - at.device_run_cmd('A', 'netmgr clear') - at.device_control('A', 'reset') - at.device_read_log('A', 1, 16, ['Welcome to AliOS Things']) - - at.device_run_cmd('A', 'netmgr connect {0} {1}'.format(ap_ssid, ap_pass)) #connect device A to wifi - responses = at.device_read_log('A', 1, 120, ['mqtt connect success!']) - if len(responses) != 1: - at.device_run_cmd('A', 'netmgr clear') - time.sleep(0.5) - at.device_control('A', 'reset') - tc.stop() - print '\nerror: device failed to make mqtt connection, logs:' - tc.dump_log() - print '\nlinkkit connect test failed' - return [1, 'failed'] - - number_of_responses = 30 - timeout = 90 - filter = ['DM Send Message, URI:', 'Publish Result: 0'] - if len(responses) == 1: - print responses[0] - responses = at.device_read_log('A', number_of_responses, timeout, filter) - - #disconnect device from alibaba cloud - at.device_run_cmd('A', 'netmgr clear') #run 'netmgr clear' command at device A - time.sleep(0.5) - at.device_control('A', 'reset') #control device A, let it reboot - tc.stop() - - ret = 0; result = 'succeed' - if len(responses) < number_of_responses: - print 'error: can not get {} lines of log containing {}'.format(number_of_responses, filter) - print 'actual number of lines: {}'.format(len(responses)) - print "responses:" - for i in range(len(responses)): - print " {}. {}".format(i+1, responses[i]) - ret = 1; result = 'failed' - - print '\nlogs:' - tc.dump_log() - - print '\nmqtt connect test {}'.format(result) - return [ret, result] - -if __name__ == '__main__': - [code, msg] = main() - sys.exit(code) diff --git a/tools/testbed/testscripts/linkkit_test.py b/tools/testbed/testscripts/linkkit_test.py deleted file mode 100644 index 1f396d94d2..0000000000 --- a/tools/testbed/testscripts/linkkit_test.py +++ /dev/null @@ -1,330 +0,0 @@ -import sys, os, time, httplib, json, subprocess, pdb, getpass - -import logging -import jpype - -from autotest import Autotest - -models={'mk3060':'0x13200'} -testnames={'short2pps':0} - -DEBUG = True - - - - -def start_jvm(): - parent_dir = os.path.dirname((os.path.abspath(__file__))) - print(parent_dir) - jar_path = os.path.join(parent_dir, "device.jar") - print(jar_path) - print(jpype.getDefaultJVMPath()) - - - if not jpype.isJVMStarted(): - jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.class.path={}".format(jar_path)) - - print(jpype.getDefaultJVMPath()) - - -def attach_jvm(): - if not jpype.isThreadAttachedToJVM(): - jpype.attachThreadToJVM() - -def detach_jvm(): - if jpype.isThreadAttachedToJVM(): - jpype.detachThreadFromJVM() - - -def stop_jvm(): - detach_jvm() - if jpype.isJVMStarted(): - jpype.shutdownJVM() - - -#main function -def main(firmware='linkkitapp@mk3060-general.bin', model='mk3060', testname='short2pps'): - global DEBUG - userid = '500001169232518525' - linkkit_test_server = 'pre-iotx-qs.alibaba.com' - server = '11.238.148.46' - #server = '116.62.245.240' - port = 34568 - wifissid = 'aos_test_01' - wifipass = 'Alios@Embedded' - - #parse input - i = 1 - while i < len(sys.argv): - arg = sys.argv[i] - if arg.startswith('--firmware='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --firmware=firmware.bin'.format(arg) - firmware = args[1] - elif arg.startswith('--model='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --model=mk3060'.format(arg) - model = args[1] - elif arg.startswith('--testname='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --testname=5pps'.format(arg) - testname = args[1] - elif arg.startswith('--userid='): - args = arg.split('=') - if len(args) != 2 or args[1].isdigit() == False: - print 'wrong argument {0} input, example: --userid=123456789012345678'.format(arg) - userid = args[1] - elif arg.startswith('--server='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --server=192.168.10.16'.format(arg) - server = args[1] - elif arg.startswith('--port='): - args = arg.split('=') - if len(args) != 2 or args[1].isdigit() == False: - print 'wrong argument {0} input, example: --port=34568'.format(arg) - port = int(args[1]) - elif arg.startswith('--wifissid='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --wifissid=test_wifi'.format(arg) - wifissid = args[1] - elif arg.startswith('--wifipass='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --wifipass=test_password'.format(arg) - wifipass = args[1] - elif arg.startswith('--debug='): - args = arg.split('=') - if len(args) != 2 or args[1].isdigit() == False: - print 'wrong argument {0} input, example: --debug=1'.format(arg) - DEBUG = (args[1] != '0') - elif arg=='--help': - print 'Usage: python {0} [--firmware=xxx.bin] [--model=xxx] [--testname=xxxx] [--userid=xxxxx] [--server=xx.x.x.x] [--port=xx] [--wifissid=wifi_ssid] [--wifipass=password] [--debug=0/1]'.format(sys.argv[0]) - return [0, 'help'] - i += 1 - - if DEBUG: - print "firmware: {0}".format(firmware) - print "model: {0}".format(model) - print "testname: {0}".format(testname) - print "userid: {0}".format(userid) - print "server: {0}".format(server) - print "port: {0}".format(port) - print "wifissid: {0}".format(wifissid) - print "wifipass: {0}".format(wifipass) - - if testname not in testnames: - print "error: unsupported testname {0}".format(repr(testname)) - return [1, 'testname {0} unsupported'.format(repr(testname))] - - if not model or model.lower() not in models: - print "error: unsupported model {0}".format(repr(model)) - return [1, 'model {0} unsupported'.format(repr(model))] - model = model.lower() - - logname=time.strftime('-%Y-%m-%d@%H-%M') - logname = testname + logname +'.log' - at=Autotest() - - print "at.start === : {0}".format(server) - if at.start(server, port, logname) == False: - print 'error: start failed' - return [1, 'connect testbed failed'] - - - print "at.ok === : {0}".format(server) - number = 1 - - timeout = 120 - allocted = at.device_allocate(model, number, timeout, 'alink') - if len(allocted) != number: - print "error: request device allocation failed" - return [1, 'allocate device failed'] - print "allocted device", allocted[0] - - devices = {'A':allocted[0]} - device = 'A' - - #subscribe device - if at.device_subscribe(devices) == False: - print 'error: subscribe to device failed, some devices may not exist in testbed' - return [1, 'subscribe device failed'] - - #program device - succeed = False; retry = 5 - addr = models[model] - print 'programming device {0} ...'.format(devices[device]) - for i in range(retry): - print "firmware = {0}".format(firmware) - if at.device_program(device, addr, firmware) == True: - succeed = True - break - time.sleep(0.5) - if succeed == False: - print 'error: program device {0} failed'.format(devices[device]) - return [1, 'program device failed'] - print 'program device {0} succeed'.format(devices[device]) - time.sleep(5) - - #connect to linkkit - succeed = False; retry = 5 - key_name = None - uuid = None - startflag=0 - - while retry > 0: - #clear previous setting and reboot - #at.device_run_cmd(device, 'kv del wifi') - - #at.device_run_cmd(device, 'netmgr clear') - time.sleep(2) - at.device_control(device, 'reset') - - time.sleep(5) - netmgr=2 - while(netmgr > 0): - print "after reset" - #connect device to linkkit - at.device_run_cmd(device, 'netmgr connect {0} {1}'.format(wifissid, wifipass), timeout=1.5) - netmgr-=1 - time.sleep(2) - - print "after connect" - #at.device_control(device, 'reboot') - time.sleep(20) - print "after reboot" - - loop = 5 - while (loop > 0): - filter = ['KEY_NAME:'] - response = at.device_run_cmd(device, 'prtkey', 1, 5.5, filter) - - print "after prtkey {0}".format(response) - lenresp = len(response) - if response == False or len(response) != 1: - loop -= 1 - continue - key_name = response[0].split()[-1] - print " key_name is : {0}".format(key_name) - - productKey = key_name.split('.',2)[0] - deviceName = key_name.split('.',2)[1] - - print " productKey is :{0}".format(productKey) - print " deviceName is :{0}".format(deviceName) - - print "connect linkkit succeed, key_name:{0}".format(key_name) - startflag = 1 - break - - retry-=1 - if startflag == 0: - continue; - - time.sleep(2) - thing_crt_flag = 0 - thing_check = 10 - while (thing_check > 0): - filter = ['THING_ID_CREAT'] - response = at.device_run_cmd(device, 'prtkey', 1, 2.5, filter) - print "after prtkey {0}".format(response) - if response == False or len(response) != 1: - thing_check -= 1 - time.sleep(2) - continue - thing_crt_flag = 1 - break - - if(thing_crt_flag == 0): - print "thing creat fail" - continue; - else: - break; - - if(startflag == 0): - print "device start fail" - time.sleep(2) - at.device_control(device, 'reset') - time.sleep(2) - return [1, 'device start fail'] - if(thing_crt_flag == 0): - print "device thing creat fail" - time.sleep(2) - at.device_control(device, 'reset') - time.sleep(2) - return [1, 'device thing creat fail'] - - sys_usr=getpass.getuser() - print("user",sys_usr) - - if sys_usr == "iot": - os.environ['JAVA_HOME'] = '/usr/local/jdk1.8.0_151' - if sys_usr == "lc122798": - os.environ['JAVA_HOME'] = '/home/lc122798/tools/jdk1.8.0_151' - - time.sleep(5) - start_jvm() - attach_jvm() - print(jpype.getDefaultJVMPath()) - - MyDevice = jpype.JClass('MyDevice') - jardevice = MyDevice(productKey, deviceName) - - - - time.sleep(10) - loopcnt = 100 - successcnt = loopcnt - while (loopcnt > 0): - print("start setProperty") - if jardevice.setProperty('LightSwitch', 1): - time.sleep(0.5) - else: - time.sleep(1) - continue - loopcnt-= 1 - cycle_ms = 1 - #time.sleep(cycle_ms) - - time.sleep(60) - - retry = 100 - recordcnt = 0 - while (retry > 0): - filter = ['PROPERTY_SET_COUNT::'] - response = at.device_run_cmd(device, 'prtkey', 1, 2.5, filter) - print "after prtkey {0}".format(response) - if response == False or len(response) != 1: - retry -= 1 - time.sleep(2) - continue - returnstr = response[0].split()[-1] - print " returnstr is : {0}".format(returnstr) - recordcnt=int(returnstr) - print("out int",recordcnt) - break - - jpype.detachThreadFromJVM() - time.sleep(2) - at.device_control(device, 'reset') - time.sleep(2) - print("out put",successcnt,recordcnt) - if(successcnt == recordcnt): - print "linkkit success" - return [0, 'linkkit success'] - else: - print "linkkit fail" - return [1, 'linkkit fail'] - - -if __name__ == '__main__': - #flush to output immediately - sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) - sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 0) - [code, msg] = main() - sys.exit(code) - diff --git a/tools/testbed/testscripts/mesh_common.py b/tools/testbed/testscripts/mesh_common.py deleted file mode 100644 index 0996a4a901..0000000000 --- a/tools/testbed/testscripts/mesh_common.py +++ /dev/null @@ -1,292 +0,0 @@ -import os, time - -#allocate devices -def allocate_devices(at, model, number, timeout, purpose='general'): - models = ['mk3060', 'esp32'] - if not model or model.lower() not in models: - print "error: unsupported model {0}".format(repr(model)) - return [] - allocated = at.device_allocate(model, number, timeout, purpose) - if len(allocated) != number: - print "error: request device allocation failed" - return [] - return allocated - -def print_device_list(devices): - device_list = list(devices) - device_list.sort() - print 'allocated devices:' - for device in device_list: - print ' {0}:{1}'.format(device, devices[device]) - print '' - -#subscribe and reboot devices -def subscribe_and_reboot_devices(at, devices): - if at.device_subscribe(devices) == False: - print 'error: subscribe to device failed, some devices may not exist in testbed' - return False - for device in list(devices): - at.device_control(device, 'reset') - time.sleep(5) - return True - -#program devices -def program_devices(at, devices, model, firmware): - print 'program devices ...', - models = {'mk3060':'0x13200', 'esp32':'0x10000'} - if model not in models: - print "error: unsupported device model {0}".format(repr(model)) - return False - device_list = list(devices) - device_list.sort() - addr = models[model] - for device in device_list: - succeed = False; retry = 5 - for i in range(retry): - if at.device_program(device, addr, firmware) == True: - succeed = True - break - time.sleep(1) - if succeed == False: - print 'error: program device {0}:{1} failed'.format(device, devices[device]) - return False - time.sleep(5) - print 'succeed\n' - return True - -#reboot and get device mac address -def reboot_and_get_mac(at, device_list, device_attr): - retry = 5 - for device in device_list: - succeed = False - for i in range(retry): - at.device_run_cmd(device, 'netmgr clear') - at.device_run_cmd(device, 'kv del alink') - mac = at.device_run_cmd(device, 'mac', 1, 0.8, ['MAC address:']) - at.device_control(device, 'reset') - if mac and len(mac) == 1: - mac = mac[0].split()[-1] - mac = mac.replace('-', '') + '0000' - device_attr[device] = {'mac':mac} - succeed = True - break; - time.sleep(5) - if succeed == False: - print 'error: reboot and get mac addr for device {0} failed'.format(device) - return False - time.sleep(5) - return True - -#set random extnetid to isolate the network -def set_random_extnetid(at, device_list): - bytes = os.urandom(6) - extnetid = '' - for byte in bytes: - extnetid = extnetid + '{0:02x}'.format(ord(byte)) - for device in device_list: - at.device_run_cmd(device, 'umesh extnetid {0}'.format(extnetid)) - -#start devices -def start_devices(at, device_list, device_attr, ap_ssid, ap_pass): - filter = [ - 'state\tdisabled', - 'state\tdetached', - 'state\tattached', - 'state\tleaf', - 'state\trouter', - 'state\tsuper_router', - 'state\tleader', - 'state\tunknown' - ] - for device in device_list: - at.device_run_cmd(device, 'umesh stop') - for device in device_list: - succeed = False; retry = 5 - role = device_attr[device]['role'] - state = [] - while retry > 0: - at.device_run_cmd(device, 'umesh stop') - for nbr in device_attr[device]['nbrs']: - at.device_run_cmd(device, 'umesh whitelist add {0}'.format(nbr)) - at.device_run_cmd(device, 'umesh whitelist enable') - at.device_run_cmd(device, 'umesh whitelist') - if role == 'leader': - at.device_run_cmd(device, 'netmgr connect {0} {1}'.format(ap_ssid, ap_pass)) - time.sleep(30) - uuid = at.device_run_cmd(device, 'uuid', 1, 1.5, ['uuid:', 'not connected']) - state = at.device_run_cmd(device, 'umesh status', 1, 1, filter) - if uuid and 'uuid:' in uuid[0] and state == ['state\t' + role]: - succeed = True - break - else: - at.device_run_cmd(device, 'umesh start') - time.sleep(30) - state = at.device_run_cmd(device, 'umesh status', 1, 1, filter) - if state == ['state\t' + role]: - succeed = True - break - at.device_run_cmd(device, 'netmgr clear') - at.device_run_cmd(device, 'kv del alink') - at.device_control(device, 'reset') - time.sleep(5) - retry -= 1 - if succeed == False: - print "error: start {0} as {1} failed, state={2}".format(device, role, state) - return False - print "form desired mesh network succeed\n" - return True - - -#get device ips -def get_device_ips(at, device_list, device_attr): - for device in device_list: - succeed = False; retry = 3 - while retry > 0: - ipaddr = at.device_run_cmd(device, 'umesh ipaddr', 2, 1.5, ['.']) - if ipaddr == False or ipaddr == [] or len(ipaddr) != 2: - retry -= 1 - continue - ipaddr[0] = ipaddr[0].replace('\t', '') - ipaddr[1] = ipaddr[1].replace('\t', '') - device_attr[device]['ipaddr'] = ipaddr[0:2] - succeed = True - break; - if succeed == False: - print 'error: get ipaddr for device {0} failed'.format(device) - return False - return True - -#print device attributes -def print_device_attrs(device_attr): - device_list = list(device_attr) - device_list.sort() - for device in device_list: - attr_str = "{0}: ".format(device) - attr_str += "mac-{0} ".format(device_attr[device]['mac']) - attr_str += "ip-{0} ".format(device_attr[device]['ipaddr'][0]) - attr_str += "role-{0} ".format(device_attr[device]['role']) - print attr_str - print '' - -#ping test -def ping_test(at, device_list, device_attr): - retry = 5 - print 'test connectivity with icmp:' - pass_num = 0; fail_num = 0 - for device in device_list: - for other in device_list: - if device == other: - continue - for pkt_len in ['20', '500', '1000']: - filter = ['bytes from'] - dst_ip = device_attr[other]['ipaddr'][0] - for i in range(retry): - response = at.device_run_cmd(device, 'umesh ping {0} {1}'.format(dst_ip, pkt_len), 1, 0.5, filter) - expected_response = '{0} bytes from {1}'.format(pkt_len, dst_ip) - if response == False or response == [] or expected_response not in response[0]: - if i < retry - 1: - continue - else: - print '{0} ping {1} with {2} bytes by local ip addr failed'.format(device, other, pkt_len) - fail_num += 1 - break - else: - pass_num += 1 - break - print 'ping: pass-{0}, fail-{1}\n'.format(pass_num, fail_num) - return [pass_num, fail_num] - -#ping external ip test -def ping_ext_test(at, device_list, dst_ip): - retry = 5 - print 'test connectivity of external ip with icmp:' - pass_num = 0 - fail_num = 0 - for device in device_list: - for pkt_len in ['20', '500', '1000']: - filter = ['bytes from'] - for i in range(retry): - response = at.device_run_cmd(device, 'umesh ping {0} {1}'.format(dst_ip, pkt_len), 1, 0.5, filter) - expected_response = '{0} bytes from {1}'.format(pkt_len, dst_ip) - if response is False or response == [] or expected_response not in response[0]: - if i < retry - 1: - continue - else: - print '{0} ping {1} with {2} bytes by local ip addr failed'.format(device, dst_ip, pkt_len) - fail_num += 1 - break - else: - pass_num += 1 - break - print 'ping: pass-{0}, fail-{1}\n'.format(pass_num, fail_num) - return [pass_num, fail_num] - -#udp test -def udp_test(at, device_list, device_attr): - for device in device_list: - ret = at.device_run_cmd(device, 'umesh help', 1, 1, ['autotest']) - if ret != ['autotest']: - print "udp test aborted: 'umesh autotest' operation not supported\n" - return [0, 0] - retry = 5 - print 'test connectivity with udp:' - pass_num = 0; fail_num = 0 - for device in device_list: - for other in device_list: - if device == other: - continue - for pkt_len in ['20', '500', '1000']: - dst_ip = device_attr[other]['ipaddr'][0] - filter = ['bytes autotest echo reply from'] - for i in range(retry): - response = at.device_run_cmd(device, 'umesh autotest {0} 1 {1}'.format(dst_ip, pkt_len), 1, 0.5, filter) - expected_response = '{0} bytes autotest echo reply from {1}'.format(pkt_len, dst_ip) - if response == False or response == [] or expected_response not in response[0]: - if i < retry - 1: - continue - else: - print '{0} send {1} with {2} bytes by local ip addr failed'.format(device, other, pkt_len) - fail_num += 1 - break - else: - pass_num += 1 - break - print 'udp: pass-{0}, fail-{1}\n'.format(pass_num, fail_num) - return [pass_num, fail_num] - -def multicast_test(at, device_list, device_attr): - for device in device_list: - ret = at.device_run_cmd(device, 'umesh help', 1, 1, ['autotest']) - if ret != ['autotest']: - print "multicast test aborted: 'umesh autotest' operation not supported\n" - return [0, 0] - retry = 20 - print 'test multicast connectivity:' - pass_num = 0; fail_num = 0 - response_num = str(len(device_list) - 1) - for pkt_len in ['20', '400']: - for device in device_list: - dst_ip = device_attr[device]['ipaddr'][1] - for index in range(retry): - at.device_run_cmd(device, 'umesh autotest {0} 1 {1}'.format(dst_ip, pkt_len)) - time.sleep(4) - response = at.device_run_cmd(device, 'umesh testcmd autotest_acked', 1, 1, [response_num]) - if response == [] or len(response) != 1 or response_num not in response[0]: - if index < retry - 1: - continue - else: - print '{0} multicast {1} bytes failed'.format(device, pkt_len) - fail_num += 1 - break - else: - pass_num += 1 - break - print 'udp: pass-{0}, fail-{1}'.format(pass_num, fail_num) - return [pass_num, fail_num] - -#restore state to default -def restore_device_status(at, device_list): - extnetid = '010203040506' - for device in device_list: - at.device_run_cmd(device, 'umesh extnetid {0}'.format(extnetid)) - at.device_run_cmd(device, 'umesh whitelist disable') diff --git a/tools/testbed/testscripts/mqtt_connect_test.py b/tools/testbed/testscripts/mqtt_connect_test.py deleted file mode 100644 index ce18b050d8..0000000000 --- a/tools/testbed/testscripts/mqtt_connect_test.py +++ /dev/null @@ -1,77 +0,0 @@ -import os, sys, time -from autotest import Testcase - -required_devices = [ [1, 'general'] ] - -def main(): - tc = Testcase('mqtt-connect') - ap_ssid = tc.ap_ssid - ap_pass = tc.ap_pass - at = tc.at - - number, purpose = required_devices[0] - [ret, result] = tc.start(number, purpose) - if ret != 0: - tc.stop() - print '\nmqtt connect test failed' - return [ret, result] - - responses = at.device_read_log('A', 1, 16, ['Welcome to AliOS Things']) - if len(responses) == 0: - tc.stop() - print '\nmqtt connect test failed: device boot up failed' - return [1, 'device failed to boot up'] - - response = at.device_run_cmd('A', 'kv get wifi', 1, 1, ['value is ']) - if len(response) > 0: - at.device_run_cmd('A', 'netmgr clear') - at.device_control('A', 'reset') - at.device_read_log('A', 1, 16, ['Welcome to AliOS Things']) - - at.device_run_cmd('A', 'netmgr connect {0} {1}'.format(ap_ssid, ap_pass)) #connect device A to wifi - responses = at.device_read_log('A', 1, 120, ['mqtt connect success!']) - if len(responses) != 1: - at.device_run_cmd('A', 'netmgr clear') - time.sleep(0.5) - at.device_control('A', 'reset') - tc.stop() - print '\nerror: device failed to make mqtt connection, logs:' - tc.dump_log() - print '\nmqtt connect test failed' - return [1, 'failed'] - - number_of_responses = 30 - timeout = 90 - filter = ['publish message:', 'publish topic msg=', 'publish success'] - if len(responses) == 1: - print responses[0] - responses = at.device_read_log('A', number_of_responses, timeout, filter) - - #disconnect device from alibaba cloud - at.device_run_cmd('A', 'netmgr clear') - time.sleep(0.5) - at.device_control('A', 'reset') - tc.stop() - - ret = 0; result = 'succeed' - if len(responses) < number_of_responses: - print 'error: can not get {} lines of log containing {}'.format(number_of_responses, filter) - print '###actual parameter %s'%len(responses) - ret = 1; result = 'failed' - - for response in responses: - if 'aos framework init' not in response: - continue - print 'error: device restart detected' - ret = 1; result = 'failed' - break - - print '\nlogs:' - tc.dump_log() - - print '\nmqtt connect test {}'.format(result) - return [ret, result] - -if __name__ == '__main__': - [code, msg] = main() - sys.exit(code) diff --git a/tools/testbed/testscripts/pv_config.py b/tools/testbed/testscripts/pv_config.py deleted file mode 100644 index 0e5e321232..0000000000 --- a/tools/testbed/testscripts/pv_config.py +++ /dev/null @@ -1,204 +0,0 @@ -#all targets defined here will be built -buildtargets = { - 'mk3060-helloworld': { - 'buildargs': 'helloworld@mk3060', - 'bincopy': ["out/helloworld@mk3060/binary/helloworld@mk3060.bin", "helloworld@mk3060-general.bin"] - }, - 'mk3060-mqttapp': { - 'buildargs': 'mqttapp@mk3060', - 'bincopy': ["out/mqttapp@mk3060/binary/mqttapp@mk3060.bin", "mqttapp@mk3060-general.bin"], - 'keyinfo':{ - 'keyfile': "example/mqttapp/mqtt_example.c", - 'keyvalue': { - 'PRODUCT_KEY': 'a16GcXEm4uG', - 'PRODUCT_SECRET': '7YgRyCVZNqAgq5x2', - 'DEVICE_NAME': 'mqtt_mk3060_test01', - 'DEVICE_SECRET': 'wJBI866M9aA22oY97eQnY3fI022rSjOs' - } - } - }, - 'mk3060-linkkitapp': { - 'buildargs': 'linkkitapp@mk3060 pvtest=y', - 'bincopy': ["out/linkkitapp@mk3060/binary/linkkitapp@mk3060.bin", "linkkitapp@mk3060-general.bin"], - 'keyinfo':{ - 'keyfile': "example/linkkitapp/linkkit_example_solo.c", - 'keyvalue': { - 'PRODUCT_KEY': 'a12iufuXqUA', - 'PRODUCT_SECRET': 'tbZ7PUfV9VY2rwCl', - 'DEVICE_NAME': 'linkkit_mk3060_test01', - 'DEVICE_SECRET': 'bvachR4vkApeZFrcQeZfkMTqc5oaBlJ1' - } - }, - }, - #'mk3080-helloworld': { - # 'buildargs': 'helloworld@mk3080', - # 'bincopy': ["out/helloworld@mk3080/binary/helloworld@mk3080.ota.bin", "helloworld@mk3080-general.bin"] - #}, - #'mk3080-mqttapp': { - # 'buildargs': 'mqttapp@mk3080', - # 'bincopy': ["out/mqttapp@mk3080/binary/mqttapp@mk3080.ota.bin", "mqttapp@mk3080-general.bin"], - # 'keyinfo':{ - # 'keyfile': "example/mqttapp/mqtt_example.c", - # 'keyvalue': { - # 'PRODUCT_KEY': 'a16GcXEm4uG', - # 'PRODUCT_SECRET': '7YgRyCVZNqAgq5x2', - # 'DEVICE_NAME': 'mqtt_mk3080_test01', - # 'DEVICE_SECRET': 'd9XY9WsMpPlsKSzobR8DYLjEh2RMjPKW' - # } - # } - #}, - #'mk3080-linkkitapp': { - # 'buildargs': 'linkkitapp@mk3080 pvtest=y', - # 'bincopy': ["out/linkkitapp@mk3080/binary/linkkitapp@mk3080.ota.bin", "linkkitapp@mk3080-general.bin"], - # 'keyinfo':{ - # 'keyfile': "example/linkkitapp/linkkit_example_solo.c", - # 'keyvalue': { - # 'PRODUCT_KEY': 'a12iufuXqUA', - # 'PRODUCT_SECRET': 'tbZ7PUfV9VY2rwCl', - # 'DEVICE_NAME': 'linkkit_mk3080_test01', - # 'DEVICE_SECRET': 'MP9HhSK9PGXFYc1CQBca250HJAm3YNzN' - # } - # }, - #}, - 'esp32-helloworld': { - 'buildargs': 'helloworld@esp32devkitc', - 'bincopy': ["out/helloworld@esp32devkitc/binary/helloworld@esp32devkitc.bin", "helloworld@esp32-general.bin"] - }, - 'esp32-mqttapp': { - 'buildargs': 'mqttapp@esp32devkitc', - 'bincopy': ["out/mqttapp@esp32devkitc/binary/mqttapp@esp32devkitc.bin", "mqttapp@esp32-general.bin"], - 'keyinfo':{ - 'keyfile': "example/mqttapp/mqtt_example.c", - 'keyvalue': { - 'PRODUCT_KEY': 'a1VmpWRfdCb', - 'PRODUCT_SECRET': 'iAOf2332l2haSn9i', - 'DEVICE_NAME': 'mqtt_esp32_test01', - 'DEVICE_SECRET': 'eQucRNkFJ4SxkfVja1o70K1Oyp2xC2mP' - } - } - }, - 'esp32-linkkitapp': { - 'buildargs': 'linkkitapp@esp32devkitc pvtest=y', - 'bincopy': ["out/linkkitapp@esp32devkitc/binary/linkkitapp@esp32devkitc.bin", "linkkitapp@esp32-general.bin"], - 'keyinfo':{ - 'keyfile': "example/linkkitapp/linkkit_example_solo.c", - 'keyvalue': { - 'PRODUCT_KEY': 'a1VmpWRfdCb', - 'PRODUCT_SECRET': 'iAOf2332l2haSn9i', - 'DEVICE_NAME': 'linkkit_esp32_test01', - 'DEVICE_SECRET': '9TZvVGnjgfrnB5lYjIraHT8DKiY99im5' - } - }, - }, - 'esp8266-helloworld': { - 'buildargs': 'helloworld@esp8266', - 'bincopy': ["out/helloworld@esp8266/binary/helloworld@esp8266.bin", "helloworld@esp8266-general.bin"], - }, - 'esp8266-mqttapp': { - 'buildargs': 'mqttapp@esp8266', - 'bincopy': ["out/mqttapp@esp8266/binary/mqttapp@esp8266.bin", "mqttapp@esp8266-general.bin"], - 'keyinfo':{ - 'keyfile': "example/mqttapp/mqtt_example.c", - 'keyvalue': { - 'PRODUCT_KEY': 'a1VmpWRfdCb', - 'PRODUCT_SECRET': 'iAOf2332l2haSn9i', - 'DEVICE_NAME': 'mqtt_esp8266_test01', - 'DEVICE_SECRET': 's5DxqBDJhhHVgdBW4KFNmO2zq17wO6O9' - } - } - }, - 'esp8266-linkkitapp': { - 'buildargs': 'linkkitapp@esp8266 pvtest=y', - 'bincopy': ["out/linkkitapp@esp8266/binary/linkkitapp@esp8266.bin", "linkkitapp@esp8266-general.bin"], - 'keyinfo':{ - 'keyfile': "example/linkkitapp/linkkit_example_solo.c", - 'keyvalue': { - 'PRODUCT_KEY': 'a1VmpWRfdCb', - 'PRODUCT_SECRET': 'iAOf2332l2haSn9i', - 'DEVICE_NAME': 'linkkit_esp8266_test01', - 'DEVICE_SECRET': 'GeWPjX7IkZ0Nb4Nh58VeIATKq9KHAuQC' - } - }, - }, - 'sv6266-helloworld': { - 'buildargs': 'helloworld@sv6266_evb', - 'bincopy': ["out/helloworld@sv6266_evb/binary/helloworld@sv6266_evb.bin", "helloworld@sv6266-general.bin"] - }, - 'rda5981-helloworld': { - 'buildargs': 'helloworld@uno-91h', - 'bincopy': ["out/helloworld@uno-91h/binary/helloworld@uno-91h.bin", "helloworld@rda5981-general.bin"] - }, -} - -testsuits = { - 'basic': { - 'tests': { - 'helloworld': {'script': 'helloworld_test.py', 'firmware_prefix':'helloworld@', 'firmware_suffix': '-general.bin'}, - 'kernel': {'script': 'kernel_test.py', 'firmware_prefix':'kernel@', 'firmware_suffix': '-general.bin'}, - } - }, - 'benchmark': { - 'tests': { - 'realtime': {'script': 'benchmark.py', 'firmware_prefix':'benchmark.realtime_test@', 'firmware_suffix': '-general.bin'}, - 'realtimesysstats': {'script': 'benchmark.py', 'firmware_prefix':'benchmark.realtime_test@', 'firmware_suffix': '-sysstats-general.bin'}, - 'pwr': {'script': 'benchmark.py', 'firmware_prefix':'benchmark.pwr_test@', 'firmware_suffix': '-general.bin'}, - } - }, - 'link': { - 'tests':{ - 'linkkit_connect': {'script':'linkkit_connect_test.py', 'firmware_prefix':'linkkitapp@', 'firmware_suffix': '-general.bin'}, - 'mqtt_connect': {'script':'mqtt_connect_test.py', 'firmware_prefix':'mqttapp@', 'firmware_suffix': '-general.bin'}, - 'coap_connect': {'script':'coap_connect_test.py', 'firmware_prefix':'coapapp@', 'firmware_suffix': '-general.bin'}, - }, - 'wifissid': 'aos_test_01', - 'wifipass': 'Alios@Embedded', - }, - 'activation': { - 'tests': { - 'acapp': {'script': 'acapp_test.py', 'firmware_prefix': 'acapp@', 'firmware_suffix':'-general.bin'}, - } - }, - 'autoywss': { - 'tests': { - 'linkkitapp': {'script':'autoywss.py', 'firmware_prefix':'linkkitapp@', 'firmware_suffix': '-autoywss.bin', 'dependencies':['autoywss.cfg']}, - }, - }, - 'autozconfig': { - 'tests': { - 'linkkitapp': {'script':'autoywss_zconfig.py', 'firmware_prefix':'linkkitapp@', 'firmware_suffix': '-autoywss.bin'}, - }, - 'wifissid': 'Yuemewifi-3766', - 'wifipass': 'aos12345', - }, -} - -models = { - 'mk3060': [ - ['basic', 'helloworld'], - ['link', 'linkkit_connect'], - ['link', 'mqtt_connect'], - #['link', 'coap_connect'], - ], - 'mk3080': [ - #['basic', 'helloworld'], - #['link', 'linkkit_connect'], - #['link', 'mqtt_connect'], - ], - 'esp32': [ - ['basic', 'helloworld'], - ['link', 'linkkit_connect'], - ['link', 'mqtt_connect'], - ], - 'esp8266': [ - ['basic', 'helloworld'], - #['link', 'linkkit_connect'], - #['link', 'mqtt_connect'], - ], - 'sv6266': [ - ['basic', 'helloworld'], - ], - 'rda5981': [ - #['basic', 'helloworld'], - ], -} - diff --git a/tools/testbed/testscripts/stability_test.py b/tools/testbed/testscripts/stability_test.py deleted file mode 100644 index 5d042474f9..0000000000 --- a/tools/testbed/testscripts/stability_test.py +++ /dev/null @@ -1,156 +0,0 @@ -import os, sys, time -from autotest import Autotest -from mesh_common import * - -required_devices = [ [1, 'general'] ] - -def main(firmware='~/lb-all.bin', model='mk3060', duration = 12 * 3600, withalink=True): - ap_ssid = 'aos_test_01' - ap_pass = 'Alios@Embedded' - server = '11.238.148.46' - port = 34568 - - #parse input - i = 1 - while i < len(sys.argv): - arg = sys.argv[i] - if arg.startswith('--firmware='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --firmware=firmware.bin'.format(arg) - return [1, 'argument {0} error'.format(arg)] - firmware = args[1] - elif arg.startswith('--model='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --model=mk3060'.format(arg) - return [1, 'argument {0} error'.format(arg)] - model = args[1].lower() - elif arg.startswith('--duration='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --duration=12'.format(arg) - return [1, 'argument {0} error'.format(arg)] - try: - tmp = float(args[1]) - except: - print 'wrong argument {0} input, example: --duration=12'.format(arg) - return [1, 'argument {0} error'.format(arg)] - duration = tmp * 3600 - elif arg.startswith('--withalink='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --withalink=1/0'.format(arg) - return [1, 'argument {0} error'.format(arg)] - withalink = (args[1] == '1') - elif arg.startswith('--wifissid='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --wifissid=test_wifi'.format(arg) - return [1, 'argument {0} error'.format(arg)] - ap_ssid = args[1] - elif arg.startswith('--wifipass='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --wifipass=test_password'.format(arg) - return [1, 'argument {0} error'.format(arg)] - ap_pass = args[1] - elif arg.startswith('--server='): - args = arg.split('=') - if len(args) != 2: - print 'wrong argument {0} input, example: --server=192.168.10.16'.format(arg) - return [1, 'argument {0} error'.format(arg)] - server = args[1] - elif arg.startswith('--port='): - args = arg.split('=') - if len(args) != 2 or args[1].isdigit() == False: - print 'wrong argument {0} input, example: --port=34568'.format(arg) - return [1, 'argument {0} error'.format(arg)] - port = int(args[1]) - elif arg=='--help': - print 'Usage: python {0} [--firmware=xxx.bin] [--model=xxx] [--duration=xx] [--withalink=1/0] [--wifissid=wifi_ssid] [--wifipass=password]'.format(sys.argv[0]) - return [0, 'help'] - i += 1 - - at=Autotest() - logname=time.strftime('%Y-%m-%d@%H-%M') - logname = 'stability-' + logname +'.log' - if at.start(server, port, logname) == False: - print 'error: start failed' - return [1, 'connect testbed failed'] - - #request device allocation - number, purpose = required_devices[0] - timeout = 3600 - allocated = allocate_devices(at, model, number, timeout, purpose) - if len(allocated) != number: - return [1, 'allocate device failed'] - - devices = {'A':allocated[0]} - device = 'A' - - #subscribe and reboot devices - result = subscribe_and_reboot_devices(at, devices) - if result == False: - return [1, 'subscribe devices failed'] - - #program devices - result = program_devices(at, devices, model, firmware) - if result == False: - return [1, 'program device failed'] - time.sleep(5) - - #restore state to default - restore_device_status(at, devices) - at.device_run_cmd(device, 'netmgr clear') - at.device_run_cmd(device, 'kv del wifi') - at.device_control(device, 'reset') - time.sleep(3) - - #connect alink - if withalink: - at.device_run_cmd(device, 'netmgr connect {0} {1}'.format(ap_ssid, ap_pass)) - - #start stability test - start_time = time.time() - pass_cnt = 0 - fail_cnt = 0 - fail_num = 0 - succees = False - while True: - if (time.time() - start_time) >= duration: - succeed = True - break - if fail_num >= 6: - succeed = False - break - response = at.device_run_cmd(device, 'devname', 1, 0.8, ['device name:']) - if response == False or len(response) != 1 or 'device name:' not in response[0]: - if fail_num == 0: - end_time = time.time() - fail_num += 1 - fail_cnt += 1 - else: - fail_num = 0 - pass_cnt += 1 - time.sleep(5) - - at.device_control(device, 'reset') - at.stop() - - print "pass: {0}, fail: {1}, success_rate: {2:.02f}%".format(pass_cnt, fail_cnt, pass_cnt*100.0/(pass_cnt+fail_cnt)) - if succeed: - print "Passed statbility test in {0:0.3f} hours".format(duration/3600) - return [0, 'succeed. duration={0:0.3f} hours'.format(duration/3600) ] - else: - duration = end_time - start_time - print "Failed stability test, device went dead in {0:0.3f} hours".format(duration/3600) - return [1, 'failed. duration={0:0.3f} hours'.format(duration/3600) ] - -if __name__ == '__main__': - #flush to output immediately - sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) - sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 0) - [code, msg] = main() - sys.exit(code) - diff --git a/tools/testbed/testscripts/ut_test.sh b/tools/testbed/testscripts/ut_test.sh deleted file mode 100644 index 47ca00e263..0000000000 --- a/tools/testbed/testscripts/ut_test.sh +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env bash - -ORIG_PATH=${PWD} -RUN_TIME=$(( 60*60 )) -MAIN_LOG=main.txt -TARGET_ARGS= -RET_CODE=0 - -#return code definations -AOS_RUN_SUCCESS=0 -TARGET_PROGRAM_NONEXIST=4 -RUN_PROGRAM_CRASHED=5 -RUN_PROGRAM_TIMEOUT=6 -PARSE_RESULT_FAIL=8 - -exit_handler() { - cd ${ORIG_PATH} - - PID_OF_TARGET=`pidof ${TARGET_BASENAME}` - if [ "${PID_OF_TARGET}" != "" ]; then - kill -9 ${PID_OF_TARGET} - fi - - if [ -f ${MAIN_LOG} ]; then - rm -f ${MAIN_LOG} - fi - - exit ${RET_CODE} -} - -#USAGE: bash aos_ut.sh target [args] -c=0 -for i in $@; do - c=$((c+1)); - if [ $c -eq 1 ]; then - TARGET_PROGRAM=$i - elif [ $c -eq 2 ]; then - TARGET_ARGS=$i - else - TARGET_ARGS="${TARGET_ARGS} ${i}" - fi -done - -TARGET_BASENAME=$(basename ${TARGET_PROGRAM}) -if [ "${TARGET_PROGRAM}" = "${TARGET_BASENAME}" ]; then - TARGET_PROGRAM="./${TARGET_PROGRAM}" -fi -PID_OF_TARGET=`pidof ${TARGET_BASENAME}` -if [ "${PID_OF_TARGET}" != "" ]; then - echo "KILLING EXISTING TARGET PROGRAM ..." - kill -9 ${PID_OF_TARGET} -fi - -ulimit -c unlimited - -echo "Start at $(date)" | tee -a ${MAIN_LOG} - -if [ ! -f dev_key ]; then - echo "Warning: security test dev_key none exist" -fi - -if [ ! -f mesh_topology.txt ]; then - echo "Warning: mesh topology config file none exist" -fi - -if [ ! -f ${TARGET_PROGRAM} ]; then - RET_CODE=${TARGET_PROGRAM_NONEXIST} - exit_handler -fi - -chmod +x ${TARGET_PROGRAM} -${TARGET_PROGRAM} ${TARGET_ARGS} | tee -a ${MAIN_LOG} & -TARGET_PID=$! - -i=1 -TARGET_RUNNING=`ps | grep ${TARGET_PID}` -while expr $i \<= ${RUN_TIME} > /dev/null && [ "${TARGET_RUNNING}" != "" ]; do - sleep 1; - i=$(( i+1 )); - TARGET_RUNNING=`ps | grep ${TARGET_PID}`; -done - -if expr $i \> ${RUN_TIME}; then - echo "Program did NOT exit in ${RUN_TIME} seconds" - RET_CODE=${RUN_PROGRAM_TIMEOUT} - exit_handler -fi - -echo "End at $(date)" | tee -a ${MAIN_LOG} - -wait ${TARGET_PID} -TARGET_RET=$? - -if [ ${TARGET_RET} -ne 0 ]; then - echo "Program crashed in ${i} seconds, ret=${TARGET_RET}" - RET_CODE=${RUN_PROGRAM_CRASHED} - exit_handler -else - echo "Program exited in ${i} seconds" -fi - -TOTAL_NUM=`tail -300 ${MAIN_LOG} | grep -a 'completed with' -A 3 | sed '$!d' | awk '{ print $1 }'` -FAIL_NUM=`tail -300 ${MAIN_LOG} | grep -a 'completed with' -A 3 | sed '$!d' | awk '{ print $4 }'` -if [ ${TOTAL_NUM} = "" ] || [ ${FAIL_NUM} = "" ]; then - echo "Parse result data failed" - RET_CODE=${PARSE_RESULT_FAIL} - exit_handler -fi - -PASS_COUNT=`echo "$TOTAL_NUM - $FAIL_NUM" | bc` -FAIL_COUNT="${FAIL_NUM}" -echo "PASS_COUNT = ${PASS_COUNT}" -echo "FAIL_COUNT = ${FAIL_COUNT}" - -RET_CODE=${AOS_RUN_SUCCESS} -exit_handler