Example #1
0
def get_environment_variables():
    """
    This function returns a dict of environment settings for a given part.

    It requires a basic setup of the prjxray environment that contains
    information about the databse directory location, the FPGA part, etc.

    One of the settings must be sourced, to set up the basic environment.
    """
    environment = dict()

    # Get base environment variables and resources' paths
    part = os.environ['XRAY_PART']
    database = os.environ['XRAY_DATABASE']
    database_dir = os.environ['XRAY_DATABASE_DIR']
    xray_root = os.environ['XRAY_DIR']
    db_root = os.path.join(database_dir, database)
    res_path = os.path.join(xray_root, 'settings', database)

    # Get device information
    part_info = get_part_information(db_root, part)
    fabric = get_fabric_for_part(db_root, part)
    resources = get_part_resources(res_path, os.environ['XRAY_PART'])

    environment['XRAY_DEVICE'] = part_info['device']
    environment['XRAY_PACKAGE'] = part_info['package']
    environment['XRAY_SPEED_GRADE'] = part_info['speedgrade']
    environment['XRAY_FABRIC'] = fabric
    for number, pin in resources['pins'].items():
        environment['XRAY_PIN_{:02d}'.format(number)] = pin

    return environment
Example #2
0
def main():
    """Rois all parts for a family by calling "make roi_only" over all parts
    with the same device as XRAY_PART.

    Example:
        prjxray$ ./utils/roi_all.py --db-root database/artix7/ --part xc7a100tfgg676-1
    """
    env = os.environ.copy()
    db_root = util.get_db_root()
    assert db_root
    part = util.get_part()
    assert part

    information = util.get_part_information(db_root, part)

    valid_devices = []
    for name, device in util.get_devices(db_root).items():
        if device['fabric'] == information['device']:
            valid_devices.append(name)

    tasks = []

    for part, data in util.get_parts(db_root).items():
        if data['device'] in valid_devices:
            cwd = os.getenv('XRAY_FUZZERS_DIR')

            tasks.append((part, cwd))

    with mp.Pool() as pool:
        for _ in pool.imap_unordered(worker, tasks):
            pass
Example #3
0
def main():
    """Rois all parts for a family by calling "make roi_only" over all parts
    with the same device as XRAY_PART.

    Example:
        prjxray$ ./utils/roi_all.py --db-root database/artix7/ --part xc7a100tfgg676-1
    """
    env = os.environ.copy()
    db_root = util.get_db_root()
    assert db_root
    part = util.get_part()
    assert part

    information = util.get_part_information(db_root, part)

    valid_devices = []
    for name, device in util.get_devices(db_root).items():
        if device['fabric'] == information['device']:
            valid_devices.append(name)

    for part, data in util.get_parts(db_root).items():
        if data['device'] in valid_devices:
            command = "make roi_only"
            env['XRAY_PART'] = part
            cwd = os.getenv('XRAY_FUZZERS_DIR')
            subprocess.run(command.split(' '), check=True, env=env, cwd=cwd)
Example #4
0
def main(argv):
    fuzzers_dir = os.path.abspath(os.path.dirname(__file__))

    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("fuzzer", help="fuzzer to run")
    parser.add_argument(
        "--retries",
        type=int,
        default=0,
        help="Retry a failed fuzzer n times.",
    )
    args = parser.parse_args()

    # Setup the logger with flush=False, it should be safe to use in a signal
    # handler.
    fuzzer_length = max(len(f) for f in os.listdir(fuzzers_dir))
    logger = Logger(args.fuzzer, datetime.utcnow(), fuzzer_length)

    # Need a signal handler on SIGCHLD otherwise get_resource doesn't return
    # anything.
    signal.signal(signal.SIGCHLD, lambda sig, frame: None)

    fuzzer_dir = os.path.join(fuzzers_dir, args.fuzzer)
    assert os.path.exists(fuzzer_dir), fuzzer_dir

    fuzzer_logdir = os.path.join(fuzzer_dir,
                                 "logs_{}".format(os.environ['XRAY_PART']))
    if not os.path.exists(fuzzer_logdir):
        os.makedirs(fuzzer_logdir)
    assert os.path.exists(fuzzer_logdir)

    # Set part information from the mapping files and set into the env
    db_root = os.path.join(os.environ['XRAY_DATABASE_DIR'],
                           os.environ['XRAY_DATABASE'])
    part = get_part_information(db_root, os.environ['XRAY_PART'])
    os.environ['XRAY_DEVICE'] = part['device']
    os.environ['XRAY_PACKAGE'] = part['package']
    os.environ['XRAY_SPEED_GRADE'] = part['speedgrade']
    fabric = get_fabric_for_part(db_root, os.environ['XRAY_PART'])
    os.environ['XRAY_FABRIC'] = fabric
    res_path = os.path.join(os.environ['XRAY_DIR'], 'settings',
                            os.environ['XRAY_DATABASE'])
    resources = get_part_resources(res_path, os.environ['XRAY_PART'])
    for number, pin in resources['pins'].items():
        os.environ['XRAY_PIN_{:02d}'.format(number)] = pin

    exit_code = -1
    args.retries += 1
    for retry_count in range(0, args.retries):
        logger.log('Running fuzzer attempt: {}', [retry_count])
        exit_code = run_fuzzer(
            args.fuzzer,
            fuzzer_dir,
            fuzzer_logdir,
            logger,
            will_retry=retry_count < (args.retries - 1),
        )
        if exit_code <= 0:
            break
        logger.log('WARNING: Fuzzer failed!')

    return exit_code