Changeset 13465


Ignore:
Timestamp:
Sep 13, 2019 9:57:55 AM (3 months ago)
Author:
Christian Andersson
Message:

Added a test for the evaluator. Related to ticket:5837

Location:
branches/dev-cw-evaluator
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-cw-evaluator/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/evaluation/ExternalProcessCacheImpl.java

    r13460 r13465  
    7171                    if (tmp.exists() && !tmp.isDirectory()) {
    7272                        sharedLib = tmp.toString();
     73                    } else {
     74                        File tmpWithLib = new File(libLoc, "lib"+lib.concat(SystemUtil.sharedLibraryExtension()));
     75                        if (tmpWithLib.exists() && !tmpWithLib.isDirectory()) {
     76                            sharedLib = tmpWithLib.toString();
     77                        }
    7378                    }
    7479                }
     
    110115        String outputArguments = getOutputArguments(ext);
    111116        String inputArguments  = getInputArguments(ext);
    112        
    113117       
    114118        if (sharedLibrary.equals("")) {
  • branches/dev-cw-evaluator/Python/src/tests_jmodelica/files/Modelica/ExtFunctionTests.mo

    r13440 r13465  
    11package ExtFunctionTests
    22
    3 model Substring
     3model Evaluator_Substring
    44    constant String full="Yy00";
    55    constant String sub=Modelica.Utilities.Strings.substring(full,1,1);
     
    88    constant Integer len = Modelica.Utilities.Strings.length(string1);
    99    constant Integer start = Modelica.Utilities.Strings.Advanced.skipWhiteSpace("   Hello", 1);
    10 end Substring;
     10end Evaluator_Substring;
     11
     12model Evaluator_Add
     13 function add1
     14     input Real a;
     15     input Real b;
     16     output Real c;
     17
     18     external "C" c=add(a,b) annotation(Library="addNumbersShared",
     19                             Include="#include \"addNumbers.h\"");
     20 end add1;
     21 
     22 function add2
     23     input Real a;
     24     input Real b;
     25     output Real c;
     26
     27     external "C" add_output(a,b,c) annotation(Library="addNumbersShared",
     28                             Include="#include \"addNumbers.h\"");
     29 end add2;
     30
     31 constant Real a = 1;
     32 constant Real b = 2;
     33 Real c = add1(a,b);
     34 Real d = add2(a,b);
     35end Evaluator_Add;
    1136
    1237model ExtFunctionTest1
  • branches/dev-cw-evaluator/Python/src/tests_jmodelica/files/Modelica/Resources/CMakeLists.txt

    r10171 r13465  
    7272#Build addNumbers library
    7373add_library(addNumbers STATIC ${ADDNUMBERS_Sources})
     74add_library(addNumbersShared SHARED ${ADDNUMBERS_Sources})
    7475if(NOT MSVC)
    7576    set_target_properties(addNumbers PROPERTIES COMPILE_FLAGS "-Wall -g -std=c89 -pedantic -Werror -O2")
     77    set_target_properties(addNumbersShared PROPERTIES COMPILE_FLAGS "-Wall -g -std=c89 -pedantic -Werror -O2")
    7678endif()
    7779
     
    107109#Install the libraries
    108110install(TARGETS addNumbers DESTINATION "${TEST_LIBRARY_INSTALL_DIR}")
     111install(TARGETS addNumbersShared DESTINATION "${TEST_LIBRARY_INSTALL_DIR}")
    109112install(TARGETS arrayFunctions DESTINATION "${TEST_LIBRARY_INSTALL_DIR}")
    110113install(TARGETS externalFunctionsC DESTINATION "${TEST_LIBRARY_INSTALL_DIR}")
  • branches/dev-cw-evaluator/Python/src/tests_jmodelica/files/Modelica/Resources/Include/addNumbers.h

    r3965 r13465  
    33
    44double add(double a, double b);
     5void add_output(double a, double b, double *c);
    56void multiplyAnArray(int* inputs, int* outputs, int size, int m);
    67
  • branches/dev-cw-evaluator/Python/src/tests_jmodelica/files/Modelica/Resources/src/addNumbers.c

    r6459 r13465  
    33double add(double a, double b)
    44{
    5   return a+b;
     5  return a + b;
     6}
     7
     8void add_output(double a, double b, double *c)
     9{
     10  *c = a + b;
    611}
    712
  • branches/dev-cw-evaluator/Python/src/tests_jmodelica/general/test_extfunctions.py

    r13446 r13465  
    2222
    2323import nose
     24import fnmatch
    2425
    2526from pymodelica import compile_fmu
     
    4344    @testattr(stddist_base = True)
    4445    def test_builtin_substring(self):
    45         """
    46         Test compiling a model with external functions in a static library.
    47         """
    48         cpath = "ExtFunctionTests.Substring"
    49         fmu_name = compile_fmu(cpath, self.fpath, compiler_options={"enable_external_evaluator":True})
    50         model = load_fmu(fmu_name)
    51        
    52         assert model.get("sub")[0] == "Y"
    53         assert model.get("string2")[0] == "line"
    54         assert model.get("len") == 16
    55         assert model.get("start") == 4
    56 
     46        cpath = "ExtFunctionTests.Evaluator_Substring"
     47        fmu_name = compile_fmu(cpath, self.fpath, compiler_options={"enable_external_evaluator":True}, compiler_log_level="d:log.txt")
     48       
     49        nbr_of_evaluator_calls = 0
     50        with open("log.txt") as f:
     51            res = fnmatch.filter(f, "Succesfully connected external function '*' to the evaluator*")
     52            nbr_of_evaluator_calls = len(res)
     53       
     54        assert nbr_of_evaluator_calls == 3, "Wrong number of external function calls, check log."
     55       
     56        model = load_fmu(fmu_name)
     57       
     58        assert model.get("sub")[0] == "Y", model.get("sub")
     59        assert model.get("string2")[0] == "line", model.get("string2")
     60        assert model.get("len") == 16, model.get("len")
     61        assert model.get("start") == 4, model.get("start")
     62   
     63    @testattr(stddist_base = True)
     64    def test_add(self):
     65        cpath = "ExtFunctionTests.Evaluator_Add"
     66        fmu_name = compile_fmu(cpath, self.fpath, compiler_options={"enable_external_evaluator":True}, compiler_log_level="d:log.txt")
     67       
     68        nbr_of_evaluator_calls = 0
     69        with open("log.txt") as f:
     70            res = fnmatch.filter(f, "Succesfully connected external function '*' to the evaluator*")
     71            nbr_of_evaluator_calls = len(res)
     72       
     73        assert nbr_of_evaluator_calls == 2, "Wrong number of external function calls, check log."
     74       
     75        model = load_fmu(fmu_name)
     76       
     77        assert model.get("c") == 3, model.get("c")
     78        assert model.get("d") == 3, model.get("d")
     79   
    5780class TestExternalStatic:
    5881
  • branches/dev-cw-evaluator/RuntimeLibrary/src/evaluator/jmi_evaluator.c

    r13440 r13465  
    187187typedef int (__stdcall *f_i_si)(const char*, int);
    188188typedef void(__stdcall *f___iddpR_ddddddddddd_)(int, double, double, R_ddddddddddd**);
     189typedef void(__stdcall *f___ddpd)(double, double, double*);
    189190typedef void (*generic_funcptr)(void);
     191
     192void jmi_call_void_fcn_ddpd(generic_funcptr fcn) {
     193    JMI_DEF(REA, arg_0)
     194    JMI_DEF(REA, arg_1)
     195    JMI_DEF(REA, arg_2)
     196
     197    JMCEVAL_parse(Real, arg_0);
     198    JMCEVAL_parse(Real, arg_1);
     199    JMCEVAL_parse(Real, arg_2);
     200   
     201    JMCEVAL_check("CALC");
     202    if (JMCEVAL_try()) {
     203        /* Calc phase */
     204        ((f___ddpd)fcn)(arg_0, arg_1, &arg_2);
     205
     206        JMCEVAL_check("DONE");
     207        JMCEVAL_print(Real, arg_2);
     208    }
     209    else {
     210        JMCEVAL_failed();
     211    }
     212}
    190213
    191214void jmi_call_void_fcn_iddpR_ddddddddddd_(generic_funcptr fcn) {
     
    400423    if (strcmp(inputs, "i,d,d,*R[d,d,d,d,d,d,d,d,d,d,d,],") == 0) {
    401424        jmi_call_void_fcn_iddpR_ddddddddddd_(fcn);
     425    } else if (strcmp(inputs, "d,d,*d,") == 0) {
     426        jmi_call_void_fcn_ddpd(fcn);
    402427    } else {
    403428        printf(ERROR_NOT_SUPPORTED_INPUT_ARGS_MSG);
Note: See TracChangeset for help on using the changeset viewer.