from test.helpers.get_dieid import genDieid 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.testsrv_db import testServerDb from test.runners.simple import SimpleTestRunner from test.helpers.setup_xml import XMLSetup 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.helpers.finisher import Finisher from test.helpers.globalVariables import globalVar # Database global object pgdbcli = testServerDb() # Configuration file amd Parse it xmlsetup = XMLSetup("setup.xml") # define clear function def clear(): # check and make call for specific operating system # _ = call('clear' if os.name =='posix' else 'cls') if os.name == 'posix': os.system('clear') else: os.system('cls') 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'] globalVar.g_mid=model_id + "-" + variant globalVar.station=nstation 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) 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) exec(command) globalVar.testid_ctl=psdb.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") def dbconnection(): if pgdbcli.open(xmlsetup) is False: sys.exit("Database connection error") print("value:", xmlsetup.getBoard('model', 'none')) 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.run(testsuite()) finish_test() if __name__ == "__main__": # Clear python console clear() # database connection dbconnection() # Execute main # main()