def main(configFile = "default_config.ini", testTO = 1, initLoop = True, consOutput = False): nargs = len(sys.argv) if (nargs >= 2): configFile = sys.argv[1] if not isfile(configFile): print("Config file does not exist creation:") confFile.create(configFile) config = configparser.ConfigParser() config.read(configFile) config.sections() board_serial_hwid= config['TESTBOARD'].get('board_serial_hwid', BOARD_SERIAL_HWID_DEFAULT) baud= config['TESTBOARD'].get('baud', BAUD_DEFAULT) board_serial_port = config['TESTBOARD'].get('board_serial_port', "0") # open the serial port ser = connectSerialPort.connect_serial(board_serial_hwid, baud, board_serial_port) if board_serial_hwid == BOARD_SERIAL_HWID_DEFAULT: board_serial_hwid = connectSerialPort.get_serial_hwid_by_port(ser.port) print("board_serial_hwid = " + board_serial_hwid) confFile.update(configFile, "TESTBOARD","board_serial_hwid" ,board_serial_hwid) ser.flushInput() if ser.isOpen(): print(ser.name + ' is open...') interface = SerialIf(testTO, initLoop, consOutput, ser, configFile) interface.name = 'basicSerial' interface.run()
def setPeltierTemp(serial_hwid, tempTarget, configFile="UNKNOWNconfFile.ini"): port = connectSerialPort.get_serial_port(serial_hwid) if serial_hwid == serial_hwid_default: serial_hwid = connectSerialPort.get_serial_hwid_by_port(port) print("peltier_serial_hwid = " + serial_hwid) confFile.update(configFile, "TEMPBENCH", "peltier_serial_hwid", serial_hwid) # start logging logging.basicConfig( level=logging.DEBUG, format="%(asctime)s:%(module)s:%(levelname)s:%(message)s") # initialize controller print(port) mc = MeerstetterTEC(port) # get the values from DEFAULT_QUERIES print(mc.get_data()) mc.set_temp(float(tempTarget)) time.sleep(2) # wait to exit stability conditions stable = "is stable" stable_id = mc.session().get_parameter( parameter_name="Temperature is Stable", address=mc.address) while stable_id == 1: stable = "is not stable" temp = str(round(mc.get_temp(), 2)) print("query for loop stability, loop {}, ".format(stable) + "obj temp: " + temp) time.sleep(5) stable_id = mc.session().get_parameter( parameter_name="Temperature is Stable", address=mc.address) if stable_id == 0: stable = "temperature regulation is not active" elif stable_id == 2: stable = "is stable" else: stable = "state is unknown" print("exit program with stability status: " + stable) #print(mc.get_data()) data = mc.get_data() print(data) return stable
def readPeltierTemp(serial_hwid, tempTarget, configFile="UNKNOWNconfFile.ini"): port = connectSerialPort.get_serial_port(serial_hwid) if serial_hwid == serial_hwid_default: serial_hwid = connectSerialPort.get_serial_hwid_by_port(port) print("peltier_serial_hwid = " + serial_hwid) confFile.update(configFile, "TEMPBENCH", "peltier_serial_hwid", serial_hwid) # start logging logging.basicConfig( level=logging.DEBUG, format="%(asctime)s:%(module)s:%(levelname)s:%(message)s") # initialize controller print(port) mc = MeerstetterTEC(port) # get the values from DEFAULT_QUERIES print(mc.get_data()) temp = str(round(mc.get_temp(), 2)) print("Peltier temp is: " + temp) return temp
def setPeltierTempImmediate(serial_hwid, tempTarget, configFile="UNKNOWNconfFile.ini"): #port = connectSerialPort.connect_serial(serial_hwid) port = connectSerialPort.get_serial_port(serial_hwid) if serial_hwid == serial_hwid_default: serial_hwid = connectSerialPort.get_serial_hwid_by_port(port) print("peltier_serial_hwid = " + serial_hwid) confFile.update(configFile, "TEMPBENCH", "peltier_serial_hwid", serial_hwid) # start logging logging.basicConfig( level=logging.DEBUG, format="%(asctime)s:%(module)s:%(levelname)s:%(message)s") # initialize controller print(port) mc = Peltier(port) # get the values from DEFAULT_QUERIES mc.display_data() ret = mc.set_temp(tempTarget) return ret
def main(configFile="default_config.ini"): #ports = get_serial_port_by_hwid(serial_hwid) #if (len(ports) >> 0): # port = ports[0] # print("identify port by hwid:" + port) #else: # ask_for_port() #ser = serial.Serial(port, baud, timeout=1) nargs = len(sys.argv) if (nargs >= 2): configFile = sys.argv[1] if not isfile(configFile): print("Config file does not exist creation:") confFile.create(configFile) config = configparser.ConfigParser() config.read(configFile) config.sections() if 'board_serial_hwid' in config['TESTBOARD']: #print('detect board serial hwid') board_serial_hwid = config['TESTBOARD']['board_serial_hwid'] else: board_serial_hwid = board_serial_hwid_default if 'baud' in config['TESTBOARD']: baud = config['TESTBOARD']['baud'] else: baud = baud_default if 'board_serial_port' in config['TESTBOARD']: board_serial_port = config['TESTBOARD']['board_serial_port'] else: board_serial_port = "0" ser = connectSerialPort.connect_serial(board_serial_hwid, baud, board_serial_port) if board_serial_hwid == board_serial_hwid_default: board_serial_hwid = connectSerialPort.get_serial_hwid_by_port(ser.port) print("board_serial_hwid = " + board_serial_hwid) confFile.update(configFile, "TESTBOARD", "board_serial_hwid", board_serial_hwid) ####INIT from conf file########### if 'testTO' in config['TESTS']: testTimeout = int(config['TESTS']['testTO']) #print(">>>>>>>>>>>>testTO read from conf file: " + str(testTimeout)) else: print("testTO init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "testTO", "INIT Value needed") exit() if 'termType' in config['TESTS']: termType = config['TESTS']['termType'] #print(">>>>>>>>>>>>term type read from conf file: " + termType) else: print("termType init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "termType", termType_default) if 'bootBoardInit' in config['TESTS']: bootBoardInit = config['TESTS']['bootBoardInit'] else: print("bootBoardInit init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "bootBoardInit", "INIT Value needed") exit() if 'rebootAfterEachTest' in config['TESTS']: rebootAfterEachTest = config['TESTS']['rebootAfterEachTest'] if 'rebootOnFailure' in config['TESTS']: rebootOnFailure = config['TESTS']['rebootOnFailure'] if 'testDuration' in config['TESTS']: testDuration = config['TESTS']['testDuration'] else: print("testDuration init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "testDuration", "INIT Value needed") exit() if 'probeDuration' in config['TESTS']: probeDuration = int(config['TESTS']['probeDuration']) else: print("probeDuration init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "probeDuration", "INIT Value needed") exit() if 'testList' in config['TESTS']: testList = ast.literal_eval(config.get('TESTS', 'testList')) #testList = config['TESTS']['testList'] #print(type(testList)) #print (testList) else: print("testList init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "testList", "INIT Value needed") exit() if 'acmegraph' in config['TESTS']: acmegraph = str2bool(config['TESTS']['acmegraph']) else: print("acmegraph init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "acmegraph", "INIT Value needed") exit() if 'prepareBoard' in config['TESTS']: prepareBoard = str2bool(config['TESTS']['prepareBoard']) if 'acmecliPath' in config['TESTS']: acmecliPath = config['TESTS']['acmecliPath'] else: print("acmecliPath init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "acmecliPath", "INIT Value needed") exit() if 'acmeName' in config['TESTS']: acmeName = config['TESTS']['acmeName'] else: print("acmeName init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "acmeName", "INIT Value needed") exit() if 'pyacmegraphCmd' in config['TESTS']: pyacmegraphCmd = config['TESTS']['pyacmegraphCmd'] else: print("pyacmegraphCmd init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "pyacmegraphCmd", "INIT Value needed") exit() if 'pyacmegraphTemplate' in config['TESTS']: pyacmegraphTemplate = config['TESTS']['pyacmegraphTemplate'] else: print("pyacmegraphTemplate init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "pyacmegraphTemplate", "INIT Value needed") exit() if 'pyacmegraphShunt' in config['TESTS']: pyacmegraphShunt = config['TESTS']['pyacmegraphShunt'] else: print("pyacmegraphShunt init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "pyacmegraphShunt", "INIT Value needed") exit() if 'logFilesPath' in config['TESTS']: logFilesPath = config['TESTS']['logFilesPath'] else: print("logFilesPath init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "logFilesPath", "INIT Value needed") exit() if 'testPath' in config['TESTS']: testPath = config['TESTS']['testPath'] else: print("testPath init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "testPath", "INIT Value needed") exit() #if 'iiocatpurePath' in config['TESTS'] : # iiocatpurePath = config['TESTS']['iiocatpurePath'] #else: # print("iiocatpurePath init value is needed in conf file: " + configFile) # confFile.update(configFile, "TESTS","iiocatpurePath" ,"INIT Value needed") # exit() if 'pyacmecapturePath' in config['TESTS']: pyacmecapturePath = config['TESTS']['pyacmecapturePath'] else: print("pyacmecapturePath init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "pyacmecapturePath", "INIT Value needed") exit() if 'pyacmecaptureVersion' in config['TESTS']: pyacmecaptureVersion = config['TESTS']['pyacmecaptureVersion'] else: try: #ToDo replace with subprocess.run(, capture_output=True) or subprocess.check_output("cmd", stderr=subprocess.STDOUT, shell=True) cmdvers = "-h | grep \"(version \" | egrep -o \"[0-9]\\.[0-9]+\"" print("python " + pyacmecapturePath + "pyacmecapture.py " + cmdvers) p = subprocess.Popen( "python " + os.path.join(pyacmecapturePath, "pyacmecapture.py ") + cmdvers, stdout=subprocess.PIPE, shell=True) out, err = p.communicate() pyacmecaptureVersion = out.decode("utf-8").rstrip() except: pyacmecaptureVersion = "default" print("pyacmecaptureVersion= " + pyacmecaptureVersion) if 'pyacmecaptureSlots' in config['TESTS']: pyacmecaptureSlots = config['TESTS']['pyacmecaptureSlots'] else: try: cmdslots = " -s " + acmeName + " system_info | grep slot | grep -v empty | egrep -o \"slot [0-9]+\" | egrep -o \"[0-9]+\" | sed \':a;N;$!ba;s/\\n/,/g\'" print(os.path.join(acmecliPath, "acme-cli") + cmdslots) p = subprocess.Popen(os.path.join(acmecliPath, "acme-cli") + cmdslots, stdout=subprocess.PIPE, shell=True) out, err = p.communicate() pyacmecaptureSlots = out.decode("utf-8").rstrip() except: pyacmecaptureSlots = "default" print("pyacmecaptureSlots= " + pyacmecaptureSlots) if 'probeList' in config['TESTS']: #probeList = config['TESTS']['probeList'] probeList = ast.literal_eval(config.get('TESTS', 'probeList')) else: print("probeList init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "probeList", "INIT Value needed") exit() if 'resultsDir' in config['TESTS']: resultsDir = config['TESTS']['resultsDir'] else: print("resultsDir init value is needed in conf file: " + configFile) confFile.update(configFile, "TESTS", "resultsDir", "INIT Value needed") exit() if 'exitOnLauncherEnd' in config['TESTS']: exitOnLauncherEnd = config['TESTS']['exitOnLauncherEnd'] else: exitOnLauncherEnd = "False" # Initialisations necessary for test launcher with tempbench disabled tempFineTune = False warmUpAuto = False TFTDuration = str(0) if "tempDieTarget" in config['TEMPBENCH']: tempbench = True print( "++++++++++TEST LAUNCHER + TEMPBENCH ENABLED for temp control++++++++++" ) if 'warmUpTest' in config['TEMPBENCH']: warmUpTest = config['TEMPBENCH']['warmUpTest'] else: print("warmUpTest init value is needed in conf file: " + configFile) confFile.update(configFile, "TEMPBENCH", "warmUpTest", "INIT Value needed") exit() if 'warmUpAuto' in config['TEMPBENCH']: warmUpAuto = config['TEMPBENCH']['warmUpAuto'] if 'rebootAfterWarmUp' in config['TEMPBENCH']: rebootAfterWarmUp = config['TEMPBENCH']['rebootAfterWarmUp'] if 'maxBootTemp' in config['TEMPBENCH']: maxBootTemp = config['TEMPBENCH']['maxBootTemp'] if 'safeTemp' in config['TEMPBENCH']: safeTemp = config['TEMPBENCH']['safeTemp'] if 'tempFineTune' in config['TEMPBENCH']: tempFineTune = str2bool(config['TEMPBENCH']['tempFineTune']) #else: # tempFineTune = False if 'TFTRamp' in config['TEMPBENCH']: TFTRamp = int(config['TEMPBENCH']['TFTRamp']) else: TFTRamp = 20 if 'TFTDuration' in config['TEMPBENCH']: TFTDuration = config['TEMPBENCH']['TFTDuration'] else: TFTDuration = str(50) if 'TFTMultiplier' in config['TEMPBENCH']: TFTMultiplier = config['TEMPBENCH']['TFTMultiplier'] else: TFTMultiplier = 2 else: tempbench = False print( "----------TEST LAUNCHER EXECUTE WITH TEMPBENCH DISABLED----------" ) if 'toaddr' in config['MAIL']: sendMail = True else: sendMail = False if 'onoffbox' in config['TESTS']: onoffbox = config['TESTS']['onoffbox'] else: onoffbox = onoffbox_default if acmegraph: pyacmegraph = pyacmegraphCmd + " --ip " + acmeName + " --template " + pyacmegraphTemplate + " " + pyacmegraphShunt + " &" print('>>>>>>> pyacmegraph = ' + pyacmegraph) ret = subprocess.call(pyacmegraph, shell=True) print("subprocess return:" + str(ret)) if tempbench: maxTFTDuration = int(float(TFTMultiplier)) * int(float(TFTDuration)) testTFTduration = str( int(float(testDuration)) + int(float(TFTDuration))) maxDuration = int(float(testDuration)) + maxTFTDuration testTimeoutMargin = 10 testTimeout = max(testTimeout, (maxDuration + testTimeoutMargin)) print("testTimeout: " + str(testTimeout)) if prepareBoard: thread_term_Init = startTermThread(termType, testTimeout, ser, configFile) thread_term_Init.threadType = "Init" bootBoardInit = rebootBoardOnInit(acmecliPath, acmeName, thread_term_Init, termType, bootBoardInit, onoffbox) if termType == "basic": if prepareBoard: thread_term_Init.join() if warmUpAuto == "True": #To be clarified need cons_timeout > 10 to force transition ITER1. Code can hang here if value is too low thread_term_WarmUp = startTermThread(termType, 15, ser, configFile) bootBoardInit = rebootBoardOnInit(acmecliPath, acmeName, thread_term_WarmUp, termType, bootBoardInit, onoffbox) else: thread_term_Test = startTermThread(termType, testTimeout, ser, configFile) bootBoardInit = rebootBoardOnInit(acmecliPath, acmeName, thread_term_Test, termType, bootBoardInit, onoffbox) else: if prepareBoard: thread_term_Test = thread_term_Init thread_term_Init.threadType = "Test" else: thread_term_Test = startTermThread(termType, testTimeout, ser, configFile) bootBoardInit = rebootBoardOnInit(acmecliPath, acmeName, thread_term_Test, termType, bootBoardInit, onoffbox) if warmUpAuto == "True": warmUp(termType, thread_term_WarmUp) print("return from warmup, waiting thread to stop") thread_term_WarmUp.join() print("start test thread") thread_term_Test = startTermThread(termType, testTimeout, ser, configFile) print("rebootAfterWarmUp = " + rebootAfterWarmUp) if rebootAfterWarmUp == "True": print("POST WARM UP reboot ") if not boardInit.rebootBoard(acmecliPath, acmeName, thread_term_Test, termType, onoffbox): print("ERROR: Fail multiple time to reboot after warm-up") exit() else: stopTest(ser) for testName in testList: if tempbench: peltierTemp = peltierOp.readPeltier(termType, thread_term_Test) #runTest(ser, testPath, testName, duration) #too intrusive affects power measurements thread_term_Test.logFileStatus = "NOT_READY" runTestNoLog(ser, testPath, testName, testDuration, TFTDuration) print("\n") if tempFineTune: # fine tune temperature time.sleep(TFTRamp) deltaTemp = int(float(thread_term_Test.dieTemp)) - int( float(thread_term_Test.tempDieTarget)) thread_term_Test.tempPeltier = str( int(float(peltierTemp)) - deltaTemp) peltierOp.setPeltierImmediate(termType, thread_term_Test) if not acmegraph: #ToDo this depends on the temp fine tune value, clean-up needed maxTrial = 100 while thread_term_Test.testStatus != "PROBE STARTED" and termType == "basic": time.sleep(1) print("waiting for probe start. current status is: " + thread_term_Test.testStatus) maxTrial -= 1 if maxTrial <= 0: print("Stop waiting for PROBE START") break pyacmecaptureParam = (pyacmecapturePath, pyacmecaptureVersion, pyacmecaptureSlots) probePower(testName, probeList, pyacmecaptureParam, str(probeDuration), resultsDir, acmeName) if waitTestEnd(thread_term_Test, testName, testTimeout, ser): print(testName + " COMPLETED SUCCESSFULLY") testSuccess = True else: print(testName + " FINISHED WITH ERROR OR TIMEOUT") testSuccess = False if waitLogFile(thread_term_Test, testName): createTestLog(testName, ser, resultsDir) if (rebootOnFailure == "True" and not testSuccess) or rebootAfterEachTest == "True": if not boardInit.rebootBoard(acmecliPath, acmeName, thread_term_Test, termType, onoffbox): print("ERROR: fail multiple time to reboot after test: " + testName + " completion") cmd = join(testPath, "launcherTeardown.sh") sendserial(cmd, ser) for testName in testList: if thread_term_Test.copyMethod == "zmodem": saveLog2Host(testName, ser, logFilesPath, resultsDir, thread_term_Test) else: print("no saveLog2Host method implemented for copymethod: " + thread_term_Test.copyMethod) print("logs available on target in directory" + thread_term_Test.boardConnectPattern[:-1] + logFilesPath) print('copy tools for postprocessing') copy_tree(join('..', 'tools'), join('..', resultsDir)) print('create dupplicated zip file') resultsDirZip = resultsDir + "zip" print('create zip archive') shutil.make_archive(join('..', resultsDirZip, resultsDir), 'zip', join('..', resultsDir)) if sendMail: sendMailConf.send_mail(configFile) if tempbench: thread_term_Test.tempPeltier = safeTemp #Safety measure set to Default Peltier Value peltierOp.setPeltierImmediate(termType, thread_term_Test) #Wait for keyboard interrupt in case of exitOnLauncherEnd == "False" if exitOnLauncherEnd == "True": print("join thread_term_Test") thread_term_Test.join() print("thread_term_Test stopped") exit() print("Press enter to go in console mode")