Exemple #1
0
    def test_case_runner_init_dut_failed(self):
        from runner import case_runner, initDUT, createLogDir
        logpath = './log'
        if not os.path.exists(logpath):
            os.mkdir(logpath)
        logpath += '/ut_runner'
        logger = createLogger('runner_logger', logpath)
        casename = 'test_case_runner_2_duts'
        casefolder = createLogDir(casename, logpath)

        from common import bench2dict
        benchfile = './bench.csv'
        benchfile = './home.csv'
        bench = bench2dict(benchfile)

        from Parser import caseParser
        mode = 'full'
        cs = caseParser(casename, mode, casefolder)
        casefile = './runner_case.csv'
        sdut, lvar, lsetup, lrun, ltear = cs.load(casefile)
        ldut = list(sdut)
        ldut[0] = 'N1wrong'
        errormessage = []
        #duts= initDUT(errormessage,bench,ldut,logger, casefolder)#['lnx1', 'lnx2']
        self.assertRaises(Exception, initDUT, errormessage, bench, ldut,
                          logger, casefolder)
Exemple #2
0
    def do_init(self, sut_name):
        sut_name_list = self.__parseline__(sut_name)
        if sut_name in self.sut:
            print('sut(%s) is existed, "setsut %s" to switch to it'%(sut_name,sut_name))
        else:
            errormessage = ''

            bench = bench2dict(self.bench_file)
            duts = initDUT(errormessage, bench, sut_name_list, self.logger, self.log_path, self.share_data)
            py_code = '''
        cs.init_duts("%s")'''%('","'.join(sut_name_list))
            self.save2py(py_code=py_code)

            last_sut='tc'
            for name in sut_name_list:
                if name in duts:
                    self.sut[name]= duts[name]
                    last_sut=name
                else:
                    print('failed to init %s'%name)
            assgin_sut = ''
            for tmp_sut_name in duts.keys():
                if tmp_sut_name!='tc':
                    assgin_sut+="        %s = cs.duts['%s']\n"%(tmp_sut_name,tmp_sut_name)
            self.save2py(py_code=assgin_sut)
            self.do_setsut(last_sut)
Exemple #3
0
    def test_suiteLoad(self):
        from runner import case_runner, initDUT, createLogDir
        logpath = './log'
        if not os.path.exists(logpath):
            os.mkdir(logpath)
        logpath += '/ut_runner'
        logger = createLogger('runner_logger', logpath)
        casename = 'test_suiteLoad'
        casefolder = createLogDir(casename, logpath)

        from common import bench2dict
        where = 'home'
        benchfile = './bench.csv'
        casefile = './suite_parser.csv'
        if where == 'home':
            benchfile = './home.csv'
            casefile = './suite1.csv'

        bench = bench2dict(benchfile)

        from Parser import suiteParser
        suite = suiteParser(casename, casefolder)

        st = suite.load(casefile)
        for i in st:
            print(i)
Exemple #4
0
    def do_init(self, sut_name):
        sut_name_list = self.__parseline__(sut_name)
        if sut_name in self.sut:
            print('sut(%s) is existed, "setsut %s" to switch to it' %
                  (sut_name, sut_name))
        else:
            errormessage = ''

            bench = bench2dict(self.bench_file)
            duts = initDUT(errormessage, bench, sut_name_list, self.logger,
                           self.log_path, self.share_data)
            py_code = '''
        cs.init_duts("%s")''' % ('","'.join(sut_name_list))
            self.save2py(py_code=py_code)

            last_sut = 'tc'
            for name in sut_name_list:
                if name in duts:
                    self.sut[name] = duts[name]
                    last_sut = name
                else:
                    print('failed to init %s' % name)
            assgin_sut = ''
            for tmp_sut_name in duts.keys():
                if tmp_sut_name != 'tc':
                    assgin_sut += "        %s = cs.duts['%s']\n" % (
                        tmp_sut_name, tmp_sut_name)
            self.save2py(py_code=assgin_sut)
            self.do_setsut(last_sut)
