test: Store brief log per test and use as default report_stdout

Change-Id: I0972ba56a42c24f3d3b1bc94bcbdaca86026046a
This commit is contained in:
Pau Espin 2020-06-11 17:57:43 +02:00
parent 57e37f95e1
commit ec28572e42
3 changed files with 13 additions and 11 deletions

View File

@ -46,6 +46,9 @@ C_CNF = 'cnf'
C_BUS = 'bus'
C_DEFAULT = '---'
FILE_LOG = 'log'
FILE_LOG_BRIEF = 'log_brief'
LOG_CTX_VAR = '_log_ctx_'
def dbg(*messages, _origin=None, _category=None, _src=None, **named_items):

View File

@ -46,7 +46,7 @@ class Test(log.Origin):
self.duration = 0
self.fail_type = None
self.fail_message = None
self.log_target = None
self.log_targets = []
self._report_stdout = None
def module_name(self):
@ -62,7 +62,8 @@ class Test(log.Origin):
def run(self):
testenv_obj = None
try:
self.log_target = log.FileLogTarget(self.get_run_dir().new_child('log')).set_all_levels(log.L_DBG).style_change(trace=True)
self.log_targets = [log.FileLogTarget(self.get_run_dir().new_child(log.FILE_LOG)).set_all_levels(log.L_DBG).style_change(trace=True),
log.FileLogTarget(self.get_run_dir().new_child(log.FILE_LOG_BRIEF)).style_change(src=False, all_origins_on_levels=(log.L_ERR, log.L_TRACEBACK))]
log.large_separator(self.suite_run.trial().name(), self.suite_run.name(), self.name(), sublevel=3)
self.status = Test.UNKNOWN
self.start_timestamp = time.time()
@ -95,8 +96,8 @@ class Test(log.Origin):
finally:
if testenv_obj:
testenv_obj.stop()
if self.log_target:
self.log_target.remove()
for log_tgt in self.log_targets:
log_tgt.remove()
def name(self):
l = log.get_line_for_src(self.path)
@ -137,9 +138,9 @@ class Test(log.Origin):
# If test overwrote the text, provide it:
if self._report_stdout is not None:
return self._report_stdout
# Otherwise vy default provide the entire test log:
if self.log_target is not None and self.log_target.log_file_path() is not None:
with open(self.log_target.log_file_path(), 'r') as myfile:
# Otherwise vy default provide the entire test brief log:
if len(self.log_targets) == 2 and self.log_targets[1].log_file_path() is not None:
with open(self.log_targets[1].log_file_path(), 'r') as myfile:
return myfile.read()
else:
return 'test log file not available'

View File

@ -32,8 +32,6 @@ FILE_MARK_TAKEN = 'taken'
FILE_CHECKSUMS = 'checksums.md5'
TIMESTAMP_FMT = '%Y-%m-%d_%H-%M-%S'
FILE_LAST_RUN = 'last_run'
FILE_LOG = 'log'
FILE_LOG_BRIEF = 'log_brief'
class Trial(log.Origin):
UNKNOWN = 'UNKNOWN'
@ -71,12 +69,12 @@ class Trial(log.Origin):
'''add a log target to log to the run dir, write taken marker, log a
starting separator.'''
run_dir = self.get_run_dir()
detailed_log = run_dir.new_child(FILE_LOG)
detailed_log = run_dir.new_child(log.FILE_LOG)
self.log_targets = [
log.FileLogTarget(detailed_log)
.set_all_levels(log.L_DBG)
.style_change(trace=True),
log.FileLogTarget(run_dir.new_child(FILE_LOG_BRIEF))
log.FileLogTarget(run_dir.new_child(log.FILE_LOG_BRIEF))
.style_change(src=False, all_origins_on_levels=(log.L_ERR, log.L_TRACEBACK))
]
log.large_separator(self.name(), sublevel=1)