diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ce751d3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,65 @@ +name: CI + +on: + push: + branches: + - main + paths-ignore: + - 'LICENSE.md' + - 'README.md' + - 'docs/**' + pull_request: + paths-ignore: + - 'LICENSE.md' + - 'README.md' + - 'docs/**' + workflow_dispatch: + inputs: + debug_enabled: + description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' + required: false + default: "false" + +jobs: + test: + name: ${{ matrix.os }} - Julia ${{ matrix.julia_version }} - ${{ github.event_name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - windows-latest + - macos-latest + arch: + - x64 + julia_version: + - '1.10' + - '1.11' + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Enable Julia cache + uses: julia-actions/cache@v2 + + - name: Install Julia + uses: julia-actions/setup-julia@v2 + with: + version: ${{ matrix.julia_version }} + arch: ${{ matrix.arch }} + show-versioninfo: true + + - name: Run Julia tests + uses: julia-actions/julia-runtest@v1 + with: + coverage: false + env: + CATALYST_DEBUG: 1 + + # Enable tmate debugging of manually-triggered workflows if the input option was provided + - name: Setup tmate session for debugging + if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled && always() }} + uses: mxschmitt/action-tmate@v3 + timeout-minutes: 15 diff --git a/src/conduit.jl b/src/conduit.jl index be990b5..d5214b5 100644 --- a/src/conduit.jl +++ b/src/conduit.jl @@ -9,6 +9,10 @@ struct ConduitNode nptr = API.conduit_node_create() return new(nptr) end + + function ConduitNode(ptr::Ptr{API.conduit_node}) + return new(ptr) + end end Base.unsafe_convert(::Type{Ptr{API.conduit_node}}, node::ConduitNode) = node.ptr @@ -23,11 +27,24 @@ function ConduitNode(f::Function) end Base.setindex!(node::ConduitNode, val, path::String) = node_set!(node, path, val) +Base.getindex(node::ConduitNode, path::String) = node_get(node, path) + +function node_get(node::ConduitNode, path::String) + if !node_has_path(node, path) + throw(KeyError(path)) + end + node_at_path = API.conduit_node_fetch(node, path) + dtype = API.conduit_node_dtype(node_at_path) + dtypename = Symbol(unsafe_string(API.conduit_datatype_name(dtype))) + return node_get(node_at_path, Val(dtypename)) +end for numtype in (:UInt8, :Int8, :UInt16, :Int16, :UInt32, :Int32, :UInt64, :Int64, :Float32, :Float64) cnumtype = Symbol(lowercase("$(numtype)")) node_set_path = Symbol("conduit_node_set_path_$(cnumtype)") node_set_path_ptr = Symbol("conduit_node_set_path_$(cnumtype)_ptr") + node_as = Symbol("conduit_node_as_$(cnumtype)") + node_as_ptr = Symbol("conduit_node_as_$(cnumtype)_ptr") @eval begin function node_set!(node::ConduitNode, path::String, val::$numtype) API.$node_set_path(node, path, val) @@ -37,6 +54,12 @@ for numtype in (:UInt8, :Int8, :UInt16, :Int16, :UInt32, :Int32, :UInt64, :Int64 API.$node_set_path_ptr(node, path, pointer(val), length(val)) return node end + function node_get(nodeptr::Ptr{API.conduit_node}, ::$(Val{cnumtype})) + return API.$node_as(nodeptr) + end + function node_get(nodeptr::Ptr{API.conduit_node}, ::$(Val{Array{cnumtype}})) + return API.$node_as_ptr(nodeptr) + end end end @@ -50,6 +73,14 @@ function node_set!(node::ConduitNode, path::String, val::ConduitNode) return node end +function node_get(nodeptr::Ptr{API.conduit_node}, ::Val{:object}) + return ConduitNode(nodeptr) +end + +function node_get(nodeptr::Ptr{API.conduit_node}, ::Val{:char8_str}) + return unsafe_string(API.conduit_node_as_char8_str(nodeptr)) +end + function node_has_path(node::ConduitNode, path::String) return Bool(API.conduit_node_has_path(node, path)) end diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 0000000..0c36332 --- /dev/null +++ b/test/Project.toml @@ -0,0 +1,2 @@ +[deps] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/runtests.jl b/test/runtests.jl new file mode 100644 index 0000000..1ebf72b --- /dev/null +++ b/test/runtests.jl @@ -0,0 +1,5 @@ +using Test + +@time @testset verbose=true showtiming=true "ParaViewCatalyst.jl tests" begin + include("test_catalyst_jll.jl") +end diff --git a/test/test_catalyst_jll.jl b/test/test_catalyst_jll.jl new file mode 100644 index 0000000..f5ddd2f --- /dev/null +++ b/test/test_catalyst_jll.jl @@ -0,0 +1,24 @@ +module TestCatalyst_jll + +using Test +using ParaViewCatalyst +using ParaViewCatalyst.API + +# Manually override the usual initialization and +# - do not provide search paths +# - request the stub implementation +# This test should then pick up the catalyst library shipped with Catalyst_jll +@testset verbose=true showtiming=true "Check stub" begin + ConduitNode() do node + node["catalyst_load/implementation"] = "stub" + catalyst_initialize(node) + end + ConduitNode() do node + status = API.catalyst_about(node) + @test status === API.catalyst_status_ok + @test node["catalyst/implementation"] == "stub" + Conduit.node_print(node, detailed=false) + end + catalyst_finalize() +end +end