Changeset 13549


Ignore:
Timestamp:
Sep 19, 2019 5:05:20 PM (3 months ago)
Author:
Christian Andersson
Message:

Added more tests for the evaluator. Related to ticket:5837

Location:
branches/dev-cw-evaluator/Python/src/tests_jmodelica
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-cw-evaluator/Python/src/tests_jmodelica/files/Modelica/ExtFunctionTests.mo

    r13482 r13549  
    11package ExtFunctionTests
     2
     3model Evaluator_Double
     4    function d_i
     5     input Integer a;
     6     output Real b;
     7
     8     external "C" b=f_d_i(a) annotation(Library="evaluatorTestsShared",
     9                             Include="#include \"evaluatorTests.h\"");
     10    end d_i;
     11   
     12    function d_idd
     13     input Integer a;
     14     input Real b;
     15     input Real c;
     16     output Real d;
     17
     18     external "C" d=f_d_idd(a,b,c) annotation(Library="evaluatorTestsShared",
     19                             Include="#include \"evaluatorTests.h\"");
     20    end d_idd;
     21   
     22   
     23    Real c = d_i(1);
     24    Real d = d_idd(1, 2.0, 3.0);
     25end Evaluator_Double;
     26
     27model Evaluator_Integer
     28    function i_ii
     29     input Integer a;
     30     input Integer b;
     31     output Integer c;
     32
     33     external "C" c=f_i_ii(a,b) annotation(Library="evaluatorTestsShared",
     34                             Include="#include \"evaluatorTests.h\"");
     35    end i_ii;
     36   
     37    Integer c = i_ii(1,2);
     38end Evaluator_Integer;
     39
     40model Evaluator_Record
     41    record R
     42        Real x0;
     43        Real x1;
     44        Real x2;
     45        Real x3;
     46        Real x4;
     47        Real x5;
     48        Real x6;
     49        Real x7;
     50        Real x8;
     51        Real x9;
     52        Real x10;
     53    end R;
     54    function iddpR_ddddddddddd_
     55     input Integer a;
     56     input Real b;
     57     input Real c;
     58     output R d;
     59
     60     external "C" f___iddpR_ddddddddddd_(a,b,c,d) annotation(Library="evaluatorTestsShared",
     61                             Include="#include \"evaluatorTests.h\"");
     62    end iddpR_ddddddddddd_;
     63   
     64    R c = iddpR_ddddddddddd_(1,2.0,3.0);
     65end Evaluator_Record;
     66
    267
    368model Evaluator_Substring
  • branches/dev-cw-evaluator/Python/src/tests_jmodelica/files/Modelica/Resources/CMakeLists.txt

    r13465 r13549  
    3838include_directories(${TOP_SRC}/RuntimeLibrary/src/jmi)
    3939
     40set(EVALUATORTESTS_Sources
     41    src/evaluatorTests.c
     42    Include/evaluatorTests.h
     43)
     44
    4045set(ADDNUMBERS_Sources
    4146    src/addNumbers.c
     
    6873        src/externalFunctionsFortran.f
    6974    )
     75endif()
     76
     77#Build evaluatorTests library
     78add_library(evaluatorTestsShared SHARED ${EVALUATORTESTS_Sources})
     79if(NOT MSVC)
     80    set_target_properties(evaluatorTestsShared PROPERTIES COMPILE_FLAGS "-Wall -g -std=c89 -pedantic -Werror -O2")
    7081endif()
    7182
     
    108119
    109120#Install the libraries
     121install(TARGETS evaluatorTestsShared DESTINATION "${TEST_LIBRARY_INSTALL_DIR}")
    110122install(TARGETS addNumbers DESTINATION "${TEST_LIBRARY_INSTALL_DIR}")
    111123install(TARGETS addNumbersShared DESTINATION "${TEST_LIBRARY_INSTALL_DIR}")
  • branches/dev-cw-evaluator/Python/src/tests_jmodelica/general/test_extfunctions.py

    r13542 r13549  
    105105        assert matches == 1, "Seems to have found an unknown shared library"
    106106   
     107    @testattr(stddist_base = True)
     108    def test_double_return(self):
     109        cpath = "ExtFunctionTests.Evaluator_Double"
     110        fmu_name = compile_fmu(cpath, self.fpath, compiler_options={"external_constant_dynamic_evaluator":True}, compiler_log_level="d:log.txt")
     111       
     112        nbr_of_evaluator_calls = 0
     113        with open("log.txt") as f:
     114            res = fnmatch.filter(f, "Succesfully connected external function '*' to the evaluator*")
     115            nbr_of_evaluator_calls = len(res)
     116       
     117        assert nbr_of_evaluator_calls == 2, "Wrong number of external function calls, check log."
     118       
     119        model = load_fmu(fmu_name)
     120       
     121        assert model.get("c") == 3.0, model.get("c")
     122        assert model.get("d") == 9.0, model.get("d")
     123   
     124    @testattr(stddist_base = True)
     125    def test_integer_return(self):
     126        cpath = "ExtFunctionTests.Evaluator_Integer"
     127        fmu_name = compile_fmu(cpath, self.fpath, compiler_options={"external_constant_dynamic_evaluator":True}, compiler_log_level="d:log.txt")
     128       
     129        nbr_of_evaluator_calls = 0
     130        with open("log.txt") as f:
     131            res = fnmatch.filter(f, "Succesfully connected external function '*' to the evaluator*")
     132            nbr_of_evaluator_calls = len(res)
     133       
     134        assert nbr_of_evaluator_calls == 1, "Wrong number of external function calls, check log."
     135       
     136        model = load_fmu(fmu_name)
     137       
     138        assert model.get("c") == 3.0, model.get("c")
     139   
     140    @testattr(stddist_base = True)
     141    def test_record(self):
     142        cpath = "ExtFunctionTests.Evaluator_Record"
     143        fmu_name = compile_fmu(cpath, self.fpath, compiler_options={"external_constant_dynamic_evaluator":True}, compiler_log_level="d:log.txt")
     144       
     145        nbr_of_evaluator_calls = 0
     146        with open("log.txt") as f:
     147            res = fnmatch.filter(f, "Succesfully connected external function '*' to the evaluator*")
     148            nbr_of_evaluator_calls = len(res)
     149       
     150        assert nbr_of_evaluator_calls == 1, "Wrong number of external function calls, check log."
     151       
     152        model = load_fmu(fmu_name)
     153       
     154        assert model.get("c.x0") == 1.0, model.get("c.x0")
     155        assert model.get("c.x1") == 2.0, model.get("c.x1")
     156        assert model.get("c.x2") == 3.0, model.get("c.x2")
     157        assert model.get("c.x3") == 3.0, model.get("c.x3")
     158        assert model.get("c.x4") == 4.0, model.get("c.x4")
     159        assert model.get("c.x5") == 5.0, model.get("c.x5")
     160        assert model.get("c.x6") == 6.0, model.get("c.x6")
     161        assert model.get("c.x7") == 7.0, model.get("c.x7")
     162        assert model.get("c.x8") == 8.0, model.get("c.x8")
     163        assert model.get("c.x9") == 9.0, model.get("c.x9")
     164        assert model.get("c.x10") == 10.0, model.get("c.x10")
     165   
    107166class TestExternalStatic:
    108167
Note: See TracChangeset for help on using the changeset viewer.