diff --git a/Project.toml b/Project.toml index 69a4db9d..ba2f2577 100644 --- a/Project.toml +++ b/Project.toml @@ -16,6 +16,7 @@ Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" ADTypes = "1" Aqua = "0.8" ChainRulesCore = "1.24" +JET = "0.9" ControlSystemsBase = "1.4" DataFrames = "1.7" DataInterpolations = "8" @@ -40,6 +41,7 @@ julia = "1.10" ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e" +JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" DataInterpolations = "82cc6244-b520-54b8-b5a6-8a565e85f1d0" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" @@ -54,4 +56,4 @@ SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["ADTypes", "Aqua", "LinearAlgebra", "OrdinaryDiffEqDefault", "OrdinaryDiffEq", "SafeTestsets", "Test", "ControlSystemsBase", "DataFrames", "DataInterpolations", "SciMLStructures", "SymbolicIndexingInterface", "ForwardDiff", "SciCompDSL", "ModelingToolkit"] +test = ["ADTypes", "Aqua", "JET", "LinearAlgebra", "OrdinaryDiffEqDefault", "OrdinaryDiffEq", "SafeTestsets", "Test", "ControlSystemsBase", "DataFrames", "DataInterpolations", "SciMLStructures", "SymbolicIndexingInterface", "ForwardDiff", "SciCompDSL", "ModelingToolkit"] diff --git a/test/jet.jl b/test/jet.jl new file mode 100644 index 00000000..408a5107 --- /dev/null +++ b/test/jet.jl @@ -0,0 +1,80 @@ +using ModelingToolkitStandardLibrary, JET, Test + +# JET.jl static analysis tests for ModelingToolkitStandardLibrary +# +# Note: This package heavily uses ModelingToolkit's @component and @connector macros +# which generate code at macro expansion time. Full package analysis with JET times out. +# Instead, we focus on testing specific utility functions that are not macro-generated. + +@testset "JET static analysis" begin + # Test that the package loads without JET-detectable issues + # We use a targeted approach since full package analysis is not feasible + # for metaprogramming-heavy packages like this one. + + @testset "Module loading" begin + # Verify modules can be accessed (basic sanity check) + @test isdefined(ModelingToolkitStandardLibrary, :Blocks) + @test isdefined(ModelingToolkitStandardLibrary, :Electrical) + @test isdefined(ModelingToolkitStandardLibrary, :Mechanical) + @test isdefined(ModelingToolkitStandardLibrary, :Thermal) + @test isdefined(ModelingToolkitStandardLibrary, :Magnetic) + @test isdefined(ModelingToolkitStandardLibrary, :Hydraulic) + end + + @testset "Utility functions - Hydraulic" begin + # Test hydraulic utility functions for type stability + # These are pure numerical functions that don't use metaprogramming + + # regPow function - regularized power + regPow = ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible.regPow + @test_opt target_modules = (ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible,) regPow( + 1.0, 0.5, 0.01 + ) + + # transition function - smooth transition between values + transition = ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible.transition + @test_opt target_modules = (ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible,) transition( + 0.0, 1.0, 0.0, 1.0, 0.5 + ) + + # friction_factor function - calculates friction factor for pipe flow + friction_factor = ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible.friction_factor + @test_opt target_modules = (ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible,) friction_factor( + 1.0, 0.01, 0.1, 0.001, 64.0 + ) + end + + @testset "Utility functions - Blocks sources" begin + # Test smooth functions used in source blocks + # These are pure numerical functions for generating smooth waveforms + + Blocks = ModelingToolkitStandardLibrary.Blocks + + # smooth_step - smooth step function + @test_opt target_modules = (Blocks,) Blocks.smooth_step(1.0, 0.01, 1.0, 0.0, 0.0) + + # smooth_xH - smooth ramp helper + @test_opt target_modules = (Blocks,) Blocks.smooth_xH(1.0, 0.01, 0.0) + + # square - square wave + @test_opt target_modules = (Blocks,) Blocks.square(1.0, 1.0, 1.0, 0.0, 0.0) + + # triangular - triangular wave + @test_opt target_modules = (Blocks,) Blocks.triangular(1.0, 1.0, 1.0, 0.0, 0.0) + end + + @testset "Digital logic - Electrical" begin + # Test digital logic table operations + E = ModelingToolkitStandardLibrary.Electrical + + # Logic enum operations + @test E.F0 isa E.Logic + @test E.F1 isa E.Logic + + # Test logic operations type stability + @test_opt target_modules = (E,) E._and2(E.F0, E.F1) + @test_opt target_modules = (E,) E._or2(E.F0, E.F1) + @test_opt target_modules = (E,) E._not(E.F0) + @test_opt target_modules = (E,) E._xor2(E.F0, E.F1) + end +end diff --git a/test/runtests.jl b/test/runtests.jl index c65f7b27..5e26b85b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,6 +7,9 @@ const GROUP = get(ENV, "GROUP", "All") @time @safetestset "Aqua" begin include("aqua.jl") end + @time @safetestset "JET" begin + include("jet.jl") + end end if GROUP == "Core" || GROUP == "All"