Exemple #5
0
    def test_case_runner_init_dut_failed(self):
        from runner import case_runner, initDUT, createLogDir
        logpath ='./log'
        if not os.path.exists(logpath):
            os.mkdir(logpath)
        logpath+='/ut_runner'
        logger = createLogger('runner_logger', logpath)
        casename = 'test_case_runner_2_duts'
        casefolder = createLogDir(casename,logpath)

        from common import bench2dict
        benchfile = './bench.csv'
        benchfile= './home.csv'
        bench =bench2dict(benchfile)


        from Parser import  caseParser
        mode = 'full'
        cs = caseParser(casename, mode, casefolder)
        casefile = './runner_case.csv'
        sdut, lvar, lsetup, lrun, ltear =cs.load(casefile)
        ldut = list(sdut)
        ldut[0]='N1wrong'
        errormessage =[]
        #duts= initDUT(errormessage,bench,ldut,logger, casefolder)#['lnx1', 'lnx2']
        self.assertRaises(Exception, initDUT,errormessage,bench, ldut,logger, casefolder)
Exemple #6
0
 def __init__(self,casename,bench, sutnames , logfiledir, outputfile =None):
     if outputfile:
         pass
     else:
         outputfile=sys.stdout
     self.benchinfo = bench2dict(bench)
     #self.benchinfo = benchinfo
     self.casename =casename
     self.sut ={}
     for sutname in sutnames:
         self.sut.update({sutname:self.benchinfo[sutname]})
     steps=[[],[],[]]
     mode ='FULL'
     self.tc= Case(casename,self.sut,steps=[[],[],[]],mode='FULL',DebugWhenFailed=False,logdir=logfiledir,caseconfigfile='../lib/case.cfg')
     self.thQureyOut = threading.Thread(target=self.QureyOutput,args = [] )#outputfile
     self.thQureyOut.start()
     self.client ='interaction'
     self.tc.AddClient(self.client)
     self.tc.troubleshooting()
     nowTime =time.time()
     self.lastCmdIssueTime=nowTime
     Cmd.__init__(self, 'tab', sys.stdin, sys.stdout)
     self.use_rawinput=True
     #import readline
     #readline.set_completer_delims('\t\n')
 #     def do_set(self,name):
 #         print(name)
     self.do_setsut(self.tc.Session.keys()[-1])
     self.helpDoc={}
     self.cmdbank=[]
Exemple #7
0
 def tes1t_InitDUTs(self):
     from runner import initDUT
     logpath = './log'
     from common import bench2dict
     bench = bench2dict('./bench.csv')
     duts = initDUT(bench, ['lnx1', 'lnx2'])
     print(duts)
Exemple #8
0
 def tes1t_InitDUTs(self):
     from runner import initDUT
     logpath ='./log'
     from common import bench2dict
     bench =bench2dict('./bench.csv')
     duts= initDUT(bench,['lnx1', 'lnx2'])
     print(duts)
Exemple #9
0
    def test_suiteLoad(self):
        from runner import case_runner, initDUT, createLogDir
        logpath ='./log'
        if not os.path.exists(logpath):
            os.mkdir(logpath)
        logpath+='/ut_runner'
        logger = createLogger('runner_logger', logpath)
        casename = 'test_suiteLoad'
        casefolder = createLogDir(casename,logpath)

        from common import bench2dict
        where= 'home'
        benchfile = './bench.csv'
        casefile = './suite_parser.csv'
        if where=='home':
            benchfile= './home.csv'
            casefile = './suite1.csv'

        bench =bench2dict(benchfile)


        from Parser import  suiteParser
        suite = suiteParser(casename, casefolder)

        st =suite.load(casefile)
        for i  in st:
            print(i)
Exemple #10
0
 def load_bench(self, bench_file=None):
     bench_file= self.bench_file if bench_file is None else bench_file
     if bench_file is not None:
         if os.path.exists(bench_file):
             self.bench =  bench2dict(bench_file)
             self.set_bench_file(bench_file)
         else:
             self.info('%s is not exist or not a valid bench file, current work dir %s'%(bench_file,os.getcwd()))
     else:
         self.info('bench file is None!')
