blob: f65ae3110b15594a680e3730fdf4661da1be3c4d [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
39 print(double_dash)
40 print("{:<50}{:>10}{:>15}".format("Test Name", "Status", "Duration (s)"))
41 print(double_dash)
42 for test in root.findall("./suite/test"):
43 status = test.find(".status")
44 name = test.attrib["name"]
45 start = status.attrib["starttime"]
46 end = status.attrib["endtime"]
47 s = datetime.strptime(start[:-4], "%Y%m%d %H:%M:%S")
48 e = datetime.strptime(end[:-4], "%Y%m%d %H:%M:%S")
49 diff = e - s
50 print("{:<50}{:>10}{:>15}".format(cut_string(name), status.attrib["status"], diff.seconds))
51 print(dash)
52
53 # check if the test has a tag that starts with "plot-",
54 # if so store the result to create plot files for Jenkins
55 for tag in test.findall("./tags/tag"):
56 if "plot-" in tag.text:
57 results[tag.text] = diff.seconds
58
59 if not os.path.isdir(plot_folder):
60 os.mkdir(plot_folder)
61
62 for k, v in results.items():
63 f = open("%s/%s.txt" % (plot_folder, k), "a")
64 f.write("%s\n" % format_key(k))
65 f.write(str(v))
66 f.close()
67
68
69if __name__ == "__main__":
70 parser = argparse.ArgumentParser(prog="collect-result")
71 parser.add_argument("-r", "--robot-output", help="he robot output.xml file to process", default="output.xml"),
72 parser.add_argument("-p", "--plot-folder", help="here to output the files needed for the Jenkins plots", default="plots")
73
74 args = parser.parse_args()
75
76 read_file(args.robot_output, args.plot_folder)