21 #include "config_test.h" 35 void fmilogger(fmi1_component_t
c, fmi1_string_t instanceName,
fmi1_status_t status, fmi1_string_t category, fmi1_string_t message, ...)
39 va_start(argp, message);
47 printf(
"Press 'Enter' to exit\n");
59 const char* name =
"INTEGER";
60 printf(
"Testing ScalarVariable %s\n", name);
66 printf(
"Test of XML file \"%s\" failed. min attribute value missmatch.\n", xmlFileName);
72 printf(
"Test of XML file \"%s\" failed. max attribute value missmatch.\n", xmlFileName);
79 const char* name =
"INTEGER_DECLAREDTYPE";
80 printf(
"Testing ScalarVariable %s\n", name);
86 printf(
"Test of XML file \"%s\" failed. min attribute value missmatch.\n", xmlFileName);
92 printf(
"Test of XML file \"%s\" failed. max attribute value missmatch.\n", xmlFileName);
99 const char* name =
"INTEGER_DECLAREDTYPE_OVERWRITE";
100 printf(
"Testing ScalarVariable %s\n", name);
106 printf(
"Test of XML file \"%s\" failed. min attribute value missmatch.\n", xmlFileName);
112 printf(
"Test of XML file \"%s\" failed. max attribute value missmatch.\n", xmlFileName);
119 const char* name =
"ENUMERATION_DECLAREDTYPE";
120 printf(
"Testing ScalarVariable %s\n", name);
126 printf(
"Test of XML file \"%s\" failed. min attribute value missmatch.\n", xmlFileName);
132 printf(
"Test of XML file \"%s\" failed. max attribute value missmatch.\n", xmlFileName);
139 const char* name =
"ENUMERATION_DECLAREDTYPE_OVERWRITE";
140 printf(
"Testing ScalarVariable %s\n", name);
146 printf(
"Test of XML file \"%s\" failed. min attribute value missmatch.\n", xmlFileName);
152 printf(
"Test of XML file \"%s\" failed. max attribute value missmatch.\n", xmlFileName);
166 {
"modelDescription_cs.xml", 0, NULL}
174 for (k = 0; k <
sizeof(
xml_test_files)/
sizeof(*xml_test_files); k++) {
175 foundxml = strcmp(xmlFileName, xml_test_files[k].filename) == 0 ? 1 : 0;
177 if (xml_test_files[k].performTest) {
178 xml_test_files[k].
fcn(xmlFileName, fmu);
185 printf(
"XML file test is not properly implemented in " __FILE__
" . Could not find the XML \"%s\" in the list of expected XML-files", xmlFileName);
196 fmi1_string_t instanceName =
"Test CS model instance";
197 fmi1_string_t fmuGUID;
198 fmi1_string_t fmuLocation =
"";
199 fmi1_string_t mimeType =
"";
200 fmi1_real_t timeout = 0.0;
206 fmi1_real_t simulation_results[] = {0.0143633, -1.62417};
207 fmi1_value_reference_t compare_real_variables_vr[] = {0, 1};
210 fmi1_real_t tstart = 0.0;
211 fmi1_real_t tcur = tstart;
212 fmi1_real_t hstep = 0.1;
213 fmi1_real_t tend = 2.0;
216 if (
sizeof(compare_real_variables_vr)/
sizeof(fmi1_value_reference_t) !=
sizeof(simulation_results)/
sizeof(fmi1_real_t)) {
217 printf(
"Number of simulation values and reference values are different\n");
225 printf(
"GUID: %s\n", fmuGUID);
230 printf(
"fmi1_import_instantiate_model failed\n");
236 printf(
"fmi1_import_initialize_slave failed\n");
241 printf(
"%10s %10s\n",
"Ball height",
"Ball speed");
242 while (tcur < tend) {
246 fmi1_value_reference_t vr = 0;
249 printf(
"rvalue = %f\n", rvalue);
253 for (k = 0; k <
sizeof(compare_real_variables_vr)/
sizeof(fmi1_value_reference_t); k++) {
254 fmi1_value_reference_t vr = compare_real_variables_vr[k];
261 printf(
"%10g %10g\n", val[0],val[1]);
267 printf(
"Simulation finished. Checking results\n");
270 for (k = 0; k <
sizeof(compare_real_variables_vr)/
sizeof(fmi1_value_reference_t); k++) {
271 fmi1_value_reference_t vr = compare_real_variables_vr[k];
275 res = rvalue - simulation_results[k];
276 res = res > 0 ? res: -res;
278 printf(
"Simulation results is wrong!\n");
279 printf(
"State [%u] %g != %g, |res| = %g\n", (
unsigned)k, rvalue, simulation_results[k], res);
292 int main(
int argc,
char *argv[])
297 const char* xmlFileName;
307 printf(
"Usage: %s <fmu_file> <temporary_dir> <modelDescription_file>\n", argv[0]);
310 for (k = 0; k < argc; k ++)
311 printf(
"argv[%d] = %s\n", k, argv[k]);
315 xmlFileName = argv[3];
317 callbacks.
malloc = malloc;
318 callbacks.
calloc = calloc;
320 callbacks.
free = free;
329 #ifdef FMILIB_GENERATE_BUILD_STAMP 330 printf(
"Library build stamp:\n%s\n", fmilib_get_build_stamp());
338 printf(
"Only version 1.0 is supported so far\n");
345 printf(
"Error parsing XML, exiting\n");
364 printf(
"Everything seems to be OK since you got this far=)!\n");
FMILIB_EXPORT const char * fmi1_import_get_GUID(fmi1_import_t *fmu)
Get FMU GUID.
FMILIB_EXPORT fmi1_import_integer_variable_t * fmi1_import_get_variable_as_integer(fmi1_import_variable_t *)
Cast general variable to a one with the specific type.
FMILIB_EXPORT int fmi1_import_get_enum_variable_min(fmi1_import_enum_variable_t *v)
Get minimal value for the variable.
jm_calloc_f calloc
Allocate zero initialized memory.
void fmilogger(fmi1_component_t c, fmi1_string_t instanceName, fmi1_status_t status, fmi1_string_t category, fmi1_string_t message,...)
FMILIB_EXPORT int fmi1_import_get_enum_variable_max(fmi1_import_enum_variable_t *v)
Get max value for the variable.
FMILIB_EXPORT void fmi1_log_forwarding_v(fmi1_component_t c, fmi1_string_t instanceName, fmi1_status_t status, fmi1_string_t category, fmi1_string_t message, va_list args)
An implementation of FMI 1.0 logger that forwards the messages to logger function inside jm_callbacks...
fmi_version_enu_t
Suported versions of FMI standard.
fmi1_callback_logger_ft logger
FMILIB_EXPORT int fmi1_import_get_integer_variable_min(fmi1_import_integer_variable_t *v)
Get minimal value for the variable.
FMILIB_EXPORT const char * jm_log_level_to_string(jm_log_level_enu_t level)
Convert log level into a string.
void importlogger(jm_callbacks *c, jm_string module, jm_log_level_enu_t log_level, jm_string message)
FMILIB_EXPORT fmi1_import_enum_variable_t * fmi1_import_get_variable_as_enum(fmi1_import_variable_t *)
Cast general variable to a one with the specific type.
FMILIB_EXPORT jm_status_enu_t fmi1_import_instantiate_slave(fmi1_import_t *fmu, fmi1_string_t instanceName, fmi1_string_t fmuLocation, fmi1_string_t mimeType, fmi1_real_t timeout, fmi1_boolean_t visible, fmi1_boolean_t interactive)
Wrapper for the FMI function fmiInstantiateSlave(...)
jm_log_level_enu_t
Log levels supported via the logger functions in jm_callbacks.
struct fmi1_xml_integer_variable_t fmi1_import_integer_variable_t
Opaque integer variable.
fmi1_callback_allocate_memory_ft allocateMemory
FMILIB_EXPORT void fmi1_log_forwarding(fmi1_component_t c, fmi1_string_t instanceName, fmi1_status_t status, fmi1_string_t category, fmi1_string_t message,...)
An implementation of FMI 1.0 logger that forwards the messages to logger function inside jm_callbacks...
struct fmi1_xml_variable_t fmi1_import_variable_t
General variable type.
FMILIB_EXPORT void fmi1_import_destroy_dllfmu(fmi1_import_t *fmu)
Free a C-API struct. All memory allocated since the struct was created is freed.
jm_log_level_enu_t log_level
Logging level.
void test_xml_modelDescription_cs_tc(const char *xmlFileName, fmi1_import_t *fmu)
int test_simulate_cs(fmi1_import_t *fmu)
FMILIB_EXPORT jm_status_enu_t fmi1_import_create_dllfmu(fmi1_import_t *fmu, fmi1_callback_functions_t callBackFunctions, int registerGlobally)
Create a C-API struct. The C-API struct is a placeholder for the FMI DLL functions.
void test_xml(const char *xmlFileName, fmi1_import_t *fmu)
FMILIB_EXPORT void fmi1_import_free_slave_instance(fmi1_import_t *fmu)
Wrapper for the FMI function fmiFreeSlaveInstance(...)
FMILIB_EXPORT fmi1_import_t * fmi1_import_parse_xml(fmi_import_context_t *c, const char *dirName)
Parse FMI 1.0 XML file found in the directory dirName.
Include file to be used in client applications of the FMI Library.
jm_malloc_f malloc
Allocate non-initialized memory.
jm_voidp context
Arbitrary context pointer passed to the logger function.
const char * jm_string
A constant string.
xml_test_files_t xml_test_files[]
FMILIB_EXPORT const char * fmi1_import_get_last_error(fmi1_import_t *fmu)
Retrieve the last error message.
FMILIB_EXPORT fmi1_status_t fmi1_import_initialize_slave(fmi1_import_t *fmu, fmi1_real_t tStart, fmi1_boolean_t StopTimeDefined, fmi1_real_t tStop)
Wrapper for the FMI function fmiInitializeSlave(...)
The callbacks struct is sent to all the modules in the library.
struct fmi_xml_context_t fmi_import_context_t
FMI version independent library context. Opaque struct returned from fmi_import_allocate_context() ...
FMILIB_EXPORT const char * fmi1_import_get_version(fmi1_import_t *fmu)
Wrapper for the FMI function fmiGetVersion()
FMILIB_EXPORT fmi_import_context_t * fmi_import_allocate_context(jm_callbacks *callbacks)
Create fmi_import_context_t structure.
fmi1_callback_free_memory_ft freeMemory
void(* fcn)(const char *xmlFileName, fmi1_import_t *fmu)
FMILIB_EXPORT fmi1_status_t fmi1_import_get_real(fmi1_import_t *fmu, const fmi1_value_reference_t vr[], size_t nvr, fmi1_real_t value[])
Wrapper for the FMI function fmiGetReal(...)
struct fmi1_import_t fmi1_import_t
FMU version 1.0 object.
FMILIB_EXPORT const char * fmi1_import_get_types_platform(fmi1_import_t *fmu)
Wrapper for the FMI function fmiGetTypesPlatform(...)
FMILIB_EXPORT fmi_version_enu_t fmi_import_get_fmi_version(fmi_import_context_t *c, const char *fileName, const char *dirName)
Unzip an FMU specified by the fileName into directory dirName and parse XML to get FMI standard versi...
int main(int argc, char *argv[])
FMILIB_EXPORT fmi1_import_variable_t * fmi1_import_get_variable_by_name(fmi1_import_t *fmu, const char *name)
Get variable by variable name.
FMILIB_EXPORT void fmi_import_free_context(fmi_import_context_t *c)
Free memory allocated for the library context.
FMILIB_EXPORT fmi1_status_t fmi1_import_terminate_slave(fmi1_import_t *fmu)
Wrapper for the FMI function fmiTerminateSlave(...)
jm_realloc_f realloc
Re-allocate memory.
struct fmi1_xml_enum_variable_t fmi1_import_enum_variable_t
Opaque enumeration variable.
jm_status_enu_t
Return status codes.
FMILIB_EXPORT void fmi1_import_free(fmi1_import_t *fmu)
Release the memory allocated.
jm_free_f free
Free-allocated memory.
jm_logger_f logger
Logging callback.
FMILIB_EXPORT fmi1_status_t fmi1_import_do_step(fmi1_import_t *fmu, fmi1_real_t currentCommunicationPoint, fmi1_real_t communicationStepSize, fmi1_boolean_t newStep)
Wrapper for the FMI function fmiDoStep(...)
FMILIB_EXPORT int fmi1_import_get_integer_variable_max(fmi1_import_integer_variable_t *v)
Get max value for the variable.