George Keishing | e7e9171 | 2021-09-03 11:28:44 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 2 | |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 3 | r""" |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 4 | Use robot framework API to extract test result data from output.xml generated |
| 5 | by robot tests. For more information on the Robot Framework API, see |
| 6 | http://robot-framework.readthedocs.io/en/3.0/autodoc/robot.result.html |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 7 | """ |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 8 | |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 9 | import csv |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 10 | import datetime |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 11 | import os |
Steven Sombar | 3e82e3b | 2019-03-21 10:33:52 -0500 | [diff] [blame] | 12 | import stat |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 13 | import sys |
| 14 | from xml.etree import ElementTree |
| 15 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 16 | from robot.api import ExecutionResult |
| 17 | from robot.result.visitor import ResultVisitor |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 18 | |
| 19 | # Remove the python library path to restore with local project path later. |
George Keishing | ddfd799 | 2023-02-16 03:39:47 -0600 | [diff] [blame] | 20 | SAVE_PATH_0 = sys.path[0] |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 21 | del sys.path[0] |
George Keishing | c2a6f09 | 2019-02-20 12:26:54 -0600 | [diff] [blame] | 22 | sys.path.append(os.path.join(os.path.dirname(__file__), "../../lib")) |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 23 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 24 | from gen_arg import * # NOQA |
George Keishing | 0967989 | 2022-12-08 08:21:52 -0600 | [diff] [blame] | 25 | from gen_print import * # NOQA |
| 26 | from gen_valid import * # NOQA |
George Keishing | 37c58c8 | 2022-12-08 07:42:54 -0600 | [diff] [blame] | 27 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 28 | # Restore sys.path[0]. |
George Keishing | ddfd799 | 2023-02-16 03:39:47 -0600 | [diff] [blame] | 29 | sys.path.insert(0, SAVE_PATH_0) |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 30 | |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 31 | |
| 32 | this_program = sys.argv[0] |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 33 | info = " For more information: " + this_program + " -h" |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 34 | if len(sys.argv) == 1: |
George Keishing | bfa859a | 2020-04-02 00:38:24 -0500 | [diff] [blame] | 35 | print(info) |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 36 | sys.exit(1) |
| 37 | |
| 38 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 39 | parser = argparse.ArgumentParser( |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 40 | usage=info, |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 41 | description=( |
| 42 | "%(prog)s uses a robot framework API to extract test result data" |
| 43 | " from output.xml generated by robot tests. For more information on" |
| 44 | " the Robot Framework API, see " |
| 45 | " http://robot-framework.readthedocs.io/en/3.0/autodoc/robot.result.html" |
| 46 | ), |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 47 | formatter_class=argparse.ArgumentDefaultsHelpFormatter, |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 48 | prefix_chars="-+", |
| 49 | ) |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 50 | |
| 51 | parser.add_argument( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 52 | "--source", |
| 53 | "-s", |
| 54 | help=( |
| 55 | "The output.xml robot test result file path. This parameter is " |
| 56 | " required." |
| 57 | ), |
| 58 | ) |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 59 | |
| 60 | parser.add_argument( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 61 | "--dest", |
| 62 | "-d", |
| 63 | help=( |
| 64 | "The directory path where the generated .csv files will go. This " |
| 65 | " parameter is required." |
| 66 | ), |
| 67 | ) |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 68 | |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 69 | parser.add_argument( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 70 | "--version_id", |
| 71 | help=( |
| 72 | "Driver version of openbmc firmware which was used during test, " |
| 73 | ' e.g. "v2.1-215-g6e7eacb". This parameter is required.' |
| 74 | ), |
| 75 | ) |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 76 | |
| 77 | parser.add_argument( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 78 | "--platform", |
| 79 | help=( |
| 80 | "OpenBMC platform which was used during test, e.g." |
| 81 | ' "Witherspoon". This parameter is required.' |
| 82 | ), |
| 83 | ) |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 84 | |
George Keishing | 19533d5 | 2018-04-09 03:08:03 -0500 | [diff] [blame] | 85 | parser.add_argument( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 86 | "--level", |
| 87 | help=( |
| 88 | "OpenBMC release level which was used during test, e.g." |
| 89 | ' "Master", "OBMC920". This parameter is required.' |
| 90 | ), |
| 91 | ) |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 92 | |
| 93 | parser.add_argument( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 94 | "--test_phase", |
| 95 | help=( |
| 96 | 'Name of testing phase, e.g. "DVT", "SVT", etc. This' |
| 97 | " parameter is optional." |
| 98 | ), |
| 99 | default="FVT", |
| 100 | ) |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 101 | |
| 102 | parser.add_argument( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 103 | "--subsystem", |
| 104 | help=( |
| 105 | 'Name of the subsystem, e.g. "OPENBMC" etc. This parameter is' |
| 106 | " optional." |
| 107 | ), |
| 108 | default="OPENBMC", |
| 109 | ) |
Vijay | e3a9837 | 2019-10-30 02:04:22 -0500 | [diff] [blame] | 110 | |
| 111 | parser.add_argument( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 112 | "--processor", |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 113 | help='Name of processor, e.g. "P9". This parameter is optional.', |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 114 | default="OPENPOWER", |
| 115 | ) |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 116 | |
George Keishing | 19533d5 | 2018-04-09 03:08:03 -0500 | [diff] [blame] | 117 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 118 | # Populate stock_list with options we want. |
| 119 | stock_list = [("test_mode", 0), ("quiet", 0), ("debug", 0)] |
| 120 | |
| 121 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 122 | def exit_function(signal_number=0, frame=None): |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 123 | r""" |
| 124 | Execute whenever the program ends normally or with the signals that we |
| 125 | catch (i.e. TERM, INT). |
| 126 | """ |
| 127 | |
| 128 | dprint_executing() |
| 129 | |
| 130 | dprint_var(signal_number) |
| 131 | |
| 132 | qprint_pgm_footer() |
| 133 | |
| 134 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 135 | def signal_handler(signal_number, frame): |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 136 | r""" |
| 137 | Handle signals. Without a function to catch a SIGTERM or SIGINT, the |
| 138 | program would terminate immediately with return code 143 and without |
| 139 | calling the exit_function. |
| 140 | """ |
| 141 | |
| 142 | # Our convention is to set up exit_function with atexit.register() so |
| 143 | # there is no need to explicitly call exit_function from here. |
| 144 | |
| 145 | dprint_executing() |
| 146 | |
| 147 | # Calling exit prevents us from returning to the code that was running |
| 148 | # when the signal was received. |
George Keishing | ddfd799 | 2023-02-16 03:39:47 -0600 | [diff] [blame] | 149 | sys.exit(0) |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 150 | |
| 151 | |
| 152 | def validate_parms(): |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 153 | r""" |
| 154 | Validate program parameters, etc. Return True or False (i.e. pass/fail) |
| 155 | accordingly. |
| 156 | """ |
| 157 | |
| 158 | if not valid_file_path(source): |
| 159 | return False |
| 160 | |
| 161 | if not valid_dir_path(dest): |
| 162 | return False |
| 163 | |
| 164 | gen_post_validation(exit_function, signal_handler) |
| 165 | |
| 166 | return True |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 167 | |
| 168 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 169 | def parse_output_xml( |
| 170 | xml_file_path, |
| 171 | csv_dir_path, |
| 172 | version_id, |
| 173 | platform, |
| 174 | level, |
| 175 | test_phase, |
| 176 | processor, |
| 177 | ): |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 178 | r""" |
| 179 | Parse the robot-generated output.xml file and extract various test |
| 180 | output data. Put the extracted information into a csv file in the "dest" |
| 181 | folder. |
| 182 | |
| 183 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 184 | xml_file_path The path to a Robot-generated output.xml |
| 185 | file. |
| 186 | csv_dir_path The path to the directory that is to |
| 187 | contain the .csv files generated by |
| 188 | this function. |
| 189 | version_id Version of the openbmc firmware |
| 190 | (e.g. "v2.1-215-g6e7eacb"). |
| 191 | platform Platform of the openbmc system. |
| 192 | level Release level of the OpenBMC system |
George Keishing | 360db63 | 2018-09-06 12:01:28 -0500 | [diff] [blame] | 193 | (e.g. "Master"). |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 194 | """ |
| 195 | |
Peter D Phan | 8e13ade | 2021-09-16 06:15:55 -0500 | [diff] [blame] | 196 | # Initialize tallies |
| 197 | total_critical_tc = 0 |
| 198 | total_critical_passed = 0 |
| 199 | total_critical_failed = 0 |
| 200 | total_non_critical_tc = 0 |
| 201 | total_non_critical_passed = 0 |
| 202 | total_non_critical_failed = 0 |
| 203 | |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 204 | result = ExecutionResult(xml_file_path) |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 205 | result.configure( |
| 206 | stat_config={ |
| 207 | "suite_stat_level": 2, |
| 208 | "tag_stat_combine": "tagANDanother", |
| 209 | } |
| 210 | ) |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 211 | |
| 212 | stats = result.statistics |
George Keishing | f8a9ebe | 2018-08-06 12:49:11 -0500 | [diff] [blame] | 213 | print("--------------------------------------") |
Peter D Phan | 8e13ade | 2021-09-16 06:15:55 -0500 | [diff] [blame] | 214 | try: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 215 | total_critical_tc = ( |
| 216 | stats.total.critical.passed + stats.total.critical.failed |
| 217 | ) |
Peter D Phan | 8e13ade | 2021-09-16 06:15:55 -0500 | [diff] [blame] | 218 | total_critical_passed = stats.total.critical.passed |
| 219 | total_critical_failed = stats.total.critical.failed |
| 220 | except AttributeError: |
| 221 | pass |
| 222 | |
| 223 | try: |
| 224 | total_non_critical_tc = stats.total.passed + stats.total.failed |
| 225 | total_non_critical_passed = stats.total.passed |
| 226 | total_non_critical_failed = stats.total.failed |
| 227 | except AttributeError: |
| 228 | pass |
| 229 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 230 | print( |
| 231 | "Total Test Count:\t %d" % (total_non_critical_tc + total_critical_tc) |
| 232 | ) |
Peter D Phan | 8e13ade | 2021-09-16 06:15:55 -0500 | [diff] [blame] | 233 | |
| 234 | print("Total Critical Test Failed:\t %d" % total_critical_failed) |
| 235 | print("Total Critical Test Passed:\t %d" % total_critical_passed) |
| 236 | print("Total Non-Critical Test Failed:\t %d" % total_non_critical_failed) |
| 237 | print("Total Non-Critical Test Passed:\t %d" % total_non_critical_passed) |
George Keishing | f8a9ebe | 2018-08-06 12:49:11 -0500 | [diff] [blame] | 238 | print("Test Start Time:\t %s" % result.suite.starttime) |
| 239 | print("Test End Time:\t\t %s" % result.suite.endtime) |
| 240 | print("--------------------------------------") |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 241 | |
George Keishing | ddfd799 | 2023-02-16 03:39:47 -0600 | [diff] [blame] | 242 | # Use ResultVisitor object and save off the test data info. |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 243 | class TestResult(ResultVisitor): |
George Keishing | ddfd799 | 2023-02-16 03:39:47 -0600 | [diff] [blame] | 244 | r""" |
| 245 | Class methods to save off the test data information. |
| 246 | """ |
| 247 | |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 248 | def __init__(self): |
George Keishing | ddfd799 | 2023-02-16 03:39:47 -0600 | [diff] [blame] | 249 | self.test_data = [] |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 250 | |
| 251 | def visit_test(self, test): |
George Keishing | ddfd799 | 2023-02-16 03:39:47 -0600 | [diff] [blame] | 252 | self.test_data += [test] |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 253 | |
George Keishing | ddfd799 | 2023-02-16 03:39:47 -0600 | [diff] [blame] | 254 | collect_data_obj = TestResult() |
| 255 | result.visit(collect_data_obj) |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 256 | |
| 257 | # Write the result statistics attributes to CSV file |
| 258 | l_csvlist = [] |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 259 | |
| 260 | # Default Test data |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 261 | l_test_type = test_phase |
George Keishing | 19533d5 | 2018-04-09 03:08:03 -0500 | [diff] [blame] | 262 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 263 | l_pse_rel = "Master" |
George Keishing | 19533d5 | 2018-04-09 03:08:03 -0500 | [diff] [blame] | 264 | if level: |
| 265 | l_pse_rel = level |
| 266 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 267 | l_env = "HW" |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 268 | l_proc = processor |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 269 | l_platform_type = "" |
| 270 | l_func_area = "" |
| 271 | |
Gunnar Mills | 096cd56 | 2018-03-26 10:19:12 -0500 | [diff] [blame] | 272 | # System data from XML meta data |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 273 | # l_system_info = get_system_details(xml_file_path) |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 274 | |
| 275 | # First let us try to collect information from keyboard input |
| 276 | # If keyboard input cannot give both information, then find from xml file. |
| 277 | if version_id and platform: |
| 278 | l_driver = version_id |
| 279 | l_platform_type = platform |
George Keishing | f8a9ebe | 2018-08-06 12:49:11 -0500 | [diff] [blame] | 280 | print("BMC Version_id:%s" % version_id) |
| 281 | print("BMC Platform:%s" % platform) |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 282 | else: |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 283 | # System data from XML meta data |
| 284 | l_system_info = get_system_details(xml_file_path) |
| 285 | l_driver = l_system_info[0] |
| 286 | l_platform_type = l_system_info[1] |
| 287 | |
| 288 | # Driver version id and platform are mandatorily required for CSV file |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 289 | # generation. If any one is not avaulable, exit CSV file generation |
| 290 | # process. |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 291 | if l_driver and l_platform_type: |
George Keishing | f8a9ebe | 2018-08-06 12:49:11 -0500 | [diff] [blame] | 292 | print("Driver and system info set.") |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 293 | else: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 294 | print( |
| 295 | "Both driver and system info need to be set. CSV" |
| 296 | " file is not generated." |
| 297 | ) |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 298 | sys.exit() |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 299 | |
| 300 | # Default header |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 301 | l_header = [ |
| 302 | "test_start", |
| 303 | "test_end", |
| 304 | "subsys", |
| 305 | "test_type", |
| 306 | "test_result", |
| 307 | "test_name", |
| 308 | "pse_rel", |
| 309 | "driver", |
| 310 | "env", |
| 311 | "proc", |
| 312 | "platform_type", |
| 313 | "test_func_area", |
| 314 | ] |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 315 | |
| 316 | l_csvlist.append(l_header) |
| 317 | |
| 318 | # Generate CSV file onto the path with current time stamp |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 319 | l_base_dir = csv_dir_path |
George Keishing | 937fe3c | 2019-10-29 11:20:34 -0500 | [diff] [blame] | 320 | l_timestamp = datetime.datetime.utcnow().strftime("%Y-%m-%d-%H-%M-%S") |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 321 | # Example: 2017-02-20-08-47-22_Witherspoon.csv |
| 322 | l_csvfile = l_base_dir + l_timestamp + "_" + l_platform_type + ".csv" |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 323 | |
George Keishing | f8a9ebe | 2018-08-06 12:49:11 -0500 | [diff] [blame] | 324 | print("Writing data into csv file:%s" % l_csvfile) |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 325 | |
George Keishing | ddfd799 | 2023-02-16 03:39:47 -0600 | [diff] [blame] | 326 | for testcase in collect_data_obj.test_data: |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 327 | # Functional Area: Suite Name |
| 328 | # Test Name: Test Case Name |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 329 | l_func_area = str(testcase.parent).split(" ", 1)[1] |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 330 | l_test_name = str(testcase) |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 331 | |
| 332 | # Test Result pass=0 fail=1 |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 333 | if testcase.status == "PASS": |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 334 | l_test_result = 0 |
George Keishing | c6f90c5 | 2023-02-16 03:09:25 -0600 | [diff] [blame] | 335 | elif testcase.status == "SKIP": |
| 336 | # Skipped test result should not be mark pass or fail. |
| 337 | continue |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 338 | else: |
| 339 | l_test_result = 1 |
| 340 | |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 341 | # Format datetime from robot output.xml to "%Y-%m-%d-%H-%M-%S" |
| 342 | l_stime = xml_to_csv_time(testcase.starttime) |
| 343 | l_etime = xml_to_csv_time(testcase.endtime) |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 344 | # Data Sequence: test_start,test_end,subsys,test_type, |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 345 | # test_result,test_name,pse_rel,driver, |
George Keishing | 360db63 | 2018-09-06 12:01:28 -0500 | [diff] [blame] | 346 | # env,proc,platform_type,test_func_area, |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 347 | l_data = [ |
| 348 | l_stime, |
| 349 | l_etime, |
| 350 | subsystem, |
| 351 | l_test_type, |
| 352 | l_test_result, |
| 353 | l_test_name, |
| 354 | l_pse_rel, |
| 355 | l_driver, |
| 356 | l_env, |
| 357 | l_proc, |
| 358 | l_platform_type, |
| 359 | l_func_area, |
| 360 | ] |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 361 | l_csvlist.append(l_data) |
| 362 | |
George Keishing | a96e27c | 2016-12-04 23:05:04 -0600 | [diff] [blame] | 363 | # Open the file and write to the CSV file |
George Keishing | ddfd799 | 2023-02-16 03:39:47 -0600 | [diff] [blame] | 364 | with open(l_csvfile, "w", encoding="utf8") as l_file: |
| 365 | l_writer = csv.writer(l_file, lineterminator="\n") |
| 366 | l_writer.writerows(l_csvlist) |
| 367 | l_file.close() |
| 368 | |
Steven Sombar | 3e82e3b | 2019-03-21 10:33:52 -0500 | [diff] [blame] | 369 | # Set file permissions 666. |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 370 | perm = ( |
| 371 | stat.S_IRUSR |
| 372 | + stat.S_IWUSR |
| 373 | + stat.S_IRGRP |
| 374 | + stat.S_IWGRP |
| 375 | + stat.S_IROTH |
| 376 | + stat.S_IWOTH |
| 377 | ) |
Steven Sombar | 3e82e3b | 2019-03-21 10:33:52 -0500 | [diff] [blame] | 378 | os.chmod(l_csvfile, perm) |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 379 | |
| 380 | |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 381 | def xml_to_csv_time(xml_datetime): |
| 382 | r""" |
| 383 | Convert the time from %Y%m%d %H:%M:%S.%f format to %Y-%m-%d-%H-%M-%S format |
| 384 | and return it. |
| 385 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 386 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 387 | datetime The date in the following format: %Y%m%d |
| 388 | %H:%M:%S.%f (This is the format |
| 389 | typically found in an XML file.) |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 390 | |
| 391 | The date returned will be in the following format: %Y-%m-%d-%H-%M-%S |
| 392 | """ |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 393 | |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 394 | # 20170206 05:05:19.342 |
George Keishing | 937fe3c | 2019-10-29 11:20:34 -0500 | [diff] [blame] | 395 | l_str = datetime.datetime.strptime(xml_datetime, "%Y%m%d %H:%M:%S.%f") |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 396 | # 2017-02-06-05-05-19 |
| 397 | l_str = l_str.strftime("%Y-%m-%d-%H-%M-%S") |
| 398 | return str(l_str) |
| 399 | |
| 400 | |
| 401 | def get_system_details(xml_file_path): |
| 402 | r""" |
| 403 | Get the system data from output.xml generated by robot and return it. |
Gunnar Mills | 28e403b | 2017-10-25 16:16:38 -0500 | [diff] [blame] | 404 | The list returned will be in the following order: [driver,platform] |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 405 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 406 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 407 | xml_file_path The relative or absolute path to the |
| 408 | output.xml file. |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 409 | """ |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 410 | |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 411 | bmc_version_id = "" |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 412 | bmc_platform = "" |
George Keishing | ddfd799 | 2023-02-16 03:39:47 -0600 | [diff] [blame] | 413 | with open(xml_file_path, "rt", encoding="utf-8") as output: |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 414 | tree = ElementTree.parse(output) |
| 415 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 416 | for node in tree.iter("msg"): |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 417 | # /etc/os-release output is logged in the XML as msg |
George Keishing | 360db63 | 2018-09-06 12:01:28 -0500 | [diff] [blame] | 418 | # Example: ${output} = VERSION_ID="v1.99.2-71-gbc49f79" |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 419 | if "${output} = VERSION_ID=" in node.text: |
George Keishing | 360db63 | 2018-09-06 12:01:28 -0500 | [diff] [blame] | 420 | # Get BMC version (e.g. v1.99.1-96-g2a46570) |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 421 | bmc_version_id = str(node.text.split("VERSION_ID=")[1])[1:-1] |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 422 | |
| 423 | # Platform is logged in the XML as msg. |
| 424 | # Example: ${bmc_model} = Witherspoon BMC |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 425 | if "${bmc_model} = " in node.text: |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 426 | bmc_platform = node.text.split(" = ")[1] |
| 427 | |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 428 | print_vars(bmc_version_id, bmc_platform) |
| 429 | return [str(bmc_version_id), str(bmc_platform)] |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 430 | |
| 431 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 432 | def main(): |
George Keishing | ddfd799 | 2023-02-16 03:39:47 -0600 | [diff] [blame] | 433 | r""" |
| 434 | Main caller. |
| 435 | """ |
| 436 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 437 | if not gen_get_options(parser, stock_list): |
| 438 | return False |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 439 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 440 | if not validate_parms(): |
| 441 | return False |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 442 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 443 | qprint_pgm_header() |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 444 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 445 | parse_output_xml( |
| 446 | source, dest, version_id, platform, level, test_phase, processor |
| 447 | ) |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 448 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 449 | return True |
| 450 | |
| 451 | |
| 452 | # Main |
| 453 | |
| 454 | if not main(): |
George Keishing | ddfd799 | 2023-02-16 03:39:47 -0600 | [diff] [blame] | 455 | sys.exit(1) |