示例#1
0
    def create(cls):
        parser = argparse.ArgumentParser(add_help=False)
        parser.add_argument('-m',
                            '--mode',
                            choices=cls.mode_class.keys(),
                            default='lpbk1')
        parser.add_argument(
            '--loglevel',
            choices=['exception', 'error', 'warning', 'info', 'debug'],
            default='warning',
            help='error level to set')
        parser.add_argument('--version',
                            help='print version information then quit',
                            action='store_true',
                            default=False)
        parser.add_argument('-h',
                            '--help',
                            action='store_true',
                            default=False,
                            help='print help message and exit')

        args, _ = parser.parse_known_args()
        if args.version:
            print("{} OPAE {}, build {}".format(basename(sys.argv[0]),
                                                fpga.version(), fpga.build()))
            sys.exit(EX_OK)
        logger = logging.getLogger("fpgadiag")
        stream_handler = logging.StreamHandler(stream=sys.stderr)
        stream_handler.setFormatter(
            logging.Formatter(
                '%(asctime)s: [%(name)-8s][%(levelname)-6s] - %(message)s'))
        logger.addHandler(stream_handler)
        logger.setLevel(getattr(logging, args.loglevel.upper()))
        test = cls.mode_class[args.mode](args.mode, parser)
        return test
示例#2
0
    def create(cls):
        parser = argparse.ArgumentParser(add_help=False)
        parser.add_argument('-m',
                            '--mode',
                            choices=cls.mode_class.keys(),
                            default='lpbk1')
        parser.add_argument(
            '--loglevel',
            choices=['exception', 'error', 'warning', 'info', 'debug'],
            default='warning',
            help='error level to set')
        parser.add_argument('--version',
                            help='print version information then quit',
                            action='store_true',
                            default=False)
        parser.add_argument('-h',
                            '--help',
                            action='store_true',
                            default=False,
                            help='print help message and exit')

        args, _ = parser.parse_known_args()
        if args.version:
            print("{} OPAE {}, build {}".format(basename(sys.argv[0]),
                                                fpga.version(), fpga.build()))
            sys.exit(EX_OK)
        test = cls.mode_class[args.mode](args.mode, parser)
        test.logger.setLevel(getattr(logging, args.loglevel.upper()))
        return test
示例#3
0
def main():
    test = fpgadiag.create()
    if not test.setup():
        sys.exit(EX_USAGE)
    tokens = test.enumerate()
    if not tokens:
        test.logger.error("Could not find suitable accelerator")
        sys.exit(EX_UNAVAILABLE)
    with fpga.open(tokens[0]) as handle:
        parent = fpga.properties(handle).parent
        with fpga.open(parent, fpga.OPEN_SHARED) as device:
            try:
                test.logger.info("{} OPAE {}, build {}".format(
                    basename(sys.argv[0]), fpga.version(), fpga.build()))
                test.run(handle, device)
            except KeyboardInterrupt:
                test.logger.info("User requested interrupt - ending execution")
            except RuntimeError as e:
                test.logger.error("Error running test: %s", e)
            else:
                return EX_OK
    return EX_SOFTWARE
示例#4
0
    def create(cls):
        parser = argparse.ArgumentParser(add_help=True)
        parser.add_argument('-c',
                            '--config',
                            help='config file listing mux configuration',
                            type=argparse.FileType('r'),
                            default='mux.json')
        parser.add_argument(
            '--loglevel',
            choices=['exception', 'error', 'warning', 'info', 'debug'],
            default='warning',
            help='error level to set')
        parser.add_argument('--version',
                            help='print version information then quit',
                            action='store_true',
                            default=False)

        args, _ = parser.parse_known_args()
        if args.version:
            print("{} OPAE {}, build {}".format(basename(sys.argv[0]),
                                                fpga.version(), fpga.build()))
            sys.exit(EX_OK)

        logger = logging.getLogger("fpgadiag")
        stream_handler = logging.StreamHandler(stream=sys.stderr)
        stream_handler.setFormatter(
            logging.Formatter(
                '%(asctime)s: [%(name)-8s][%(levelname)-6s] - %(message)s'))
        logger.addHandler(stream_handler)
        logger.setLevel(getattr(logging, args.loglevel.upper()))

        config = json.load(args.config)
        app_classes = dict([(n.__name__, n)
                            for n in set(cls.mode_class.values())])
        bits = int(math.ceil(math.log(len(config), 2)))

        apps = []
        modes = {'nlb0': 'lpbk1', 'nlb7': 'sw'}
        for i, c in enumerate(config):
            app_name = c.get('app')
            if app_name not in app_classes:
                logging.warning("app not recognized: %s", app_name)
                continue
            if c['disabled']:
                logging.info('app %s is disabled', app_name)
                continue
            app_parser = argparse.ArgumentParser(add_help=False)
            app_parser.add_argument('-m', '--mode')
            app_parser.add_argument('-h',
                                    '--help',
                                    action='store_true',
                                    default=False)
            app_mode = c['config'].get('mode', modes.get(app_name))
            app = app_classes[app_name](app_mode, app_parser)
            app_config = c['config']
            app_args = ['--mode', app_mode]
            for k, v in app_config.iteritems():
                if type(v) is bool:
                    if v:
                        app_args.append('--{}'.format(k))
                else:
                    app_args.extend(['--{}'.format(k), str(v)])
            app.write_csr32 = mux_csrwrite(app.write_csr32, i << (18 - bits))
            app.write_csr64 = mux_csrwrite(app.write_csr64, i << (18 - bits))
            if not app.setup(app_args):
                sys.exit(EX_USAGE)
            apps.append(app)
        return apps