summaryrefslogtreecommitdiff
path: root/test-cli
diff options
context:
space:
mode:
authorHector Fernandez <hector@iatec.biz>2020-03-09 09:03:28 +0100
committerHector Fernandez <hector@iatec.biz>2020-03-09 09:03:28 +0100
commita03055f657d2e970e45e7ea2a3e66857f821eabd (patch)
tree398c136bba073f7a7959fba1b95ab19f2c23281a /test-cli
parent9f07a57d89a927aa9b172c1bf20c7ab563658c73 (diff)
downloadboard-a03055f657d2e970e45e7ea2a3e66857f821eabd.zip
board-a03055f657d2e970e45e7ea2a3e66857f821eabd.tar.gz
board-a03055f657d2e970e45e7ea2a3e66857f821eabd.tar.bz2
Solved problems with consumption test. Fixed error when getting mac address.
Diffstat (limited to 'test-cli')
-rw-r--r--test-cli/.idea/workspace.xml43
-rw-r--r--test-cli/test/helpers/amper.py155
-rw-r--r--test-cli/test/helpers/int_registers.py15
-rw-r--r--test-cli/test/tests/qamp.py1
-rw-r--r--test-cli/test/tests/qamper.py51
-rw-r--r--test-cli/test_main.py4
6 files changed, 239 insertions, 30 deletions
diff --git a/test-cli/.idea/workspace.xml b/test-cli/.idea/workspace.xml
index cd587e0..7e0aea1 100644
--- a/test-cli/.idea/workspace.xml
+++ b/test-cli/.idea/workspace.xml
@@ -2,26 +2,11 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="4991a6e0-1b9d-4824-9b6e-5ac031eb4816" name="Default Changelist" comment="">
+ <change afterPath="$PROJECT_DIR$/test/helpers/amper.py" afterDir="false" />
+ <change afterPath="$PROJECT_DIR$/test/tests/qamper.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/helpers/get_dieid.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/helpers/int_registers.py" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/helpers/testsrv_db.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/helpers/testsrv_db.py" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/runners/simple.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/runners/simple.py" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/test/helpers/int_registers.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/helpers/int_registers.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/test/tests/qamp.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qamp.py" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/tests/qaudio.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qaudio.py" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/tests/qbutton.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qbutton.py" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/tests/qduplex_ser.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qduplex_ser.py" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/tests/qeeprom.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qeeprom.py" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/tests/qethernet.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qethernet.py" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/tests/qflash.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qflash.py" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/tests/qi2c.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qi2c.py" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/tests/qiperf.py" beforeDir="false" />
- <change beforePath="$PROJECT_DIR$/test/tests/qnand.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qnand.py" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/tests/qram.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qram.py" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/tests/qrtc.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qrtc.py" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/tests/qscreen.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qscreen.py" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/tests/qserial.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qserial.py" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/tests/qusb.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qusb.py" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/tests/qwifi.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qwifi.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/test_main.py" beforeDir="false" afterPath="$PROJECT_DIR$/test_main.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@@ -29,6 +14,13 @@
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
+ <component name="FileTemplateManagerImpl">
+ <option name="RECENT_TEMPLATES">
+ <list>
+ <option value="Python Script" />
+ </list>
+ </option>
+ </component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
@@ -43,9 +35,14 @@
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
- <property name="last_opened_file_path" value="$PROJECT_DIR$/test_main.py" />
+ <property name="last_opened_file_path" value="$PROJECT_DIR$/test/tests" />
<property name="settings.editor.selected.configurable" value="Errors" />
</component>
+ <component name="RecentsManager">
+ <key name="CopyFile.RECENT_KEYS">
+ <recent name="$PROJECT_DIR$/test/tests" />
+ </key>
+ </component>
<component name="RunManager">
<configuration name="test" type="PythonConfigurationType" factoryName="Python">
<module name="test-cli" />
@@ -87,18 +84,18 @@
<option name="version" value="1" />
</component>
<component name="WindowStateProjectService">
- <state x="451" y="210" width="1084" height="713" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1583487479234">
+ <state x="451" y="210" width="1084" height="713" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1583495767719">
<screen x="67" y="27" width="1853" height="1053" />
</state>
- <state x="451" y="210" width="1084" height="713" key="#com.intellij.execution.impl.EditConfigurationsDialog/67.27.1853.1053@67.27.1853.1053" timestamp="1583487479234" />
+ <state x="451" y="210" width="1084" height="713" key="#com.intellij.execution.impl.EditConfigurationsDialog/67.27.1853.1053@67.27.1853.1053" timestamp="1583495767719" />
<state width="717" height="568" key="DebuggerActiveHint" timestamp="1583488899608">
<screen x="67" y="27" width="1853" height="1053" />
</state>
<state width="717" height="568" key="DebuggerActiveHint/67.27.1853.1053@67.27.1853.1053" timestamp="1583488899608" />
- <state x="776" y="324" width="424" height="484" key="FileChooserDialogImpl" timestamp="1583487456480">
+ <state x="776" y="324" width="424" height="484" key="FileChooserDialogImpl" timestamp="1583495745960">
<screen x="67" y="27" width="1853" height="1053" />
</state>
- <state x="776" y="324" width="424" height="484" key="FileChooserDialogImpl/67.27.1853.1053@67.27.1853.1053" timestamp="1583487456480" />
+ <state x="776" y="324" width="424" height="484" key="FileChooserDialogImpl/67.27.1853.1053@67.27.1853.1053" timestamp="1583495745960" />
<state width="1830" height="344" key="GridCell.Tab.-1.bottom" timestamp="1583490172702">
<screen x="67" y="27" width="1853" height="1053" />
</state>
diff --git a/test-cli/test/helpers/amper.py b/test-cli/test/helpers/amper.py
new file mode 100644
index 0000000..45ec7db
--- /dev/null
+++ b/test-cli/test/helpers/amper.py
@@ -0,0 +1,155 @@
+import serial
+import scanf
+import time
+
+
+class Amper(object):
+ __ser = None
+ __port = '/dev/ttyUSB0'
+ __speed = 115200
+ __parity = None
+ __rtscts = 0
+ __timeout = 1
+ __isThere = False
+ __version = None
+ __voltage = 0.0
+ __current = 0.0
+ __alarm_condition = 0
+
+ def __init__(self, port='/dev/ttyUSB0', serial_speed=115200, parity=serial.PARITY_NONE, rtscts=0):
+ self.__port = port
+ self.__speed = serial_speed
+ self.__parity = parity
+ self.__rtscts = rtscts
+
+ def open(self):
+ try:
+ if self.__ser is not None:
+ self.close()
+ self.__ser = serial.Serial(port=self.__port,
+ baudrate=self.__speed,
+ timeout=self.__timeout,
+ parity=self.__parity,
+ rtscts=self.__rtscts,
+ bytesize=serial.EIGHTBITS,
+ stopbits=serial.STOPBITS_ONE,
+ xonxoff=0)
+
+ self.__ser.flushInput()
+ self.__ser.flushOutput()
+ self.__ser.break_condition = False
+ return True
+ except serial.SerialException as err:
+ print(err)
+ return False
+
+ def close(self):
+ if self.__ser is not None:
+ self.__ser.close()
+ self.__ser = None
+ self.__isThere = False
+ self.__version = None
+ self.__voltage = 0.0
+ self.__current = 0.0
+ self.__alarm_condition = 0
+
+ def __write(self, data):
+ data += "\n\r"
+ dat = data.encode('ascii')
+ self.__ser.write(dat)
+
+ def __read(self):
+ return self.__ser.readline().decode().rstrip()
+
+ def __set_voltage_underlimit(self, under_limit):
+ if self.__isThere and self.__ser is not None:
+ self.__write('AT+VIN_UV_W_LIM={}'.format(under_limit))
+ dat = self.__read()
+ print(dat)
+
+ def __get_voltage_underlimit(self):
+ self.__write('AT+VIN_UV_W_LIM=?')
+ dat = self.__read()
+ res = scanf.scanf("%f", dat)
+ return res[0]
+
+ def __set_voltage_overlimit(self, over_limit):
+ if self.__isThere and self.__ser is not None:
+ self.__write('AT+VIN_OV_W_LIM={}'.format(over_limit))
+ dat = self.__read()
+ print(dat)
+
+ def __get_voltage_overlimit(self):
+ if self.__isThere and self.__ser is not None:
+ self.__write('AT+VIN_OV_W_LIM?')
+ dat = self.__read()
+ res = scanf.scanf("%f", dat)
+ return res[0]
+
+ def __set_current_overlimit(self, over_limit):
+ if self.__isThere and self.__ser is not None:
+ self.__write('AT+IOUT_W_LIM={}'.format(over_limit))
+ dat = self.__read()
+ print(dat)
+
+ def __get_current_overlimit(self):
+ if self.__isThere and self.__ser is not None:
+ self.__write('AT+IOUT_W_LIM?')
+ dat = self.__read()
+ dat = self.__read()
+ res = scanf.scanf("%f", dat)
+ return res[0]
+
+ def hello(self):
+ self.__isThere = False
+ if self.__ser is None:
+ return False
+ self.__write('at+ver?')
+ dat = self.__read()
+ res = scanf.scanf("ISEE Amper v%3c", dat)
+ if res is None:
+ return False
+ self.__isThere = True
+ self.__version = res[0]
+ return True
+
+ def getVersion(self):
+ return self.__version
+
+ def getVoltage(self):
+ if self.__isThere and self.__ser is not None:
+ self.__write('at+vin?')
+ dat = self.__read()
+ res = scanf.scanf("%f", dat)
+ self.__voltage = res[0]
+ # print(self.__voltage)
+ return self.__voltage
+ else:
+ return None
+
+ def getCurrent(self):
+ if self.__isThere and self.__ser is not None:
+ self.__write('at+in?')
+ dat = self.__read()
+ res = scanf.scanf("%f", dat)
+ self.__current = res[0]
+ # print(self.__current)
+ else:
+ return None
+ return self.__current
+
+ def getAlarm(self):
+ if self.__isThere and self.__ser is not None:
+ self.__write('at+st_mfr?')
+ dat = self.__read()
+ # print(dat)
+ self.__alarm_condition = (int(dat) & 0x0F)
+ # print(self.__alarm_condition)
+ return self.__alarm_condition
+
+ def clearAlarm(self):
+ if self.__isThere and self.__ser is not None:
+ self.__write('at+CLRFAULT')
+ dat = self.__read()
+ # print(dat)
+
diff --git a/test-cli/test/helpers/int_registers.py b/test-cli/test/helpers/int_registers.py
index cf2e35b..030035d 100644
--- a/test-cli/test/helpers/int_registers.py
+++ b/test-cli/test/helpers/int_registers.py
@@ -1,6 +1,7 @@
import mmap
import os
import struct
+import sh
MAP_MASK = mmap.PAGESIZE - 1
WORD = 4
@@ -47,10 +48,14 @@ def get_mac(modelid):
mac = None
if modelid.find("IGEP0034") == 0 or modelid.find("SOPA0000") == 0:
- # registers: mac_id0_lo, mac_id0_hi
- registers = [0x44e10630, 0x44e10634]
- mac = ""
- for rg in registers:
- mac = mac + read(rg)
+ # # registers: mac_id0_lo, mac_id0_hi
+ # registers = [0x44e10630, 0x44e10634]
+ # mac = ""
+ # for rg in registers:
+ # mac = mac + read(rg)
+ # #erase trailing zeros
+ # mac = mac[4::1]
+ mac = sh.cat("/sys/class/net/eth0/address")
+
return mac
diff --git a/test-cli/test/tests/qamp.py b/test-cli/test/tests/qamp.py
index cf18fc5..56511c8 100644
--- a/test-cli/test/tests/qamp.py
+++ b/test-cli/test/tests/qamp.py
@@ -36,6 +36,7 @@ class Qamp(unittest.TestCase):
self._ser.close()
def execute(self):
+
# Open Serial port ttyUSB0
error = 0
try:
diff --git a/test-cli/test/tests/qamper.py b/test-cli/test/tests/qamper.py
new file mode 100644
index 0000000..2b02302
--- /dev/null
+++ b/test-cli/test/tests/qamper.py
@@ -0,0 +1,51 @@
+import unittest
+from test.helpers.amper import Amper
+
+
+class Qamper(unittest.TestCase):
+ params = None
+
+ # varlist: undercurrent, overcurrent
+ def __init__(self, testname, testfunc, varlist):
+ self.params = varlist
+ super(Qamper, self).__init__(testfunc)
+
+ if "undercurrent" in varlist:
+ self._undercurrent = varlist["undercurrent"]
+ else:
+ raise Exception('undercurrent param inside Qamp must be defined')
+ if "overcurrent" in varlist:
+ self._overcurrent = varlist["overcurrent"]
+ else:
+ raise Exception('overcurrent param inside Qamp must be defined')
+ self._testMethodDoc = testname
+
+ def execute(self):
+ amp = Amper()
+ print(amp)
+ if not amp.open():
+ print("1")
+ self.fail("failed: can not open serial port")
+ return
+
+ if not amp.hello():
+ print("2")
+ self.fail("failed: can not communicate")
+ return
+
+ result = amp.getCurrent()
+ print(result)
+
+ amp.close()
+
+
+
+
+
+
+ # # In order to give a valid result it is importarnt to define an under current value
+ # if self._current > float(self._overcurrent):
+ # self.fail("failed: OVERCURRENT DETECTED ( {} )".format(self._current))
+ #
+ # if self._current < float(self._undercurrent):
+ # self.fail("failed: UNDERCURRENT DETECTED ( {} )".format(self._current))
diff --git a/test-cli/test_main.py b/test-cli/test_main.py
index 48ec534..0e863dc 100644
--- a/test-cli/test_main.py
+++ b/test-cli/test_main.py
@@ -22,7 +22,7 @@ from test.tests.qscreen import Qscreen
from test.tests.qwifi import Qwifi
from test.tests.qrtc import Qrtc
from test.tests.qduplex_ser import Qduplex
-from test.tests.qamp import Qamp
+from test.tests.qamper import Qamper
from test.tests.qflash import Qflasher
from test.tests.qnand import Qnand
from test.helpers.globalVariables import globalVar
@@ -71,7 +71,7 @@ def add_test_task(suite, testdefname, paramlist):
elif testdefname == "RTC":
suite.addTest(Qrtc(testdefname, "execute", paramlist))
elif testdefname == "CONSUMPTION":
- suite.addTest(Qamp(testdefname, "execute", paramlist))
+ suite.addTest(Qamper(testdefname, "execute", paramlist))
# elif testdefname == "SATA":
# suite.addTest(Qsata(testdefname, "execute", paramlist))
elif testdefname == "DMESG":