Joey Armstrong | 9fadcbe | 2024-01-17 19:00:37 -0500 | [diff] [blame] | 1 | # Copyright 2017-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Matteo Scandolo | 142e627 | 2020-04-29 17:36:59 -0700 | [diff] [blame] | 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 | |
| 15 | import argparse |
| 16 | import os |
| 17 | import xml.etree.ElementTree as ET |
| 18 | from datetime import datetime |
| 19 | |
| 20 | dash = "-" * 75 |
| 21 | double_dash = "=" * 75 |
| 22 | |
| 23 | |
| 24 | def cut_string(str): |
| 25 | return (str[:48] + "..") if len(str) > 50 else str |
| 26 | |
Matteo Scandolo | 3ed8987 | 2020-07-15 17:01:02 -0700 | [diff] [blame] | 27 | |
Matteo Scandolo | 142e627 | 2020-04-29 17:36:59 -0700 | [diff] [blame] | 28 | def format_key(str): |
| 29 | return str.replace("plot-", "").replace("-", " ") |
| 30 | |
Matteo Scandolo | 3ed8987 | 2020-07-15 17:01:02 -0700 | [diff] [blame] | 31 | |
Matteo Scandolo | 142e627 | 2020-04-29 17:36:59 -0700 | [diff] [blame] | 32 | def 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 Scandolo | 3ed8987 | 2020-07-15 17:01:02 -0700 | [diff] [blame] | 41 | start_timer = 0 |
Matteo Scandolo | 142e627 | 2020-04-29 17:36:59 -0700 | [diff] [blame] | 42 | 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 Scandolo | 3ed8987 | 2020-07-15 17:01:02 -0700 | [diff] [blame] | 53 | time = start_timer + diff.seconds |
Matteo Scandolo | 3022859 | 2020-05-08 15:25:56 -0700 | [diff] [blame] | 54 | print("{:<50}{:>10}{:>15}".format(cut_string(name), status.attrib["status"], time)) |
Matteo Scandolo | 142e627 | 2020-04-29 17:36:59 -0700 | [diff] [blame] | 55 | 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 Scandolo | 3022859 | 2020-05-08 15:25:56 -0700 | [diff] [blame] | 61 | results[tag.text] = time |
Matteo Scandolo | 3ed8987 | 2020-07-15 17:01:02 -0700 | [diff] [blame] | 62 | start_timer = time |
Matteo Scandolo | 142e627 | 2020-04-29 17:36:59 -0700 | [diff] [blame] | 63 | |
| 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 | |
| 74 | if __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) |