Skip to content
Permalink
Browse files

Copy from fmi2 to fmi1 (DefaultExperiment changes)

  • Loading branch information
filip-stenstrom committed Dec 10, 2019
1 parent 3f4a94e commit 9c3433130a164c50f0017162e3540bf09b14e9e8
@@ -64,6 +64,9 @@ compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU_DUMMY_ME_MODEL_IDENTIFIER}" "me" "fm
compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU_DUMMY_CS_MODEL_IDENTIFIER}" "cs" "fmu1_dll_cs" "${XML_CS_PATH}" "${SHARED_LIBRARY_CS_PATH}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU_DUMMY_CS_MODEL_IDENTIFIER}" "cs_tc" "fmu1_dll_cs" "${XML_CS_TC_PATH}" "${SHARED_LIBRARY_CS_PATH}")

add_executable (fmi1_import_default_experiment_test ${RTTESTDIR}/FMI1/fmi1_import_default_experiment_test.c)
target_link_libraries (fmi1_import_default_experiment_test ${FMILIBFORTEST} )

add_executable (fmi1_xml_parsing_test ${RTTESTDIR}/FMI1/fmi1_xml_parsing_test.c)
target_link_libraries (fmi1_xml_parsing_test ${FMILIBFORTEST} )
add_executable (fmi_import_xml_test ${RTTESTDIR}/FMI1/fmi_import_xml_test.c)
@@ -83,6 +86,7 @@ to_native_c_path("${TEST_OUTPUT_FOLDER}/${FMU_DUMMY_CS_MODEL_IDENTIFIER}_cs_tc.f
# set(FMU_TEMPFOLDER ${TEST_OUTPUT_FOLDER}/tempfolder)
to_native_c_path(${TEST_OUTPUT_FOLDER}/tempfolder FMU_TEMPFOLDER)

add_test(ctest_fmi1_xml_parsing_test fmi1_import_default_experiment_test ${RTTESTDIR}/FMI1/parser_test_xmls/default_experiment/)
add_test(ctest_fmi1_xml_parsing_test fmi1_xml_parsing_test ${RTTESTDIR}/FMI1/parser_test_xmls/)
ADD_TEST(ctest_fmi_import_me_test fmi_import_me_test ${FMU_ME_PATH} ${FMU_TEMPFOLDER})
ADD_TEST(ctest_fmi_import_cs_test fmi_import_cs_test ${FMU_CS_PATH} ${FMU_TEMPFOLDER} "modelDescription_cs.xml")
@@ -114,6 +118,7 @@ set_target_properties(
fmi1_capi_me_test
fmi1_logger_test
fmi1_xml_parsing_test
fmi1_import_default_experiment_test
PROPERTIES FOLDER "Test/FMI1")

SET_TESTS_PROPERTIES (
@@ -0,0 +1,112 @@
#include <stdio.h>

#include <fmilib.h>
#include "config_test.h"
#include "fmil_test.h"

static fmi1_import_t *parse_xml(const char *model_desc_path)
{
jm_callbacks *cb = jm_get_default_callbacks();
fmi_import_context_t *ctx = fmi_import_allocate_context(cb);
fmi1_import_t *xml;

if (ctx == NULL) {
return NULL;
}

xml = fmi1_import_parse_xml(ctx, model_desc_path);

fmi_import_free_context(ctx);
return xml;
}

/* get values from DefaultExperiment */
static int test_default_experiment_defined(fmi1_import_t *xml)
{
/* test defined */
ASSERT_MSG(fmi1_import_get_default_experiment_has_start(xml) == 1, "test_undefined, has_start: incorrect");
ASSERT_MSG(fmi1_import_get_default_experiment_has_stop(xml) == 1, "test_undefined, has_stop: incorrect");
ASSERT_MSG(fmi1_import_get_default_experiment_has_tolerance(xml) == 1, "test_undefined, has_tolerance: incorrect");

/* test value */
ASSERT_MSG(fmi1_import_get_default_experiment_start(xml) == 2.3, "test_defined: incorrect startTime");
ASSERT_MSG(fmi1_import_get_default_experiment_stop(xml) == 3.55, "test_defined: incorrect stopTime");
ASSERT_MSG(fmi1_import_get_default_experiment_tolerance(xml) == 1e-6, "test_defined: incorrect tolerance");

return TEST_OK;
}

/* get default values from DefaultExperiment */
static int test_default_experiment_undefined(fmi1_import_t *xml)
{
/* test defined */
ASSERT_MSG(fmi1_import_get_default_experiment_has_start(xml) == 0, "test_undefined, has_start: incorrect");
ASSERT_MSG(fmi1_import_get_default_experiment_has_stop(xml) == 0, "test_undefined, has_stop: incorrect");
ASSERT_MSG(fmi1_import_get_default_experiment_has_tolerance(xml) == 0, "test_undefined, has_tolerance: incorrect");

/* test value */
ASSERT_MSG(fmi1_import_get_default_experiment_start(xml) == 0.0, "test_undefined: incorrect default startTime");
ASSERT_MSG(fmi1_import_get_default_experiment_stop(xml) == 1.0, "test_undefined: incorrect default stopTime");
ASSERT_MSG(fmi1_import_get_default_experiment_tolerance(xml) == 1e-4, "test_undefined: incorrect default tolerance");

return TEST_OK;
}

/* get mix of default and user defined values from DefaultExperiment */
static int test_default_experiment_mixed(fmi1_import_t *xml)
{
/* test defined */
ASSERT_MSG(fmi1_import_get_default_experiment_has_start(xml) == 1, "test_mixed, has_start: incorrect");
ASSERT_MSG(fmi1_import_get_default_experiment_has_stop(xml) == 0, "test_mixed, has_stop: incorrect");
ASSERT_MSG(fmi1_import_get_default_experiment_has_tolerance(xml) == 1, "test_mixed, has_tolerance: incorrect");

/* test value */
ASSERT_MSG(fmi1_import_get_default_experiment_start(xml) == 2.3, "test_mixed: incorrect default startTime");
ASSERT_MSG(fmi1_import_get_default_experiment_stop(xml) == 1.0, "test_mixed: incorrect default stopTime");
ASSERT_MSG(fmi1_import_get_default_experiment_tolerance(xml) == 1e-6, "test_mixed: incorrect default tolerance");

return TEST_OK;
}

int main(int argc, char **argv)
{
#define PATH_BUF_SIZE 1000
char path_buf[PATH_BUF_SIZE]; /* buffer for path to md */
fmi1_import_t *xml;
int ret = 1;
if (argc != 2) {
printf("Usage: %s <path to dir that contains 'defined' and 'undefined' "
"parent dirs of modelDescription files (including trailing file separator "
"(slash or backslash))>\n", argv[0]);
return CTEST_RETURN_FAIL;
}

printf("Running fmi1_import_variable_test\n");

/* test 1 */
xml = parse_xml(strcat(strncpy(path_buf, argv[1], PATH_BUF_SIZE), "defined"));
if (xml == NULL) {
return CTEST_RETURN_FAIL;
}
ret &= test_default_experiment_defined(xml);
fmi1_import_free(xml);

/* test 2 */
xml = parse_xml(strcat(strncpy(path_buf, argv[1], PATH_BUF_SIZE), "undefined"));
if (xml == NULL) {
return CTEST_RETURN_FAIL;
}
ret &= test_default_experiment_undefined(xml);
fmi1_import_free(xml);

/* test 3 */
xml = parse_xml(strcat(strncpy(path_buf, argv[1], PATH_BUF_SIZE), "mixed"));
if (xml == NULL) {
return CTEST_RETURN_FAIL;
}
ret &= test_default_experiment_mixed(xml);
fmi1_import_free(xml);

return ret == 0 ? CTEST_RETURN_FAIL : CTEST_RETURN_SUCCESS;
#undef PATH_BUF_SIZE
}
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<fmiModelDescription
fmiVersion="1.0"
modelName="myModelName"
guid="myGuid"
modelIdentifier="myModelIdentifier"
description="myDescription"
author="myAuthor"
generationTool="myGenerationTool"
generationDateAndTime="2002-05-30T09:00:00"
version="myModelVersion"
variableNamingConvention="structured"
numberOfContinuousStates="0"
numberOfEventIndicators="0">

<DefaultExperiment
startTime="2.3"
stopTime="3.55"
tolerance="1e-6"
/>

<ModelVariables/>

</fmiModelDescription>
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<fmiModelDescription
fmiVersion="1.0"
modelName="myModelName"
guid="myGuid"
modelIdentifier="myModelIdentifier"
description="myDescription"
author="myAuthor"
generationTool="myGenerationTool"
generationDateAndTime="2002-05-30T09:00:00"
version="myModelVersion"
variableNamingConvention="structured"
numberOfContinuousStates="0"
numberOfEventIndicators="0">

<DefaultExperiment
startTime="2.3"
tolerance="1e-6"
/>

<ModelVariables/>

</fmiModelDescription>
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<fmiModelDescription
fmiVersion="1.0"
modelName="myModelName"
guid="myGuid"
modelIdentifier="myModelIdentifier"
description="myDescription"
author="myAuthor"
generationTool="myGenerationTool"
generationDateAndTime="2002-05-30T09:00:00"
version="myModelVersion"
variableNamingConvention="structured"
numberOfContinuousStates="0"
numberOfEventIndicators="0">

<DefaultExperiment/>

<ModelVariables/>

</fmiModelDescription>
@@ -169,13 +169,31 @@ FMILIB_EXPORT unsigned int fmi1_import_get_number_of_continuous_states(fmi1_impo
/** \brief Get the number of event indicators. */
FMILIB_EXPORT unsigned int fmi1_import_get_number_of_event_indicators(fmi1_import_t* fmu);

/** \brief Get the start time for default experiment as specified in the XML file. */
/** \brief Get if the start time for default experiment is specified in the XML file. */
FMILIB_EXPORT int fmi1_import_get_default_experiment_has_start(fmi1_import_t* fmu);

/** \brief Get if the stop time for default experiment is specified in the XML file. */
FMILIB_EXPORT int fmi1_import_get_default_experiment_has_stop(fmi1_import_t* fmu);

/** \brief Get if the tolerance for default experiment is specified in the XML file. */
FMILIB_EXPORT int fmi1_import_get_default_experiment_has_tolerance(fmi1_import_t* fmu);

/** \brief Get the start time for default experiment as specified in the XML file.
If it is not specified, a default value of 0.0 is returned.
To determine if it is specified, use the following function: #fmi1_import_get_default_experiment_has_start
*/
FMILIB_EXPORT double fmi1_import_get_default_experiment_start(fmi1_import_t* fmu);

/** \brief Get the stop time for default experiment as specified in the XML file. */
/** \brief Get the stop time for default experiment as specified in the XML file.
If it is not specified, a default value of 1.0 is returned.
To determine if it is specified, use the following function: #fmi1_import_get_default_experiment_has_stop
*/
FMILIB_EXPORT double fmi1_import_get_default_experiment_stop(fmi1_import_t* fmu);

/** \brief Get the tolerance default experiment as specified in the XML file. */
/** \brief Get the tolerance for default experiment as specified in the XML file.
If it is not specified, a default value of 1e-4 is returned.
To determine if it is specified, use the following function: #fmi1_import_get_default_experiment_has_tolerance
*/
FMILIB_EXPORT double fmi1_import_get_default_experiment_tolerance(fmi1_import_t* fmu);

/** \brief Get the type of the FMU (model exchange or co-simulation) */
@@ -225,6 +225,33 @@ unsigned int fmi1_import_get_number_of_event_indicators(fmi1_import_t* fmu) {
return fmi1_xml_get_number_of_event_indicators(fmu->md);
}

int fmi1_import_get_default_experiment_has_start(fmi1_import_t* fmu) {
if(!fmu->md) {
jm_log_error(fmu->callbacks, module,"No FMU is loaded");
return 0;
}

return fmi1_xml_get_default_experiment_has_start(fmu->md);
}

int fmi1_import_get_default_experiment_has_stop(fmi1_import_t* fmu) {
if(!fmu->md) {
jm_log_error(fmu->callbacks, module,"No FMU is loaded");
return 0;
}

return fmi1_xml_get_default_experiment_has_stop(fmu->md);
}

int fmi1_import_get_default_experiment_has_tolerance(fmi1_import_t* fmu) {
if(!fmu->md) {
jm_log_error(fmu->callbacks, module,"No FMU is loaded");
return 0;
}

return fmi1_xml_get_default_experiment_has_tolerance(fmu->md);
}

double fmi1_import_get_default_experiment_start(fmi1_import_t* fmu) {
if(!fmu->md) {
jm_log_error(fmu->callbacks, module,"No FMU is loaded");
@@ -187,16 +187,16 @@ unsigned int fmi1_xml_get_number_of_continuous_states(fmi1_xml_model_description

unsigned int fmi1_xml_get_number_of_event_indicators(fmi1_xml_model_description_t* md);

double fmi1_xml_get_default_experiment_start(fmi1_xml_model_description_t* md);

void fmi1_xml_set_default_experiment_start(fmi1_xml_model_description_t* md, double);
int fmi1_xml_get_default_experiment_has_start(fmi1_xml_model_description_t* md);
int fmi1_xml_get_default_experiment_has_stop(fmi1_xml_model_description_t* md);
int fmi1_xml_get_default_experiment_has_tolerance(fmi1_xml_model_description_t* md);

double fmi1_xml_get_default_experiment_start(fmi1_xml_model_description_t* md);
double fmi1_xml_get_default_experiment_stop(fmi1_xml_model_description_t* md);

void fmi1_xml_set_default_experiment_stop(fmi1_xml_model_description_t* md, double);

double fmi1_xml_get_default_experiment_tolerance(fmi1_xml_model_description_t* md);

void fmi1_xml_set_default_experiment_start(fmi1_xml_model_description_t* md, double);
void fmi1_xml_set_default_experiment_stop(fmi1_xml_model_description_t* md, double);
void fmi1_xml_set_default_experiment_tolerance(fmi1_xml_model_description_t* md, double);

fmi1_fmu_kind_enu_t fmi1_xml_get_fmu_kind(fmi1_xml_model_description_t* md);

0 comments on commit 9c34331

Please sign in to comment.
You can’t perform that action at this time.