From 43be7f41f86aaf2ce2ceeecd282e9a88c8398172 Mon Sep 17 00:00:00 2001 From: Eduardo Montoya Date: Thu, 5 May 2022 23:03:25 +0200 Subject: [PATCH] [thci] logging cleanup (#7654) Remove excesive logging redundancy: - `API` decorator is enough to show test script calls with arguments - `__executeCommand` already prints all OT commands and arguments - Command timestamp is irrelevant in most cases - Some extra detail logging lines are left commented in case they are needed for some debugging As a result test logs are much easier to follow and resulting files are much smaller. --- tools/harness-thci/OpenThread.py | 279 ++-------------------------- tools/harness-thci/OpenThread_BR.py | 10 - 2 files changed, 19 insertions(+), 270 deletions(-) diff --git a/tools/harness-thci/OpenThread.py b/tools/harness-thci/OpenThread.py index 7af1d1b79..3d856e4b1 100644 --- a/tools/harness-thci/OpenThread.py +++ b/tools/harness-thci/OpenThread.py @@ -60,12 +60,11 @@ from GRLLibs.UtilityModules.enums import ( PlatformDiagnosticPacket_Direction, PlatformDiagnosticPacket_Type, ) - from GRLLibs.UtilityModules.enums import DevCapb -import commissioner -from commissioner_impl import OTCommissioner from IThci import IThci +import commissioner +from commissioner_impl import OTCommissioner ZEPHYR_PREFIX = 'ot ' """CLI prefix used for OpenThread commands in Zephyr systems""" @@ -117,6 +116,8 @@ def watched(func): raise finally: _callStackDepth -= 1 + if _callStackDepth == 0: + print('\n') return wrapped_api_func @@ -250,7 +251,7 @@ class OpenThreadTHCI(object): def __sendCommand(self, cmd, expectEcho=True): cmd = self._cmdPrefix + cmd - self.log("command: %s", cmd) + # self.log("command: %s", cmd) self._cliWriteLine(cmd) if expectEcho: self.__expect(cmd, endswith=True) @@ -287,7 +288,7 @@ class OpenThreadTHCI(object): time.sleep(0.01) continue - self.log("readline: %s", line) + # self.log("readline: %s", line) # skip empty lines if line: response.append(line) @@ -317,13 +318,14 @@ class OpenThreadTHCI(object): expected str: the expected string times int: number of tries """ - self.log('Expecting [%s]' % (expected)) + #self.log('Expecting [%s]' % (expected)) deadline = time.time() + timeout while True: line = self.__readCliLine() if line is not None: - self.log("readline: %s", line) + #self.log("readline: %s", line) + pass if line is None: if time.time() >= deadline: @@ -334,7 +336,7 @@ class OpenThreadTHCI(object): matched = line.endswith(expected) if endswith else line == expected if matched: - self.log('Expected [%s]' % (expected)) + #self.log('Expected [%s]' % (expected)) return raise Exception('failed to find expected string[%s]' % expected) @@ -356,7 +358,8 @@ class OpenThreadTHCI(object): def log(self, fmt, *args): try: msg = fmt % args - print('%s - %s - %s' % (self.port, time.strftime('%b %d %H:%M:%S'), msg)) + # print('%s - %s - %s' % (self.port, time.strftime('%b %d %H:%M:%S'), msg)) + print('%s %s' % (self.port, msg)) except Exception: pass @@ -369,7 +372,6 @@ class OpenThreadTHCI(object): def intialize(self, params): """initialize the serial port with baudrate, timeout parameters""" self.port = params.get('SerialPort', '') - self.log('%s intialize: %r', self.__class__.__name__, params) # params example: {'EUI': 1616240311388864514L, 'SerialBaudRate': None, 'TelnetIP': '192.168.8.181', 'SerialPort': None, 'Param7': None, 'Param6': None, 'Param5': 'ip', 'TelnetPort': '22', 'Param9': None, 'Param8': None} try: @@ -440,7 +442,6 @@ class OpenThreadTHCI(object): def __disableRouterEligible(self): """disable router role """ - print('call __disableRouterEligible') cmd = 'routereligible disable' self.__executeCommand(cmd) @@ -458,8 +459,6 @@ class OpenThreadTHCI(object): True: successful to set the device mode False: fail to set the device mode """ - print('call __setDeviceMode') - print(mode) cmd = 'mode %s' % mode return self.__executeCommand(cmd)[-1] == 'Done' @@ -474,9 +473,7 @@ class OpenThreadTHCI(object): True: successful to set the ROUTER_UPGRADE_THRESHOLD False: fail to set ROUTER_UPGRADE_THRESHOLD """ - print('call __setRouterUpgradeThreshold') cmd = 'routerupgradethreshold %s' % str(iThreshold) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' def __setRouterDowngradeThreshold(self, iThreshold): @@ -491,9 +488,7 @@ class OpenThreadTHCI(object): True: successful to set the ROUTER_DOWNGRADE_THRESHOLD False: fail to set ROUTER_DOWNGRADE_THRESHOLD """ - print('call __setRouterDowngradeThreshold') cmd = 'routerdowngradethreshold %s' % str(iThreshold) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' def __setRouterSelectionJitter(self, iRouterJitter): @@ -506,9 +501,7 @@ class OpenThreadTHCI(object): True: successful to set the ROUTER_SELECTION_JITTER False: fail to set ROUTER_SELECTION_JITTER """ - print('call _setRouterSelectionJitter') cmd = 'routerselectionjitter %s' % str(iRouterJitter) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' def __setAddressfilterMode(self, mode): @@ -518,7 +511,6 @@ class OpenThreadTHCI(object): True: successful to set address filter mode. False: fail to set address filter mode. """ - print('call setAddressFilterMode() ' + mode) cmd = 'macfilter addr ' + mode return self.__executeCommand(cmd)[-1] == 'Done' @@ -529,7 +521,6 @@ class OpenThreadTHCI(object): True: successful to start OpenThread stack and thread interface up False: fail to start OpenThread stack """ - print('call startOpenThread') if self.hasActiveDatasetToCommit: if self.__executeCommand('dataset commit active')[0] != 'Done': raise Exception('failed to commit active dataset') @@ -573,19 +564,6 @@ class OpenThreadTHCI(object): self.isPowerDown = False return True - def __stopOpenThread(self): - """stop OpenThread stack - - Returns: - True: successful to stop OpenThread stack and thread interface down - False: fail to stop OpenThread stack - """ - self.log('call stopOpenThread') - if self.__executeCommand('thread stop')[-1] == 'Done': - return self.__executeCommand('ifconfig down')[-1] == 'Done' - else: - return False - @watched def __isOpenThreadRunning(self): """check whether or not OpenThread is running @@ -607,8 +585,7 @@ class OpenThreadTHCI(object): detached_states = ["detached", "disabled"] return self.__executeCommand('state')[0] not in detached_states - # rloc16 might be hex string or integer, need to return actual allocated - # router id + # rloc16 might be hex string or integer, need to return actual allocated router id def __convertRlocToRouterId(self, xRloc16): """mapping Rloc16 to router id @@ -622,9 +599,6 @@ class OpenThreadTHCI(object): rloc16 = None routerid = None - print(routerList) - print(xRloc16) - for index in routerList: cmd = 'router %s' % index router = self.__executeCommand(cmd) @@ -737,13 +711,11 @@ class OpenThreadTHCI(object): return maskSet def __setChannelMask(self, channelMask): - self.log('call _setChannelMask') cmd = 'dataset channelmask %s' % channelMask self.hasActiveDatasetToCommit = True return self.__executeCommand(cmd)[-1] == 'Done' def __setSecurityPolicy(self, securityPolicySecs, securityPolicyFlags): - print('call _setSecurityPolicy') cmd = 'dataset securitypolicy %s %s' % ( str(securityPolicySecs), securityPolicyFlags, @@ -761,8 +733,6 @@ class OpenThreadTHCI(object): True: successful to set key switch guard time False: fail to set key switch guard time """ - print('%s call setKeySwitchGuardTime' % self) - print(iKeySwitchGuardTime) cmd = 'keysequence guardtime %s' % str(iKeySwitchGuardTime) if self.__executeCommand(cmd)[-1] == 'Done': self.sleep(1) @@ -772,7 +742,6 @@ class OpenThreadTHCI(object): def __getCommissionerSessionId(self): """ get the commissioner session id allocated from Leader """ - print('%s call getCommissionerSessionId' % self) return self.__executeCommand('commissioner sessionid')[0] # pylint: disable=no-self-use @@ -801,8 +770,6 @@ class OpenThreadTHCI(object): True: successful to set the Thread Networkname False: fail to set the Thread Networkname """ - print('%s call setNetworkName' % self) - print(networkName) networkName = self._deviceEscapeEscapable(networkName) cmd = 'networkname %s' % networkName datasetCmd = 'dataset networkname %s' % networkName @@ -823,8 +790,6 @@ class OpenThreadTHCI(object): True: successful to set the channel False: fail to set the channel """ - print('%s call setChannel' % self) - print(channel) cmd = 'channel %s' % channel datasetCmd = 'dataset channel %s' % channel self.hasSetChannel = True @@ -834,7 +799,6 @@ class OpenThreadTHCI(object): @API def getChannel(self): """get current channel""" - print('%s call getChannel' % self) return self.__executeCommand('channel')[0] @API @@ -848,15 +812,12 @@ class OpenThreadTHCI(object): True: successful to set the extended address False: fail to set the extended address """ - print('%s call setMAC' % self) - print(xEUI) if not isinstance(xEUI, str): address64 = self.__convertLongToHex(xEUI, 16) else: address64 = xEUI cmd = 'extaddr %s' % address64 - print(cmd) if self.__executeCommand(cmd)[-1] == 'Done': self.mac = address64 return True @@ -874,8 +835,6 @@ class OpenThreadTHCI(object): Returns: specific type of MAC address """ - print('%s call getMAC' % self) - print(bType) # if power down happens, return extended address assigned previously if self.isPowerDown: macAddr64 = self.mac @@ -888,34 +847,29 @@ class OpenThreadTHCI(object): return self._deviceGetEtherMac() else: macAddr64 = self.__executeCommand('extaddr')[0] - print(macAddr64) return int(macAddr64, 16) @API def getLL64(self): """get link local unicast IPv6 address""" - print('%s call getLL64' % self) return self.__executeCommand('ipaddr linklocal')[0] @API def getRloc16(self): """get rloc16 short address""" - print('%s call getRloc16' % self) rloc16 = self.__executeCommand('rloc16')[0] return int(rloc16, 16) @API def getRloc(self): """get router locator unicast Ipv6 address""" - print('%s call getRloc' % self) return self.__executeCommand('ipaddr rloc')[0] def __getGlobal(self): """get global unicast IPv6 address set if configuring multiple entries """ - print('%s call getGlobal' % self) globalAddrs = [] rlocAddr = self.getRloc() @@ -930,18 +884,10 @@ class OpenThreadTHCI(object): fullIp = ModuleHelper.GetFullIpv6Address(ip6Addr).lower() - print('address %s' % fullIp) - - if fullIp.startswith('fe80'): - print('link local') - continue - - if fullIp.startswith(rlocAddr[0:19]): - print('mesh local') + if fullIp.startswith('fe80') or fullIp.startswith(rlocAddr[0:19]): continue globalAddrs.append(fullIp) - print('global') return globalAddrs @@ -956,9 +902,6 @@ class OpenThreadTHCI(object): True: successful to set the Thread network key False: fail to set the Thread network key """ - print('%s call setNetworkKey' % self) - print(key) - if not isinstance(key, str): networkKey = self.__convertLongToHex(key, 32) cmd = 'networkkey %s' % networkKey @@ -983,8 +926,6 @@ class OpenThreadTHCI(object): True: successful to add a given extended address to the denylist entry False: fail to add a given extended address to the denylist entry """ - print('%s call addBlockedMAC' % self) - print(xEUI) if isinstance(xEUI, str): macAddr = xEUI else: @@ -1000,7 +941,6 @@ class OpenThreadTHCI(object): self._addressfilterMode = 'denylist' cmd = 'macfilter addr add %s' % macAddr - print(cmd) ret = self.__executeCommand(cmd)[-1] == 'Done' self._addressfilterSet.add(macAddr) @@ -1021,8 +961,6 @@ class OpenThreadTHCI(object): True: successful to add a given extended address to the allowlist entry False: fail to add a given extended address to the allowlist entry """ - print('%s call addAllowMAC' % self) - print(xEUI) if isinstance(xEUI, str): macAddr = xEUI else: @@ -1033,7 +971,6 @@ class OpenThreadTHCI(object): self._addressfilterMode = 'allowlist' cmd = 'macfilter addr add %s' % macAddr - print(cmd) ret = self.__executeCommand(cmd)[-1] == 'Done' self._addressfilterSet.add(macAddr) @@ -1050,8 +987,6 @@ class OpenThreadTHCI(object): True: successful to clear the denylist False: fail to clear the denylist """ - print('%s call clearBlockList' % self) - # remove all entries in denylist print('clearing denylist entries:') for addr in self._addressfilterSet: @@ -1075,8 +1010,6 @@ class OpenThreadTHCI(object): True: successful to clear the allowlist False: fail to clear the allowlist """ - print('%s call clearAllowList' % self) - # remove all entries in allowlist print('clearing allowlist entries:') for addr in self._addressfilterSet: @@ -1095,7 +1028,6 @@ class OpenThreadTHCI(object): @API def getDeviceRole(self): """get current device role in Thread Network""" - print('%s call getDeviceRole' % self) return self.__executeCommand('state')[0] @API @@ -1108,9 +1040,6 @@ class OpenThreadTHCI(object): Returns: True: ready to set Thread Network parameter for joining desired Network """ - print('%s call joinNetwork' % self) - print(eRoleId) - self.deviceRole = eRoleId mode = '-' if ModuleHelper.LeaderDutChannelFound and not self.hasSetChannel: @@ -1213,9 +1142,7 @@ class OpenThreadTHCI(object): Returns: The Thread network Partition Id """ - print('%s call getNetworkFragmentID' % self) if not self.__isOpenThreadRunning(): - print('OpenThread is not running') return None leaderData = self.__executeCommand('leaderdata') @@ -1228,7 +1155,6 @@ class OpenThreadTHCI(object): Returns: The extended address of parent in hex format """ - print('%s call getParentAddress' % self) eui = None parentInfo = self.__executeCommand('parent') @@ -1237,10 +1163,6 @@ class OpenThreadTHCI(object): break elif 'Ext Addr' in line: eui = line.split()[2] - print(eui) - # elif 'Rloc' in line: - # rloc16 = line.split()[1] - # print(rloc16) else: pass @@ -1249,7 +1171,6 @@ class OpenThreadTHCI(object): @API def powerDown(self): """power down the Thread device""" - print('%s call powerDown' % self) self.__sendCommand('reset', expectEcho=False) if not self.IsBorderRouter: @@ -1261,7 +1182,6 @@ class OpenThreadTHCI(object): @API def powerUp(self): """power up the Thread device""" - print('%s call powerUp' % self) self.isPowerDown = False if not self.__isOpenThreadRunning(): @@ -1299,7 +1219,6 @@ class OpenThreadTHCI(object): True: successful to reset and rejoin the Thread Network False: fail to reset and rejoin the Thread Network """ - print('%s call reboot' % self) self.reset_and_wait_for_connection() self.__startOpenThread() return self.wait_for_attach_to_the_network(expected_role="", timeout=self.NETWORK_ATTACHMENT_TIMEOUT) @@ -1315,7 +1234,6 @@ class OpenThreadTHCI(object): True: successful to reset and rejoin Thread Network False: fail to reset and rejoin the Thread Network """ - print('%s call resetAndRejoin' % self) self.powerDown() time.sleep(timeout) self.powerUp() @@ -1331,8 +1249,6 @@ class OpenThreadTHCI(object): hop_limit: hop limit """ - print('%s call ping' % self.port) - print('destination: %s' % strDestination) cmd = 'ping %s %s 1 1 %d %d' % (strDestination, str(ilength), hop_limit, timeout) self.__executeCommand(cmd) @@ -1345,10 +1261,7 @@ class OpenThreadTHCI(object): destination: the multicast destination address of ICMPv6 echo request length: the size of ICMPv6 echo request payload """ - print('%s call multicast_Ping' % self) - print('destination: %s' % destination) cmd = 'ping %s %s' % (destination, str(length)) - print(cmd) self.__sendCommand(cmd) # wait echo reply self.sleep(1) @@ -1364,12 +1277,9 @@ class OpenThreadTHCI(object): True: successful to set the Thread Network PAN ID False: fail to set the Thread Network PAN ID """ - print('%s call setPANID' % self) - print(xPAN) panid = '' if not isinstance(xPAN, str): panid = str(hex(xPAN)) - print(panid) cmd = 'panid %s' % panid datasetCmd = 'dataset panid %s' % panid @@ -1379,8 +1289,6 @@ class OpenThreadTHCI(object): @API def reset(self): """factory reset""" - print('%s call reset' % self) - self._deviceBeforeReset() self.__sendCommand('factoryreset', expectEcho=False) @@ -1418,13 +1326,9 @@ class OpenThreadTHCI(object): True: successful to remove the router from the Thread Network False: fail to remove the router from the Thread Network """ - print('%s call removeRouter' % self) - print(xRouterId) routerId = self.__convertRlocToRouterId(xRouterId) - print(routerId) if routerId is None: - print('no matched xRouterId') return False cmd = 'releaserouterid %s' % routerId @@ -1433,8 +1337,6 @@ class OpenThreadTHCI(object): @API def setDefaultValues(self): """set default mandatory Thread Network parameter value""" - print('%s call setDefaultValues' % self) - # initialize variables self.networkName = ModuleHelper.Default_NwkName self.networkKey = ModuleHelper.Default_NwkKey @@ -1502,7 +1404,6 @@ class OpenThreadTHCI(object): @API def getDeviceConncetionStatus(self): """check if serial port connection is ready or not""" - print('%s call getDeviceConnectionStatus' % self) return self.deviceConnected @API @@ -1516,10 +1417,7 @@ class OpenThreadTHCI(object): True: successful to set the data polling rate for sleepy end device False: fail to set the data polling rate for sleepy end device """ - print('%s call setPollingRate' % self) - iPollingRate = int(iPollingRate * 1000) - print(iPollingRate) if self.__sedPollPeriod != iPollingRate: if not iPollingRate: @@ -1545,7 +1443,6 @@ class OpenThreadTHCI(object): False: fail to set the data poll period for sleepy end device """ cmd = 'pollperiod %d' % iPollPeriod - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -1565,9 +1462,6 @@ class OpenThreadTHCI(object): True: successful to set the link quality False: fail to set the link quality """ - print('%s call setLinkQuality' % self) - print(EUIadr) - print(LinkQuality) # process EUIadr euiHex = hex(EUIadr) euiStr = str(euiHex) @@ -1581,7 +1475,6 @@ class OpenThreadTHCI(object): print(address64) cmd = 'macfilter rss add-lqi %s %s' % (address64, str(LinkQuality)) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -1600,10 +1493,7 @@ class OpenThreadTHCI(object): True: successful to set the link quality False: fail to set the link quality """ - print('%s call setOutBoundLinkQuality' % self) - print(LinkQuality) cmd = 'macfilter rss add-lqi * %s' % str(LinkQuality) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -1617,10 +1507,8 @@ class OpenThreadTHCI(object): True: successful to remove the prefix entry from border router False: fail to remove the prefix entry from border router """ - print('%s call removeRouterPrefix' % self) assert (ipaddress.IPv6Network(prefixEntry.decode())) cmd = 'prefix remove %s/64' % prefixEntry - print(cmd) if self.__executeCommand(cmd)[-1] == 'Done': # send server data ntf to leader return self.__executeCommand('netdata register')[-1] == 'Done' @@ -1656,7 +1544,6 @@ class OpenThreadTHCI(object): True: successful to configure the border router with a given prefix entry False: fail to configure the border router with a given prefix entry """ - print('%s call configBorderRouter' % self) assert (ipaddress.IPv6Network(P_Prefix.decode())) # turn off default domain prefix if configBorderRouter is called before joining network @@ -1699,7 +1586,6 @@ class OpenThreadTHCI(object): pass cmd = 'prefix add %s/64 %s %s' % (P_Prefix, parameter, prf) - print(cmd) if self.__executeCommand(cmd)[-1] == 'Done': # if prefix configured before starting OpenThread stack # do not send out server data ntf pro-actively @@ -1722,11 +1608,8 @@ class OpenThreadTHCI(object): True: successful to set NETWORK_ID_TIMEOUT False: fail to set NETWORK_ID_TIMEOUT """ - print('%s call setNetworkIDTimeout' % self) - print(iNwkIDTimeOut) iNwkIDTimeOut /= 1000 cmd = 'networkidtimeout %s' % str(iNwkIDTimeOut) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -1754,8 +1637,6 @@ class OpenThreadTHCI(object): True: successful to set the key sequence False: fail to set the key sequence """ - print('%s call setKeySequenceCounter' % self) - print(iKeySequenceValue) # avoid key switch guard timer protection for reference device self.__setKeySwitchGuardTime(0) @@ -1769,7 +1650,6 @@ class OpenThreadTHCI(object): @API def getKeySequenceCounter(self): """get current Thread Network key sequence""" - print('%s call getKeySequenceCounter' % self) keySequence = self.__executeCommand('keysequence counter')[0] return keySequence @@ -1784,13 +1664,10 @@ class OpenThreadTHCI(object): True: successful to increment the key sequence with a given value False: fail to increment the key sequence with a given value """ - print('%s call incrementKeySequenceCounter' % self) - print(iIncrementValue) # avoid key switch guard timer protection for reference device self.__setKeySwitchGuardTime(0) currentKeySeq = self.getKeySequenceCounter() keySequence = int(currentKeySeq, 10) + iIncrementValue - print(keySequence) return self.setKeySequenceCounter(keySequence) @API @@ -1804,9 +1681,6 @@ class OpenThreadTHCI(object): Returns: True: successful to set the network requirement """ - print('%s call setNetworkDataRequirement' % self) - print(eDataRequirement) - if eDataRequirement == Device_Data_Requirement.ALL_DATA: self.networkDataRequirement = 'n' return True @@ -1827,7 +1701,6 @@ class OpenThreadTHCI(object): True: successful to configure the border router with a given external route prefix False: fail to configure the border router with a given external route prefix """ - print('%s call configExternalRouter' % self) assert (ipaddress.IPv6Network(P_Prefix.decode())) prf = '' stable = '' @@ -1845,7 +1718,6 @@ class OpenThreadTHCI(object): cmd = 'route add %s/64 %s %s' % (P_Prefix, stable, prf) else: cmd = 'route add %s/64 %s' % (P_Prefix, prf) - print(cmd) if self.__executeCommand(cmd)[-1] == 'Done': # send server data ntf to leader @@ -1858,13 +1730,10 @@ class OpenThreadTHCI(object): Returns: neighboring routers' extended address """ - print('%s call getNeighbouringRouters' % self) routerInfo = [] routerList = self.__executeCommand('router list')[0].split() - print(routerList) if 'Done' in routerList: - print('no neighbouring routers') return None for index in routerList: @@ -1887,7 +1756,6 @@ class OpenThreadTHCI(object): else: pass - print(routerInfo) return routerInfo @API @@ -1899,16 +1767,11 @@ class OpenThreadTHCI(object): """ eui = None rloc16 = None - - print('%s call getChildrenInfo' % self) - childrenInfoAll = [] childrenInfo = {'EUI': 0, 'Rloc16': 0, 'MLEID': ''} childrenList = self.__executeCommand('child list')[0].split() - print(childrenList) if 'Done' in childrenList: - print('no children') return None for index in childrenList: @@ -1937,7 +1800,6 @@ class OpenThreadTHCI(object): childrenInfoAll.append(childrenInfo['EUI']) # childrenInfoAll.append(childrenInfo) - print(childrenInfoAll) return childrenInfoAll @API @@ -1952,8 +1814,6 @@ class OpenThreadTHCI(object): False: fail to set the extended PAN ID """ xpanid = '' - print('%s call setXpanId' % self) - print(xPanId) if not isinstance(xPanId, str): xpanid = self.__convertLongToHex(xPanId, 16) cmd = 'extpanid %s' % xpanid @@ -1976,7 +1836,6 @@ class OpenThreadTHCI(object): A list including extended address of neighboring routers, parent as well as children """ - print('%s call getNeighbouringDevices' % self) neighbourList = [] # get parent info @@ -1996,7 +1855,6 @@ class OpenThreadTHCI(object): for entry in routerNeighbours: neighbourList.append(entry) - print(neighbourList) return neighbourList @API @@ -2010,11 +1868,7 @@ class OpenThreadTHCI(object): True: successful to set the Partition ID False: fail to set the Partition ID """ - print('%s call setPartationId' % self) - print(partationId) - cmd = 'partitionid preferred %s' % (str(hex(partationId)).rstrip('L')) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -2039,27 +1893,22 @@ class OpenThreadTHCI(object): else: for fullIp in globalAddrs: if fullIp.startswith(filterByPrefix): - print('target global %s' % fullIp) return fullIp - print('no global address matched') return str(globalAddrs[0]) @API def getShortAddress(self): """get Rloc16 short address of Thread device""" - print('%s call getShortAddress' % self) return self.getRloc16() @API def getULA64(self): """get mesh local EID of Thread device""" - print('%s call getULA64' % self) return self.__executeCommand('ipaddr mleid')[0] @API def setMLPrefix(self, sMeshLocalPrefix): """set mesh local prefix""" - print('%s call setMLPrefix' % self) cmd = 'dataset meshlocalprefix %s' % sMeshLocalPrefix self.hasActiveDatasetToCommit = True return self.__executeCommand(cmd)[-1] == 'Done' @@ -2067,7 +1916,6 @@ class OpenThreadTHCI(object): @API def getML16(self): """get mesh local 16 unicast address (Rloc)""" - print('%s call getML16' % self) return self.getRloc() @API @@ -2089,10 +1937,7 @@ class OpenThreadTHCI(object): True: successful to set slaac address to Thread interface False: fail to set slaac address to Thread interface """ - print('%s call forceSetSlaac' % self) - print(slaacAddress) cmd = 'ipaddr add %s' % str(slaacAddress) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -2102,13 +1947,11 @@ class OpenThreadTHCI(object): @API def enableAutoDUTObjectFlag(self): """set AutoDUTenable flag""" - print('%s call enableAutoDUTObjectFlag' % self) self.AutoDUTEnable = True @API def getChildTimeoutValue(self): """get child timeout""" - print('%s call getChildTimeoutValue' % self) childTimeout = self.__executeCommand('childtimeout')[0] return int(childTimeout) @@ -2124,7 +1967,6 @@ class OpenThreadTHCI(object): strDestinationAddr, ' '.join([str(tlv) for tlv in listTLV_ids]), ) - print(cmd) return self.__sendCommand(cmd, expectEcho=False) @@ -2140,7 +1982,6 @@ class OpenThreadTHCI(object): strDestinationAddr, ' '.join([str(tlv) for tlv in listTLV_ids]), ) - print(cmd) return self.__executeCommand(cmd) @@ -2153,10 +1994,8 @@ class OpenThreadTHCI(object): # TODO: Support the whole Native Commissioner functionality # Currently it only aims to trigger a Discovery Request message to pass # Certification test 5.8.4 - print('%s call startNativeCommissioner' % self) self.__executeCommand('ifconfig up') cmd = 'joiner start %s' % (strPSKc) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -2190,7 +2029,6 @@ class OpenThreadTHCI(object): Returns: A boolean indicates whether this function succeed. """ - if self.externalCommissioner is not None: self.externalCommissioner.stop() return not self.externalCommissioner.isActive() @@ -2203,13 +2041,11 @@ class OpenThreadTHCI(object): True: successful to start Commissioner False: fail to start Commissioner """ - print('%s call startCollapsedCommissioner' % self) if self.__startOpenThread(): self.wait_for_attach_to_the_network(expected_role=self.deviceRole, timeout=self.NETWORK_ATTACHMENT_TIMEOUT, raise_assert=True) cmd = 'commissioner start' - print(cmd) if self.__executeCommand(cmd)[-1] == 'Done': self.isActiveCommissioner = True self.sleep(20) # time for petition process @@ -2250,7 +2086,6 @@ class OpenThreadTHCI(object): str(timeout), ) - print(cmd) if self.__executeCommand(cmd)[-1] == 'Done': if self.logThreadStatus == self.logStatus['stop']: self.logThread = ThreadRunner.run(target=self.__readCommissioningLogs, args=(120,)) @@ -2273,7 +2108,6 @@ class OpenThreadTHCI(object): True: successful to set provisioning Url False: fail to set provisioning Url """ - print('%s call setProvisioningUrl' % self) self.provisioningUrl = strURL if self.deviceRole == Thread_Device_Role.Commissioner: cmd = 'commissioner provisioningurl %s' % (strURL) @@ -2288,9 +2122,7 @@ class OpenThreadTHCI(object): True: successful to start commissioner candidate petition process False: fail to start commissioner candidate petition process """ - print('%s call allowCommission' % self) cmd = 'commissioner start' - print(cmd) if self.__executeCommand(cmd)[-1] == 'Done': self.isActiveCommissioner = True # time for petition process and at least one keep alive @@ -2321,7 +2153,6 @@ class OpenThreadTHCI(object): self.__executeCommand('ifconfig up') strPSKd = self.__normalizePSKd(strPSKd) cmd = 'joiner start %s %s' % (strPSKd, self.provisioningUrl) - print(cmd) if self.__executeCommand(cmd)[-1] == 'Done': maxDuration = 150 # seconds self.joinCommissionedStatus = self.joinStatus['ongoing'] @@ -2360,14 +2191,12 @@ class OpenThreadTHCI(object): while not rawLogs.empty(): rawLogEach = rawLogs.get() - print(rawLogEach) if '[THCI]' not in rawLogEach: continue EncryptedPacket = PlatformDiagnosticPacket() infoList = rawLogEach.split('[THCI]')[1].split(']')[0].split('|') for eachInfo in infoList: - print(eachInfo) info = eachInfo.split('=') infoType = info[0].strip() infoValue = info[1].strip() @@ -2426,7 +2255,6 @@ class OpenThreadTHCI(object): True: successful to send MGMT_ED_SCAN message. False: fail to send MGMT_ED_SCAN message """ - print('%s call MGMT_ED_SCAN' % self) channelMask = '0x' + self.__convertLongToHex(self.__convertChannelMask(listChannelMask)) cmd = 'commissioner energy %s %s %s %s %s' % ( channelMask, @@ -2435,7 +2263,6 @@ class OpenThreadTHCI(object): xScanDuration, sAddr, ) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -2449,7 +2276,6 @@ class OpenThreadTHCI(object): True: successful to send MGMT_PANID_QUERY message. False: fail to send MGMT_PANID_QUERY message. """ - print('%s call MGMT_PANID_QUERY' % self) panid = '' channelMask = '0x' + self.__convertLongToHex(self.__convertChannelMask(listChannelMask)) @@ -2457,7 +2283,6 @@ class OpenThreadTHCI(object): panid = str(hex(xPanId)) cmd = 'commissioner panid %s %s %s' % (panid, channelMask, sAddr) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -2468,7 +2293,6 @@ class OpenThreadTHCI(object): True: successful to send MGMT_ANNOUNCE_BEGIN message. False: fail to send MGMT_ANNOUNCE_BEGIN message. """ - print('%s call MGMT_ANNOUNCE_BEGIN' % self) channelMask = '0x' + self.__convertLongToHex(self.__convertChannelMask(listChannelMask)) cmd = 'commissioner announce %s %s %s %s' % ( channelMask, @@ -2476,7 +2300,6 @@ class OpenThreadTHCI(object): xPeriod, sAddr, ) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -2487,7 +2310,6 @@ class OpenThreadTHCI(object): True: successful to send MGMT_ACTIVE_GET False: fail to send MGMT_ACTIVE_GET """ - print('%s call MGMT_ACTIVE_GET' % self) cmd = 'dataset mgmtgetcommand active' if Addr != '': @@ -2499,8 +2321,6 @@ class OpenThreadTHCI(object): cmd += ' -x ' cmd += tlvs - print(cmd) - return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -2530,7 +2350,6 @@ class OpenThreadTHCI(object): True: successful to send MGMT_ACTIVE_SET False: fail to send MGMT_ACTIVE_SET """ - print('%s call MGMT_ACTIVE_SET' % self) cmd = 'dataset mgmtsetcommand active' if listActiveTimestamp is not None: @@ -2664,8 +2483,6 @@ class OpenThreadTHCI(object): if BogusTLV is not None: cmd += '8202aa55' - print(cmd) - return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -2676,7 +2493,6 @@ class OpenThreadTHCI(object): True: successful to send MGMT_PENDING_GET False: fail to send MGMT_PENDING_GET """ - print('%s call MGMT_PENDING_GET' % self) cmd = 'dataset mgmtgetcommand pending' if Addr != '': @@ -2688,8 +2504,6 @@ class OpenThreadTHCI(object): cmd += ' -x ' cmd += tlvs - print(cmd) - return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -2712,7 +2526,6 @@ class OpenThreadTHCI(object): True: successful to send MGMT_PENDING_SET False: fail to send MGMT_PENDING_SET """ - print('%s call MGMT_PENDING_SET' % self) cmd = 'dataset mgmtsetcommand pending' if listPendingTimestamp is not None: @@ -2760,8 +2573,6 @@ class OpenThreadTHCI(object): cmd += sessionid - print(cmd) - return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -2772,7 +2583,6 @@ class OpenThreadTHCI(object): True: successful to send MGMT_COMM_GET False: fail to send MGMT_COMM_GET """ - print('%s call MGMT_COMM_GET' % self) cmd = 'commissioner mgmtget' if len(TLVs) != 0: @@ -2780,8 +2590,6 @@ class OpenThreadTHCI(object): cmd += ' -x ' cmd += tlvs - print(cmd) - return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -2800,7 +2608,6 @@ class OpenThreadTHCI(object): True: successful to send MGMT_COMM_SET False: fail to send MGMT_COMM_SET """ - print('%s call MGMT_COMM_SET' % self) cmd = 'commissioner mgmtset' if xCommissionerSessionID is not None: @@ -2827,31 +2634,29 @@ class OpenThreadTHCI(object): cmd += ' -x ' cmd += '000300' + '%04x' % xChannelTlv - print(cmd) - return self.__executeCommand(cmd)[-1] == 'Done' @API def setActiveDataset(self, listActiveDataset=()): - print('%s call setActiveDataset' % self) + # Unused by the scripts + pass @API def setCommisionerMode(self): - print('%s call setCommissionerMode' % self) + # Unused by the scripts + pass @API def setPSKc(self, strPSKc): - print('%s call setPSKc' % self) cmd = 'dataset pskc %s' % strPSKc self.hasActiveDatasetToCommit = True return self.__executeCommand(cmd)[-1] == 'Done' @API def setActiveTimestamp(self, xActiveTimestamp): - print('%s call setActiveTimestamp' % self) self.activetimestamp = xActiveTimestamp - cmd = 'dataset activetimestamp %s' % str(xActiveTimestamp) self.hasActiveDatasetToCommit = True + cmd = 'dataset activetimestamp %s' % str(xActiveTimestamp) return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -2865,9 +2670,7 @@ class OpenThreadTHCI(object): True: successful to set Joiner UDP Port False: fail to set Joiner UDP Port """ - print('%s call setUdpJoinerPort' % self) cmd = 'joinerport %d' % portNumber - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -2878,16 +2681,12 @@ class OpenThreadTHCI(object): True: successful to stop commissioner False: fail to stop commissioner """ - print('%s call commissionerUnregister' % self) cmd = 'commissioner stop' - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API def sendBeacons(self, sAddr, xCommissionerSessionId, listChannelMask, xPanId): - print('%s call sendBeacons' % self) self.__sendCommand('scan', expectEcho=False) - return True @API def updateRouterStatus(self): @@ -2896,7 +2695,6 @@ class OpenThreadTHCI(object): @API def __updateRouterStatus(self): - print('%s call updateRouterStatus' % self) cmd = 'state' while True: state = self.__executeCommand(cmd)[0] @@ -2912,20 +2710,16 @@ class OpenThreadTHCI(object): @API def setRouterThresholdValues(self, upgradeThreshold, downgradeThreshold): - print('%s call setRouterThresholdValues' % self) self.__setRouterUpgradeThreshold(upgradeThreshold) self.__setRouterDowngradeThreshold(downgradeThreshold) @API def setMinDelayTimer(self, iSeconds): - print('%s call setMinDelayTimer' % self) cmd = 'delaytimermin %s' % iSeconds - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API def ValidateDeviceFirmware(self): - print('%s call ValidateDeviceFirmware' % self) return 'OPENTHREAD' in self.UIStatusMsg @API @@ -2992,16 +2786,12 @@ class OpenThreadTHCI(object): @API def setCSLtout(self, tout=30): self.ssedTimeout = tout - self.log('call setCSLtout') cmd = 'csl timeout %u' % self.ssedTimeout - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API def setCSLchannel(self, ch=11): - self.log('call setCSLchannel') cmd = 'csl channel %u' % ch - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -3014,9 +2804,7 @@ class OpenThreadTHCI(object): period is converted from unit ms to ten symbols (160us per 10 symbols). """ - self.log('call setCSLperiod') cmd = 'csl period %u' % (period * 6.25) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @staticmethod @@ -3073,14 +2861,11 @@ class OpenThreadTHCI(object): @API def LinkMetricsSingleReq(self, dst_addr, metrics): - self.log('call LinkMetricsSingleReq') cmd = 'linkmetrics query %s single %s' % (dst_addr, self.getMetricsFlagsFromHexStr(metrics)) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API def LinkMetricsMgmtReq(self, dst_addr, type_, flags, metrics, series_id): - self.log('call LinkMetricsMgmtReq') cmd = 'linkmetrics mgmt %s ' % dst_addr if type_ == 'FWD': cmd += 'forward %d %s' % (series_id, self.getForwardSeriesFlagsFromHexOrStr(flags)) @@ -3092,27 +2877,21 @@ class OpenThreadTHCI(object): cmd += ' register %s' % (self.getMetricsFlagsFromHexStr(metrics)) else: cmd += ' clear' - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API def LinkMetricsGetReport(self, dst_addr, series_id): - self.log('call LinkMetricsGetReport') cmd = 'linkmetrics query %s forward %d' % (dst_addr, series_id) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' # TODO: Series Id is not in this API. @API def LinkMetricsSendProbe(self, dst_addr, ack=True, size=0): - self.log('call LinkMetricsSendProbe') cmd = 'linkmetrics probe %s %d' % (dst_addr, size) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API def setTxPower(self, level): - self.log('call setTxPower') cmd = 'txpower ' if level == 'HIGH': cmd += '127' @@ -3122,28 +2901,23 @@ class OpenThreadTHCI(object): cmd += '-128' else: print('wrong Tx Power level') - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API def sendUdp(self, destination, port, payload='hello'): - self.log('call sendUdp') assert payload is not None, 'payload should not be none' cmd = 'udp send %s %d %s' % (destination, port, payload) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API def send_udp(self, interface, destination, port, payload='12ABcd'): ''' payload hexstring ''' - self.log('call send_udp') assert payload is not None, 'payload should not be none' assert interface == 0, "non-BR must send UDP to Thread interface" self.__udpOpen() time.sleep(0.5) cmd = 'udp send %s %s -x %s' % (destination, port, payload) - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' def __udpOpen(self): @@ -3161,21 +2935,16 @@ class OpenThreadTHCI(object): @API def sendMACcmd(self, enh=False): - self.log('call sendMACcmd') cmd = 'mac send datarequest' - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API def sendMACdata(self, enh=False): - self.log('call sendMACdata') cmd = 'mac send emptydata' - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API def setCSLsuspension(self, suspend): - self.log('call setCSLsuspension') if suspend: self.__setPollPeriod(240 * 1000) else: @@ -3184,7 +2953,6 @@ class OpenThreadTHCI(object): @API def set_max_addrs_per_child(self, num): cmd = 'childip max %d' % int(num) - print(cmd) self.__executeCommand(cmd) @API @@ -3220,11 +2988,9 @@ class OpenThreadTHCI(object): def __getMlIid(self): """get the Mesh Local IID.""" - print('%s call __getMlIid' % self.port) # getULA64() would return the full string representation mleid = ModuleHelper.GetFullIpv6Address(self.getULA64()).lower() mliid = mleid[-19:].replace(':', '') - print('mliid: %s' % mliid) return mliid def __setMlIid(self, sMlIid): @@ -3249,8 +3015,6 @@ class OpenThreadTHCI(object): @API def stopListeningToAddr(self, sAddr): - print('%s call stopListeningToAddr' % self.port) - cmd = 'ipmaddr del ' + sAddr try: self.__executeCommand(cmd) @@ -3316,7 +3080,6 @@ class OpenThreadTHCI(object): @API def setParentPrio(self, prio): cmd = 'parentpriority %u' % prio - print(cmd) return self.__executeCommand(cmd)[-1] == 'Done' @API @@ -3385,10 +3148,6 @@ class OpenThreadTHCI(object): class OpenThread(OpenThreadTHCI, IThci): - # Used for reference firmware version control for Test Harness. - # This variable will be updated to match the OpenThread reference firmware - # officially released. - def _connect(self): print('My port is %s' % self) self.__lines = [] diff --git a/tools/harness-thci/OpenThread_BR.py b/tools/harness-thci/OpenThread_BR.py index 26c6b252a..b8566fe49 100644 --- a/tools/harness-thci/OpenThread_BR.py +++ b/tools/harness-thci/OpenThread_BR.py @@ -392,7 +392,6 @@ class OpenThread_BR(OpenThreadTHCI, IThci): raise AssertionError('Invalid interface set to send UDP: {} ' 'Available interface options: 0 - Thread; 1 - Ethernet'.format(interface)) cmd = '/home/pi/reference-device/send_udp.py %s %s %s %s' % (ifname, dst, port, payload) - print(cmd) self.bash(cmd) @API @@ -401,12 +400,10 @@ class OpenThread_BR(OpenThreadTHCI, IThci): dst = 'ff02::1' cmd = '/home/pi/reference-device/send_mld_query.py %s %s' % (ifname, dst) - print(cmd) self.bash(cmd) @API def ip_neighbors_flush(self): - print('%s call clear_cache' % self.port) # clear neigh cache on linux cmd1 = 'sudo ip -6 neigh flush nud all nud failed nud noarp dev eth0' cmd2 = 'sudo ip -6 neigh list nud all dev eth0 ' \ @@ -417,7 +414,6 @@ class OpenThread_BR(OpenThreadTHCI, IThci): @API def ip_neighbors_add(self, addr, lladdr, nud='noarp'): - print('%s ip_neighbors_add' % self.port) cmd1 = 'sudo ip -6 neigh delete %s dev eth0' % addr cmd2 = 'sudo ip -6 neigh add %s dev eth0 lladdr %s nud %s' % (addr, lladdr, nud) cmd = '%s ; %s' % (cmd1, cmd2) @@ -425,7 +421,6 @@ class OpenThread_BR(OpenThreadTHCI, IThci): @API def get_eth_ll(self): - print('%s get_eth_ll' % self.port) cmd = "ip -6 addr list dev eth0 | grep 'inet6 fe80' | awk '{print $2}'" ret = self.bash(cmd)[0].split('/')[0] return ret @@ -468,8 +463,6 @@ class OpenThread_BR(OpenThreadTHCI, IThci): destination: the multicast destination address of ICMPv6 echo request length: the size of ICMPv6 echo request payload """ - print('%s call multicast_Ping' % self.port) - print('destination: %s' % destination) hop_limit = 5 if self.IsHost or self.IsBackboneRouter: @@ -639,8 +632,6 @@ class OpenThread_BR(OpenThreadTHCI, IThci): @API def mdns_query(self, dst='ff02::fb', service='_meshcop._udp.local', addrs_blacklist=[]): - print('mdns_query %s %s %s' % (dst, service, addrs_blacklist)) - # For BBR-TC-03 or DH test cases (empty arguments) just send a query if dst == 'ff02::fb' and not addrs_blacklist: self.bash('dig -p 5353 @%s %s ptr' % (dst, service), sudo=False) @@ -675,7 +666,6 @@ class OpenThread_BR(OpenThreadTHCI, IThci): # Override forceSetSlaac @API def forceSetSlaac(self, slaacAddress): - print('forceSetSlaac %s' % slaacAddress) self.bash('ip -6 addr add %s/64 dev wpan0' % slaacAddress) # Override stopListeningToAddr