[Fuego] [PATCH 2/9] common: add a generic function to split test outputs

Liu Wenlong liuwl.fnst at cn.fujitsu.com
Wed Jan 31 07:50:07 UTC 2018


Functional.LTP can split the test outputs to separated log file for each case.
Now, I add some links to those separated log files, which can help users to
check the error log for each case quickly, especially for those tests who had
heavy logs.

So, now I wanna to add this support for some Functional tests.

Signed-off-by: Liu Wenlong <liuwl.fnst at cn.fujitsu.com>
---
 engine/scripts/parser/common.py | 64 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/engine/scripts/parser/common.py b/engine/scripts/parser/common.py
index 61f9d0c..5594fd5 100644
--- a/engine/scripts/parser/common.py
+++ b/engine/scripts/parser/common.py
@@ -605,6 +605,70 @@ def process_data(ref_section_pat, test_results, plot_type, label):
 
     return process(measurements)
 
+def make_dirs(dir_path):
+    if os.path.exists(dir_path):
+        return
+
+    try:
+        os.makedirs(dir_path)
+    except OSError:
+        pass
+
+def split_output_per_testcase (regex_string, measurements):
+    '''
+        For this Functional test, there is an testlog.txt file
+        that contains the output log of each testcase. This function
+        splits output.log into the log files of each case
+    '''
+    # open input
+    try:
+        output_all = open(TEST_LOG)
+    except IOError:
+        print('"%s" cannot be opened.' % TEST_LOG)
+
+    # prepare for outputs, the depth of the folder is the same as the LTP log files
+    result_dir = '%s/logs/%s/%s.%s.%s.%s/result' % (FUEGO_RW, TESTDIR, NODE_NAME, TESTSPEC, BUILD_NUMBER, BUILD_ID)
+    make_dirs(result_dir)
+
+    lines = output_all.readlines()
+    output_all.close()
+
+    in_loop = 0
+    test_index = 0
+    test_set = "default"
+    for line in lines:
+        if in_loop == 0:
+            if len(measurements) > test_index:
+                parts = measurements.keys()[test_index].split(".")
+                test_logfile = parts[-1]
+                test_set = ".".join(parts[:-1])
+            else:
+                test_logfile = "test_end"
+            in_loop = 1
+            test_index += 1
+
+            try:
+                out_dir = result_dir + '/%s/outputs' % test_set
+                make_dirs(out_dir)
+                output_each = open(out_dir+"/tmp.log", "w")
+            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:
+            output_each.close()
+            os.rename(out_dir+"/tmp.log", out_dir+"/%s.log" % test_logfile)
+
+    if in_loop == 1:
+        output_each.close()
+        os.rename(out_dir+"/tmp.log", out_dir+"/%s.log" % test_logfile)
+
 def main():
     pass
 
-- 
2.7.4





More information about the Fuego mailing list