def pauseTest(self): configGlobal.setStop(True) configGlobal.setPause(True) while True: if configGlobal.getPause() == False: break time.sleep(1)
def timing(self): print(self.curTaskLeftTime) while self.curTaskLeftTime > 0: if configGlobal.getStop(): break self.curTaskLeftTime -= 1 time.sleep(1) if self.curTaskLeftTime == 0: configGlobal.setStop(True) time.sleep(1)
def afterTestItem(self, curTest): if not self.curTestStatus: self.results[curTest] = 0 else: results = list(set(self.curTestStatus.values())) if len(results) > 1 or results[0] != 1: self.results[curTest] = 0 else: self.results[curTest] = 1 print(self.results) print(self.curTestStatus) self.curTestStatus = {} self.curTestIdx += 1 self.isResume = False configGlobal.setPause(False) configGlobal.setStop(False) if self.curTestIdx < self.totalTests: self.execNext()
def lpRepeat(self,temperature): self.isRepeat=True self.curTest['test']='lp_cfx' lpRepeatConfig=self.getConfig('lp_cfx',temperature) repeatNums=int(lpRepeatConfig["repetation"]) seconds=int(lpRepeatConfig["duration"]) stopSeconds=int(lpRepeatConfig["powerDown"]) res=[] for i in range(repeatNums): print ( 'No:'+str(i)) self.setWxzt(temperature) time.sleep(int(lpRepeatConfig["wait"])) self.curTest['repeator']=i configGlobal.setStop(False) res.append(self.lp(temperature,seconds)) time.sleep(stopSeconds) self.compute('lp_cfx',res.copy(),temperature) self.isRepeat=False
def lp(self,temperature,seconds=0): lpConfig=self.getConfig('lp',temperature) if not self.isRepeat: self.curTest['test']='lp' self.curTest['repeator']=None if seconds==0: self.setWxzt(temperature) seconds=int(lpConfig["duration"]) time.sleep(int(lpConfig["wait"])) configGlobal.setStop(False) frequency=int(lpConfig["frequency"]) samples=int(lpConfig["samples"]) buf = np.empty((len(self.objectMap.values()), 0), dtype=np.float64) while seconds>0: self.singal.wait() s1=self.niRead(self.niDevName,samples,self.objectMap.values()) buf = np.column_stack((buf, s1)) temp={'test':self.curTest['test'],'repeator':self.curTest['repeator'],'buf':buf} self.queue.put(temp) time.sleep(frequency) seconds-=1 if not self.isRepeat: self.compute('lp',buf.copy(),temperature) return buf.copy()
def resumeTest(self): configGlobal.setStop(False) configGlobal.setPause(False) self.isResume = True self.execNext()
def execNext(self): canExec = self.__canExec() if not canExec[0]: raise Exception(canExec[1]) if self.curTestIdx >= self.totalTests: return True curTest = self.testItems[self.curTestIdx] curConfig = self.config[curTest] if not self.isResume or self.curTestStatus == {}: self.initCurrentTestStatus(curConfig, curTest) print(self.curTestStatus) steps = curConfig["steps"] for step in steps: try: testDuration = int(step["testDurations"]) stepName = step['name'] temperature = int(step["temperature"]) speed = int(step["speed"]) accelate = int(step["accelation"]) sampleNums = int(step["samples"][0]["totalSamples"]) sampleFreq = int(step["samples"][0]["frequence"]) except: raise Exception("cast test duration failure") task = TestTask(self.devices[self.device], self.queue) if step["warmUp"]["needed"]: configGlobal.setStop(False) warmUpStatus = self.curTestStatus[curTest + '_' + stepName + '_warmup'] warmUpDuration = step["warmUp"]["duration"] self.curTaskLength = int(warmUpDuration) if warmUpStatus == -1 or warmUpStatus == 2: self.curTaskLeftTime = int(warmUpDuration) if warmUpStatus == 2: warmUpDuration = self.curTaskLeftTime self.curTestStatus[curTest + '_' + stepName + '_warmup'] = 2 self.warmUp(task, step["warmUp"]["temperature"]) self.timing() task.stopDevTask() if configGlobal.getPause(): return self.curTestStatus[curTest + '_' + stepName + '_warmup'] = 1 if speed and accelate: task.configTask(sampleNums, self.device, temperature, self.testObjects.values(), sampleFreq, speed, accelate) else: task.configTask(sampleNums, self.device, temperature, self.testObjects.values(), sampleFreq) configGlobal.setStop(False) taskStatus = self.curTestStatus[curTest + '_' + stepName + '_runTest'] self.curTaskLength = int(testDuration) if taskStatus == -1 or taskStatus == 2: if taskStatus == -1: self.curTaskLeftTime = testDuration self.curTestStatus[curTest + '_' + stepName + '_runTest'] = 2 threads = [] t1 = threading.Thread(target=task.runTask) threads.append(t1) t2 = threading.Thread(target=self.recvTestData, args=[sampleFreq]) threads.append(t2) for t in threads: t.setDaemon(True) t.start() time.sleep(1) self.timing() task.stopDevTask() if configGlobal.getPause(): return self.curTestStatus[curTest + '_' + stepName + '_runTest'] = 1 if "after" in step: configGlobal.setStop(False) action = step["after"]["action"] self.curTaskLength = int(step["after"]["duration"]) afterStatus = self.curTestStatus[curTest + '_' + stepName + '_aftertest_' + action] if afterStatus == -1 or afterStatus == 2: if afterStatus == -1: self.curTaskLeftTime = int(step["after"]["duration"]) self.curTestStatus[curTest + '_' + stepName + '_aftertest_' + action] = 2 self.timing() if configGlobal.getPause(): return self.curTestStatus[curTest + '_' + stepName + '_aftertest_' + action] = 1 self.afterTestItem(curTest)