Exemple #11
0
def run_case_in_suite(casename, currentBenchfile, currentBenchinfo,logger, stop_at_fail,logdir, cmd, dry_run):

    patDash  = re.compile('\s*(python |python[\d.]+ |python.exe |)\s* cr.py\s+(.+)\s*', re.DOTALL|re.IGNORECASE)
    m =  re.match(patDash, cmd)
    returncode = 0
    if m:
        argstring = m.group(2)
        import shlex
        lstArg = shlex.split(argstring)
        #0-case.csv, 1-bench, 2-mode, 4...-2- args
        casefile = lstArg[0]
        benchfile = lstArg[1]
        mode       = lstArg[2]
        args= lstArg[3:]
        newBenchInfo =None
        if currentBenchfile!=benchfile:
           # from common import bench2dict
            bench =bench2dict(benchfile)
            releaseDUTs()
        else:
            bench = currentBenchinfo
        from Parser import  caseParser

        cs = caseParser(casename, mode, logdir, logger)
        sdut, lvar, lsetup, lrun, ltear =cs.load(casefile)
        ldut = list(sdut)
        errormessage =[]

        duts= initDUT(errormessage,bench,ldut,logger, logdir, dry_run)
        seq = [cs.seqSetup, cs.seqRun, cs.seqTeardown]
        returncode, caseErrorMessage= case_runner(casename,duts,seq, mode)
    else:
        import subprocess
        pp =None
        if cmd.startswith('\w+.py') :
            exe_cmd ='python '+ cmd+" "+logdir
            pp = subprocess.Popen(args = exe_cmd ,shell =True)

        import time
        ChildRuning = True
        first =True
        while ChildRuning:
            if pp.poll() is None:
                interval = 1
                if first:
                    first=False
                time.sleep(interval)
            else:
                ChildRuning = False

        returncode = pp.returncode
Exemple #12
0
    def test_PowerShell(self):
        from runner import case_runner, initDUT, createLogDir, createLogger
        logpath ='./log'
        if not os.path.exists(logpath):
            os.mkdir(logpath)
        logpath+='/PowerShell'
        logger = createLogger('PowerShell', logpath)
        casename = 'PowerShell_1'
        casefolder = createLogDir(casename,logpath)

        from common import bench2dict
        where= 'nohome'
        benchfile = './bench.csv'
        casefile = './powershell.csv'
        if where=='home':
            benchfile= './home.csv'
            casefile = './home_case.csv'

        bench =bench2dict(benchfile)


        from Parser import  caseParser
        mode = 'full'
        cs = caseParser(casename, mode, casefolder)

        sdut, lvar, lsetup, lrun, ltear =cs.load(casefile)
        ldut = list(sdut)
        errormessage =[]
        duts= initDUT(errormessage,bench,ldut,logger, casefolder)#['lnx1', 'lnx2']
        seq = [cs.seqSetup, cs.seqRun, cs.seqTeardown]
        case= case_runner(casename,duts,seq, mode)


        print(duts)
        for name in duts.keys():
            dut = duts[name]
            if dut :
                dut.SessionAlive=False
Exemple #13
0
    def test_PowerShell(self):
        from runner import case_runner, initDUT, createLogDir, createLogger
        logpath = './log'
        if not os.path.exists(logpath):
            os.mkdir(logpath)
        logpath += '/PowerShell'
        logger = createLogger('PowerShell', logpath)
        casename = 'PowerShell_1'
        casefolder = createLogDir(casename, logpath)

        from common import bench2dict
        where = 'nohome'
        benchfile = './bench.csv'
        casefile = './powershell.csv'
        if where == 'home':
            benchfile = './home.csv'
            casefile = './home_case.csv'

        bench = bench2dict(benchfile)

        from Parser import caseParser
        mode = 'full'
        cs = caseParser(casename, mode, casefolder)

        sdut, lvar, lsetup, lrun, ltear = cs.load(casefile)
        ldut = list(sdut)
        errormessage = []
        duts = initDUT(errormessage, bench, ldut, logger,
                       casefolder)  #['lnx1', 'lnx2']
        seq = [cs.seqSetup, cs.seqRun, cs.seqTeardown]
        case = case_runner(casename, duts, seq, mode)

        print(duts)
        for name in duts.keys():
            dut = duts[name]
            if dut:
                dut.SessionAlive = False
