diff --git a/cross_checks/Project.toml b/cross_checks/Project.toml index 2d080b64..d1355218 100644 --- a/cross_checks/Project.toml +++ b/cross_checks/Project.toml @@ -2,6 +2,7 @@ ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63" Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" +Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa" FMI = "14a09403-18e3-468f-ad8a-74f8dda2d9ac" diff --git a/cross_checks/README.md b/cross_checks/README.md index 2ed67d91..7299bc0a 100644 --- a/cross_checks/README.md +++ b/cross_checks/README.md @@ -54,6 +54,7 @@ optional arguments: hasn't been executed (e.g. officially not compliant FMUs if they are not skipped) --commitfailed Also commit the result file for failed FMUs + --plotfailed Plot result for failed FMUs (e.g. debugging) -h, --help show this help message and exit ``` diff --git a/cross_checks/cross_check.jl b/cross_checks/cross_check.jl index 8c77d130..3202145c 100644 --- a/cross_checks/cross_check.jl +++ b/cross_checks/cross_check.jl @@ -14,6 +14,7 @@ using DelimitedFiles using Tables using Statistics using DifferentialEquations +using Plots, Colors import Base64 @@ -66,6 +67,9 @@ function parse_commandline() "--commitfailed" help = "Also commit the result file for failed FMUs" action = :store_true + "--plotfailed" + help = "Plot result for failed FMUs" + action = :store_true end println("Arguments used for cross check:") @@ -75,18 +79,19 @@ function parse_commandline() return parse_args(s) end -function runCrossCheckFmu( +function runCrossCheckFMU( checkPath::String, resultPath::String, check::FmuCrossCheck, skipnotcompliant::Bool, commitrejected::Bool, commitfailed::Bool, + plotfailed::Bool )::FmuCrossCheck pathToFMU = joinpath(checkPath, "$(check.fmuCheck).fmu") fmuToCheck = nothing - try + #try if !(check.notCompliant && skipnotcompliant) fmuToCheck = loadFMU(pathToFMU) info(fmuToCheck) @@ -200,11 +205,34 @@ function runCrossCheckFmu( if commitfailed mkpath(resultPath) cd(resultPath) + rm("passed", force = true) rm("rejected", force = true) rm("README.md", force = true) touch("failed") end + if plotfailed + mkpath(resultPath) + cd(resultPath) + + names = keys(GfmuRefValues) + num = length(names)-1 + colors = distinguishable_colors(num, [RGB(1,1,1), RGB(0,0,0)]) + + fig = plot() + for j in 1:num + ts = GfmuRefValues[1] + vals = GfmuRefValues[1+j] + plot!(fig, ts, vals; style=:solid, color=colors[j], label="$(names[j])") + + ts = GsimData.values.t + vals = collect(u[j] for u in GsimData.values.saveval) + plot!(fig, ts, vals; style=:dash, color=colors[j], label=:none) + end + display(fig) + @assert false + end + end else check.skipped = true @@ -218,28 +246,28 @@ function runCrossCheckFmu( end end check.error = nothing - catch e - @warn e - check.result = nothing - check.skipped = false - io = IOBuffer() - showerror(io, e) - check.error = String(take!(io)) - check.success = false - mkpath(resultPath) - cd(resultPath) - rm("rejected", force = true) - rm("passed", force = true) - rm("README.md", force = true) - if commitfailed - touch("failed") - end - finally - try - unloadFMU(fmuToCheck) - catch - end - end + # catch e + # @warn e + # check.result = nothing + # check.skipped = false + # io = IOBuffer() + # showerror(io, e) + # check.error = String(take!(io)) + # check.success = false + # mkpath(resultPath) + # cd(resultPath) + # rm("rejected", force = true) + # rm("passed", force = true) + # rm("README.md", force = true) + # if commitfailed + # touch("failed") + # end + # finally + # try + # unloadFMU(fmuToCheck) + # catch + # end + # end return check end @@ -261,6 +289,7 @@ function main() skipnotcompliant = haskey(ENV, "crosscheck_skipnotcompliant") ? true : parsed_args["skipnotcompliant"] commitrejected = parsed_args["commitrejected"] commitfailed = parsed_args["commitfailed"] + plotfailed = haskey(ENV, "crosscheck_plotfailed") ? true : parsed_args["plotfailed"] # checking of inputs if fmiVersion != "2.0" @@ -307,7 +336,7 @@ function main() end # Excecute FMUs - crossChecks = getFmusToTest(fmiCrossCheckRepoPath, fmiVersion, os) + crossChecks = getFMUsToTest(fmiCrossCheckRepoPath, fmiVersion, os) if !includeFatals crossChecks = filter(c -> (!(c.system in EXCLUDED_SYSTEMS)), crossChecks) end @@ -338,13 +367,14 @@ function main() cd(checkPath) println("Checking $check for $checkPath and expecting $resultPath") - check = runCrossCheckFmu( + check = runCrossCheckFMU( checkPath, resultPath, check, skipnotcompliant, commitrejected, commitfailed, + plotfailed, ) crossChecks[index] = check end diff --git a/cross_checks/cross_check_lib.jl b/cross_checks/cross_check_lib.jl index b5d3e162..186e8bd4 100644 --- a/cross_checks/cross_check_lib.jl +++ b/cross_checks/cross_check_lib.jl @@ -42,7 +42,7 @@ Returns a array of all available FMI Cross Checks - `fmiVersion::String`: FMI Version used for running the FMUs. Note: Currently only 2.0 officially supported - `os::String`: The operating system that is used for running the FMUs """ -function getFmusToTest( +function getFMUsToTest( repoPath::String, fmiVersion::String, os::String,