Skip to content

Commit

Permalink
Tools: fix junit report and add firmware version on report
Browse files Browse the repository at this point in the history
  • Loading branch information
khancyr committed Nov 17, 2023
1 parent b6a9505 commit 595b7c8
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ mav.*
!Tools/environment_install/install-prereqs-ubuntu.sh
!Tools/environment_install/install-prereqs-arch.sh
!Tools/completion
autotest_result_*_junit.xml
autotest_result_*_junit.xml
6 changes: 1 addition & 5 deletions Tools/autotest/autotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,7 @@ class TestResults(object):
def __init__(self):
"""Init test results class."""
self.date = time.asctime()
self.githash = util.run_cmd('git rev-parse HEAD',
output=True,
directory=util.reltopdir('.')).strip()
if sys.version_info.major >= 3:
self.githash = self.githash.decode('utf-8')
self.githash = util.get_git_hash()
self.tests = []
self.files = []
self.images = []
Expand Down
1 change: 1 addition & 0 deletions Tools/autotest/fakepos.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def kt2mps(x):
def mps2kt(x):
return x / 0.514444444


udp = udp_out("127.0.0.1:5501")

latitude = -35
Expand Down
8 changes: 8 additions & 0 deletions Tools/autotest/pysim/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,14 @@ def load_local_module(fname):
return ret


def get_git_hash(short=False):
short_v = "--short=8 " if short else ""
githash = run_cmd(f'git rev-parse {short_v}HEAD', output=True, directory=reltopdir('.')).strip()
if sys.version_info.major >= 3:
githash = githash.decode('utf-8')
return githash


if __name__ == "__main__":
import doctest
doctest.testmod()
71 changes: 66 additions & 5 deletions Tools/autotest/vehicle_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,7 @@ def __init__(self,
if spec is None:
raise ImportError
except ImportError as e:
raise ImportError(f"Junit export need junitparser package.\n {e} \nTry: python -m pip install junitparser")
raise ImportError(f"Junit export need junitparser package.\n {e} \nTry: python3 -m pip install junitparser")

self.mavproxy = None
self._mavproxy = None # for auto-cleanup on failed tests
Expand Down Expand Up @@ -6124,6 +6124,58 @@ def get_autopilot_capabilities(self):
m = self.assert_receive_message('AUTOPILOT_VERSION', timeout=10)
return m.capabilities

def decode_flight_sw_version(self, flight_sw_version: int):
""" Decode 32 bit flight_sw_version mavlink parameter
corresponds to encoding in ardupilot GCS_MAVLINK::send_autopilot_version."""
fw_type_id = (flight_sw_version >> 0) % 256
patch = (flight_sw_version >> 8) % 256
minor = (flight_sw_version >> 16) % 256
major = (flight_sw_version >> 24) % 256
if fw_type_id == 0:
fw_type = "dev"
elif fw_type_id == 64:
fw_type = "alpha"
elif fw_type_id == 128:
fw_type = "beta"
elif fw_type_id == 192:
fw_type = "rc"
elif fw_type_id == 255:
fw_type = "official"
else:
fw_type = "undefined"
return major, minor, patch, fw_type

def get_autopilot_firmware_version(self):
self.mav.mav.command_long_send(self.sysid_thismav(),
1,
mavutil.mavlink.MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES,
0, # confirmation
1, # 1: Request autopilot version
0,
0,
0,
0,
0,
0)
m = self.assert_receive_message('AUTOPILOT_VERSION', timeout=10)
self.fcu_firmware_version = self.decode_flight_sw_version(m.flight_sw_version)

def hex_values_to_int(hex_values):
# Convert ascii codes to characters
hex_chars = [chr(int(hex_value)) for hex_value in hex_values]
# Convert hex characters to integers, handle \x00 case
int_values = [0 if hex_char == '\x00' else int(hex_char, 16) for hex_char in hex_chars]
return int_values

fcu_hash_to_hex = ""
for i in hex_values_to_int(m.flight_custom_version):
fcu_hash_to_hex += f"{i:x}"
self.fcu_firmware_hash = fcu_hash_to_hex
self.progress(f"Firmware Version {self.fcu_firmware_version}")
self.progress(f"Firmware hash {self.fcu_firmware_hash}")
self.githash = util.get_git_hash(short=True)
self.progress(f"Git hash {self.githash}")

def GetCapabilities(self):
'''Get Capabilities'''
self.assert_capability(mavutil.mavlink.MAV_PROTOCOL_CAPABILITY_PARAM_FLOAT)
Expand Down Expand Up @@ -8312,6 +8364,7 @@ def init(self):
# recv_match and those will not be in self.mav.messages until
# you do this!
self.wait_heartbeat()
self.get_autopilot_firmware_version()
self.progress("Sim time: %f" % (self.get_sim_time(),))
self.apply_default_parameters()

Expand Down Expand Up @@ -13585,9 +13638,8 @@ def create_junit_report(self, test_name: str, results: List[Result], skip_list:
xml_filename = f"autotest_result_{frame}_{test_name}_junit.xml"
self.progress(f"Writing test result in jUnit format to {xml_filename}\n")

suites = TestSuite("ArduPilot Autotest")
suites.timestamp = datetime.now().replace(microsecond=0).isoformat()
suite = TestSuite(f"Autotest {frame} {test_name}")
suite.timestamp = datetime.now().replace(microsecond=0).isoformat()
for result in results:
case = TestCase(f"{result.test.name}", f"{frame}", result.time_elapsed)
# f"{result.test.description}"
Expand All @@ -13599,9 +13651,18 @@ def create_junit_report(self, test_name: str, results: List[Result], skip_list:
(test, reason) = skipped
case = TestCase(f"{test.name}", f"{test.function}")
case.result = [Skipped(f"Skipped : {reason}")]
# Add suite to JunitXml

suite.add_property("Firmware Version Major", self.fcu_firmware_version[0])
suite.add_property("Firmware Version Minor", self.fcu_firmware_version[1])
suite.add_property("Firmware Version Rev", self.fcu_firmware_version[2])
suite.add_property("Firmware hash", self.fcu_firmware_hash)
suite.add_property("Git hash", self.githash)
mavproxy_version = util.MAVProxy_version()
suite.add_property("Mavproxy Version Major", mavproxy_version[0])
suite.add_property("Mavproxy Version Minor", mavproxy_version[1])
suite.add_property("Mavproxy Version Rev", mavproxy_version[2])

xml = JUnitXml()
xml.add_testsuite(suites)
xml.add_testsuite(suite)
xml.write(xml_filename, pretty=True)

Expand Down

0 comments on commit 595b7c8

Please sign in to comment.