Exemple #14
0
        from runner import case_runner, initDUT, createLogDir      ,createLogger
        if os.path.exists(sys.argv[-1]):
            pass
        else:
            sys.argv.append(defaultlogdir)
        if not os.path.exists(defaultlogdir):
            os.mkdir(defaultlogdir)
        defaultlogdir=sys.argv[-1]
        basename_casename = os.path.basename(sys.argv[1])
        casefolder = createLogDir(basename_casename,defaultlogdir)
        logger = createLogger(basename_casename, casefolder)


        from common import bench2dict
        benchfile = sys.argv[2]
        bench =bench2dict(benchfile)


        from Parser import  caseParser
        mode = sys.argv[3]
        case_file_name =os.path.abspath(sys.argv[1])
        cs = caseParser(case_file_name, mode, casefolder)
        casefile = case_file_name
        sdut, lvar, lsetup, lrun, ltear =cs.load(casefile, sys.argv)
        ldut = list(sdut)
        errormessage =[]
        sharedata ={}
        #duts= initDUT(errormessage,bench,ldut,logger, casefolder)#['lnx1', 'lnx2']
        duts= initDUT(errormessage,bench, ldut,logger, casefolder, sharedata)
        seq = [cs.seqSetup, cs.seqRun, cs.seqTeardown]
Exemple #15
0
    def __init__(self, benchfile, dutname):
        #global pid, keyboard
        #keyboard = PyKeyboard()
        self.flag_running = True
        pid = os.getpid()
        self.tmCreated = datetime.datetime.now()
        self.tmTimeStampOfLastCmd = self.tmCreated
        self.share_data ={}
        Cmd.__init__(self, 'tab', sys.stdin, sys.stdout)#)#
        try:
            from readline import rl
            self.rl = rl
        except ImportError:
            pass
#script file

        name = 'tc'

        fullname = name[:60]
        removelist = '\-_.'
        pat = r'[^\w' + removelist + ']'
        name = re.sub(pat, '', fullname)
        tm = ''
        if name == 'tc':
            tm = '-' + self.tmCreated.isoformat('_')

        tm = re.sub(pat, '', tm)
        fullname = name + tm
        self.tcName = fullname
        if self.case_path:
            pass
        else:
            self.case_path = '../../test'
        if not os.path.exists(self.case_path):
            os.mkdir(self.case_path)
        self.script_csv_file_name = '%s/%s.csv' % (self.case_path, self.tcName)
        self.script_py_file_name = '%s/%s.py' % (self.case_path, self.tcName)
        ###########

        fullname = 'tc'
        removelist = '\-_.'
        pat = r'[^\w' + removelist + ']'
        name = re.sub(pat, '', fullname)
        tm = ''
        if name == 'tc':
            tm = '-' + self.tmCreated.isoformat('_')

        tm = re.sub(pat, '', tm)
        self.dftCaseFile = name + tm + '.csv'


        self.tcName = 'tc'
        self.sutname = 'tc'
        self.tabend = 'disable'
        self.record = [['#var'],
                       ['defaultTime', '30'],
                       ['#setup'],
                       ['#SUT_Name', 'Command_or_Function', 'Expect', 'Max_Wait_Time', 'TimeStamp', 'Interval']
                       ]
        for record in self.record:
            self.save2file(None,[record])
        self.save2py(py_file_start)
        # self.save2file(self.record[0])

        logpath = '../../log'


        if not os.path.exists(logpath):
            os.mkdir(logpath)
        logpath = createLogDir('ia', logpath)
        self.logger = createLogger('ia', logpath)
        # benchfile = './bench.csv'

        if os.path.exists(benchfile):
            bench = bench2dict(benchfile)
            self.bench_file= benchfile
            self.bench= bench
            self.log_path= logpath

            errormessage = ''
            duts = initDUT(errormessage, bench, dutname, self.logger, logpath, self.share_data)
            py_code = '''
        cs.load_bench(bench_file)
        cs.init_duts("%s")'''%( '","'.join(dutname))
            self.save2py(py_code=py_code)
            self.sut = duts
            self.sut['tc']=self

            assgin_sut = ''
            for tmp_sut_name in duts.keys():
                if tmp_sut_name!='tc':
                    assgin_sut+="        %s = cs.duts['%s']\n"%(tmp_sut_name,tmp_sut_name)
            self.save2py(assgin_sut)
            th = threading.Thread(target=self.show)
            th.start()
            th = threading.Thread(target=self.checkQuestionMarkEnd)
            th.start()
            self.do_setsut(dutname[0])
            self.helpDoc = {}
            self.cmdbank = []
            for sut in self.sut.keys():
                self.CreateDoc4Sut(sut)
        else:
            self.sut = {}
            self.do_setsut('tc')
            self.helpDoc = {}
            self.cmdbank = []
            self.output = 'no test bench assigned, please try "set bench [path/file_name] or [file_name]", the default path is ../../test'
            print(self.output)
        self.update =True
        keyboard_monitor_thread = threading.Thread(target=self.monitor_keyboard)
        keyboard_monitor_thread.start()
