[Fuego] [PATCH] common: improve the log separation function
Tim.Bird at sony.com
Tim.Bird at sony.com
Thu Mar 8 02:13:50 UTC 2018
Comments inline below...
> -----Original Message-----
> From: Liu Wenlong
>
> Tim said, "split_output_per_testcase assumes that test information
> precedes the line indicating the testcase. I would like the routine
> to also be able to handle test information that follows the testcase
> result line."
>
> I think it's a good opinion, so I add some improvements for this
> function.
Thanks.
>
> Signed-off-by: Liu Wenlong <liuwl.fnst at cn.fujitsu.com>
> ---
> engine/scripts/parser/common.py | 74
> +++++++++++++++++++++++++++++++----------
> 1 file changed, 57 insertions(+), 17 deletions(-)
>
> diff --git a/engine/scripts/parser/common.py
> b/engine/scripts/parser/common.py
> index 5594fd5..ef2f63e 100644
> --- a/engine/scripts/parser/common.py
> +++ b/engine/scripts/parser/common.py
> @@ -614,7 +614,7 @@ def make_dirs(dir_path):
> except OSError:
> pass
>
> -def split_output_per_testcase (regex_string, measurements):
> +def split_output_per_testcase (regex_string, measurements,
> info_follows_regex=0):
> '''
> For this Functional test, there is an testlog.txt file
> that contains the output log of each testcase. This function
> @@ -636,38 +636,78 @@ def split_output_per_testcase (regex_string,
> measurements):
> in_loop = 0
> test_index = 0
> test_set = "default"
> + test_log_file = "test_start"
> + new_log_file = 0
> + close_log_file = 0
> + output_each = None
> for line in lines:
> if in_loop == 0:
> - if len(measurements) > test_index:
> + in_loop = 1
> + new_log_file = 1
> +
> + # if we match the regex, then we should know that,
> + # 1. this is the last line of the testcase log file(info_follows_regex = 0)
> + # 2. this is the first line of new testcase log file(info_follows_regex = 1)
> + # no matter what the situation, we all should new file a log file and close
> + # the current log file.
> + m = re.compile(regex_string).match(line)
> + if m is not None:
> + in_loop = 0
> + close_log_file = 1
> +
> + # this is the last line of the testcase log file(info_follows_regex = 0)
> + if info_follows_regex == 0 and new_log_file == 0:
> + output_each.write("%s" % line)
> + #2. this is the first line of new testcase log file(info_follows_regex = 1)
> + elif info_follows_regex == 1:
> + if output_each is not None:
> + output_each.close()
> + os.rename(out_dir+"/tmp.log", out_dir+"/%s.log" %
> test_log_file)
> + # if info follows regex and the current line contains regex, then the
> current
> + # line is the first line of new testcase log file.
> + in_loop = 1
> + new_log_file = 1
> + close_log_file = 0
> + test_log_file = "default"
There's no 'else' here. What does the code do
if info_follows_regex == 0 and new_log_file != 0
??
Apparently nothing. Is this what is desired?
> +
> + # If new_log_file is true, it means the current line should be written in a
> new created
> + # log file.
> + if in_loop and new_log_file == 0:
> + output_each.write("%s" % line)
> +
> + # find the name of new test log file.
> + # create new log file and record the current line.
> + if new_log_file:
> + # if info follows regex and it's the first loop, we should write the
> current
> + # line to "test_start.log" and shouldn't change the value of
> test_index.
> + if info_follows_regex == 1 and test_log_file == "test_start":
> + test_index -= 1
> + elif len(measurements) > test_index:
> parts = measurements.keys()[test_index].split(".")
> - test_logfile = parts[-1]
> + test_log_file = parts[-1]
> test_set = ".".join(parts[:-1])
> else:
> - test_logfile = "test_end"
> - in_loop = 1
> - test_index += 1
> + test_log_file = "test_end"
>
> + test_index += 1
> try:
> out_dir = result_dir + '/%s/outputs' % test_set
> make_dirs(out_dir)
> output_each = open(out_dir+"/tmp.log", "w")
> + new_log_file = 0;
> + output_each.write("%s" % line)
> except IOError:
> print('"%s" cannot be created or "%s/tmp.log" cannot be opened.' %
> (out_dir, out_dir))
>
> - if in_loop:
> - output_each.write("%s" % line)
> -
> - m = re.compile(regex_string).match(line)
> - if m is not None:
> - in_loop = 0
> -
> - if in_loop == 0:
> + # close the current log file if it's open.
> + if close_log_file:
> output_each.close()
> - os.rename(out_dir+"/tmp.log", out_dir+"/%s.log" % test_logfile)
> + os.rename(out_dir+"/tmp.log", out_dir+"/%s.log" % test_log_file)
> + close_log_file = 0
>
> - if in_loop == 1:
> + if in_loop:
> output_each.close()
> - os.rename(out_dir+"/tmp.log", out_dir+"/%s.log" % test_logfile)
> + os.rename(out_dir+"/tmp.log", out_dir+"/%s.log" % test_log_file)
>
> def main():
> pass
> --
> 2.7.4
OK - applied. Thanks!
- - Tim
More information about the Fuego
mailing list