All of lore.kernel.org
 help / color / mirror / Atom feed
* [Fuego] [PATCH] common: improve the log separation function
@ 2018-03-05 15:07 Liu Wenlong
  2018-03-08  2:13 ` Tim.Bird
  0 siblings, 1 reply; 2+ messages in thread
From: Liu Wenlong @ 2018-03-05 15:07 UTC (permalink / raw)
  To: fuego

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.

Signed-off-by: Liu Wenlong <liuwl.fnst@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"
+
+        # 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




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Fuego] [PATCH] common: improve the log separation function
  2018-03-05 15:07 [Fuego] [PATCH] common: improve the log separation function Liu Wenlong
@ 2018-03-08  2:13 ` Tim.Bird
  0 siblings, 0 replies; 2+ messages in thread
From: Tim.Bird @ 2018-03-08  2:13 UTC (permalink / raw)
  To: liuwl.fnst, fuego

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@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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-03-08  2:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-05 15:07 [Fuego] [PATCH] common: improve the log separation function Liu Wenlong
2018-03-08  2:13 ` Tim.Bird

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.