Exemple #16
0
    def __init__(self, benchfile, dutname):
        #global pid, keyboard
        #keyboard = PyKeyboard()
        self.flag_running = True
        pid = os.getpid()
        self.tmCreated = datetime.datetime.now()
        self.tmTimeStampOfLastCmd = self.tmCreated
        self.share_data = {}
        Cmd.__init__(self, 'tab', sys.stdin, sys.stdout)  #)#
        try:
            from readline import rl
            self.rl = rl
        except ImportError:
            pass
#script file

        name = 'tc'

        fullname = name[:60]
        removelist = '\-_.'
        pat = r'[^\w' + removelist + ']'
        name = re.sub(pat, '', fullname)
        tm = ''
        if name == 'tc':
            tm = '-' + self.tmCreated.isoformat('_')

        tm = re.sub(pat, '', tm)
        fullname = name + tm
        self.tcName = fullname
        if self.case_path:
            pass
        else:
            self.case_path = '../../test'
        if not os.path.exists(self.case_path):
            os.mkdir(self.case_path)
        self.script_csv_file_name = '%s/%s.csv' % (self.case_path, self.tcName)
        self.script_py_file_name = '%s/%s.py' % (self.case_path, self.tcName)
        ###########

        fullname = 'tc'
        removelist = '\-_.'
        pat = r'[^\w' + removelist + ']'
        name = re.sub(pat, '', fullname)
        tm = ''
        if name == 'tc':
            tm = '-' + self.tmCreated.isoformat('_')

        tm = re.sub(pat, '', tm)
        self.dftCaseFile = name + tm + '.csv'

        self.tcName = 'tc'
        self.sutname = 'tc'
        self.tabend = 'disable'
        self.record = [['#var'], ['defaultTime', '30'], ['#setup'],
                       [
                           '#SUT_Name', 'Command_or_Function', 'Expect',
                           'Max_Wait_Time', 'TimeStamp', 'Interval'
                       ]]
        for record in self.record:
            self.save2file(None, [record])
        self.save2py(py_file_start)
        # self.save2file(self.record[0])

        logpath = '../../log'

        if not os.path.exists(logpath):
            os.mkdir(logpath)
        logpath = createLogDir('ia', logpath)
        self.logger = createLogger('ia', logpath)
        # benchfile = './bench.csv'

        if os.path.exists(benchfile):
            bench = bench2dict(benchfile)
            self.bench_file = benchfile
            self.bench = bench
            self.log_path = logpath

            errormessage = ''
            duts = initDUT(errormessage, bench, dutname, self.logger, logpath,
                           self.share_data)
            py_code = '''
        cs.load_bench(bench_file)
        cs.init_duts("%s")''' % ('","'.join(dutname))
            self.save2py(py_code=py_code)
            self.sut = duts
            self.sut['tc'] = self

            assgin_sut = ''
            for tmp_sut_name in duts.keys():
                if tmp_sut_name != 'tc':
                    assgin_sut += "        %s = cs.duts['%s']\n" % (
                        tmp_sut_name, tmp_sut_name)
            self.save2py(assgin_sut)
            th = threading.Thread(target=self.show)
            th.start()
            th = threading.Thread(target=self.checkQuestionMarkEnd)
            th.start()
            self.do_setsut(dutname[0])
            self.helpDoc = {}
            self.cmdbank = []
            for sut in self.sut.keys():
                self.CreateDoc4Sut(sut)
        else:
            self.sut = {}
            self.do_setsut('tc')
            self.helpDoc = {}
            self.cmdbank = []
            self.output = 'no test bench assigned, please try "set bench [path/file_name] or [file_name]", the default path is ../../test'
            print(self.output)
        self.update = True
        keyboard_monitor_thread = threading.Thread(
            target=self.monitor_keyboard)
        keyboard_monitor_thread.start()
