Beispiel #1
0
def validate_cross_check_result(result_dir):
    """ Validate a cross-check result

    Parameters:
        result_dir  path to the directory that contains the results

    Returns:
        a list of problems
    """

    problems = []

    t = segments(result_dir)

    fmi_version, fmi_type, platform, importing_tool_name, importing_tool_version, exporting_tool_name, exporting_tool_version, model_name = t[
        -8:]

    repo_dir = os.path.join(*t[:-9])

    fmu_dir = os.path.join(repo_dir, 'fmus', fmi_version, fmi_type, platform,
                           exporting_tool_name, exporting_tool_version,
                           model_name)

    ref_filename = os.path.join(fmu_dir, model_name + '_ref.csv')
    opt_filename = os.path.join(fmu_dir, model_name + '_ref.opt')

    # check file sizes
    for root, dirs, files in os.walk(result_dir):
        for file in files:
            filename = os.path.join(root, file)
            filesize = os.path.getsize(filename)
            if filesize > 1e6:
                problems.append("%s is larger than 1 MB (%.1f MB)" %
                                (filename, filesize * 1e-6))

    _, model_name = os.path.split(result_dir)

    not_compliant_file = os.path.join(result_dir,
                                      'notCompliantWithLatestRules')
    passed_file = os.path.join(result_dir, 'passed')

    if os.path.isfile(not_compliant_file) or not os.path.isfile(passed_file):
        return problems  # stop here

    # check the output file
    res_filename = os.path.join(result_dir, model_name + '_out.csv')

    try:
        result = read_csv(res_filename)
    except Exception as e:
        problems.append("Error in %s. %s" % (res_filename, e))
        return problems  # stop here

    try:
        reference = read_csv(ref_filename)
        opt = read_ref_opt_file(opt_filename)
    except Exception as e:
        problems.append("Error in %s. %s" % (res_filename, e))
        return problems  # stop here

    problem = validate_result(result=result,
                              reference=reference,
                              t_start=opt['StartTime'],
                              t_stop=opt['StopTime'])

    if problem is not None:
        problems.append("Error in %s. %s" % (res_filename, problem))

    return problems
Beispiel #2
0
def validate_test_fmu(model_dir):
    """ Validate an exported FMU

    Parameters:
        model_dir  path to the directory that contains the exported FMU

    Returns:
        a list of problems
    """

    problems = []

    # check file sizes
    for root, dirs, files in os.walk(model_dir):
        for file in files:
            filename = os.path.join(root, file)
            filesize = os.path.getsize(filename)
            maxsize = 10e6 if file.endswith('.fmu') else 1e6
            if filesize > maxsize:
                problems.append("%s is larger than %g MB (%g MB)" %
                                (filename, maxsize * 1e-6, filesize * 1e-6))

    if 'notCompliantWithLatestRules' in files:
        return problems  # stop here

    path, model_name = os.path.split(model_dir)
    path, _ = os.path.split(path)
    path, _ = os.path.split(path)
    path, platform = os.path.split(path)
    path, fmi_type = os.path.split(path)
    _, fmi_version = os.path.split(path)

    fmu_filename = os.path.join(model_dir, model_name + '.fmu')

    # validate the modelDescription.xml
    try:
        model_description = read_model_description(fmu_filename, validate=True)
    except Exception as e:
        problems.append("Error in %s. %s" % (fmu_filename, e))
        return problems  # stop here

    # check FMI version
    if model_description.fmiVersion != fmi_version:
        problems.append("%s is not an FMI %s FMU" %
                        (fmu_filename, fmi_version))
        return problems  # stop here

    # check FMI type
    if fmi_type == 'cs' and model_description.coSimulation is None:
        problems.append("%s does not support co-simulation" % fmu_filename)
        return problems  # stop here
    elif fmi_type == 'me' and model_description.modelExchange is None:
        problems.append("%s does not support model-exchange" % fmu_filename)
        return problems  # stop here

    # collect the variable names
    variable_names = [v.name for v in model_description.modelVariables]

    # check the reference options file
    try:
        ref_opts_filename = os.path.join(model_dir, model_name + '_ref.opt')
        read_ref_opt_file(ref_opts_filename)
    except Exception as e:
        problems.append("Error in %s. %s" % (ref_opts_filename, e))

    # check the CSVs
    for suffix, required in [('_in.csv', False), ('_ref.csv', True)]:

        csv_filename = os.path.join(model_dir, model_name + suffix)

        if not required and not os.path.isfile(csv_filename):
            continue

        try:
            read_csv(csv_filename, variable_names=variable_names)
        except Exception as e:
            problems.append("Error in %s. %s" % (csv_filename, e))

    return problems
Beispiel #3
0
def validate_test_fmu(model_dir):
    """ Validate an exported FMU

    Parameters:
        model_dir  path to the directory that contains the exported FMU

    Returns:
        a list of problems
    """

    problems = []

    _, model_name = os.path.split(model_dir)

    if os.path.isfile(os.path.join(model_dir, 'notCompliantWithLatestRules')):
        return []

    fmu_filename = os.path.join(model_dir, model_name + '.fmu')

    # validate the modelDescription.xml
    try:
        model_description = read_model_description(fmu_filename, validate=True)
    except Exception as e:
        problems.append("Error in %s. %s" % (fmu_filename, e))
        return problems  # stop here

    # collect the variable names
    variable_names = [v.name for v in model_description.modelVariables]

    # check the reference options file
    try:
        ref_opts_filename = os.path.join(model_dir, model_name + '_ref.opt')
        read_ref_opt_file(ref_opts_filename)
    except Exception as e:
        problems.append("Error in %s. %s" % (ref_opts_filename, e))

    # check the CSVs
    for suffix, required in [('_cc.csv', True), ('_in.csv', False),
                             ('_ref.csv', True)]:

        csv_filename = os.path.join(model_dir, model_name + suffix)

        if not required and not os.path.isfile(csv_filename):
            continue

        try:
            read_csv(csv_filename, variable_names=variable_names)
        except Exception as e:
            problems.append("Error in %s. %s" % (csv_filename, e))

    # check compliance checker log file
    cc_logfile = model_name + '_cc.log'

    if not os.path.isfile(os.path.join(model_dir, cc_logfile)):
        problems.append("%s is missing in %s" % (cc_logfile, model_dir))

    # check ReadMe
    if not os.path.isfile(os.path.join(
            model_dir, 'ReadMe.txt')) and not os.path.isfile(
                os.path.join(model_dir, 'ReadMe.pdf')):
        problems.append("Readme.[txt|pdf] is missing in %s" % model_dir)

    if platform in ['win32', 'win64']:
        cc_script = model_name + '_cc.bat'
    else:
        cc_script = model_name + '_cc.sh'

    if not os.path.isfile(os.path.join(model_dir, cc_script)):
        problems.append("%s is missing in %s" % (cc_script, model_dir))

    return problems