From 09de774dcc1a5abc1c8f3a00fdb039aa3c522f52 Mon Sep 17 00:00:00 2001 From: Manel Caro Date: Wed, 4 Mar 2020 17:46:36 +0100 Subject: SOPA Initial Commit --- test-cli/test/tests/qeeprom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test-cli/test/tests/qeeprom.py') diff --git a/test-cli/test/tests/qeeprom.py b/test-cli/test/tests/qeeprom.py index f72f78f..2bab248 100644 --- a/test-cli/test/tests/qeeprom.py +++ b/test-cli/test/tests/qeeprom.py @@ -4,7 +4,7 @@ import uuid class Qeeprom(unittest.TestCase): - def __init__(self, testname, testfunc): + def __init__(self, testname, testfunc, varlist): super(Qeeprom, self).__init__(testfunc) self._testMethodDoc = testname -- cgit v1.1 From a615dac03a9ea7897bf3947ba8d31278b2cea121 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Thu, 5 Mar 2020 16:29:31 +0100 Subject: Modify tests. --- test-cli/test/tests/qeeprom.py | 62 +++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 28 deletions(-) (limited to 'test-cli/test/tests/qeeprom.py') diff --git a/test-cli/test/tests/qeeprom.py b/test-cli/test/tests/qeeprom.py index 2bab248..5bb0755 100644 --- a/test-cli/test/tests/qeeprom.py +++ b/test-cli/test/tests/qeeprom.py @@ -1,38 +1,44 @@ -from test.helpers.syscmd import SysCommand +import sh import unittest -import uuid + class Qeeprom(unittest.TestCase): + __position = None + __uuid = None + __eeprompath = None + + # varlist: position, uuid, eeprompath def __init__(self, testname, testfunc, varlist): super(Qeeprom, self).__init__(testfunc) self._testMethodDoc = testname + if "position" in varlist: + self.__position = varlist["position"] + else: + raise Exception('position param inside Qeeprom must be defined') + if "uuid" in varlist: + self.__uuid = varlist["uuid"] + else: + raise Exception('uuid param inside Qeeprom must be defined') + if "eeprompath" in varlist: + self.__eeprompath = varlist["eeprompath"] + else: + raise Exception('eeprompath param inside Qeeprom must be defined') def execute(self): - str_cmd = "find /sys/ -iname 'eeprom'" - eeprom_location = SysCommand("eeprom_location", str_cmd) - if eeprom_location.execute() == 0: - self.__raw_out = eeprom_location.getOutput() - if self.__raw_out == "": - self.fail("Unable to get EEPROM location. IS EEPROM CONNECTED?") - return -1 - eeprom=self.__raw_out.decode('ascii') - test_uuid = uuid.uuid4() - str_cmd="echo '{}' > {}".format(str(test_uuid), eeprom) - eeprom_write = SysCommand("eeprom_write", str_cmd) - if eeprom_write.execute() == 0: - self.__raw_out = eeprom_write.getOutput() - if self.__raw_out == "": - self.fail("Unable to write on the EEPROM?") - return -1 - str_cmd = "head -2 {}".format(eeprom) - eeprom_read = SysCommand("eeprom_read", str_cmd) - if eeprom_read.execute() == 0: - self.__raw_out = eeprom_read.getOutput() - if self.__raw_out == "": - self.fail("Unable to read from the EEPROM?") - return -1 - if(str(self.__raw_out).find(str(test_uuid)) == -1): - self.fail("failed: READ/WRITE mismatch") + # write data into the eeprom + p = sh.dd(sh.echo(self._uuid), "of=" + self.__eeprompath, "bs=1", "seek=" + self.__position) + if p.exit_code == 0: + # read data from the eeprom + p = sh.dd("if=" + self.__eeprompath, "bs=1", "skip=" + self.__position, "count=" + len(self.__uuid)) + if p.exit_code == 0: + uuid_rx = p.stdout.decode('ascii') + # compare both values + if (uuid_rx != self.__uuid): + self.fail("failed: mismatch between written and received values.") + + else: + self.fail("failed: Unable to read from the EEPROM device.") else: - self.fail("failed: could not complete find eeprom command") + self.fail("failed: Unable to write on the EEPROM device.") + -- cgit v1.1 From dd9ffc52507c391271d0821636c683fd7562b46a Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Thu, 5 Mar 2020 18:50:47 +0100 Subject: Modified postgre functions. --- test-cli/test/tests/qeeprom.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'test-cli/test/tests/qeeprom.py') diff --git a/test-cli/test/tests/qeeprom.py b/test-cli/test/tests/qeeprom.py index 5bb0755..c2293c2 100644 --- a/test-cli/test/tests/qeeprom.py +++ b/test-cli/test/tests/qeeprom.py @@ -5,10 +5,9 @@ import unittest class Qeeprom(unittest.TestCase): __position = None - __uuid = None __eeprompath = None - # varlist: position, uuid, eeprompath + # varlist: position, eeprompath def __init__(self, testname, testfunc, varlist): super(Qeeprom, self).__init__(testfunc) self._testMethodDoc = testname @@ -16,25 +15,23 @@ class Qeeprom(unittest.TestCase): self.__position = varlist["position"] else: raise Exception('position param inside Qeeprom must be defined') - if "uuid" in varlist: - self.__uuid = varlist["uuid"] - else: - raise Exception('uuid param inside Qeeprom must be defined') if "eeprompath" in varlist: self.__eeprompath = varlist["eeprompath"] else: raise Exception('eeprompath param inside Qeeprom must be defined') def execute(self): + # generate some data + data_tx = "isee_test" # write data into the eeprom - p = sh.dd(sh.echo(self._uuid), "of=" + self.__eeprompath, "bs=1", "seek=" + self.__position) + p = sh.dd(sh.echo(data_tx), "of=" + self.__eeprompath, "bs=1", "seek=" + self.__position) if p.exit_code == 0: # read data from the eeprom - p = sh.dd("if=" + self.__eeprompath, "bs=1", "skip=" + self.__position, "count=" + len(self.__uuid)) + p = sh.dd("if=" + self.__eeprompath, "bs=1", "skip=" + self.__position, "count=" + len(data_tx)) if p.exit_code == 0: - uuid_rx = p.stdout.decode('ascii') + data_rx = p.stdout.decode('ascii') # compare both values - if (uuid_rx != self.__uuid): + if data_rx != data_tx: self.fail("failed: mismatch between written and received values.") else: -- cgit v1.1 From 98d40cecc9818360984188755e455aa53933aab0 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Fri, 6 Mar 2020 09:38:18 +0100 Subject: changed parameter names of tests --- test-cli/test/tests/qeeprom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test-cli/test/tests/qeeprom.py') diff --git a/test-cli/test/tests/qeeprom.py b/test-cli/test/tests/qeeprom.py index c2293c2..acdc1f6 100644 --- a/test-cli/test/tests/qeeprom.py +++ b/test-cli/test/tests/qeeprom.py @@ -27,7 +27,7 @@ class Qeeprom(unittest.TestCase): p = sh.dd(sh.echo(data_tx), "of=" + self.__eeprompath, "bs=1", "seek=" + self.__position) if p.exit_code == 0: # read data from the eeprom - p = sh.dd("if=" + self.__eeprompath, "bs=1", "skip=" + self.__position, "count=" + len(data_tx)) + p = sh.dd("if=" + self.__eeprompath, "bs=1", "skip=" + self.__position, "count=" + str(len(data_tx))) if p.exit_code == 0: data_rx = p.stdout.decode('ascii') # compare both values -- cgit v1.1 From 9f07a57d89a927aa9b172c1bf20c7ab563658c73 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Fri, 6 Mar 2020 12:46:27 +0100 Subject: Fixed multiple errors. --- test-cli/test/tests/qeeprom.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test-cli/test/tests/qeeprom.py') diff --git a/test-cli/test/tests/qeeprom.py b/test-cli/test/tests/qeeprom.py index acdc1f6..d2c55ef 100644 --- a/test-cli/test/tests/qeeprom.py +++ b/test-cli/test/tests/qeeprom.py @@ -3,12 +3,13 @@ import unittest class Qeeprom(unittest.TestCase): - + params = None __position = None __eeprompath = None # varlist: position, eeprompath def __init__(self, testname, testfunc, varlist): + self.params = varlist super(Qeeprom, self).__init__(testfunc) self._testMethodDoc = testname if "position" in varlist: -- cgit v1.1 From c685367cbd6abf1c6ae442df759e39b25a907d3b Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Mon, 9 Mar 2020 12:39:50 +0100 Subject: Fixed several test procedures. --- test-cli/test/tests/qeeprom.py | 1 - 1 file changed, 1 deletion(-) (limited to 'test-cli/test/tests/qeeprom.py') diff --git a/test-cli/test/tests/qeeprom.py b/test-cli/test/tests/qeeprom.py index d2c55ef..1921bf7 100644 --- a/test-cli/test/tests/qeeprom.py +++ b/test-cli/test/tests/qeeprom.py @@ -34,7 +34,6 @@ class Qeeprom(unittest.TestCase): # compare both values if data_rx != data_tx: self.fail("failed: mismatch between written and received values.") - else: self.fail("failed: Unable to read from the EEPROM device.") else: -- cgit v1.1 From 09b3bb38fc7305c9b47c29bc90ebc9c636827307 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Wed, 17 Jun 2020 09:44:56 +0200 Subject: SOPA0000: Added support for saving results (strings or files) in the DB. It also saves a final DMESG file. --- test-cli/test/tests/qeeprom.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test-cli/test/tests/qeeprom.py') diff --git a/test-cli/test/tests/qeeprom.py b/test-cli/test/tests/qeeprom.py index 1921bf7..a65ca97 100644 --- a/test-cli/test/tests/qeeprom.py +++ b/test-cli/test/tests/qeeprom.py @@ -39,3 +39,7 @@ class Qeeprom(unittest.TestCase): else: self.fail("failed: Unable to write on the EEPROM device.") + def getresults(self): + # resultlist is a python list of python dictionaries + resultlist = [] + return resultlist -- cgit v1.1 From db3b1e45c47a1ef23c1ad67114a09cbec0976681 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Thu, 25 Jun 2020 11:45:31 +0200 Subject: Solved bugs. Adapted to DB changes. --- test-cli/test/tests/qeeprom.py | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'test-cli/test/tests/qeeprom.py') diff --git a/test-cli/test/tests/qeeprom.py b/test-cli/test/tests/qeeprom.py index a65ca97..cafbc7f 100644 --- a/test-cli/test/tests/qeeprom.py +++ b/test-cli/test/tests/qeeprom.py @@ -6,12 +6,14 @@ class Qeeprom(unittest.TestCase): params = None __position = None __eeprompath = None + __resultlist = None # resultlist is a python list of python dictionaries # varlist: position, eeprompath def __init__(self, testname, testfunc, varlist): self.params = varlist super(Qeeprom, self).__init__(testfunc) self._testMethodDoc = testname + self.__resultlist = [] if "position" in varlist: self.__position = varlist["position"] else: @@ -33,13 +35,42 @@ class Qeeprom(unittest.TestCase): data_rx = p.stdout.decode('ascii') # compare both values if data_rx != data_tx: + # Both data are different + self.__resultlist.append( + { + "desc": "Test result", + "data": "FAILED: mismatch between written and received values.", + "type": "string" + } + ) self.fail("failed: mismatch between written and received values.") else: + self.__resultlist.append( + { + "desc": "Test result", + "data": "FAILED: Unable to read from the EEPROM device.", + "type": "string" + } + ) self.fail("failed: Unable to read from the EEPROM device.") else: + self.__resultlist.append( + { + "desc": "Test result", + "data": "FAILED: Unable to write on the EEPROM device.", + "type": "string" + } + ) self.fail("failed: Unable to write on the EEPROM device.") + # Test successful + self.__resultlist.append( + { + "desc": "Test result", + "data": "OK", + "type": "string" + } + ) + def getresults(self): - # resultlist is a python list of python dictionaries - resultlist = [] - return resultlist + return self.__resultlist -- cgit v1.1 From 34df86b37d6838b115e65e5f3a332344afeb86b8 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Wed, 1 Jul 2020 10:45:34 +0200 Subject: Changes to adapt to new way to save results in DB. Created audio test. Added protections against unexpected status in DB. --- test-cli/test/tests/qeeprom.py | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) (limited to 'test-cli/test/tests/qeeprom.py') diff --git a/test-cli/test/tests/qeeprom.py b/test-cli/test/tests/qeeprom.py index cafbc7f..7fc9fcd 100644 --- a/test-cli/test/tests/qeeprom.py +++ b/test-cli/test/tests/qeeprom.py @@ -36,41 +36,14 @@ class Qeeprom(unittest.TestCase): # compare both values if data_rx != data_tx: # Both data are different - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: mismatch between written and received values.", - "type": "string" - } - ) self.fail("failed: mismatch between written and received values.") else: - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: Unable to read from the EEPROM device.", - "type": "string" - } - ) self.fail("failed: Unable to read from the EEPROM device.") else: - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: Unable to write on the EEPROM device.", - "type": "string" - } - ) self.fail("failed: Unable to write on the EEPROM device.") - # Test successful - self.__resultlist.append( - { - "desc": "Test result", - "data": "OK", - "type": "string" - } - ) - def getresults(self): return self.__resultlist + + def gettextresult(self): + return "" -- cgit v1.1 From d46bce422fd03cd57d1ba336361da17d6efb48db Mon Sep 17 00:00:00 2001 From: Manel Caro Date: Fri, 31 Jul 2020 02:07:37 +0200 Subject: TEST restructure --- test-cli/test/tests/qeeprom.py | 77 ++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 29 deletions(-) (limited to 'test-cli/test/tests/qeeprom.py') diff --git a/test-cli/test/tests/qeeprom.py b/test-cli/test/tests/qeeprom.py index 7fc9fcd..7900381 100644 --- a/test-cli/test/tests/qeeprom.py +++ b/test-cli/test/tests/qeeprom.py @@ -1,46 +1,65 @@ -import sh import unittest - +import os class Qeeprom(unittest.TestCase): params = None - __position = None - __eeprompath = None __resultlist = None # resultlist is a python list of python dictionaries + __QEepromName = None + __i2cBus = None + __device = None # varlist: position, eeprompath def __init__(self, testname, testfunc, varlist): self.params = varlist super(Qeeprom, self).__init__(testfunc) self._testMethodDoc = testname + self.__xmlObj = varlist["xml"] + self.__QEepromName = varlist.get('name', 'qeeprom') + self.__i2cAddress = varlist.get('i2c_address', self.__xmlObj.getKeyVal(self.__QEepromName, "i2c_address", "0050")) + self.__i2cBus = varlist.get('i2c_bus', self.__xmlObj.getKeyVal(self.__QEepromName, "i2c_bus", "0")) + self.__device = '/sys/bus/i2c/devices/{}-{}/eeprom'.format(self.__i2cBus, self.__i2cAddress) + self.__resultlist = [] - if "position" in varlist: - self.__position = varlist["position"] - else: - raise Exception('position param inside Qeeprom must be defined') - if "eeprompath" in varlist: - self.__eeprompath = varlist["eeprompath"] - else: - raise Exception('eeprompath param inside Qeeprom must be defined') + + def __check_device(self): + if os.path.isfile(self.__device): + return True + return False + + def __eeprom_write(self, data): + try: + f = open(self.__device, "wb") + f.write(data) + f.close() + except IOError as Error: + return False, '{}'.format(Error.errno) + return True, '' + + def __eeprom_read(self, size): + try: + f = open(self.__device, "rb") + data = f.read(size) + f.close() + except IOError as Error: + return False, '{}'.format(Error.errno) + return True, data + def execute(self): - # generate some data - data_tx = "isee_test" - # write data into the eeprom - p = sh.dd(sh.echo(data_tx), "of=" + self.__eeprompath, "bs=1", "seek=" + self.__position) - if p.exit_code == 0: - # read data from the eeprom - p = sh.dd("if=" + self.__eeprompath, "bs=1", "skip=" + self.__position, "count=" + str(len(data_tx))) - if p.exit_code == 0: - data_rx = p.stdout.decode('ascii') - # compare both values - if data_rx != data_tx: - # Both data are different - self.fail("failed: mismatch between written and received values.") - else: - self.fail("failed: Unable to read from the EEPROM device.") - else: - self.fail("failed: Unable to write on the EEPROM device.") + if not self.__check_device(): + self.fail("cannot open device {}".format(self.__device)) + + data = bytes('AbcDeFgHijK098521', 'utf-8') + + v, w = self.__eeprom_write(data) + if not v: + self.fail("eeprom: {} write test failed".format(w)) + v, r = self.__eeprom_read(len(data)) + if not v: + self.fail("eeprom: {} read test failed".format(r)) + if r != data: + self.fail("mismatch between write and read bytes") + def getresults(self): return self.__resultlist -- cgit v1.1