Exemple #17
0
def run1case(casename, cmd,benchfile, benchinfo, dut_pool, logdir, logger, sharedata, dry_run =False):
    errormessage = ''
    caselogger = createLogger('caselog.txt', logdir)
    bench = benchinfo
    try:
        for dut_name in dut_pool:
            try:
                dut_pool[dut_name].logger = caselogger
                dut_pool[dut_name].openLogfile(logdir)
                dut_pool[dut_name].FailFlag    =False # the flag means in Session's perspective view, case failed
                dut_pool[dut_name].ErrorMessage=None # to store the error message
                dut_pool[dut_name].info(dut_pool[dut_name].name, 'session info reseted')
            except Exception as e:
                caselogger.error('failed to update logger for dut:%s'%dut_name)

        patDash  = re.compile('\s*(python |python[\d.]+ |python.exe |)\s*(cr.py|cr.exe)\s+(.+)\s*', re.DOTALL|re.IGNORECASE)
        m =  re.match(patDash, cmd)
        returncode = 1
        if m:

            argstring = m.group(3)
            import shlex
            if os.name =='nt':
                posix =False
            else:
                posix =True
            lstArg = shlex.split(argstring, posix=posix)
            #0-case.csv, 1-bench, 2-mode, 4...-2- args
            casefile = lstArg[0]
            case_benchfile = lstArg[1]
            case_mode       = lstArg[2]
            case_args= lstArg
            case_args.insert(0,'cr.py')


            if case_benchfile!=benchfile:
                #from common import bench2dict
                caselogger.info('loading a new bench:%s'%case_benchfile)
                global gPathLocker
                gPathLocker.acquire()
                bench =bench2dict(case_benchfile)
                gPathLocker.release()
                benchfile = case_benchfile
                caselogger.info('releasing duts in old dut_pool')
                releaseDUTs(dut_pool, caselogger)
                dut_pool ={}
            from Parser import  caseParser
            caselogger.info('loading case: %s'% casename)
            cs = caseParser(casename, case_mode, logdir, caselogger)
            sdut, lvar, lsetup, lrun, ltear =cs.load(casefile, case_args)
            ldut = list(sdut)
            newduts= []
            oldduts = []
            for nd in ldut:
                if dut_pool.has_key(nd):
                    oldduts.append(nd)
                    dut_pool[nd].FailFlag    =False # the flag means in Session's perspective view, case failed
                    dut_pool[nd].ErrorMessage=None # to store the error message
                    caselogger.info(dut_pool[nd].name+ ' cleared FailFlag and ErrorMessage')
                else:
                    newduts.append(nd)
            if dry_run is not True:
                for od in oldduts :
                    dut_pool[od].FailFlag    =False # the flag means in Session's perspective view, case failed
                    dut_pool[od].ErrorMessage=None
                    if dut_pool[od].isAlive() :
                        dut_pool[od].logger = caselogger
                        dut_pool[od].openLogfile(logdir)
                    else:
                        dut_pool[od].closeSession()
                        dut_pool.pop(od)
                        newduts.append(od)
            errormessage =[]
            duts= initDUT(errormessage,bench,newduts,caselogger, logdir,sharedata, dry_run=dry_run)


            #duts['cfa84'].isAlive()
            #duts['sba94'].isAlive()
            #print('initedduts')
            for k in duts.keys():
                dut_pool[k]=duts[k]
            #print('initedduts 2')
            for key in duts.keys():
                dut_pool[key]= duts[key]
            #print('initedduts 3 ' )
            seq = [cs.seqSetup, cs.seqRun, cs.seqTeardown]
            caselogger.info('starting to run case: %s'%cmd)
            returncode, STRerrormessage= case_runner(casename,dut_pool,seq, case_mode, caselogger)

            if returncode:
                import pprint
                STRerrormessage = pprint.pformat(STRerrormessage)
                caselogger.error('Case Failed:')
                for line in STRerrormessage.replace('\\r', '\r').replace('\\n', '\n').replace('\r\n', '\n').split('\n'):
                    caselogger.error(line)
                errormessage.append(STRerrormessage)

            else:
                caselogger.info('Case PASS')

        else:
            import subprocess
            pp =None

            patPython = re.compile(r'\s*(python\s+|python.exe\s+|)(.*[./\w_-]+.py)', re.IGNORECASE|re.DOTALL)
            m=re.match(patPython, cmd)
            if m :
                newcmd =m.group(2)
                if os.path.exists('y.exe'):
                    exe_cmd ='python -O '+ cmd+" -l "+logdir
                else:
                    exe_cmd ='python '+ cmd+" -l "+logdir
                caselogger.info('running case: %s'%exe_cmd)
                pp = subprocess.Popen(args = exe_cmd ,shell =True,stderr=subprocess.PIPE)
                import time
                ChildRuning = True
                first =True
                while ChildRuning:
                    if pp.poll() is None:
                        interval = 1
                        if first:
                            first=False
                        time.sleep(interval)
                    else:
                        ChildRuning = False

                returncode = pp.returncode
            if returncode:
                try:
                    stdout, stderr =pp.communicate()
                    try:
                        with open('%s/case_error.txt'%logdir,'r') as f:
                            errormessage +='\n'.join(f.readlines()[:10])
                    except Exception as e:
                        pass

                        if stderr!='':
                            errormessage +=stderr
                        else:
                            errormessage = stderr
                        with open('%s/case_error.txt'%logdir,'a+') as f:
                            f.write(stderr)

                except Exception as e:
                    print(e)
    except KeyboardInterrupt :
        sys.exit(1)
    except Exception as e:

        if returncode ==0:
            returncode =1

        #import traceback
        errormessage = '%s\n%s'%(e.__str__(),traceback.format_exc())
        caselogger.error('Case FAIL')
        for line in errormessage.split('\n'):
            caselogger.error(line)
    return  returncode, errormessage, benchfile,bench, dut_pool
