summaryrefslogtreecommitdiff
path: root/test-cli/test/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'test-cli/test/helpers')
-rw-r--r--test-cli/test/helpers/finisher.py151
-rw-r--r--test-cli/test/helpers/globalVariables.py1
-rw-r--r--test-cli/test/helpers/int_registers.py1
-rw-r--r--test-cli/test/helpers/syscmd.py1
-rw-r--r--test-cli/test/helpers/testsrv_db.py49
5 files changed, 46 insertions, 157 deletions
diff --git a/test-cli/test/helpers/finisher.py b/test-cli/test/helpers/finisher.py
deleted file mode 100644
index 73142d9..0000000
--- a/test-cli/test/helpers/finisher.py
+++ /dev/null
@@ -1,151 +0,0 @@
-from test.helpers.syscmd import SysCommand
-from test.helpers.globalVariables import globalVar
-import binascii
-import uuid
-import subprocess
-from PIL import Image, ImageDraw, ImageFont
-import qrcode
-import PIL
-
-class Finisher(object):
- __muhb = None
- __final_to_burn_to_eeprom = None
- __qr_image = None
-
- def __init__(self, muhb = None):
- self.__muhb = muhb
- self.__final_to_burn_to_eeprom = bytearray()
- self.__qr_image = None
- pass
-
- def eeprom_burn(self):
- ## Create binary file
- str_cmd2 = "find /sys/ -iname 'eeprom'"
- eeprom_location = SysCommand("eeprom_location", str_cmd2)
- if eeprom_location.execute() == 0:
- raw_out = eeprom_location.getOutput()
- if raw_out == "":
- self.fail("Unable to get EEPROM location. IS EEPROM CONNECTED?")
- eeprom = raw_out.decode('ascii')
- eeprom = eeprom.strip('\n')
- ## push binary data to eeprom like if working with files
- file2 = open(eeprom, "w+b")
- file2.write(self.__final_to_burn_to_eeprom)
- else:
- self.fail("failed: could not complete find eeprom command")
-
- def generate_qr_stamp(self):
- # Generate QR to put in a stamp
- qr = qrcode.QRCode(
- version=1,
- error_correction=qrcode.constants.ERROR_CORRECT_L,
- box_size=10,
- border=4,
- )
- # Use board_uuid to generate the QR code
- qr.add_data(globalVar.g_uuid)
- qr.make(fit=True)
- # Save QR as image stamp.png
- img = qr.make_image()
- # Store QR as a class atrib
- self.__qr_image = img
- img.save('/home/root/stamp.png')
-
- def print_stamp(self):
- # Print stamp by sending a cmd to the printer
- str_cmd3 = "lpr -o scaling=4 stamp.png".format(self.__display)
- printstamp = SysCommand("printstamp", str_cmd3)
- if printstamp.execute() != 0:
- self.fail("failed: could not print stamp")
-
- def generate_screen(self):
- # Generate green image with board uuid and QR maybe pasted on top of green image
- # Define image size
- W = 1250
- H = 703
- # Create blank rectangle to write on
- image = Image.new('RGB', (W, H), (46, 204, 113, 0))
- draw = ImageDraw.Draw(image)
- message = "TEST OK\n\n" + "Board UUID: "+ globalVar.g_uuid
- font = ImageFont.truetype('/usr/share/fonts/truetype/dejavuu/DejaVuSans.ttf', 40)
- # Calculate the width and height of the text to be drawn, given font size
- w, h = draw.textsize(message, font=font)
- # Write the text to the image, where (x,y) is the top left corner of the text
- draw.text(((W-w)/2,(H-h)/2), message, align='center', font=font)
- #draw.image(self.__qr_image)
- image.save('/home/root/test/files/test_ok.png')
-
- def show_result_screen(self):
- # If test OK show test_OK.png located in /home/root, If test fail show test_fail.png, located in /home/root/test/files/test_KO.png
- if globalVar.fstatus:
- str_cmd4 = "fbi -T 1 --noverbose -d /dev/{} test/files/test_ok.png".format('fb0')
- else:
- str_cmd4 = "fbi -T 1 --noverbose -d /dev/{} test/files/test_ko.png".format('fb0')
-
- display_image = SysCommand("display_image", str_cmd4)
- #print(display_image.execute())
- if display_image.execute() != -1:
- self.fail("failed: could not display the image")
-
-
- def end_ok(self):
- # Burn retrieved igep eeprom struct
- new = self.__muhb[0][0]
-
- # Convert from string to hex
- hnew = new.encode()
- # Magic_id and default crc32 0x6d, 0x6a, 0x6d, 0xe4 with endianess changed so that u-boot loads it correctly
- # IF magic ever changes this magic_id should be changed. At the end always magic_id of test and u-boot should
- # be the same
- magic_id = bytes([0xe4, 0x6d, 0x6a, 0x6d])
- default_igep_crc32 = bytes([0x00, 0x00, 0x00, 0x00])
-
- # Create bytearray
- to_calculate = bytearray()
- # Build the final hex binary for crc32 operation
- to_calculate.extend(magic_id)
- to_calculate.extend(default_igep_crc32)
- to_calculate.extend(hnew)
-
- # Calculate crc32!
- new_crc32 = binascii.crc32(to_calculate)
- hnew_crc32 = new_crc32.to_bytes(4, byteorder="little")
-
- # Recreate final eeprom struct in bytearray
- self.__final_to_burn_to_eeprom = bytearray()
- self.__final_to_burn_to_eeprom.extend(magic_id)
- self.__final_to_burn_to_eeprom.extend(hnew_crc32)
- self.__final_to_burn_to_eeprom.extend(hnew)
- self.eeprom_burn()
-
- # Generate QR stamp
- self.generate_qr_stamp()
- # Send print stamp command
- #self.print_stamp()
- # Generate green image with board uuid and QR maybe pasted on top of green image
- self.generate_screen()
- # Show test_ok.png image in screen
- self.show_result_screen()
-
- def end_fail(self):
- # Burn igep eeprom bug struct
- hnew = self.__muhb.encode()
- default_fail = bytes([0xD0, 0xBA, 0xD0, 0xBA])
- self.__final_burn_to_eeprom = bytearray()
- self.__final_to_burn_to_eeprom.extend(default_fail)
- self.__final_to_burn_to_eeprom.extend(default_fail)
- self.__final_to_burn_to_eeprom.extend(hnew)
- self.__final_to_burn_to_eeprom.extend(default_fail)
- self.__final_to_burn_to_eeprom.extend(default_fail)
- self.__final_to_burn_to_eeprom.extend(default_fail)
- self.__final_to_burn_to_eeprom.extend(default_fail)
- self.__final_to_burn_to_eeprom.extend(default_fail)
- self.__final_to_burn_to_eeprom.extend(default_fail)
- self.__final_to_burn_to_eeprom.extend(default_fail)
- self.__final_to_burn_to_eeprom.extend(default_fail)
- self.__final_to_burn_to_eeprom.extend(default_fail)
- self.__final_to_burn_to_eeprom.extend(default_fail)
- self.__final_to_burn_to_eeprom.extend(default_fail)
- self.eeprom_burn()
- # Show test_ko.png image in screen
- self.show_result_screen() \ No newline at end of file
diff --git a/test-cli/test/helpers/globalVariables.py b/test-cli/test/helpers/globalVariables.py
index 6b89f4d..baaae57 100644
--- a/test-cli/test/helpers/globalVariables.py
+++ b/test-cli/test/helpers/globalVariables.py
@@ -6,3 +6,4 @@ def globalVar():
g_mid = ""
outdata = "NONE"
station = ""
+ taskid_ctl = ""
diff --git a/test-cli/test/helpers/int_registers.py b/test-cli/test/helpers/int_registers.py
index 22a3d9b..0feb8da 100644
--- a/test-cli/test/helpers/int_registers.py
+++ b/test-cli/test/helpers/int_registers.py
@@ -55,6 +55,7 @@ def get_mac(modelid):
# mac = mac + read(rg)
# #erase trailing zeros
# mac = mac[4::1]
+ # # To be finished...
mac = sh.cat("/sys/class/net/eth0/address").strip()
return mac
diff --git a/test-cli/test/helpers/syscmd.py b/test-cli/test/helpers/syscmd.py
index a869bd7..6114449 100644
--- a/test-cli/test/helpers/syscmd.py
+++ b/test-cli/test/helpers/syscmd.py
@@ -1,6 +1,5 @@
import unittest
import subprocess
-from test.helpers.globalVariables import globalVar
class TestSysCommand(unittest.TestCase):
diff --git a/test-cli/test/helpers/testsrv_db.py b/test-cli/test/helpers/testsrv_db.py
index 9fb61fd..c9372fc 100644
--- a/test-cli/test/helpers/testsrv_db.py
+++ b/test-cli/test/helpers/testsrv_db.py
@@ -51,14 +51,13 @@ class TestSrv_Database(object):
try:
res = self.__sqlObject.db_execute_query(sql)
# print(res)
- return res;
+ return res
except Exception as err:
r = find_between(str(err), '#', '#')
# print(r)
return None
def get_test_params_list(self, testid):
- '''get the board test list'''
sql = "SELECT * FROM isee.f_get_test_params_list({})".format(testid)
# print('>>>' + sql)
try:
@@ -71,7 +70,6 @@ class TestSrv_Database(object):
return None
def open_test(self, board_uuid):
- '''get the board test list'''
sql = "SELECT * FROM isee.f_open_test('{}')".format(board_uuid)
# print('>>>' + sql)
try:
@@ -84,7 +82,6 @@ class TestSrv_Database(object):
return None
def run_test(self, testid_ctl, testid):
- '''get the board test list'''
sql = "SELECT isee.f_run_test({},{})".format(testid_ctl, testid)
# print('>>>' + sql)
try:
@@ -95,7 +92,6 @@ class TestSrv_Database(object):
return None
def finish_test(self, testid_ctl, testid, newstatus):
- '''get the board test list'''
sql = "SELECT isee.f_finish_test({},{},'{}')".format(testid_ctl, testid, newstatus)
# print('>>>' + sql)
try:
@@ -117,3 +113,46 @@ class TestSrv_Database(object):
# print(r)
return None
+ def get_board_macaddr(self, board_uuid):
+ sql = "SELECT * FROM isee.f_get_board_macaddr('{}')".format(board_uuid)
+ # print('>>>' + sql)
+ try:
+ res = self.__sqlObject.db_execute_query(sql)
+ # print(res)
+ return res[0][0]
+ except Exception as err:
+ r = find_between(str(err), '#', '#')
+ # print(r)
+ return None
+
+ def create_process(self, testid_ctl):
+ sql = "SELECT * FROM isee.f_create_process({})".format(testid_ctl)
+ # print('>>>' + sql)
+ try:
+ res = self.__sqlObject.db_execute_query(sql)
+ # print(res)
+ return res[0][0]
+ except Exception as err:
+ r = find_between(str(err), '#', '#')
+ # print(r)
+ return None
+
+ def create_task_result(self, taskid_ctl, name, newstatus):
+ sql = "SELECT isee.f_create_task_result({},'{}','{}')".format(taskid_ctl, name, newstatus)
+ # print('>>>' + sql)
+ try:
+ self.__sqlObject.db_execute_query(sql)
+ except Exception as err:
+ r = find_between(str(err), '#', '#')
+ # print(r)
+ return None
+
+ def update_taskctl_status(self, taskid_ctl, newstatus):
+ sql = "SELECT isee.f_update_taskctl_status({},'{}')".format(taskid_ctl, newstatus)
+ # print('>>>' + sql)
+ try:
+ self.__sqlObject.db_execute_query(sql)
+ except Exception as err:
+ r = find_between(str(err), '#', '#')
+ # print(r)
+ return None