21 #include "config_test.h" 30 const char* loadingstr =
"Loading '";
33 (strcmp(module,
"FMILIB") == 0) &&
34 (strncmp(message,
"Loading '", strlen(loadingstr)) == 0)
37 jm_snprintf(buf, 10000,
"[INFO][FMILIB] Loading '-----' binary with '------' platform types\n");
58 printf(
"fmi1_import_instantiate_model failed\n");
64 fmi1_value_reference_t* vr;
68 "###### Reals ######",
70 "OK HIGHT_SPEED = #r1#",
72 "OK BOUNCE_COF = #r3#",
76 "Bad reference #r100#",
77 "###### Integers ######",
78 "OK LOGGER_TEST_INTEGER = #i0#",
82 "Bad reference #i100#",
83 "###### Booleans ######",
84 "OK LOGGER_TEST_BOOLEAN = #b0#",
88 "Bad reference #b100#",
89 "###### Strings ######",
90 "OK LOGGER_TEST = #s0#",
94 "Bad reference #s100#" 97 n =
sizeof(str)/
sizeof(*str);
98 vr = calloc(n,
sizeof(fmi1_value_reference_t));
99 for (k = 0; k < n; k++) {
110 #define MESSAGE_SIZE_TO_EXPAND_AND_PRINT 3000 111 #if JM_MAX_ERROR_MESSAGE_SIZE + 200 > MESSAGE_SIZE_TO_EXPAND_AND_PRINT 112 #error This test triggers the logger function to allocate more memory than the default size JM_MAX_ERROR_MESSAGE_SIZE. If you change JM_MAX_ERROR_MESSAGE_SIZE, please update this test. 117 str[0] = (
const char*)&longmessage;
121 char repmsg[] =
"#r0# ";
122 for (k = 0; k <
sizeof(longmessage)/
sizeof(*longmessage) - 1; k++) {
123 longmessage[k] = repmsg[k%(
sizeof(repmsg)/
sizeof(*repmsg) - 1)];
125 longmessage[k] =
'\0';
142 int main(
int argc,
char *argv[])
151 int register_active_fmu;
156 printf(
"Usage: %s <fmu_file> <temporary_dir> <output_file>\n", argv[0]);
164 logFile = fopen(outfile,
"wb");
167 printf(
"Could not open output file %s\n", outfile);
171 callbacks.
malloc = malloc;
172 callbacks.
calloc = calloc;
174 callbacks.
free = free;
183 #ifdef FMILIB_GENERATE_BUILD_STAMP 184 printf(
"Library build stamp:\n%s\n", fmilib_get_build_stamp());
192 printf(
"Only version 1.0 is supported so far\n");
199 printf(
"Error parsing XML, exiting\n");
203 register_active_fmu = 1;
206 printf(
"Could not create the DLL loading mechanism(C-API test).\n");
FMILIB_EXPORT jm_status_enu_t fmi1_import_instantiate_model(fmi1_import_t *fmu, fmi1_string_t instanceName)
Wrapper for the FMI function fmiInstantiateModel(...)
jm_calloc_f calloc
Allocate zero initialized memory.
FMILIB_EXPORT int jm_snprintf(char *str, size_t size, const char *fmt,...)
C89 compatible implementation of C99 snprintf.
int test_logger(fmi1_import_t *fmu)
fmi_version_enu_t
Suported versions of FMI standard.
fmi1_callback_logger_ft logger
FMILIB_EXPORT const char * jm_log_level_to_string(jm_log_level_enu_t level)
Convert log level into a string.
#define MESSAGE_SIZE_TO_EXPAND_AND_PRINT
jm_log_level_enu_t
Log levels supported via the logger functions in jm_callbacks.
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...
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.
#define VAR_S_LOGGER_TEST
int main(int argc, char *argv[])
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.
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.
FMILIB_EXPORT fmi1_status_t fmi1_import_set_string(fmi1_import_t *fmu, const fmi1_value_reference_t vr[], size_t nvr, const fmi1_string_t value[])
Wrapper for the FMI function fmiSetString(...)
jm_voidp context
Arbitrary context pointer passed to the logger function.
const char * jm_string
A constant string.
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 fmi_import_context_t * fmi_import_allocate_context(jm_callbacks *callbacks)
Create fmi_import_context_t structure.
fmi1_callback_free_memory_ft freeMemory
struct fmi1_import_t fmi1_import_t
FMU version 1.0 object.
void logger(jm_callbacks *c, jm_string module, jm_log_level_enu_t log_level, jm_string message)
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...
FMILIB_EXPORT void fmi_import_free_context(fmi_import_context_t *c)
Free memory allocated for the library context.
jm_realloc_f realloc
Re-allocate memory.
jm_status_enu_t
Return status codes.
FMILIB_EXPORT void fmi1_import_free(fmi1_import_t *fmu)
Release the memory allocated.
FMILIB_EXPORT void fmi1_import_free_model_instance(fmi1_import_t *fmu)
Wrapper for the FMI function fmiFreeModelInstance(...)
jm_free_f free
Free-allocated memory.
jm_logger_f logger
Logging callback.