Exemple #18
0
            print(errormessage)
        from runner import case_runner, initDUT, createLogDir, createLogger
        if os.path.exists(sys.argv[-1]):
            pass
        else:
            sys.argv.append(defaultlogdir)
        if not os.path.exists(defaultlogdir):
            os.mkdir(defaultlogdir)
        defaultlogdir = sys.argv[-1]
        basename_casename = os.path.basename(sys.argv[1])
        casefolder = createLogDir(basename_casename, defaultlogdir)
        logger = createLogger(basename_casename, casefolder)

        from common import bench2dict
        benchfile = sys.argv[2]
        bench = bench2dict(benchfile)

        from Parser import caseParser
        mode = sys.argv[3]
        case_file_name = os.path.abspath(sys.argv[1])
        cs = caseParser(case_file_name, mode, casefolder)
        casefile = case_file_name
        sdut, lvar, lsetup, lrun, ltear = cs.load(casefile, sys.argv)
        ldut = list(sdut)
        errormessage = []
        sharedata = {}
        #duts= initDUT(errormessage,bench,ldut,logger, casefolder)#['lnx1', 'lnx2']
        duts = initDUT(errormessage, bench, ldut, logger, casefolder,
                       sharedata)
        seq = [cs.seqSetup, cs.seqRun, cs.seqTeardown]