blob: 0624e3d6fd6884ea4139f2353148c4b1f5715573 [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
Matteo Scandoloe5ed3a62020-07-15 17:01:02 -070027
Matteo Scandolo142e6272020-04-29 17:36:59 -070028def format_key(str):
29 return str.replace("plot-", "").replace("-", " ")
30
Matteo Scandoloe5ed3a62020-07-15 17:01:02 -070031
Matteo Scandolo142e6272020-04-29 17:36:59 -070032def read_file(file, plot_folder):
33 # create element tree object
34 tree = ET.parse(file)
35
36 # get root element
37 root = tree.getroot()
38
39 results = {}
40
Matteo Scandoloe5ed3a62020-07-15 17:01:02 -070041 start_timer = 0
Matteo Scandolo142e6272020-04-29 17:36:59 -070042 print(double_dash)
43 print("{:<50}{:>10}{:>15}".format("Test Name", "Status", "Duration (s)"))
44 print(double_dash)
45 for test in root.findall("./suite/test"):
46 status = test.find(".status")
47 name = test.attrib["name"]
48 start = status.attrib["starttime"]
49 end = status.attrib["endtime"]
50 s = datetime.strptime(start[:-4], "%Y%m%d %H:%M:%S")
51 e = datetime.strptime(end[:-4], "%Y%m%d %H:%M:%S")
52 diff = e - s
Matteo Scandoloe5ed3a62020-07-15 17:01:02 -070053 time = start_timer + diff.seconds
Matteo Scandolo30228592020-05-08 15:25:56 -070054 print("{:<50}{:>10}{:>15}".format(cut_string(name), status.attrib["status"], time))
Matteo Scandolo142e6272020-04-29 17:36:59 -070055 print(dash)
56
57 # check if the test has a tag that starts with "plot-",
58 # if so store the result to create plot files for Jenkins
59 for tag in test.findall("./tags/tag"):
60 if "plot-" in tag.text:
Matteo Scandolo30228592020-05-08 15:25:56 -070061 results[tag.text] = time
Matteo Scandoloe5ed3a62020-07-15 17:01:02 -070062 start_timer = time
Matteo Scandolo142e6272020-04-29 17:36:59 -070063
64 if not os.path.isdir(plot_folder):
65 os.mkdir(plot_folder)
66
67 for k, v in results.items():
68 f = open("%s/%s.txt" % (plot_folder, k), "a")
69 f.write("%s\n" % format_key(k))
70 f.write(str(v))
71 f.close()
72
73
74if __name__ == "__main__":
75 parser = argparse.ArgumentParser(prog="collect-result")
76 parser.add_argument("-r", "--robot-output", help="he robot output.xml file to process", default="output.xml"),
77 parser.add_argument("-p", "--plot-folder", help="here to output the files needed for the Jenkins plots", default="plots")
78
79 args = parser.parse_args()
80
81 read_file(args.robot_output, args.plot_folder)