summaryrefslogtreecommitdiff
path: root/test-cli
diff options
context:
space:
mode:
Diffstat (limited to 'test-cli')
-rw-r--r--test-cli/setup.xml2
-rw-r--r--test-cli/test/helpers/plc.py23
-rw-r--r--test-cli/test/tests/qplc.py27
3 files changed, 36 insertions, 16 deletions
diff --git a/test-cli/setup.xml b/test-cli/setup.xml
index 1146e8e..26a9af2 100644
--- a/test-cli/setup.xml
+++ b/test-cli/setup.xml
@@ -18,7 +18,7 @@
<qplc firmwarepath="/root/hwtest-files/firmware" firmware="" firmware_md5=""
factory_tool="/root/hwtest-files/apps/configlayer" gen_ip="0" gen_mac="1"
mtd_device="/dev/mtd0" factory_password="betera" firmware_password="paterna"
- plc_test_ip="10.10.1.254" skipflash="0"
+ skipflash="0"
/>
</setup>
<usb>
diff --git a/test-cli/test/helpers/plc.py b/test-cli/test/helpers/plc.py
index c9ef774..069058d 100644
--- a/test-cli/test/helpers/plc.py
+++ b/test-cli/test/helpers/plc.py
@@ -6,6 +6,7 @@ from sh import Command
from test.helpers.gpio import gpio
import time
+
class dcpPLC(object):
__nReset = None
__Phy = None
@@ -40,7 +41,6 @@ class dcpPLC(object):
self.__nRest = gpio('69', 'out', '1')
self.__nRest = gpio('75', 'out', '1')
-
def SaveFirmware(self, firmare):
self.setSaveFirmwareMode()
try:
@@ -50,26 +50,33 @@ class dcpPLC(object):
return False, "plc flash firmware failed {} ".format(Error.exit_code)
return True, ''
- def set_plc (self, var, value, password):
+ def set_plc(self, var, value, password):
try:
res = self.__myConfigTool("-o", "SET", "-p", "{}={}".format(var, value), "-w", "{}".format(password))
print(res)
except ErrorReturnCode as Error:
- return False, "set var failed {} {}".format(var,Error.exit_code)
+ return False, "set var failed {} {}".format(var, Error.exit_code)
return True, ''
- def set_plc2 (self, var1, value1, var2, value2, password):
+ def set_plc2(self, var1, value1, var2, value2, password):
try:
- res = self.__myConfigTool("-o", "SET", "-p", "{}={}".format(var1, value1), "-p", "{}={}".format(var2, value2), "-w", "{}".format(password))
+ res = self.__myConfigTool("-o", "SET", "-p", "{}={}".format(var1, value1), "-p",
+ "{}={}".format(var2, value2), "-w", "{}".format(password))
print(res)
except ErrorReturnCode as Error:
return False, "set var failed {}".format(Error.exit_code)
return True, ''
-
- def get_plc (self, var, value, password):
+ def get_plc(self, var, value, password):
try:
self.__myConfigTool("-o", "GET", "-p", "{}".format(var), '{}'.format(value), "-w", "{}".format(password))
except ErrorReturnCode as Error:
- return False, "set var failed {} {}".format(var,Error.exit_code)
+ return False, "set var failed {} {}".format(var, Error.exit_code)
return True, ''
+
+ def discover(self):
+ try:
+ self.__myConfigTool("-o", "DISCOVER")
+ except ErrorReturnCode:
+ return False
+ return True
diff --git a/test-cli/test/tests/qplc.py b/test-cli/test/tests/qplc.py
index 48d600a..28310c6 100644
--- a/test-cli/test/tests/qplc.py
+++ b/test-cli/test/tests/qplc.py
@@ -6,6 +6,8 @@ import sh
import stat
import time
import ping3
+from netifaces import AF_INET
+import netifaces as ni
from test.helpers.md5 import md5_file
from test.helpers.plc import dcpPLC
@@ -34,7 +36,6 @@ class Qplc(unittest.TestCase):
self.__gen_mac = varlist.get('gen_mac', self.__xmlObj.getKeyVal(self.__QPLCName, "gen_mac", "0"))
self.__mtd_device = varlist.get('mtd_device', self.__xmlObj.getKeyVal(self.__QPLCName, "mtd_device", "/dev/mtd0"))
self.__firmware_Path = varlist.get('firmwarepath', self.__xmlObj.getKeyVal(self.__QPLCName, "firmwarepath", "/root/hwtest-files/firmware"))
- self.__plc_test_ip = varlist.get('plc_test_ip', self.__xmlObj.getKeyVal(self.__QPLCName, "plc_test_ip", "10.10.1.254"))
self.__skipflash = varlist.get('skipflash', self.__xmlObj.getKeyVal(self.__QPLCName, "skipflash", "0"))
self.__plc = dcpPLC(self.__factoryTool, self.__mtd_device)
self.__factory_password = varlist.get('factory_password', self.__xmlObj.getKeyVal(self.__QPLCName, "factory_password", "0"))
@@ -82,25 +83,37 @@ class Qplc(unittest.TestCase):
self.fail('BUG: ?????')
logObj.getlogger().info("MAC {}".format(res[0]))
plcMAC = res[0][0]
- time.sleep(12)
+ # wait for PLC to be turned on
+ attemptcounter = 0
+ plcfound = False
+ while attemptcounter < 5 and not plcfound:
+ if self.__plc.discover():
+ plcfound = True
+ else:
+ attemptcounter += 1
+ time.sleep(5)
+ # mandatory wait before configuring the PLC chip
+ time.sleep(2)
self.__plc.set_plc2('SYSTEM.PRODUCTION.SECTOR0_UNLOCK_PASSWORD',
self.__factory_password,
'SYSTEM.PRODUCTION.MAC_ADDR',
'{}'.format(plcMAC),
self.__firmware_password)
- #self.__plc.set_plc('SYSTEM.PRODUCTION.SECTOR0_UNLOCK_PASSWORD', self.__factory_password, self.__firmware_password)
- #plcMAC = res[0][0]
- #self.__plc.set_plc('SYSTEM.PRODUCTION.MAC_ADDR', '{}'.format(plcMAC), self.__firmware_password)
+ # plc reset to save changes
self.__plc.setPLCReset()
time.sleep(int(self.__plc_reset_wait))
+ # calculate the IP of the GPLC0000 board to ping
+ ip_eth01 = ni.ifaddresses('eth0:1')[AF_INET][0]['addr'] # plc_test_ip = 10.10.1.113
+ ip_eth01_splited = ip_eth01.split('.')
+ ip_eth01_splited[3] = str(int(ip_eth01_splited[3]) + 100)
+ plc_test_ip = ".".join(ip_eth01_splited) # plc_test_ip = 10.10.1.213
# ping against the GPLC0000 board
ping3.EXCEPTIONS = True
try:
- ping3.ping(self.__plc_test_ip, timeout=0.1)
+ ping3.ping(plc_test_ip, timeout=0.1)
except:
self.fail('PLC ping timeout')
-
def getresults(self):
return self.__resultlist