summaryrefslogtreecommitdiff
path: root/test-cli/test_main.py
diff options
context:
space:
mode:
authorManel Caro <mcaro@iseebcn.com>2020-03-04 17:46:36 +0100
committerManel Caro <mcaro@iseebcn.com>2020-03-04 17:46:36 +0100
commit09de774dcc1a5abc1c8f3a00fdb039aa3c522f52 (patch)
treec4bd3963d0df01d2e3a33732247388ed4651b186 /test-cli/test_main.py
parentb6932fbaf898724ae87c29f8965621610f377084 (diff)
downloadboard-09de774dcc1a5abc1c8f3a00fdb039aa3c522f52.zip
board-09de774dcc1a5abc1c8f3a00fdb039aa3c522f52.tar.gz
board-09de774dcc1a5abc1c8f3a00fdb039aa3c522f52.tar.bz2
SOPA Initial Commit
Diffstat (limited to 'test-cli/test_main.py')
-rw-r--r--test-cli/test_main.py125
1 files changed, 66 insertions, 59 deletions
diff --git a/test-cli/test_main.py b/test-cli/test_main.py
index 3c4d1cb..a44b7d1 100644
--- a/test-cli/test_main.py
+++ b/test-cli/test_main.py
@@ -6,6 +6,7 @@ import sys
import os
import unittest
from test.helpers.testsrv_db import TestSrv_Database
+from test.helpers.setup_xml import XMLSetup
from test.runners.simple import SimpleTestRunner
from test.tests.qbutton import Qbutton
from test.helpers.syscmd import TestSysCommand
@@ -24,8 +25,17 @@ from test.tests.qrtc import Qrtc
from test.tests.qduplex_ser import Qduplex
from test.tests.qamp import Qamp
from test.tests.qflash import Qflasher
-from test.helpers.finisher import Finisher
+from test.tests.qnand import Qnand
from test.helpers.globalVariables import globalVar
+import socket
+import re
+from test.helpers.iseelogger import ISEE_Logger
+import logging
+
+
+psdbObj = TestSrv_Database()
+xmlObj = None
+loggerObj = None
# define clear function
def clear():
@@ -34,85 +44,82 @@ def clear():
def create_board():
- psdb = TestSrv_Database()
- psdb.open("setup.xml")
- tree = XMLParser.parse('setup.xml')
- root = tree.getroot()
- suite = unittest.TestSuite()
- for element in root.iter('board'):
- # print(str(element.tag) + str(element.attrib))
- model_id = element.attrib['model']
- variant = element.attrib['variant']
- nstation = element.attrib['station']
+ model_id = xmlObj.gettagKey('board', 'model')
+ variant = xmlObj.gettagKey('board', 'variant')
+
+ # get model id
globalVar.g_mid=model_id + "-" + variant
- globalVar.station=nstation
- processor_id=genDieid(globalVar.g_mid)
+
+ # get station number
+ hstname = socket.gethostname()
+ if (re.search("^Station\d{2}$", hstname)):
+ globalVar.station = int(re.search("\d{2}", hstname).group(0))
+ else:
+ raise Exception('Station number not configured')
+ exit(3)
+
+ processor_id = genDieid(globalVar.g_mid)
print(globalVar.g_mid)
print(processor_id)
- globalVar.g_uuid = psdb.create_board(processor_id, model_id, variant, bmac = None)
+ s = globalVar.g_uuid = psdbObj.create_board(processor_id, model_id, variant, bmac = None)
+
+def createvarlist(testvars):
+ varlist = {}
+ for row in testvars:
+ varname,testparam = row
+ varlist[varname] = testparam
+ return varlist
+
def testsuite():
- psdb=TestSrv_Database()
- psdb.open("setup.xml")
suite = unittest.TestSuite()
- tests=psdb.getboard_comp_test_list(globalVar.g_uuid)
- for i in range(len(tests)):
- #newstr = oldstr.replace("M", "")
- variables=str(tests[i][0]).split(",")
- testname=variables[0].replace('(', '')
- testdes=variables[1]
- testfunc=variables[2]
- if len(tests)>2:
- testparam=variables[3].replace(')', '')
- testparam = testparam.replace('"', '')
- testparam = testparam.replace(';', "','")
- if testparam == "":
- command = "suite.addTest({}('{}','execute'))".format(testfunc, testname)
- else:
- command="suite.addTest({}('{}','execute','{}'))".format(testfunc,testname,testparam)
- else:
- print(testname)
- command = "suite.addTest({}('{}','execute'))".format(testfunc, testname)
+ tests = psdbObj.getboard_comp_test_list(globalVar.g_uuid)
+ for row in tests:
+ testdefname,testfunc = row
+ testvars = psdbObj.getboard_test_variables(globalVar.g_uuid, testdefname)
+ varlist = createvarlist(testvars)
+ command = "suite.addTest({}('{}','execute', varlist))".format(testfunc, testdefname)
exec(command)
- globalVar.testid_ctl=psdb.open_testbatch(globalVar.g_uuid)
+
+ globalVar.testid_ctl=psdbObj.open_testbatch(globalVar.g_uuid)
return suite
def finish_test():
- psdb = TestSrv_Database()
- psdb.open("setup.xml")
- auxs = psdb.close_testbatch(globalVar.g_uuid, globalVar.testid_ctl)
- globalVar.fstatus = auxs[0][0]
- # Burn eeprom struct
- psdb = TestSrv_Database()
- psdb.open("setup.xml")
- # We should call getboard_eeprom only if test was ok
- if globalVar.fstatus:
- aux = psdb.getboard_eeprom(globalVar.g_uuid)
- finish = Finisher(aux)
- finish.end_ok()
- else:
- finish = Finisher(globalVar.g_uuid)
- finish.end_fail()
- # Update set_test current_test with 'END' so that it finally gets painted in green
- psdb = TestSrv_Database()
- psdb.open("setup.xml")
- psdb.update_set_test_row(globalVar.station, globalVar.testid_ctl, globalVar.g_uuid, "END","FINISH")
+ psdbObj.close_testbatch(globalVar.g_uuid, globalVar.testid_ctl)
+ # Update Set Test status with FINISH so that status column is not modified because close_testbatch already did it.
+ psdbObj.update_set_test_row(globalVar.station, globalVar.testid_ctl, globalVar.g_uuid, 'END', 'FINISH')
def main():
- #addtesttomodel()
- #addtestdef()
create_board()
- #globalVar.g_uuid = "1f59c654-0cc6-11e8-8d51-e644f56b8edd"
try:
os.remove("test_results.dat")
except:
pass
- runner = SimpleTestRunner()
+ runner = SimpleTestRunner(psdbObj)
runner.run(testsuite())
finish_test()
if __name__ == "__main__":
+ # Clear the shell screen
clear()
- main()
+
+ # create logger
+ loggerObj = ISEE_Logger(logging.INFO)
+ # logger = loggerObj.getlogger().info("Starting test script...")
+
+ # Try to parse the setup.xml file
+ try:
+ xmlObj = XMLSetup("setup.xml")
+ except:
+ print("Error: Cannot parse setup.xml file")
+ exit(1)
+
+ # Try to connect to the DB, according to setup.xml configuration
+ if psdbObj.open(xmlObj):
+ main()
+ else:
+ print("Error: Cannot open DB connection")
+ exit(2)
+