from test.helpers.get_dieid import genDieid from subprocess import call import xml.etree.ElementTree as XMLParser import errno 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 from test.helpers.syscmd import SysCommand from test.tests.qiperf import QIperf from test.tests.qethernet import Qethernet from test.tests.qaudio import Qaudio from test.tests.qram import Qram from test.tests.qusb import Qusb from test.tests.qi2c import Qi2c from test.tests.qeeprom import Qeeprom from test.tests.qserial import Qserial 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.qflash import Qflasher 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(): # check and make call for specific operating system _ = call('clear' if os.name =='posix' else 'cls') def create_board(): model_id = xmlObj.gettagKey('board', 'model') variant = xmlObj.gettagKey('board', 'variant') # get model id globalVar.g_mid=model_id + "-" + variant # 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) 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(): suite = unittest.TestSuite() 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=psdbObj.open_testbatch(globalVar.g_uuid) return suite def finish_test(): 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(): create_board() try: os.remove("test_results.dat") except: pass runner = SimpleTestRunner(psdbObj) runner.run(testsuite()) finish_test() if __name__ == "__main__": # Clear the shell screen clear() # 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)