blob: 1e15ab1dbd7671d10d8c5bd22a6882c92a1f7cf9 [file] [log] [blame]
Matteo Scandolo142e6272020-04-29 17:36:59 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import argparse
16import os
17import xml.etree.ElementTree as ET
18from datetime import datetime
19
20dash = "-" * 75
21double_dash = "=" * 75
22
23
24def cut_string(str):
25 return (str[:48] + "..") if len(str) > 50 else str
26
27def format_key(str):
28 return str.replace("plot-", "").replace("-", " ")
29
30def read_file(file, plot_folder):
31 # create element tree object
32 tree = ET.parse(file)
33
34 # get root element
35 root = tree.getroot()
36
37 results = {}
38
Matteo Scandolo30228592020-05-08 15:25:56 -070039
40 startTimer = 0
Matteo Scandolo142e6272020-04-29 17:36:59 -070041 print(double_dash)
42 print("{:<50}{:>10}{:>15}".format("Test Name", "Status", "Duration (s)"))
43 print(double_dash)
44 for test in root.findall("./suite/test"):
45 status = test.find(".status")
46 name = test.attrib["name"]
47 start = status.attrib["starttime"]
48 end = status.attrib["endtime"]
49 s = datetime.strptime(start[:-4], "%Y%m%d %H:%M:%S")
50 e = datetime.strptime(end[:-4], "%Y%m%d %H:%M:%S")
51 diff = e - s
Matteo Scandolo30228592020-05-08 15:25:56 -070052 time = startTimer + diff.seconds
53 print("{:<50}{:>10}{:>15}".format(cut_string(name), status.attrib["status"], time))
Matteo Scandolo142e6272020-04-29 17:36:59 -070054 print(dash)
55
56 # check if the test has a tag that starts with "plot-",
57 # if so store the result to create plot files for Jenkins
58 for tag in test.findall("./tags/tag"):
59 if "plot-" in tag.text:
Matteo Scandolo30228592020-05-08 15:25:56 -070060 results[tag.text] = time
61 startTimer = time
Matteo Scandolo142e6272020-04-29 17:36:59 -070062
63 if not os.path.isdir(plot_folder):
64 os.mkdir(plot_folder)
65
66 for k, v in results.items():
67 f = open("%s/%s.txt" % (plot_folder, k), "a")
68 f.write("%s\n" % format_key(k))
69 f.write(str(v))
70 f.close()
71
72
73if __name__ == "__main__":
74 parser = argparse.ArgumentParser(prog="collect-result")
75 parser.add_argument("-r", "--robot-output", help="he robot output.xml file to process", default="output.xml"),
76 parser.add_argument("-p", "--plot-folder", help="here to output the files needed for the Jenkins plots", default="plots")
77
78 args = parser.parse_args()
79
80 read_file(args.robot_output, args.plot_folder)