2020-05-28 12:47:38 +00:00
|
|
|
from __future__ import unicode_literals
|
2021-01-26 02:49:01 +00:00
|
|
|
|
2020-05-28 12:47:38 +00:00
|
|
|
import glob
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import threading
|
2021-01-26 02:49:01 +00:00
|
|
|
|
2020-05-28 12:47:38 +00:00
|
|
|
import ttfw_idf
|
2021-01-26 02:49:01 +00:00
|
|
|
from SimpleWebSocketServer import SimpleWebSocketServer, WebSocket
|
|
|
|
from tiny_test_fw import Utility
|
2020-05-28 12:47:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class IDEWSProtocol(WebSocket):
|
|
|
|
|
|
|
|
def handleMessage(self):
|
|
|
|
try:
|
|
|
|
j = json.loads(self.data)
|
|
|
|
except Exception as e:
|
|
|
|
Utility.console_log('Server ignores error: {}'.format(e), 'orange')
|
|
|
|
return
|
|
|
|
event = j.get('event')
|
|
|
|
if event and 'prog' in j and ((event == 'gdb_stub' and 'port' in j) or
|
|
|
|
(event == 'coredump' and 'file' in j)):
|
|
|
|
payload = {'event': 'debug_finished'}
|
|
|
|
self.sendMessage(json.dumps(payload))
|
|
|
|
Utility.console_log('Server sent: {}'.format(payload))
|
|
|
|
else:
|
|
|
|
Utility.console_log('Server received: {}'.format(j), 'orange')
|
|
|
|
|
|
|
|
def handleConnected(self):
|
|
|
|
Utility.console_log('{} connected to server'.format(self.address))
|
|
|
|
|
|
|
|
def handleClose(self):
|
|
|
|
Utility.console_log('{} closed the connection'.format(self.address))
|
|
|
|
|
|
|
|
|
|
|
|
class WebSocketServer(object):
|
|
|
|
HOST = '127.0.0.1'
|
|
|
|
PORT = 1123
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
server = SimpleWebSocketServer(self.HOST, self.PORT, IDEWSProtocol)
|
|
|
|
while not self.exit_event.is_set():
|
|
|
|
server.serveonce()
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.exit_event = threading.Event()
|
|
|
|
self.thread = threading.Thread(target=self.run)
|
|
|
|
self.thread.start()
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, exc_type, exc_value, traceback):
|
|
|
|
self.exit_event.set()
|
|
|
|
self.thread.join(10)
|
|
|
|
if self.thread.is_alive():
|
|
|
|
Utility.console_log('Thread cannot be joined', 'orange')
|
|
|
|
|
|
|
|
|
|
|
|
@ttfw_idf.idf_custom_test(env_tag='test_jtag_arm', group='test-apps')
|
|
|
|
def test_monitor_ide_integration(env, extra_data):
|
|
|
|
config_files = glob.glob(os.path.join(os.path.dirname(__file__), 'sdkconfig.ci.*'))
|
|
|
|
config_names = [os.path.basename(s).replace('sdkconfig.ci.', '') for s in config_files]
|
|
|
|
rel_proj_path = 'tools/test_apps/system/monitor_ide_integration'
|
|
|
|
for name in config_names:
|
|
|
|
Utility.console_log('Checking config "{}"... '.format(name), 'green', end='')
|
|
|
|
dut = env.get_dut('panic', rel_proj_path, app_config_name=name)
|
2020-07-21 09:00:04 +00:00
|
|
|
monitor_path = os.path.join(dut.app.idf_path, 'tools/idf_monitor.py')
|
|
|
|
elf_path = os.path.join(dut.app.binary_path, 'panic.elf')
|
2020-05-28 12:47:38 +00:00
|
|
|
dut.start_app()
|
|
|
|
# Closing the DUT because we will reconnect with IDF Monitor
|
|
|
|
env.close_dut(dut.name)
|
|
|
|
|
|
|
|
with WebSocketServer(), ttfw_idf.CustomProcess(' '.join([monitor_path,
|
|
|
|
elf_path,
|
2021-01-14 15:17:14 +00:00
|
|
|
'--port', str(dut.port),
|
2020-05-28 12:47:38 +00:00
|
|
|
'--ws', 'ws://{}:{}'.format(WebSocketServer.HOST,
|
|
|
|
WebSocketServer.PORT)]),
|
|
|
|
logfile='monitor_{}.log'.format(name)) as p:
|
|
|
|
p.pexpect_proc.expect(re.compile(r'Guru Meditation Error'), timeout=10)
|
|
|
|
p.pexpect_proc.expect_exact('Communicating through WebSocket', timeout=5)
|
|
|
|
# "u?" is for Python 2 only in the following regular expressions.
|
|
|
|
# The elements of dictionary can be printed in different order depending on the Python version.
|
|
|
|
p.pexpect_proc.expect(re.compile(r"WebSocket sent: \{u?.*'event': u?'" + name + "'"), timeout=5)
|
|
|
|
p.pexpect_proc.expect_exact('Waiting for debug finished event', timeout=5)
|
|
|
|
p.pexpect_proc.expect(re.compile(r"WebSocket received: \{u?'event': u?'debug_finished'\}"), timeout=5)
|
|
|
|
p.pexpect_proc.expect_exact('Communications through WebSocket is finished', timeout=5)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_monitor_ide_integration()
|