示例#1
0
 def open(self):
     try:
         self.serial = serial.serial_for_url(self.port, self.baudrate) #, parity=parity, rtscts=rtscts, xonxoff=xonxoff, timeout=1)
     except AttributeError:
         # happens when the installed pyserial is older than 2.5. use the
         # Serial class directly then.
         self.serial = serial.Serial(self.port, self.baudrate) #, parity=parity, rtscts=rtscts, xonxoff=xonxoff, timeout=1)
     except:
         env_setting.msg( 'connect fail. port={0} baudrate={1}'.format(self.port, self.baudrate) )
     else:
         self.connected = True
示例#2
0
    def __init__(self, **kwargs):
        # kwargs['port'] and kwargs['baudrate'] can be configured as argument
        # if port isn't assigned, scan comport and connect to any comport
        if 'port' in kwargs:
            self.port = kwargs['port']
        else:
            self.port, desc, hwid = comports().next()
            env_setting.msg( 'auto scan comport={}'.format(self.port) )

        if 'baudrate' in kwargs:
            self.baudrate = int(kwargs['baudrate'])
        else:
            self.baudrate = 115200
            env_setting.msg( 'default baudrate={}'.format(self.baudrate) )

        self.connected = False
        self.reading = False
        self.read_data = ''
示例#3
0
def main():
    if len(sys.argv) == 2:
        testplan_file = sys.argv[1]
    else:
        testplan_file = "testplan.xml"

    testplan = TestPlan(testplan_file)
    try:
        testplan = TestPlan(testplan_file)
    except:
        env_setting.msg('read XML error')
        exit(1)
    
    env_setting.setup_dir_result()
    
    env_setting.msg('testplan inforamtion:')
    env_setting.msg( '\tproduct: {}\t'.format(testplan.info['product']) )
    env_setting.msg( '\tauthor: {}\t'.format(testplan.info['author']) )
    env_setting.msg( '\tdescription:' )
    env_setting.msg( '\t\t{}'.format(testplan.info['description']) )

    for testitem in testplan.get_TestItem_all():
        env_setting.msg('testitem: name="{name}"\tskip={skip}'.format(**testitem.info) )

        if testitem.info['skip'] :
            env_setting.msg('skip...')
            continue
        else:
            env_setting.msg('start...')

        try:
            way = testplan.ways[ testitem.info['way'] ]
        except KeyError:
            env_setting.msg('aquire way={way} fail'.format( **testitem.info ))
            continue

        # run test item
        way.open()
        for op in testitem.get_operation_all():
            way.recv_start()
            env_setting.msg('\toperation[{id}] {name}'.format(**op.info))
            for step in op.get_step_all():
                env_setting.msg_d('tag={} text={}'.format(step[0], step[2]))
                if step[0] == 'msg':
                    print '[ToDo] show msg:'
                    print step[1]
                elif step[0] == 'way':
                    if hasattr(way, step[1]['op']):
                        method = getattr(way, step[1]['op'])
                        method(step[2])
                    else:
                        env_setting.msg("way={} doesn't support op={}".format(op.info['id'], step[1]['op']))
                elif step[0] == 'verify':
                    result_handle = {
                        'occour': result.occour,
                        'equal': result.equal,
                        're_match': result.re_match,
                        'copy': result.copy,
                        'dump': result.dump
                    }.get( step[1]['method'] )
                    
                    if result_handle is None:
                        env_setting.msg("unknown verification method={}".format(step[1]['method']))
                    else:
                        result_handle(step[2], way.get_data(), step[1]['name'], 'result.txt');
                else:
                    env_setting.msg("not support step={}".format(step[0]))
            way.recv_stop()
        way.close()
示例#4
0
def copy( pattern, source, name, filename):
    try:
        shutil.copy( pattern, env_setting.dir_result+name)
    except IOError as description:
        env_setting.msg("copy result file fail->{}".format(description))