|
| 1 | +#= |
| 2 | +This file is part of OpenModelica. |
| 3 | +Copyright (c) 1998-2023, Open Source Modelica Consortium (OSMC), |
| 4 | +c/o Linköpings universitet, Department of Computer and Information Science, |
| 5 | +SE-58183 Linköping, Sweden. |
| 6 | +
|
| 7 | +All rights reserved. |
| 8 | +
|
| 9 | +THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE |
| 10 | +GPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. |
| 11 | +ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES |
| 12 | +RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, |
| 13 | +ACCORDING TO RECIPIENTS CHOICE. |
| 14 | +
|
| 15 | +The OpenModelica software and the OSMC (Open Source Modelica Consortium) |
| 16 | +Public License (OSMC-PL) are obtained from OSMC, either from the above |
| 17 | +address, from the URLs: http://www.openmodelica.org or |
| 18 | +http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica |
| 19 | +distribution. GNU version 3 is obtained from: |
| 20 | +http://www.gnu.org/copyleft/gpl.html. The New BSD License is obtained from: |
| 21 | +http://www.opensource.org/licenses/BSD-3-Clause. |
| 22 | +
|
| 23 | +This program is distributed WITHOUT ANY WARRANTY; without even the implied |
| 24 | +warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS |
| 25 | +EXPRESSLY SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE |
| 26 | +CONDITIONS OF OSMC-PL. |
| 27 | +=# |
| 28 | + |
| 29 | +using Test |
| 30 | + |
| 31 | +""" |
| 32 | +Run single test process. |
| 33 | +
|
| 34 | +Start a new Julia process. |
| 35 | +Kill process and throw an error when timeout is reached. |
| 36 | +Catch InterruptException, kill process and rethorw InterruptException. |
| 37 | +
|
| 38 | +# Arguments |
| 39 | + - `library`: Modelica library name. |
| 40 | + - `version`: Library version. |
| 41 | + - `model`: Modelica model from library to test. |
| 42 | + - `testdir`: Test working directory. |
| 43 | +
|
| 44 | +# Keywords |
| 45 | + - `timeout=10*60::Integer`: Timeout in seconds. Defaults to 10 minutes. |
| 46 | +""" |
| 47 | +function singleTest(library, version, model, testdir; |
| 48 | + timeout=10*60::Integer) |
| 49 | + |
| 50 | + mkpath(testdir) |
| 51 | + logFile = joinpath(testdir, "runSingleTest.log") |
| 52 | + rm(logFile, force=true) |
| 53 | + |
| 54 | + @info "Testing $model" |
| 55 | + |
| 56 | + cmd = Cmd(`$(joinpath(Sys.BINDIR, "julia")) runSingleTest.jl $(library) $(version) $(model) $(testdir)`, dir=@__DIR__) |
| 57 | + @info cmd |
| 58 | + plp = pipeline(cmd, stdout=logFile, stderr=logFile) |
| 59 | + process = run(plp, wait=false) |
| 60 | + |
| 61 | + try |
| 62 | + timer = Timer(0; interval=1) |
| 63 | + for _ in 1:timeout |
| 64 | + wait(timer) |
| 65 | + if !process_running(process) |
| 66 | + close(timer) |
| 67 | + break |
| 68 | + end |
| 69 | + end |
| 70 | + if process_running(process) |
| 71 | + @error "Killing $(process)" |
| 72 | + kill(process) |
| 73 | + end |
| 74 | + catch e |
| 75 | + if isa(e, InterruptException) && process_running(p) |
| 76 | + @error "Killing process $(cmd)." |
| 77 | + kill(p) |
| 78 | + end |
| 79 | + rethrow(e) |
| 80 | + end |
| 81 | + |
| 82 | + println(read(logFile, String)) |
| 83 | + |
| 84 | + status = (process.exitcode == 0) && |
| 85 | + isfile(joinpath(testdir, "$(model).fmu")) && |
| 86 | + isfile(joinpath(testdir, "FMI_results.csv")) |
| 87 | + |
| 88 | + return status |
| 89 | +end |
| 90 | + |
| 91 | +""" |
| 92 | +Run all tests. |
| 93 | +
|
| 94 | +# Arguments |
| 95 | + - `libraries::Vector{Tuple{S,S}}`: Vector of tuples with library and version to test. |
| 96 | + - `models::Vector{Vector{S}}`: Vector of vectors with models to test for each library. |
| 97 | +
|
| 98 | +# Keywords |
| 99 | + - `workdir`: Root working directory. |
| 100 | +""" |
| 101 | +function runTests(libraries::Vector{Tuple{S,S}}, |
| 102 | + models::Vector{Vector{S}}; |
| 103 | + workdir=abspath(joinpath(@__DIR__, "temp"))) where S<:AbstractString |
| 104 | + |
| 105 | + rm(workdir, recursive=true, force=true) # This can break on Windows when some program or file is still open |
| 106 | + mkpath(workdir) |
| 107 | + |
| 108 | + @testset "OpenModelica" begin |
| 109 | + for (i, (library, version)) in enumerate(libraries) |
| 110 | + @testset verbose=true "$library" begin |
| 111 | + libdir = joinpath(workdir, library) |
| 112 | + mkpath(libdir) |
| 113 | + |
| 114 | + for model in models[i] |
| 115 | + modeldir = joinpath(libdir, model) |
| 116 | + @testset "$model" begin |
| 117 | + @test singleTest(library, version, model, modeldir) |
| 118 | + end |
| 119 | + end |
| 120 | + end |
| 121 | + end |
| 122 | + end |
| 123 | + |
| 124 | + return |
| 125 | +end |
| 126 | + |
| 127 | +libraries = [ |
| 128 | + ("Modelica", "4.0.0") |
| 129 | +] |
| 130 | + |
| 131 | +models = [ |
| 132 | + [ |
| 133 | + "Modelica.Blocks.Examples.Filter", |
| 134 | + "Modelica.Electrical.Analog.Examples.CauerLowPassAnalog", |
| 135 | + "Modelica.Blocks.Examples.RealNetwork1", |
| 136 | + "Modelica.Electrical.Digital.Examples.FlipFlop", |
| 137 | + "Modelica.Mechanics.Rotational.Examples.FirstGrounded", |
| 138 | + "Modelica.Mechanics.Rotational.Examples.CoupledClutches", |
| 139 | + "Modelica.Mechanics.MultiBody.Examples.Elementary.DoublePendulum", |
| 140 | + "Modelica.Mechanics.MultiBody.Examples.Elementary.FreeBody", |
| 141 | + "Modelica.Fluid.Examples.TraceSubstances.RoomCO2WithControls", |
| 142 | + "Modelica.Clocked.Examples.SimpleControlledDrive.ClockedWithDiscreteTextbookController", |
| 143 | + "Modelica.Fluid.Examples.PumpingSystem" |
| 144 | + ] |
| 145 | +] |
0 commit comments