forked from espressif/esp-idf
tiny-test-fw: support save performance to junit report:
1. support get performance from DUT 2. update performance to `testcase.stdout` in JunitReport
This commit is contained in:
@@ -65,12 +65,14 @@ class IDFRecvThread(DUT.RecvThread):
|
|||||||
def __init__(self, read, dut):
|
def __init__(self, read, dut):
|
||||||
super(IDFRecvThread, self).__init__(read, dut)
|
super(IDFRecvThread, self).__init__(read, dut)
|
||||||
self.exceptions = _queue.Queue()
|
self.exceptions = _queue.Queue()
|
||||||
|
self.performances = _queue.Queue()
|
||||||
|
|
||||||
def collect_performance(self, comp_data):
|
def collect_performance(self, comp_data):
|
||||||
matches = self.PERFORMANCE_PATTERN.findall(comp_data)
|
matches = self.PERFORMANCE_PATTERN.findall(comp_data)
|
||||||
for match in matches:
|
for match in matches:
|
||||||
Utility.console_log("[Performance][{}]: {}".format(match[0], match[1]),
|
Utility.console_log("[Performance][{}]: {}".format(match[0], match[1]),
|
||||||
color="orange")
|
color="orange")
|
||||||
|
self.performances.put((match[0], match[1]))
|
||||||
|
|
||||||
def detect_exception(self, comp_data):
|
def detect_exception(self, comp_data):
|
||||||
for pattern in self.EXCEPTION_PATTERNS:
|
for pattern in self.EXCEPTION_PATTERNS:
|
||||||
@@ -155,6 +157,7 @@ class IDFDUT(DUT.SerialDUT):
|
|||||||
super(IDFDUT, self).__init__(name, port, log_file, app, **kwargs)
|
super(IDFDUT, self).__init__(name, port, log_file, app, **kwargs)
|
||||||
self.allow_dut_exception = allow_dut_exception
|
self.allow_dut_exception = allow_dut_exception
|
||||||
self.exceptions = _queue.Queue()
|
self.exceptions = _queue.Queue()
|
||||||
|
self.performances = _queue.Queue()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_mac(cls, app, port):
|
def get_mac(cls, app, port):
|
||||||
@@ -338,30 +341,48 @@ class IDFDUT(DUT.SerialDUT):
|
|||||||
pass
|
pass
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _queue_read_all(source_queue):
|
||||||
|
output = []
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
output.append(source_queue.get(timeout=0))
|
||||||
|
except _queue.Empty:
|
||||||
|
break
|
||||||
|
return output
|
||||||
|
|
||||||
|
def _queue_copy(self, source_queue, dest_queue):
|
||||||
|
data = self._queue_read_all(source_queue)
|
||||||
|
for d in data:
|
||||||
|
dest_queue.put(d)
|
||||||
|
|
||||||
|
def _get_from_queue(self, queue_name):
|
||||||
|
self_queue = getattr(self, queue_name)
|
||||||
|
if self.receive_thread:
|
||||||
|
recv_thread_queue = getattr(self.receive_thread, queue_name)
|
||||||
|
self._queue_copy(recv_thread_queue, self_queue)
|
||||||
|
return self._queue_read_all(self_queue)
|
||||||
|
|
||||||
def stop_receive(self):
|
def stop_receive(self):
|
||||||
if self.receive_thread:
|
if self.receive_thread:
|
||||||
while True:
|
for name in ["performances", "exceptions"]:
|
||||||
try:
|
source_queue = getattr(self.receive_thread, name)
|
||||||
self.exceptions.put(self.receive_thread.exceptions.get(timeout=0))
|
dest_queue = getattr(self, name)
|
||||||
except _queue.Empty:
|
self._queue_copy(source_queue, dest_queue)
|
||||||
break
|
|
||||||
super(IDFDUT, self).stop_receive()
|
super(IDFDUT, self).stop_receive()
|
||||||
|
|
||||||
def get_exceptions(self):
|
def get_exceptions(self):
|
||||||
""" Get exceptions detected by DUT receive thread. """
|
""" Get exceptions detected by DUT receive thread. """
|
||||||
if self.receive_thread:
|
return self._get_from_queue("exceptions")
|
||||||
while True:
|
|
||||||
try:
|
def get_performance_items(self):
|
||||||
self.exceptions.put(self.receive_thread.exceptions.get(timeout=0))
|
"""
|
||||||
except _queue.Empty:
|
DUT receive thread will automatic collect performance results with pattern ``[Performance][name]: value\n``.
|
||||||
break
|
This method is used to get all performance results.
|
||||||
exceptions = []
|
|
||||||
while True:
|
:return: a list of performance items.
|
||||||
try:
|
"""
|
||||||
exceptions.append(self.exceptions.get(timeout=0))
|
return self._get_from_queue("performances")
|
||||||
except _queue.Empty:
|
|
||||||
break
|
|
||||||
return exceptions
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
super(IDFDUT, self).close()
|
super(IDFDUT, self).close()
|
||||||
|
@@ -17,6 +17,8 @@ import os
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import functools
|
import functools
|
||||||
|
import socket
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import junit_xml
|
import junit_xml
|
||||||
|
|
||||||
@@ -72,11 +74,13 @@ MANDATORY_INFO = {
|
|||||||
|
|
||||||
class JunitReport(object):
|
class JunitReport(object):
|
||||||
# wrapper for junit test report
|
# wrapper for junit test report
|
||||||
# TODO: Don't support by multi-thread (although not likely to be used this way).
|
# TODO: JunitReport methods are not thread safe (although not likely to be used this way).
|
||||||
|
|
||||||
JUNIT_FILE_NAME = "XUNIT_RESULT.xml"
|
JUNIT_FILE_NAME = "XUNIT_RESULT.xml"
|
||||||
JUNIT_DEFAULT_TEST_SUITE = "test-suite"
|
JUNIT_DEFAULT_TEST_SUITE = "test-suite"
|
||||||
JUNIT_TEST_SUITE = junit_xml.TestSuite(JUNIT_DEFAULT_TEST_SUITE)
|
JUNIT_TEST_SUITE = junit_xml.TestSuite(JUNIT_DEFAULT_TEST_SUITE,
|
||||||
|
hostname=socket.gethostname(),
|
||||||
|
timestamp=datetime.utcnow().isoformat())
|
||||||
JUNIT_CURRENT_TEST_CASE = None
|
JUNIT_CURRENT_TEST_CASE = None
|
||||||
_TEST_CASE_CREATED_TS = 0
|
_TEST_CASE_CREATED_TS = 0
|
||||||
|
|
||||||
@@ -124,6 +128,18 @@ class JunitReport(object):
|
|||||||
cls._TEST_CASE_CREATED_TS = time.time()
|
cls._TEST_CASE_CREATED_TS = time.time()
|
||||||
return test_case
|
return test_case
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def update_performance(cls, performance_items):
|
||||||
|
"""
|
||||||
|
Update performance results to ``stdout`` of current test case.
|
||||||
|
|
||||||
|
:param performance_items: a list of performance items. each performance item is a key-value pair.
|
||||||
|
"""
|
||||||
|
assert cls.JUNIT_CURRENT_TEST_CASE
|
||||||
|
|
||||||
|
for item in performance_items:
|
||||||
|
cls.JUNIT_CURRENT_TEST_CASE.stdout += "[{}]: {}\n".format(item[0], item[1])
|
||||||
|
|
||||||
|
|
||||||
def test_method(**kwargs):
|
def test_method(**kwargs):
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user